我想從面陣列中刪除重複的面 - 我已經嘗試了下面的一些代碼,但我不知道如何完成它。從面陣列中刪除重複的面 - Three.js
首先我很驚訝地發現:
new THREE.Vector3(0,0,0) == new THREE.Vector3(0,0,0)
產生false(我希望它產生真正的),此外,下面還代碼產生false(我再次希望它產生真正的)。
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?
}
}
現在我不知道該如何從這裏PROCEDE簡單地檢查vertex1 == vertex2不起作用,因爲我在第一個代碼塊中介紹了它。在比較它們時,我是否真的需要提取每張臉的x,y和z座標?此外頂點的順序是否重要?
嗨安東,你可以請更新你的問題,以你當前的情況的一個簡單的例子,你到目前爲止嘗試過什麼? – rafaelcastrocouto
@rafaelcastrocouto謝謝你的評論我已經爲我的問題添加了更多的細節 - 我意識到最初它太簡單了。 –