Point surface of mesh towards another object

假装没事ソ 提交于 2019-12-24 07:20:56

问题


As a continuation to: Point one object to face a distant object

I'm trying to get a mesh's surface to point to another object. I want a far away object to point to a close object, whenever the far object moves.

Here is a sample of what is happening: http://jsfiddle.net/UsVUv/

1) I create 2 mesh objects. 2) Since the far mesh is facing up, I rotate it so that it can be seen from the camera. -> farMesh.rotation = new THREE.Vector3(Math.PI/2, 0, 0); 3) When the far mesh is moved, I call the following to get it to keep looking at the near mesh. The face of the far mesh does not look at the near mesh, but the edge of its plane does. -> farMesh.lookAt(nearMesh.position); 4) I then try to rotate the mesh back so it faces the camera again, but that removes the rotation that the lookAt did. -> farMesh.rotation = new THREE.Vector3(Math.PI/2, 0, 0);

You can comment out the lines 1), 2), and 3) in the sample to see what is happening.


回答1:


Yes, the farMesh.lookAt() and farMesh.rotation are competing with each other.

What you need to do, instead, is rotate the farMesh plane geometry as soon as it is created with applyMatrix() like so:

    farMesh.geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );

So to summarize, applyMatrix() transforms the object's geometry, and lookAt() sets the object's rotation vector.

Here is an updated Fiddle: http://jsfiddle.net/UsVUv/1/



来源:https://stackoverflow.com/questions/11508357/point-surface-of-mesh-towards-another-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!