Reputation: 1
We are building an IOT application and using Autodesk Forge to position sensors in a 3D model. We were able to position the sensors in the 3D model and find the room that the sensors are positioned at. We are also adding zones to the 3d model and we would like to query the sensors or rooms within a zone or space. We couldn't find documentation about this. Can you please point to documentation or example codes that would help us indentify the rooms or sensors inside a zone or space?
Upvotes: 0
Views: 315
Reputation: 9942
There is no out-of-the-box support for these kind of spatial queries in the viewer API but you could build a simple one yourself. The viewer API does provide a way to retrieve bounding boxes of individual elements:
function getElementBoundingBox(model, dbid) {
const tree = model.getInstanceTree();
const frags = model.getFragmentList();
let nodeBounds = new THREE.Box3();
let fragBounds = new THREE.Box3();
tree.enumNodeFragments(dbid, function (fragid) {
frags.getWorldBounds(fragid, fragBounds);
nodeBounds.union(fragBounds);
}, true);
return nodeBounds;
}
And then you can use the THREE.Box3 methods to do check whether the bounding box includes a given 3D point, or another bounding box:
const spaceBounds = getElementBounds(viewer.model, someSpaceDbID);
const roomBounds = getElementBounds(viewer.model, someRoomDbID);
console.log(spaceBounds.containsBox(roomBounds));
const devicePosition = new THREE.Vector3(10.0, 20.0, 30.0);
console.log(spaceBounds.containsPoint(devicePosition));
Upvotes: 2