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

查看:75
本文介绍了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?

这是一些示例代码,我还在 http://jsfiddle 设置了一个 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() 如果对象有一个旋转的父对象,将无法正常工作.

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.

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

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

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

three.js r.57

three.js r.57

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

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