问题描述
如何获得由三个顶点定义的三角形的旋转度(x,y,z)。
这里有一个 fiddle 来说明这个问题……感谢 THREE.Triangle,我能够得到三角形 normal
和 midpoint
,请记住网格旋转始终为 (0,0),顶点改变而不是变换矩阵。
我的最佳尝试仅在有限范围内有效 [(-0.4,-0.4,-0.4),(0.4,0.4,0.4)],超出此范围至少有一个轴完全关闭。有人告诉我,我可能正面临万向节锁,或者我可能需要四元数来计算旋转。
function computeRotation() {
const vertices = mesh.geometry.attributes.position.array;
const vec1 = new THREE.Vector3(...vertices.slice(0,3));
const vec2 = new THREE.Vector3(...vertices.slice(3,6));
const vec3 = new THREE.Vector3(...vertices.slice(6,9));
const triangle = new THREE.Triangle(vec1,vec2,vec3);
const normal = new THREE.Vector3();
const midPoint = new THREE.Vector3();
triangle.getNormal(normal);
triangle.getMidpoint(midPoint);
// X and Y axes
var matrix = new THREE.Matrix4().lookAt(
normal,new THREE.Vector3(0,0),1,0)
);
const { x,y } = new THREE.Euler().setFromRotationMatrix(matrix);
// Z axis
const dir = new THREE.Vector3().subVectors( vec1,midPoint ).normalize();
var matrix = new THREE.Matrix4().lookAt(
dir,0)
);
const z = new THREE.Euler().setFromRotationMatrix(matrix).y * -1;
return {x,z};
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)