拥有两个查看器时在两个 Forge Viewer 中运行相同的轨道

Orbiting same in both Forge Viewer while having two viewer

我的应用程序中有两个查看器,我希望他们都以相同的位置和摄像机角度绕同一轨道运行,并且在放大和缩小时也遵循相同的方向。

有什么办法吗?

我已经应用了以下解决方案,但它延迟了一秒钟。

viewer2.addEventListener(Autodesk.Viewing.CAMERA_CHANGE_EVENT, function()
       {
        if(!viewer1CameraChangeMutex) {
              clearTimeout(viewer2CameraChangeMutex);
              viewer.restoreState(viewer2.getState());
              viewer2CameraChangeMutex=setTimeout(function(){viewer2CameraChangeMutex=undefined},1000)
           }
       });
viewer.addEventListener(Autodesk.Viewing.CAMERA_CHANGE_EVENT, function()
       {
        if(!viewer2CameraChangeMutex) {
               clearTimeout(viewer1CameraChangeMutex);
               viewer2.restoreState(viewer.getState());
               viewer1CameraChangeMutex=setTimeout(function(){viewer1CameraChangeMutex=undefined},1000)
           }
        });

您可以阻止不必要的事件乒乓 b/w 观众,例如更改查看器 1 上的视图 --> 更改查看器 1 上的事件,然后将视图状态设置为查看器 2 --> 更改查看器 2 上的事件,然后更改查看器 1 状态 --> 更改查看器 1 上的事件......,通过比较视口状态和仅当视口状态不同时才将视图状态设置为其他查看器。

下面是用于上述解释的示例代码片段。

    function compare(stateA, stateB)
    {
        var viewportA = stateA["viewport"] || {};
        var viewportB = stateB["viewport"] || {};

        //compare all members of viewportA and viewportB, return true when all members are same. 
       if( viewportA["name"] !== viewportB["name"] ||
            viewportA["projection"] !== viewportB["projection"] ||
            viewportA["isOrthographic"] !== viewportB["isOrthographic"] ||
            .......//compare all other members of viewport. 
                   //Please note you need to afforded small numeric error for numeric value comparison.
             )
       {

            return false;
       }
       
       return true;
    }


    var sfilter = {
       viewport: true
    };

    viewer3d1.addEventListener(Autodesk.Viewing.CAMERA_CHANGE_EVENT, function () {
        var v1state = viewer3d1.getState(sfilter);
        var v2state = viewer3d2.getState(sfilter);

        if (!compare(v1state, v2state)) {
            viewer3d2.restoreState(viewer3d1.getState(sfilter), sfilter, true);
        }
    });

    viewer3d2.addEventListener(Autodesk.Viewing.CAMERA_CHANGE_EVENT, function () {
        var v1state = viewer3d1.getState(sfilter);
        var v2state = viewer3d2.getState(sfilter);
        if (!compare(v1state, v2state)) {
            viewer3d1.restoreState(viewer3d2.getState(sfilter), sfilter, true);
        }
    });