I would like to display a quite big model in the Autodesk platform services viewer. However, I experience severe performance issues. In the Autodesk Blog I read that suppressing the loading of model data could help, so I added to my code:
viewer.loadDocumentNode(document, bubbleNode, {
skipPropertyDb: true,
});
Unfortunately, it is now no longer possible to isolate objects on select nor to use viewer.fitToView()
because the dbId-fragment relation is missing.
Is there a way to load this relation just for the selected objects? Or can we use viewer.fitToView()
also without having the relation at all?
Since you're not loading properties db, you can rely on instance tree and methods that use it, like fitToView.
To bypass that, we need to "remake" selection tool, find the fragments of the selected element and adjust the view.
First step (dbId selection) can be addressed with clientToWorld method:
let result = this.viewer.clientToWorld(event.canvasX, event.canvasY, true);
Then, with the proper dbId we need to find the correlated fragments
async getFragsIdsFromdbId(dbId) {
const fragsIds = this.fragList.fragments.fragId2dbId.map((id, fragId) => id == dbId ? fragId : -1).filter(i => i > -1);
return fragsIds;
}
Where this.fraglist
is obtained with this.viewer.model.getFragmentList()
Now, for each fragment we get its bounding box
async getBoxFromFrag(fragId) {
const boxCoordinates = this.fragList.fragments.boxes.slice(fragId * 6, (fragId * 6) + 6);
const boxMin = new THREE.Vector3(boxCoordinates[0], boxCoordinates[1], boxCoordinates[2]);
const boxMax = new THREE.Vector3(boxCoordinates[3], boxCoordinates[4], boxCoordinates[5]);
const fragBox = new THREE.Box3(boxMin, boxMax);
return fragBox;
}
Lastly, we adjust the view based on the merged boxes from the frags acquired for the selected dbId
let fits = await viewer.navigation.fitBounds(false, box);
You can find a live demo at https://joaomartins-callmejohn.github.io/aps-viewer-fitnselect-noprops/