Select mutliple faces around intersecting face

As you can see in below image,
we can change or select face with raycaster.
is there any way to select faces around that face like shown in image

There’s no robust way built into three.js to get the adjacent faces. There are different options depending on what you need and your desired level of fidelity, though. If you need the exactly adjacent faces then you can create something like a half edge data structure out the geometry and then get the connected faces.

If you just need roughly a set of faces near the triangle you can cast multiple rays and take the set of triangles that they hit. This will likely miss triangles in a lot of cases especially when they are small, though, and may become a performance bottleneck if the geometry you’re casting against is complex.

If you’re looking a set of faces in a circle around the hit point on the surface of the geometry you can use three-mesh-bvh, which is a library I maintain. It can help improve raycast performance against complex meshes as well as perform shape casting using something like a sphere to get all the triangles that intersect the shape. That’s demonstrated in the following example where you can “paint” triangle faces:

https://gkjohnson.github.io/three-mesh-bvh/example/bundle/collectTriangles.html

(left click to paint, right click to erase, scroll wheel to change brush size)

Note that that won’t work for dynamic geometry, though.

3 Likes

How would you define adjacent faces?
By shared vertices or sides?

Summary

In this picture the orange face is raycasted. The intersect_success[0].face has keys { a, b, c } pointed to corresponding vertices.

ex: intersect_success[0].face.a = 401;
ex: intersect_success[0].face.b = 402;
ex: intersect_success[0].face.c = 399;

Initially when creating geometry faces, I ran this function:

[‘a’, ‘b’, ‘c’ ].forEach( function(abc) { var v_idx = face[abc];
( geometry.vertices[ v_idx ].f_ref || (geometry.vertices[ v_idx ].f_ref = ) ).push(v_idx); } );

Basically, it adds an array “f_ref” of faces sharing that vertex as a key to that vertex object.

ex: geometry.vertices[402].f_ref = [1491, 1492]’

Now finding the adjacent faces can be done in few mili seconds after single raycast.

1 Like