Merge or group the triangles of model which have close normal and compute edge

Hi guys,I wanna handle the model geometry in order to select the region of irregular Polygons. In other application like blender and visiual
component, they can merge faces and compute edge. So I can select the region instead of triangle.

The component snap in VC:

In order to snap edge and points. I use EdgesGeometry:

But I encountered some difficulties in snap face. I wanna classify triangles according to normal , and set a threshold. But it has a poor performance especially in no-Index BufferGeometry. I run my code in editor, and it has a long running time:

And I upload the model and code to my OSS. You can run in three editor.If you have some better function or you are Interested in this topic, please reply me, thanks



There some things that can be optimized. Here are a few that I see from a first glance, maybe there are more:

  • You scan all triangles and make a separate mesh for each of them – I’m not sure whether this is actually necessary
  • In the classification loop you scan all triangle meshes by looking for their name – this is very slow operation as it pushes the time complexity to O(n2).
  • New instances of vectors a, b and c are created for each triangle (in the second loop) – would it be possible to reuse a, b and c created once?
  • It is not needed to use Math.floor(… * 1000) / 1000) for the threshold, rounding to some precision gives no value in this case
  • Similarly, instead of converting to radians with acos, it might be possible to compare the raw dot product with the cosine of the threshold
  • Imagine there are three non-connected consecutive triangles with the same normals … will your algorithm combine them in one mesh?

Thanks to your reply , it was very helpful to me. What method is there to determine whether two triangles are adjacent to solve the problem that there are three non-connected consecutive triangles with the same normal.