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

Computing face normals on newly created faces

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

截图如下:

代码的主要部分如下:

//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