Three.js旋转移动Object3D中的对象,以始终面对相机 [英] Three.js Rotate objects inside of moving Object3D to always face the camera

查看:5224
本文介绍了Three.js旋转移动Object3D中的对象,以始终面对相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点陌生,Threejs只是想知道如何使移动网格总是面对相机在一个场景。我有一个容器Object3D内有100个网格,并在x和y轴上旋转此容器。有没有办法强制网格内的容器总是面对相机?

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?

这里是一些示例代码,我还设置了一个jsFiddle在 http://jsfiddle.net/nickelWeb/rZtJX/4/

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 );   
}



我尝试过使用.lookAt似乎工作。我知道有一种方法来做到这一点,我只是不知道在哪里看。任何帮助将不胜感激。谢谢!

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!

推荐答案

Object.lookAt()

您的问题的最简单的解决方法是保持父对象的固定,然后围绕对象旋转摄像机。

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

这样, Object.lookAt()将按预期工作。

更新小提琴: http://jsfiddle.net/rZtJX/5/

three.js r.57

three.js r.57

这篇关于Three.js旋转移动Object3D中的对象,以始终面对相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆