我想从一组面孔中删除重复的面孔 - 我尝试了下面的一些代码,但我不确定如何完成它。
首先,我惊讶地发现:
new THREE.Vector3(0,0,0) == new THREE.Vector3(0,0,0)
产生假(我希望它产生真),此外,下面的代码也产生假(我再次希望它产生真)。
var triangleGeometry = new THREE.Geometry();
triangleGeometry.vertices.push(new THREE.Vector3( 0.0, 1.0, 0.0));
triangleGeometry.vertices.push(new THREE.Vector3(-1.0, -1.0, 0.0));
triangleGeometry.vertices.push(new THREE.Vector3( 1.0, -1.0, 0.0));
triangleGeometry.faces.push(new THREE.Face3(0, 1, 2));
var triangleGeometry2 = new THREE.Geometry();
triangleGeometry2.vertices.push(new THREE.Vector3( 0.0, 1.0, 0.0));
triangleGeometry2.vertices.push(new THREE.Vector3(-1.0, -1.0, 0.0));
triangleGeometry2.vertices.push(new THREE.Vector3( 1.0, -1.0, 0.0));
triangleGeometry2.faces.push(new THREE.Face3(0, 1, 2));
triangleGeometry2.faces[0] === triangleGeometry.faces[0] - yields false
至于我的代码来确定一个人脸是否已经在一个人脸数组中,我写了以下内容:
function faceInArray(arrayOfFaces,face)
{ // https://stackoverflow.com/questions/29759480/how-to-customize-object-equality-for-javascript-set
// Determine whether a face is in an array of faces
// The ES6 Set object does not have any compare methods or custom compare extensibility.
// For this reason this function will be called before adding an face to an array of faces
// to ensure that duplicate faces are not placed in an array
for(let i = 0; i < arrayOfFaces.length; i++)
{
vertexaFaceFromArray = buildingGeometry.vertices[arrayOfFaces[i].a]
vertexbFaceFromArray = buildingGeometry.vertices[arrayOfFaces[i].b]
vertexcFaceFromArray = buildingGeometry.vertices[arrayOfFaces[i].c]
vertexaFace = buildingGeometry.vertices[face.a]
vertexbFace = buildingGeometry.vertices[face.b]
vertexcFace = buildingGeometry.vertices[face.c]
// Compare the vertices in each face I'm not sure how to do this?
}
}
现在我不确定如何从这里开始,因为简单地检查 vertex1 == vertex2 不起作用,因为我在第一个代码块中演示了。在比较它们时,我真的需要提取每张脸的 x、y 和 z 坐标吗?此外,顶点的顺序是否重要?