我需要通过创建几个圆柱体然后使用Three.js库将它们旋转到不同的方向来创建球体。我试过遍历2个饼图,这些饼图更改了旋转轴的设置,但没有用。我该怎么办 ?
var cylinder;
var cylinderMaterial = new THREE.MeshPhongMaterial(
{ color: 0x5500DD,
specular: 0xD1F5FD,
shininess: 100 } );
var cylinderGeo = new THREE.CylinderGeometry( 3, 3, 500, 32 );
var cylinder = new THREE.Mesh( cylinderGeo, cylinderMaterial );
var untransformedCylinder = cylinder.clone();
console.log("Untransformed cylinder matrix:")
console.log(untransformedCylinder.matrix);
scene.add(untransformedCylinder);
var maxCorner = new THREE.Vector3( 1, 1, 1 );
var minCorner = new THREE.Vector3( -1, -1, -1 );
var cylAxis = new THREE.Vector3().subVectors( maxCorner, minCorner );
cylAxis.normalize();
var theta = Math.acos( cylAxis.y );
var rotationAxis = new THREE.Vector3(1, 0, 0);
rotationAxis.normalize();
cylinder.matrixAutoUpdate = false;
cylinder.matrix.makeRotationAxis( rotationAxis, theta );
console.log("Theta: " + theta);
console.log(" cos: " + Math.cos(theta));
console.log(" sin: " + Math.sin(theta));
console.log("Transformed cylinder matrix:")
console.log(cylinder.matrix);
scene.add( cylinder );
最佳答案
您应该在cylinder.setRotationFromMatrix(cylinder.matrix);
后面添加cylinder.matrix.makeRotationAxis( rotationAxis, theta );