【问题标题】:How to render normals to surface of object in three.js如何在three.js中将法线渲染到对象的表面
【发布时间】: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

【问题讨论】:

  • 你需要计算正常的什么?你有bufferGeometrygeometry 吗?或者你有三个vector,它们是面顶点的法线?这个问题完全不完整。
  • 我的几何形状与threejs示例中的几何形状相同。 CylinderGeometry
  • 我建议检查你的几何面并手动计算每个三角形的法线。

标签: javascript three.js quaternions normalize


【解决方案1】:

您想查看网格的顶点法线。你可以像这样使用VertexNormalsHelper

var vnh = new THREE.VertexNormalsHelper( mesh, 1, 0xff0000 );
scene.add( vnh );

VertexNormalsHelper

three.js r.84

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-02-08
  • 1970-01-01
  • 2021-12-18
  • 2018-11-26
  • 2022-06-15
  • 1970-01-01
  • 2012-09-02
  • 1970-01-01
相关资源
最近更新 更多