【发布时间】:2017-08-29 12:40:08
【问题描述】:
我在threejs.org 中找到了the example,它绘制了法线箭头,这正是我所需要的。但是箭头是复杂的对象,由 ArrowHelper 创建。 我查看了源代码并找到了 setDirection 方法。
function setDirection( dir ) {
// dir is assumed to be normalized
if ( dir.y > 0.99999 ) {
this.quaternion.set( 0, 0, 0, 1 );
} else if ( dir.y < - 0.99999 ) {
this.quaternion.set( 1, 0, 0, 0 );
} else {
axis.set( dir.z, 0, - dir.x ).normalize();
radians = Math.acos( dir.y );
this.quaternion.setFromAxisAngle( axis, radians );
}
};
我尝试使用四元数来实现设置 Vector3 旋转的算法,但我仍然有看 {x: 0, y: 0, z: 0} 的 norlams。
我的问题是: 如何计算向量以便从表面绘制法线到空间,以获得相同的图片:
UPD:
我使用 CylinderGeometry。
UPD2:
我已经解决了。 Look at my codepen
【问题讨论】:
-
你需要计算正常的什么?你有
bufferGeometry或geometry吗?或者你有三个vector,它们是面顶点的法线?这个问题完全不完整。 -
我的几何形状与threejs示例中的几何形状相同。
CylinderGeometry -
我建议检查你的几何面并手动计算每个三角形的法线。
标签: javascript three.js quaternions normalize