我在Object3d
有一个Three.JS
,它是一组Mesh物体。
我想围绕Y轴旋转这个组,在它的中心,远离世界中心(0,0,0)。
我只知道Group.rotate.y += deg
代码,但对于每个轴方向,它总是围绕(0,0,0)旋转对象,而不是我的组中心!
我怎样才能解决这个问题?
阅读评论
看看Object3D的rotateOnAxis(axis, angle)
函数。它应该是这样的:
//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
This answer帮助了我,但代码不太正确。轴必须是单位矢量,object.rotateOnAxis()
是增量的。
这是一个工作示例:
var axis = new THREE.Vector3(4, 0, 7).normalize();
var speed = 0.01;
// set up scene, etc.
function animate () {
// other code
if (object) {
object.rotateOnAxis(axis, speed);
}
}
见How to rotate a 3D object on axis three.js?
我这样解决了这个问题:
我为ThreeJS创建了'ObjectControls'模块,允许您旋转单个OBJECT(或组),而不是SCENE。
包括图书馆:
用法:
var controls = new THREE.ObjectControls(camera,renderer.domElement,yourMesh);
你可以在这里找到现场演示:https://albertopiras.github.io/threeJS-object-controls/
这是回购:https://github.com/albertopiras/threeJS-object-controls。