Bry*_*ger 5 rotation three.js translate-animation
我创建了一组立方体,我正在尝试弄清楚如何设置中心以便我可以旋转它们。
这是小提琴:https : //jsfiddle.net/of1vfhzz/
我在这里添加立方体:
side1 = new THREE.Object3D();
addCube({ name: 'side1topleft', x: -8.5, y: 7.5, z: 5 });
addCube({ name: 'side1topmiddle', x: -4, y: 7.5, z: 5 });
addCube({ name: 'side1topright', x: .5, y: 7.5, z: 5 });
addCube({ name: 'side1middleleft', x: -8.5, y: 3, z: 5 });
addCube({ name: 'side1middlemiddle', x: -4, y: 3, z: 5 });
addCube({ name: 'side1middleright', x: .5, y: 3, z: 5 });
addCube({ name: 'side1bottomleft', x: -8.5, y: -1.5, z: 5 });
addCube({ name: 'side1bottommiddle', x: -4, y: -1.5, z: 5 });
addCube({ name: 'side1bottomright', x: .5, y: -1.5, z: 5 });
scene.add(side1);
function addCube(data) {
var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
cube.position.x = data.x
cube.position.y = data.y
cube.position.z = data.z
cube.rotation.set(0, 0, 0);
cube.name = data.name;
side1.add(cube);
}
Run Code Online (Sandbox Code Playgroud)
然后在渲染场景中我围绕 y 轴旋转它,但我需要设置中心。我试过了translate,但我不明白。
Wes*_*ley 11
您希望网格体组围绕组中心旋转。
一种选择是平移网格几何形状,以便作为一个集合,它们以本地原点为中心。
如果您不想这样做,那么您可以创建一个祖父母对象pivot,然后旋转它。
在您的情况下,side1是您的子网格物体的父级。所以使用这个模式:
var pivot = new THREE.Group();
scene.add( pivot );
pivot.add( side1 );
side1.position.set( 4, - 3, - 5 ); // the negative of the group's center
Run Code Online (Sandbox Code Playgroud)
在动画循环中,旋转枢轴;
pivot.rotation.z += 0.02;
Run Code Online (Sandbox Code Playgroud)
小提琴: https: //jsfiddle.net/of1vfhzz/1/
三.js r.77
| 归档时间: |
|
| 查看次数: |
7807 次 |
| 最近记录: |