我假设你的意思是希望一个物体围绕它几何形状内的一个特定点旋转。
比如,cylinderGeometry
围绕它的“中心”旋转。如果你希望它围绕它的“端点”旋转,则需要在创建完圆柱几何体后将其平移,使得几何体内的所需点现在位于原点。
geometry.translate( 0, cylinderHeight/2, 0 );
现在,当你旋转这个圆柱体时,它将绕着它的末端旋转,而不是中间部分。
它绕着旋转的末端也会位于您设置的圆柱体网格的位置。
显然,您可以对任何几何图形执行此操作,而不仅仅是圆柱体。
three.js r.147
// CYLINDER
var cyl_material = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
var cyl_width = 1;
var cyl_height = 5;
// THREE.CylinderGeometry(bottomRadius, topRadius, height, segmentsRadius, segmentsHeight, openEnded )
var cylGeometry = new THREE.CylinderGeometry(cyl_width, cyl_width, cyl_height, 20, 1, false);
// translate the cylinder geometry so that the desired point within the geometry is now at the origin
cylGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, cyl_height/2, 0 ) );
var cylinder = new THREE.Mesh(cylGeometry, cyl_material);
scene.add( cylinder );
cylinder.rotation.x = 0.5*Math.PI;
//rotates a mesh's geometry about a specified axis and pivot
//the axis is a normalized Vector3
const rotateAbout = (mesh, axis, axisPosition, angle) => {
mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(mesh.position.x-axisPosition.x, mesh.position.y-axisPosition.y, mesh.position.z-axisPosition.z)); //translate geometry to axis location
mesh.geometry.applyMatrix(new THREE.Matrix4().makeRotationAxis(axis, angle)); //rotate geometry about axis
mesh.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(axisPosition.x-mesh.position.x, axisPosition.y-mesh.position.y, axisPosition.z-mesh.position.z)); //translate geometry back to original location
}