如何在Forge Viewer中卸载默认扩展? [英] How do I unload a deafult extension in Forge Viewer?

查看:0
本文介绍了如何在Forge Viewer中卸载默认扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Autodesk卸载查看器中的扩展,我从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...');
});

是否有任何建议卸载默认扩展? 我正在使用V7查看器,我在V6中尝试了同样的结果。

推荐答案

您可以使用查看器事件来确保扩展存在并且可以卸载。您的卸载代码是正确的,您只需要等待完整的几何图形加载。使用此查看器事件,您可以在加载几何时卸载默认扩展模块

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

这将在加载扩展后立即卸载它。

或者,您也可以通过取消注册来阻止加载扩展。Autodesk.Viewing.theExtensionManager.unregisterExtension('Autodesk.Explode');这将导致错误,因为查看器仍在尝试加载扩展,但查看器仍将按预期工作。

这篇关于如何在Forge Viewer中卸载默认扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆