Hi,
I want to add a button that is similar to Section Box button in Revit for selectedObjects in SpeckleAdmin. I’m not familiar with threejs so I don’t know where to start. I’m thinking of these steps:
Get bounding box of selected objects using computeBoundingBox. I don’t know how to get all geometries from selectedObjects.
Hello @htlcnn! This is a good request/feature proposal
Having played with this before, I strongly suggest starting without the caps (ie, shading the areas that are cut). I see threejs has quite a few examples now for clipping! They can be a good place to start.
The below advice comes with a big caveat: it’s been months since I last touched the viewer code, so I’m a bit rusty. Here goes:
If you foresee that the clipping will always be one box for the whole scene, you can add these clipping planes in the speckle renderer’s initialisation stage and store them as “scene globals”.
would resize them dynamically when the scene is loaded.
you can probably use something like the transform controls in this example to allow users to drag the box’es sides (constrained, obviously, on the normals of the box, or, probs easier, on the global XYZ).
Minor note: Theoretically, the bounding sphere of the scene should be more or less up-to-date always in the viewer, so you don’t need to recalculate this.
@dimitrie Thanks for the guide!
I’ve been trying to implement clipping_stencil example in SpeckleRenderer.js. Each time I change SpeckleRenderer, I have to run npm run build again and wait. Is there any faster way?
In the threejs example, the planes depend on each other, their materials is set when initialized. So are the geometries that the planes cut. But geometries are not available until after we finish initialisation and constructor. That’s what I’m struggling and still haven’t found any solution.
Yep, npm run dev! See this line. This will trigger a rebuild/refresh on file changes. Nevertheless, because of the way the redender interacts with the rest of the DOM, you’ll still need to refresh the page… (I used to debug this by always having a small stream handy so it loads fast in the viewer).
Maybe this example is better: it seems to set the renderer.clippingPlanes property only, and the geometry is just there, in the scene. If you push this to a fork/branch I can have a better look at the code (and even maybe contribute). I believe the stencil example is more complex - as it does colour in the “cut” parts.