三.js 围绕 Y 轴旋转 Object3d [英] three.js rotate Object3d around Y axis at it center

查看:40
本文介绍了三.js 围绕 Y 轴旋转 Object3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Three.JS 中有一个 Object3d,它是一组 Mesh 对象.
我想围绕 Y 轴旋转这个组,在它的中心,远离世界中心 (0,0,0).
我只知道 Group.rotate.y += deg 代码,但对于每个轴方向,它始终围绕 (0,0,0) 旋转对象,而不是我的组中心!
我怎样才能解决这个问题?

I have an Object3d in Three.JS that is a group of some Mesh objects.
I want to rotate this group around the Y axis, at it center, that is far from world center (0,0,0).
I just know the Group.rotate.y += deg code, but for each axis direction it always rotate the object around (0,0,0), not my group center!
How can i fix this?

阅读评论

推荐答案

看看 Object3D 的 rotateOnAxis(axis, angle) 函数.它应该是这样的:

Have a look at Object3D's rotateOnAxis(axis, angle) function. It should be something like:

//declared once at the top of your code
var axis = new THREE.Vector3(0.5,0.5,0);//tilted a bit on x and y - feel free to plug your different axis here
//in your update/draw function
rad += radIncrement;
object.rotateOnAxis(axis,rad);

HTH

这篇关于三.js 围绕 Y 轴旋转 Object3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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