简体   繁体   English

如何在 Forge Viewer 中卸载默认扩展?

[英]How do I unload a deafult extension in Forge Viewer?

I tried to unload extension in Viewer from Autodesk, I call extension inside the callback from Viewing.Initializer, but it seems to Extensions in this part of code is not loaded yet.我试图从 Autodesk 的 Viewer 中卸载扩展,我在 Viewing.Initializer 的回调中调用了扩展,但似乎这部分代码中的扩展尚未加载。

var viewer;
var options = {
    env: 'AutodeskProduction',
    api: 'derivativeV2',  // for models uploaded to EMEA change this option to 'derivativeV2_EU'

    // Function to define the method to get the token and renew it
    getAccessToken: function (onTokenReady) {
        let token = '';
        let timeInSeconds = 3600; // TODO: Use value provided by Forge Authentication (OAuth) API

        // Code to get my token and time remaining
        onTokenReady(token, timeInSeconds);

    }
};

/**
 * Initializer function, when load the viewer
 */
Autodesk.Viewing.Initializer(options, function () {
    // Extensions
    var config3d = {
        extensions: ['forgeExtension', 'EventsTutorial', 'Autodesk.DocumentBrowser'],
    };

    // The dom element, where load the viewer
    var htmlDiv = document.getElementById('forgeViewer');
    viewer = new Autodesk.Viewing.GuiViewer3D(htmlDiv, config3d);


   //
   // Here I want to unload 'Autodesk.Explode'
   let explodeExtension = viewer.getExtension('Autodesk.Explode'); // explodeExtension is null
   explodeExtension.unload();
   //
   //

    var startedCode = viewer.start();
    if (startedCode > 0) {
        console.error('Failed to create a Viewer: WebGL not supported.');
        return;
    }

    console.log('Initialization complete, loading a model next...');
});

Any suggestion to unload a deafult Extension?卸载默认扩展的任何建议? I´m using V7 viewer, I tried in V6 with the same result.我正在使用 V7 查看器,我在 V6 中尝试了相同的结果。

You can use viewer events to make sure the extensions are there and can be unloaded.您可以使用查看器事件来确保扩展存在并且可以卸载。 Your unloading code is correct you just need to wait for the full geometry to load.您的卸载代码是正确的,您只需要等待加载完整的几何图形。 Using this viewer event you can unload the default extentions when the geometry is loaded使用此查看器事件,您可以在加载几何图形时卸载默认范围

viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, (x) =>  {
let explodeExtension = viewer.getExtension('Autodesk.Explode'); /
explodeExtension.unload();} );

This will unload the extension as soon as it loads.这将在加载后立即卸载扩展。

Alternativly you could prevent the extension from being loaded at all by unregistering it.或者,您可以通过取消注册来阻止加载扩展。 Autodesk.Viewing.theExtensionManager.unregisterExtension('Autodesk.Explode'); This would result in an error tho since the viewer is still trying to load the extensions but the viewer will still work as expected.这将导致错误,因为查看器仍在尝试加载扩展,但查看器仍会按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM