Using layers to optimize application performance with Raycaster

In this video, I’ll demonstrate how utilizing layers can significantly enhance the efficiency of raycasting in Three.js
We don’t need to manage separate arrays which meshes should include in raycasting or not.

1 Like

Layers are one of the underused features of Three.js. I don’t see layers being used often. They do need to attract more attention.

As for raycasting, is raycasting with layers faster than raycasting with groups?

  • When groups are used, raycasting traverses only the members of the group.
  • When layers are used, raycasting traverses all objects, checks the layer bitmask and only if the correct bit is set, then it performs raycasting.

So, in both cases the raycasting works only on the selected objects, but in the case of layers, it also scans all other objects.

1 Like

Yes. approach you are suggesting will work.

But I think layers will be helpful when we do not want to store objects separately.

when we have application with lot of objects and we want to apply raycating with variety of groups at different stages of application.
Like I want to apply raycasting on sketchLayer entities in sketchMode, apply raycasting to another layers meshes in another layers.
With layers we don’t have to manage separate objects for different stages of our application