select multiple faces around raycaster face, but under complex geometric conditions, the program runs for too long or even gets stuck







Hi guys,I write a case that show multiple faces around raycaster face according to normal and shared Vertex, but the function cost too long time especially in complex situations. I wanna share my case and if you have some way to improve it, please reply me.

single cube
complex model
ps: click to chose a face

Most likely the code can be improved taking care of how JS handles things. This could improve the speed a lot. However, if you need fast interactivity with complex shapes, it might be feasible to preprocess objects. One possible way is this:

Program A (run only once per object, non-interactive, slow):

  • load STL model
  • process triangles by making all joint triangles as a group (this is slow), this way you will end up with the same model, but will have complex faces grouped as subobjects
  • save the model as GLB file

Program B (run by users, interactive, fast):

  • load the GLB model processed by program A
  • when you click on the object, find intersection with one of the subobjects (this is fast), recolor the triangles
  • enjoy clicking and selecting complex faces
1 Like

Thanks, pre-processing is a good way to solve this problem,I will try this way and share in next day

Another option is to use cascading filters: i.e. you first use simple calculations to remove as much faces as it is possible. And when this is done, you apply the slow and accurate filter only to the remaining faces.

Here is a demo which removes 99% of all faces in real time with two simple and fast filters.

  • filter 1 - keep only faces with a similar normal vector
  • filter 2 - keep only faces with a similar plane

And here is a draft implementation of these two filters. Note, that for these filter no objects are created (see lines 89-113) – all calculations are done in-place. For example, the snapshot shows that these two preliminary filters reduce the number of faces from 50054 down to only 310 (which is 99.4% reduction).

https://codepen.io/boytchev/full/yLRZByN

image

1 Like

It is awesome way and it has been a great help to me, thanks.

I combined our methods to come up with the final demo:

  • filter 1 - keep only faces with a similar normal vector
  • filter 2 - keep only faces with a similar plane
  • filter 3 - Remove faces that do not share vertices with select face

Finally, this method can quickly obtain accurate results without pre-processing, and is real-time.

In demo, the green part is the result.




DEMO: https://codepen.io/FeiyuYan95/pen/YzJggeM

1 Like