本文介绍了three.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
这篇关于three.js在其中心围绕Y轴旋转Object3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!