Three.js使使用Three.ShapeGeometry创建的文本面向相机

Three.js使使用Three.ShapeGeometry创建的文本面向相机,three.js,Three.js,我用文本创建了一个形状测量。如何在移动摄影机时使文本面向摄影机 ... this.textGeometry = new THREE.ShapeGeometry(THREE.FontUtils.generateShapes(value, parameters)); this.textValue = new THREE.Mesh(this.textGeometry, new THREE.MeshBasicMaterial({ color: color, side: THREE.DoubleSide

我用文本创建了一个形状测量。如何在移动摄影机时使文本面向摄影机

...

this.textGeometry = new THREE.ShapeGeometry(THREE.FontUtils.generateShapes(value, parameters));
this.textValue = new THREE.Mesh(this.textGeometry, new THREE.MeshBasicMaterial({ color: color, side: THREE.DoubleSide }));
this.textValue.matrixAutoUpdate = true;
this.add(this.textValue)

...
我想我的问题是我修改了父四元数3D对象:

this.quaternion.setFromAxisAngle (axis, radians); 
那么唯一的操作是:

textValue.quaternion.copy (camera.quaternion); 
这还不够


考虑到四元数的状态,如何修正旋转?

我认为这应该可以解决问题:

this.textValue.lookAt( camera.position );

如果您不关心调用基updateMatrix函数, 这可能是一个解决方案

yourShapeGeometry.prototype.updateMatrix = function(){
 // THREE.Object3D.prototype.updateMatrix.call(this);
 fixOrientation(this.textValue); 
}

function fixOrientation(mesh){
  mesh.setRotationFromQuaternion(camera.quaternion);
  mesh.updateMatrix();
}
或者只需编辑文本网格的updateMatrix,如

textMesh.updateMatrixWorld = updateSpriteWorld;
function updateSpriteWorld(){

        if ( this.matrixWorldNeedsUpdate === true || force === true ) {

                this.setRotationFromQuaternion(camera.quaternion);
                this.updateMatrix();
                this.matrixWorld.copy( this.matrix );
                this.matrixWorldNeedsUpdate = false;

                force = true;
        }

        // update children

        for ( var i = 0, l = this.children.length; i < l; i ++ ) {

            this.children[ i ].updateSpriteWorld( force );

        }
}
textMesh.updateMatrixWorld=updateScriteWorld;
函数updateScriteWorld(){
if(this.matrixWorldNeedsUpdate==true | | force==true){
此.setRotationfrom四元数(camera.quaternion);
this.updateMatrix();
this.matrixWorld.copy(this.matrix);
this.matrixWorldNeedsUpdate=false;
力=真;
}
//更新子项
for(var i=0,l=this.children.length;i
这篇文章对你没有帮助?没有,因为我有一个shapegeometry
textValue.quaternion.copy(camera.quaternion)
textValue的父对象应该是场景,或者至少是一个未旋转的对象。好的,我认为我的问题是父对象本身就是一个旋转的对象,根据您的解决方案,文本会旋转,但这是不正确的。如何纠正旋转?唯一的解决方案是满足我提到的家长要求。
lookAt()
不支持带有旋转和/或平移家长的对象,这显然是OP的情况。此外,在进行类似精灵的相机对齐时,这实际上不会使其平行?你需要看的是属于一个平面的最近点,与远处和附近的摄像机平行,而不是摄像机?@pailhead这是一个近似值。透视投影会引起一些变形,但如果一个平面平行于投影平面,这是一回事,如果它有一个角度,那又是另一回事?