Objective: I currently have a specific object ID that I can look up and compute the bounding box. My aim here is to find object points that lie on the planes of the bounding box. Currently, I employ a suboptimal approach to ray casting from each outside plane direction inward in a grid pattern, where the threshold is set close enough; however, this seems highly inefficient and possibly redundant.
Issue: I’m unaware of any way I can achieve this without just doing rayCasting. Any suggestions or pointers would be greatly appreciated!!!
Tangential Question: Is it safe to assume that Speckle Scene will always set +Z as the up-vector of the world? I don’t see anywhere in the documentation that claims it needs to be in the +Z direction. Just want to double-check this before building on top of this assumption.
What a nice challenge! I believe there is something that you can leverage from the viewer API to greatly increase efficiency and speed.
Assuming the points you want to test belong to the objects and the objects are meshes:
The viewer API constructs a two level BVH as it’s acceleration structure. The bottom level consists of each object’s own BVH, and it’s that is what you can leverage. You can access this acceleration structure from the BatchObject. You can then use the BVH’s shapecast function to do your plane intersection tests. Now this is where it gets tricky. You will need to checkout it’s documentation for a better understanding what the function expects from you. We’re also using this for some of our extensions. Example here and here. I might be able to help more here.
Like stated in the assumptions above, we build acceleration structures for meshes only. Points/line currently do not have acceleration structures but hopefully will in the future
The viewer itself does not assume any specific basis for the geometry you load in. Establishing the up vector is done by the control’s up property. Do note that there are some assumptions regarding basis which are enforced by three.js, however they are documented.
What it’s safe to assume however is that speckle data sent over using speckle official connectors will always have +Z as the up-vector (which personally makes my eye twitch a little bit )