Looking to determine the area of triangles surrounding a specific vertex within a mesh using Three.js.
I am aware that in three.js, faces represent the connections between vertices in a mesh. However, I have yet to find an effective method for identifying the indices of all triangles adjacent to a given vertex.
The code snippet provided below is my current solution, but when dealing with a large mesh consisting of more than 16,000 unique vertices and over 5,000 faces, the loop iteration exceeds 80 million times, leading to significant delays.
In addition, the conditional statement within the loop which checks whether the 'a', 'b', or 'c' position in a face matches the current vertex being processed does not yield the correct results.
var objectFace = object.geometry.faces;
var objectVertex = object.geometry.vertices;
for( var m = 0; m < objectVertex.length; m++ ) {
for( var q = 0; q < objectFace.length; q++ ) {
fArray = objectFace[q];
if ( fArray.a = m || fArray.b = m || fArray.c = m ) {
var va = fArray.a;
var vb = fArray.b;
var vc = fArray.c;
var v1 = objectVertex[va];
var v2 = objectVertex[vb];
var v3 = objectVertex[vc];
var vec1 = [( v2.x - v1.x ), ( v2.y - v1.y ), ( v2.z - v1.z )];
var vec2 = [( v3.x - v1.x ), ( v3.y - v1.y ), ( v3.z - v1.z )];
//calculate triangle area using Heron's equation
//store area values in array
}
};
};
To calculate the area, one must perform a cross product of the two vectors and apply Heron's equation accordingly.
Your assistance on this matter would be highly appreciated.
*ps My JavaScript abilities may not be top-notch, hence why this approach was devised.