title: Events to listen to before updating camera
body: <p>Updating camera and target based on dbid of a selected node. The code starts with MobileVR function. 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 for GEOMETRY_LOADED_EVENT, OBJECT_TREE_CREATED_EVENT and EXTENSION_LOADED_EVENT. Currently it works with using a timeout setTimeout(() => { onSpaceObjectTreeCreated(); }, 3000); see image 1, but not without the the timeout image 2. Is there some other event that I should wait before running the code or updating the camera? </p>
  
  <pre><code>function onSpaceObjectTreeCreated() {
    const nav = viewer.navigation;
    const cam = nav.getCamera();
    const it = viewer.model.getData().instanceTree;
  
    let xPos, yPos, zPos;    
  
    it.enumNodeFragments(nodeId, (frag) =&gt; {
      const mesh = viewer.impl.getRenderProxy(viewer.model, frag);
      xPos = mesh.matrixWorld.elements[12];
      yPos = mesh.matrixWorld.elements[13];
      zPos = mesh.matrixWorld.elements[14];
      console.log('x: ' + xPos + ' y: ' + yPos + ' z: ' + zPos);
    }, false);
    zPos = -41000;
  
    cam.position.set(xPos, yPos, zPos);
    cam.target.set(xPos, yPos + 10000, zPos);
  }
  
  function onViewerGeometryLoaded() {
    const nav = viewer.navigation;
    const cam = nav.getCamera();
  
    if (nodeId == -1) {
      viewer.setGroundShadow(false);
      let xValue = viewer.getCamera().position.x;
      let yValue = viewer.getCamera().position.y;
      let zValue = viewer.getCamera().position.z;
      let bbz = viewer.model.getData().bbox.min.z;
      let zValue2 = zValue - bbz;
  
      zValue = zValue * 0.3;
      yValue = (zValue2 * 0.7071) * -1;
  
      let nav = viewer.navigation;
      let cam = viewer.getCamera();
      cam.position.set(xValue, yValue, zValue);        
    } else {
      setTimeout(() =&gt; {
          onSpaceObjectTreeCreated();
      }, 3000);
    }
  
    viewer.impl.sceneUpdated();
    viewer.navigation.updateCamera();
    document.getElementById("toolbar-vrTool").click();
  };
  
  function afterViewerEvents() {
    var events = [
      Autodesk.Viewing.GEOMETRY_LOADED_EVENT,
      Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT,
      Autodesk.Viewing.EXTENSION_LOADED_EVENT
    ];
  
    async.each(events,
      function (event, callback) {            
          var handler = function (ev) {
              viewer.removeEventListener(
                  event, handler);
              console.log('Event: ' + event);
              console.log('Ev: ' + ev.extensionId);
              callback();
          };
          viewer.addEventListener(
              event, handler);
      },
      function (err) {
          onViewerGeometryLoaded();
      });
  }
  
  function mobileVR(arkUrn: string, lviUrn: string, zOffset: number, spaceId: number) {
  
    let element = document.getElementById("mobileViewer");
    viewer = new Autodesk.Viewing.Private.GuiViewer3D(element);
    let options = {
      'env': 'AutodeskProduction',
      'getAccessToken': getToken,
      'refreshToken': getToken
    };
    av.Initializer(
      options,
      () =&gt; {
          viewer.initialize();
  
          loadDocument(arkUrn, zOffset);
          if (lviUrn != "") {
              loadDocument(lviUrn, zOffset);
          }            
          viewer.loadExtension('Autodesk.Viewing.WebVR');
       }
    );
  
    nodeId = spaceId;
    afterViewerEvents();
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/NRYaq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NRYaq.jpg" alt="Image 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/xo6sG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xo6sG.jpg" alt="Image 2"></a></p>