I am currently grappling with the task of eliminating duplicate faces from an array of faces. I've made an attempt at some code, but I find myself stuck on how to complete it.
One thing that caught me off guard was this:
new THREE.Vector3(0,0,0) == new THREE.Vector3(0,0,0)
The above comparison evaluates to false (though I would have expected it to be true). Similarly, the following snippet also results in false (once again, against my expectation of true).
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] - leads to a false result
In terms of my strategy for determining if a face already exists within an array of faces, here's what I've come up with:
function faceInArray(arrayOfFaces,face)
{
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]
// Still unsure about comparing the vertices effectively
}
}
At this point, I'm uncertain about the next steps. Simple comparisons like vertex1 == vertex2 aren't yielding the desired outcomes, as demonstrated earlier. Would breaking down the coordinates of each face be necessary for comparison? Also, does the order of vertices play a crucial role?