Reputation: 137
Updating camera and target based on dbid of a selected node. I am updating camera and target according to frag mesh retrieved with dbid and then moving to VR mode. Currently I have an event listeners GEOMETRY_LOADED_EVENT and OBJECT_TREE_CREATED_EVENT. Is there some other event that I should wait before running the code or updating the camera?
const nav = viewer.navigation;
const cam = nav.getCamera();
const it = viewer.model.getData().instanceTree;
let xPos, yPos, zPos;
it.enumNodeFragments(nodeId, (frag) => {
const mesh = viewer.impl.getRenderProxy(viewer.model, frag);
xPos = mesh.matrixWorld.elements[12];
yPos = mesh.matrixWorld.elements[13];
zPos = mesh.matrixWorld.elements[14];
}, false);
cam.position.set(xPos, yPos, zPos);
cam.target.set(xPos, yPos + 10000, zPos);
viewer.impl.sceneUpdated();
viewer.navigation.updateCamera();
document.getElementById("toolbar-vrTool").click();
Upvotes: 1
Views: 113
Reputation: 4375
Those two events should ensure that your model is fully loaded and that your code can safely access the model hierarchy, this article may be useful: Asynchronous viewer events notification
Upvotes: 1