我已经添加了精灵位置公式,并且效果很好。但是当我旋转对象时,文本随相机旋转(远离对象)。我想固定文本的位置,当我旋转对象时,它应该与对象一起旋转(离对象不远)。谁能帮我吗?我的代码段如下。
如果(intersects.length> 0){
if ( INTERSECTED != intersects[ 0 ].object ) {
if ( INTERSECTED && INTERSECTED.material.emissive != null ){
INTERSECTED.material.emissive.setHex( INTERSECTED.currentHex );
}
INTERSECTED = intersects[0].object;
if ( INTERSECTED && INTERSECTED.material.emissive != null ){
sprite1.scale.set(maxSize/2,maxSize/2,1);
//sprite position formula
sprite1.position.set( intersects[0].point.x+(maxSize/2), intersects[0].point.y, intersects[0].point.z );
var bb = new THREE.Box3().setFromObject(INTERSECTED);
INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
INTERSECTED.material.emissive.setHex( 0xff000 );
context1.clearRect(0,0,640,480);
var message = value;
var metrics = context1.measureText(message);
var width = metrics.width;
context1.fillStyle = "rgba(0,0,0,0.95)"; // black border
context1.fillRect( 0,0, width+8,20+8);
context1.fillStyle = "rgba(255,255,255,0.95)"; // white filler
context1.fillRect( 2,2, width+4,20+4 );
context1.fillStyle = "rgba(0,0,0,1)"; // text color
context1.fillText( message, 4,20 );
texture1.needsUpdate = true;
});
}
} }