变换
移动
顶点移动
const box = new THREE.BoxGeometry(1, 1, 1);
box1.translate(); // 修改几何体的顶点位置物体移动
当设置 Object3D 物体位置时,以其父元素的位置来定位子元素的位置,如果没有父元素,则是世界坐标。即假使设置了父元素的位置,子元素位置随之改变
const mesh = new THREE.Mesh(box, material);
// 修改3D物体的位置mesh.position.x = 1;mesh.position.y = 1;mesh.position.z = 1;
// 修改3D物体的位置mesh.position.set(2, 0, 0);
mesh.position.setX();mesh.position.setY();mesh.position.setZ();旋转
顶点旋转
const box = new THREE.BoxGeometry(1, 1, 1);
// 沿着自身的轴旋转box.rotateX();box.rotateY();box.rotateZ();物体旋转
const mesh = new THREE.Mesh(box, material);
// 以XYZ轴顺序旋转cube.rotation = new THREE.Euler(0, 0, 0);
// 沿着自身的轴旋转mesh.rotation.x = Math.PI / 4;mesh.rotation.y = Math.PI / 4;mesh.rotation.z = Math.PI / 4;
// 沿着自身的轴旋转mesh.rotateX(Math.PI / 4);mesh.rotateY(Math.PI / 4);mesh.rotateZ(Math.PI / 4);
// 沿着自身指定的轴旋转mesh.rotateOnAxis(new THREE.Vector3(0, 1, 0), Math.PI / 4);
// 沿着世界指定轴旋转mesh.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), Math.PI / 4);缩放
顶点缩放
const box = new THREE.BoxGeometry(1, 1, 1);
// x,y,z 方向缩放box.scale(1, 1, 1);物体缩放
const mesh = new THREE.Mesh(box, material);
// x,y,z 方向缩放mesh.scale.set(1, 1, 1);