javascript - 在新创建的面上计算面法线

标签 javascript three.js normals face

我在场景中有一个简单的 CricleGeometry,我正在复制它的顶点并创建新的面来模拟拉伸(stretch)。 创建新面孔后,我运行“computeFaceNormals()”,但它们的方向是交替的。我怎样才能让所有面朝外?

截图如下: enter image description here

这是代码的主要部分:

//geometry
geometry = new THREE.CircleGeometry(100, 12);

geometry.mergeVertices();

material = new THREE.MeshPhongMaterial( { color: 0xffa800 } );


///////////////////////////////////////////////////////////////

//CREATE NEW FACES

///////////////////////////////////////////////////////////////


var sideGeo = new THREE.Geometry(); 

//duplicate vertices
for ( var v = 0; v < geometry.vertices.length; v++ ) {

    sideGeo.vertices.push( geometry.vertices[ v ].clone() );
    sideGeo.vertices.push( geometry.vertices[ v ].clone() );

}

//translate every second vertex on Z by 10
for ( var v = 0; v < sideGeo.vertices.length; v += 2 ) {

    sideGeo.vertices[ v ].z += 100;

}

//add them to faces
for ( var v = 0; v < sideGeo.vertices.length -2; v++ ) {

    //vertices IDs
    var a = v;
    var b = v + 1;
    var c = v + 2;

    //add them to a face
    var f = new THREE.Face3(a, b, c);
    sideGeo.faces.push(f);


}

//merge with original geo and compute face normals
geometry.merge(sideGeo);

geometry.computeFaceNormals();


//mesh
mesh = new THREE.Mesh(geometry, material);

scene.add(mesh);

最佳答案

当您调用 Geometry.computeFaceNormals() 时,面法线的方向由面顶点的缠绕顺序决定。

在three.js中,当看脸的正面时,你需要按照逆时针顺序指定你的顶点。在这种情况下,由 computeFaceNormals() 计算的面部法线将指向您。

three.js r.75

关于javascript - 在新创建的面上计算面法线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36360023/

相关文章:

javascript - 在不同文件中导出不同路由的实际函数

javascript - 将 DIV 插入 Google map 图层

opengl-es-2.0 - 我可以在 OpenGL ES 中指定每个面法线并实现非平滑/平坦着色吗?

c++ - 如何在 Maya Api 中对齐顶点和法线?

javascript - Angular2 Observables 最佳实践

javascript - Python HTML输出(第一次尝试),几个问题(含代码)

javascript - 旋转表格中的图像

three.js - Threejs 的 ShaderMaterial 反射和光泽度问题

three.js - 在three.js中获取鼠标点击点的3D坐标

python - OpenGL 对象没有光照