简体   繁体   English

相邻三角形Three.js的面积

[英]Area of adjacent triangles Three.js

I am trying to find the area of triangles adjacent to a particular vertex in a mesh in Three.js. 我试图在Three.js的网格中找到与特定顶点相邻的三角形区域。

I know that faces in three.js represent how vertices in a mesh are connected, but I haven't found an efficient way to find the set of indices of all triangles adjacent to a specific vertex. 我知道Three.js中的面代表了网格中顶点的连接方式,但是我还没有找到一种有效的方法来查找与特定顶点相邻的所有三角形的索引集。

The code below is the best I could come up with, but given a large mesh with over 16,000 vertices (non-duplicated) and over 5,000 faces, the loop is running > 80m times which takes way too long. 下面的代码是我能想到的最好的代码,但是考虑到一个大型网格具有超过16,000个顶点(非重复)和超过5,000个面,循环运行> 80m次,这会花费太长时间。

Also, my if function that checks whether the a, b, or c position in a face matches that of the vertex currently in the loop does not work at all. 另外,我的if函数(用于检查面中的a,b或c位置是否与当前循环中的顶点的位置匹配)根本不起作用。

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 area of triangle with Heron's equation
            //store area values in array

        }
    };
};

I then calculate the area by crossing the two vectors and plugging them in to Heron's equation. 然后,我将两个向量相交并将其插入Heron方程中,从而计算出面积。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

*ps I know my JS skills are not very good but this is the best I could come up with. * ps我知道我的JS技能不是很好,但这是我能想到的最好的。

It seems that you're trying to do this for all vertices. 看来您正在尝试对所有顶点执行此操作。 So instead of looping trough every vertex, every face, and then sorting out the non-incident faces, you could just loop over the faces and accumulate the results for the according vertices: 因此,您不必遍历每个顶点,每个面,然后整理出非偶发面,而只需遍历面并累加相应顶点的结果即可:

[Pseudo code]
for each face
    a := calculate face area
    areas[facce.first vertex] += a
    areas[facce.second vertex] += a
    areas[facce.third vertex] += a
next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM