How to disable intersectability of an object durying raycasting?

  • Objective: I want to be able to raytrace ignoring select objectIds and there children. I know that in three.js, you can select a group of objects to perform ray casting on. Currently, I’m looking for a way to apply that logic to the viewer, renderer, and scene. Would appreciate any recommendations!!

  • Issue: I’m unsure of the approach to take to achieve this. Everything in the scene is loaded in as a ContentGroup, and besides modifying the geometry of that object directly, I’m not sure how to achieve this.

  • Example:

For some reference, I'm trying to use this raycasting approach. I was thinking of building this logic into

  const renderer = viewer.getRenderer();
 const intersections = renderer.intersections.intersectRay(
      renderer.scene,
      renderer.renderingCamera,
      ray,
      ObjectLayers.STREAM_CONTENT_MESH,
      false, // nearest
      undefined, // bounds
      true, // firstOnly 
      false // tasOnly
    );

I have several use cases in mind for this. An application that I think would be particularly helpful in future versions is applying this to MeasurementExtension, to prevent incorrect object selection when trying to measure objects in an isolated object view. With this addition, the measurement tool would be usable only in the context of isolated objects.

Hi @Leul_Tesfaye

Ray-Scene intersection is drastically different in the speckle viewer compared to stock three.js. The viewer builds a BVH acceleration structure and intersections happen against that structure, whereas stock three.js just tests each triangle in the scene, as you can see here. This different approach makes intersections in the viewer several orders of magnitude faster than stock three.js, if used properly. The viewer’s acceleration structure uses the three-mesh-bvh library with a bunch of custom additions on top.

The only current builtin way to ignore intersections is via the objectLayers argument, however that will not give you the granularity that you want

My suggestion is that you don’t try to restrict intersection to specific objects. Intersect with the BVH with firstOnly=false so you get a complete intersection chain and then prune the results based on you requirements. This is what we already do internally for various use cases like : ignoring ghosted objects and hidden when clicking, ignoring snapping of the measurement tool to ghosted/hidden geometry, or atomic/non atomic object selection when picking in the web app etc.

If you really wanted to, you might be able to achieve it via a custom shapecast of the viewer’s top level acceleration structure only, but I don’t think it’s worth the effort unless the use case and context are really niche.

Cheers