Three.js Rotate objects inside of moving Object3D to always face the camera

做~自己de王妃 提交于 2019-12-18 09:42:17

问题


I'm somewhat new to Threejs was just wondering how to make moving mesh always face the camera in a scene. I have 100 meshes inside of a container Object3D, and am rotating this container on the x and y axis. Is there any way to force the meshes inside of the container to always face the camera?

Here is some sample code, I've also set up a jsFiddle at http://jsfiddle.net/nickelWeb/rZtJX/4/

for(var k = 0; k<numMeshes; k++){
     meshes[k].lookAt( camera.position );   
}

I have tried just using the .lookAt() method but it doesn't seem to be working. I know there has to a way to do this i'm just not sure where to look. Any help would be appreciated. Thanks!


回答1:


Object.lookAt() will not work correctly if the object has a parent that is rotated.

The absolute easiest solution to your problem is to hold the parent object fixed and rotate the camera around the object instead.

That way, Object.lookAt() will work as expected.

Updated fiddle: http://jsfiddle.net/rZtJX/5/

three.js r.57



来源:https://stackoverflow.com/questions/15603111/three-js-rotate-objects-inside-of-moving-object3d-to-always-face-the-camera

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