我在场景中有一个简单的 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);