Create only faces/sides with raycast collision in a mesh?

Is it possible in three.js to create only the faces which colliding with raycast in a certain mesh?

The layout problem in my artistic skills: (red edge == collision)

in the picture,we have 3 boxes. box1 and box3 togather got 4 sides/faces colliding with rays, and from box2 1 collision.
== so 5 sides/faces in totals .

→ so is there a way to create only the 5 sides (equavelate to 5 PlaneGeometries i guess), instead creating 3 BoxGeometries (which improve performence), directly from the raycasting detections?

Raycasting in three.js refers to objects present in the scene. You can specify which objects should be included in raycasting.

According to your drawing, you have to judge beforehand, based on the position, which surfaces will be hit by the rays. Then you will not create boxes in your example, but some single (red) planes.

1 Like

yeah i guess i need to workaround that way

@Joe1
I can’t get the goal though.
Compute dot-product between plane’s normal and the normalized vector from the center of the plane to the point of view. If the result is greater than 0, then the plane counts as visible. :thinking:

thanks for reply, hofk’s suggestion and yours will work fine in simple scenarios or this example i gave.

i think my layout problem is too simplistic (my mistake lol :upside_down_face:).
but if we expand the problem, the question should be more like:

  • “creating only objects visible to certain view (let say camera for example) + a condition which is creating only the faces that are visible (not the whole mesh)”.

now it comes to occlusion culling algorithm + apply to only the faces visible to the ray.
i didnt find any three.js implementation of occlusion culling. i guess i going to implement occlusion culling myself somehow…