long story short, I'm making a live line chart and I'm using three.js due to the high number of lines per second that needs to be pushed inside this thing, so, now I'd need to draw the text values for the x and y axis, after a pretty long struggle ( because I'm a total noob @ threejs ) I figured out the wonderful technique of using the canvas as a sprite ( which is darn rad ).(长话短说,我正在制作一个实时折线图,并且由于每秒需要插入大量线,因此我正在使用three.js,因此,现在我需要绘制文本值对于x轴和y轴,经过了很长时间的奋斗(因为我是一个总的noob @ threejs),我才想到了使用画布作为sprite(darn rad)的绝妙技术。)
This is the code that I use(这是我使用的代码)
/// 2D REALM
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
metrics = null,
textHeight = 100,
textWidth = 0,
actualFontSize = 2;
context.fillStyle = '#FF0000';
var size = 250;
canvas.width = size;
canvas.height = size;
function addText(position, text) {
context.textAlign = 'center';
context.font = '24px Arial';
context.fillText("Game Over", size/2, size/2);
var texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
var material = new THREE.SpriteMaterial( { map: texture, color: 0x333333, fog: false } );
var sprite = new THREE.Sprite( material );
sprite.position.set(0,100,0);
return sprite;
}
. . .
$(document).ready(function() {
h = $(window).height() - $('.speed-graph').outerHeight() - $('.speed-toolbar').outerHeight() - $('.channel-toolbar').outerHeight() - $('.status_bar').outerHeight() + 1;
w = $(window).width() - $('.palette').outerWidth();
camera = new THREE.PerspectiveCamera( 75, parseFloat(w) / parseFloat(h), 0.1, 5000 );
//renderer.setSize( window.innerWidth, window.innerHeight );
console.log("w: " + w + " | h: " + h);
renderer.setSize(w, h);
$('body').append( renderer.domElement );
var material = new THREE.LineBasicMaterial({ color: 0x000000, linewidth: 1 });
var geometry = new THREE.Geometry();
geometry.vertices.push( new THREE.Vector3(-10 , 0, 0 ) );
geometry.vertices.push( new THREE.Vector3(8 , 0, 0 ) );
lines['line'].push( new THREE.Line( geometry, material ))
text = addText(new Array(0, 9), "lorem ipsum");
//lines['label'].push( addText(new Array(0, 9), "0") );
scene.add( lines['line'][0] );
scene.add( text );
camera.position.z = 5;
render();
});
now, the lines get drawn as they should, but I had no luck at all with the text.(现在,线条已经按需绘制,但是我对文字完全没有运气。)
I can't understand the reason why I can't see the text, because I don't get any compiler error.(我不明白为什么看不到文本的原因,因为我没有得到任何编译器错误。)
ask by holographix translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…