如何在three.js中将法线渲染到对象的表面

时间:2021-10-06 05:03:30

I found the example in threejs.org, that draws arrows normals, it is what I need. But arrows is complexed object and created by ArrowHelper. I looked in source code and found setDirection method.

我在threejs.org中找到了这个例子,它绘制了箭头法线,这是我需要的。但箭头是复杂的对象,由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 );

    }

};

I tried to immpliment algorithm for setting rotation for Vector3 with using quaternion, but I still have norlams that looks at {x: 0, y: 0, z: 0}.

我尝试使用四元数来改进为Vector3设置旋转的算法,但是我仍然有看到{x:0,y:0,z:0}的norlams。

And my question is: How to calculate an vector in order to draw a normal line from surface into space, in order to get the same picuter: 如何在three.js中将法线渲染到对象的表面

我的问题是:如何计算矢量以便从表面到空间绘制法线,以获得相同的图像:

UPD:
I use CylinderGeometry.

UPD:我使用CylinderGeometry。

UPD2:
I've resolved it. Look at my codepen

UPD2:我已经解决了。看看我的codepen

1 个解决方案

#1


2  

You want to view the vertex normals of your mesh. You can use VertexNormalsHelper like so:

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

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

VertexNormalsHelper

three.js r.84

#1


2  

You want to view the vertex normals of your mesh. You can use VertexNormalsHelper like so:

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

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

VertexNormalsHelper

three.js r.84