0

I want to know that fitToView() finished completely.
Some program procedures do not work after fitToView() without setTimeout(). For example, the following code not work.

const dbid = [1141]
this.viewer.select(dbid)
this.viewer.fitToView(dbid, viewer.model)
zoom() //This will not work

//code from: 
function zoom (){
    var nav = viewer.navigation
    var pos = nav.getPosition()
    var target = nav.getTarget()
    var viewdir = new THREE.Vector3()
    viewdir.subVectors (pos, target).normalize()
    // zooms out by 100 along the view direction
    viewdir.multiplyScalar (1000)
    pos.add(viewdir)
    nav.setPosition(pos)
}

The following code work well.

this.viewer.fitToView(dbid, viewer.model)
setTimeout(function(){
    zoom() //This will work fine
}, 2000)

However, I don't want to use the setTimeout as much as possible.
Is there a way to know that fitToView () is finished completely?

k-oshima
  • 37
  • 4

1 Answers1

1

If you use version 3.2.1 of the viewer a new event Autodesk.Viewing.CAMERA_TRANSITION_COMPLETED, it will be fired while following transitions are finished:

Go Home transition Focus / Fit to View transition Restore State transition Named Views transition Any other camera transitions

// Hook the event

viewer.addEventListener(Autodesk.Viewing.CAMERA_TRANSITION_COMPLETED, function(){
console.log('camera is no longer moving');

});

// Trigger an action that will move the camera and fire the event

viewer.fitToView();

You can see more about the Viewer Version changes here. https://developer.autodesk.com/en/docs/viewer/v2/overview/changelog/3.2.1/

Jaime Rosales
  • 1,106
  • 1
  • 6
  • 8