I use ‘aabb’ bounding box in some scenes in my project, but ‘aabb’ bounding box has error in some scenes, I possibly need ‘oobb’ bounding box, and there is ‘OBB’ class in threejs, can speckle/viewer add this attribute in ‘BatchObject’?
The OBB
implementation from three.js is just a box that has a rotation. We can’t use this in speckle because our objects do not have a local space, aka we do not define a local transformation for objects, which we could apply to the bounding box and thus rotating it along with the object.
You might be looking after the minimal bounding box of objects, which is a non-trivial issue. I suggest you have a look here for more details.
However I am curious why you need an oriented bounding box to begin with. Maybe there are alternatives to your issue
Cheers
@alex Thank you for your reply!
In fact, I would like to do some collision related functions, it is because speckle does not have local variation of objects, so it leads to some tilted components enclosing the box much larger than it looks visually, which causes errors in the collision results, so I am considering the use of ‘OBB’ objects, ‘OBB’ can be a more perfect solution to the problem I encountered, and ‘OBB’ objects are more efficient than real Physical collision engine is relatively easy to implement.
This is all I can think of so far, do you have any other suggestions?
@zm1072223921 I’ve explored bounding box implementations, particularly from a Speckle Automate perspective, and faced similar challenges with OBBs over the years. While OBBs can provide a more accurate initial fit, I’ve found that voxelisation often offers a better balance of compute efficiency and accuracy, especially for collision detection or clash analysis.
With a voxelisation pipeline, you can progressively refine the resolution of the voxelised elements, enabling iterative and adaptive analyses. This can be more effective than relying solely on OBBs, which typically only improve the first-pass fit but don’t adapt well to subsequent refinements.
I understand your concern about tilted components leading to oversized bounding boxes. If integrating voxelisation into your workflow isn’t viable, another approach could be precomputing OBBs externally for critical objects and then passing that data into your scene as needed. While Speckle objects don’t have local transformations, precomputed data could act as a workaround.
Have you considered combining voxelisation for broad-phase collision checks with a fallback to OBBs or other geometry-specific methods for more detailed analysis? It could provide a flexible solution that balances initial speed and detailed accuracy.
ThreeJS Manual - Voxel Geometry
If you want to do any kind of intersection testing (which is is the basis for collision detection) you can use the already existing two-level BVH acceleration structures that the viewer provides. The BVH is backed by the excellent three-mesh-bvh library.
Each mesh object will have it’s BVH which we’re wrapped as an AccelerationStructure
type that you can access from the BatchObject
’s accelerationStructure property. This object BVH is what we call the bottom level BVH
Because the viewer organizes objects in batches, each batch of objects will form it’s own BVH that we call the top level BVH which is basically a BVH made of other BVHs (loosely speaking). You can access this acceleration structure from the batch’s renderObject
in the following way
// This will get you all mesh batches in the scene.
// If you want a specific batch you can use `getBatch`(https://speckle.guide/viewer/speckle-renderer-api.html#getbatch
const batch = viewer.getRenderer().batcher.getBatches(undefined, GeometryType.MESH)
const renderableObject = batch.renderObject as SpeckleMesh | SpeckleInstancedMesh
const topLevelAccelerationStructure = renderableObject.TAS
You can use both object level and batch level acceleration structures to do the intersection/collision testing. For example, the BoxSelection
extension uses the TAS to detect object to box inclusion. Because the AccelerationStructure
type is just a wrapper, you can directly use the three-mesh-bvh’s API. I suggest you have a read on their github page and see what it can do.
Internally, the viewer uses these acceleration structures a lot because they’re fast. Really fast if used properly. However you do need to pay the price in increased complexity. Let me know if you need more guidance on this topic
Cheers