-->

Default Navigation speed in Forge Viewer

2020-04-22 02:10发布

问题:

How can the default navigation speed be changed in the Forge Viewer? The default setting is far to fast for my sample models. I should like to write code so that the speed may be changed during a session.

回答1:

Copy an existing navigation tool from the viewer3D.js implementation, modify the speed parameters as you wish or expose methods to do so dynamically from your app, then set it active.

You can check the implementation of OrbitDollyPanTool L#14545 in viewer3D.js

Autodesk.Viewing.OrbitDollyPanTool = function( viewerImpl, viewerApi ){
    var avp = Autodesk.Viewing.Private;
    var _this = this;
    var kScreenEpsilon = 0.001;
    var kEpsilon = 0.00001;
    var kAutoDeltaZ  = 1.5;         // Dolly increment
    var kAutoDeltaXY = 0.01;
    var kAutoScreenXY = 20;
    var kDollyDragScale = 100.0;
    var kDollyPinchScale = 0.5;
    var kOrbitScale = 2.0;

    // ...

That tool is instantiated as follow (L#40923):

Viewer3D.prototype.createControls = function( ) {
    var self = this;
    var impl = self.impl;

    self.navigation = new av.Navigation(impl.camera);
    self.__initAutoCam(impl);

    self.utilities = new av.ViewingUtilities(impl, self.autocam, self.navigation);
    self.clickHandler = new av.DefaultHandler(impl, self.navigation, self.utilities);
    self.toolController = new av.ToolController(impl, self, self.autocam, self.utilities, self.clickHandler);
    self.toolController.registerTool( new av.GestureHandler(self) );

    self.toolController.registerTool( av.theHotkeyManager );
    self.toolController.activateTool( av.theHotkeyManager.getName() );

    self.registerUniversalHotkeys();

    self.toolController.registerTool( new av.OrbitDollyPanTool(impl, self) );
    self.toolController.activateTool( "gestures" );

    return self.toolController;
}; 


回答2:

I recently found out that you can use viewer.navigation.fitBounds(true, THREE.Box3) which will impact the navigation speed to match the extends defined by those bounds.