首页 > 解决方案 > 在three.js中按照平面旋转组

问题描述

我有一组形状很少(球体几何、线条和平面)。组中有一个平面需要与组外的另一个平面类似地定向。但我希望小组也有相应的方向。

这是我尝试过的

let lookatpos = new THREE.Vector3(/*Normal to the plane from group*/);
            
//change the group lookat to the normal of the plane
group.lookAt(lookatpos);

let v2 = new THREE.Vector3(/*normal to the second plane*/);

var axis = lookatpos.clone().cross(v2);
var angle = Math.acos(lookatpos.dot(v2));

if (angle == NaN)
  return;
var rotationWorldMatrix = new THREE.Matrix4();
rotationWorldMatrix.makeRotationAxis(axis.normalize(), angle);
currentmesh.matrix.multiply(rotationWorldMatrix);
group.matrix.multiply(rotationWorldMatrix);
currentmesh.rotation.setFromRotationMatrix(currentmesh.matrix);
group.rotation.setFromRotationMatrix(group.matrix);

根据我从 Rotate plane 获得的提示,使其与另一个平面平行

但是我正在反转组的方向,尝试否定法线,但问题仍然存在。有人可以帮我吗?

标签: matrixgraphicsthree.js3drotation

解决方案


推荐阅读