繁体   English   中英

Forge Viewer 作为另一个查看器的扩展

[英]Forge Viewer as Extension for another viewer

我们在一个 div 中有两个伪造查看器。 我们同时初始化了这些查看器并显示了不同的模型。 是否可以将 Autodesk Forge 查看器初始化为另一个查看器的扩展并在该查看器中显示不同的模型?

没有用于在另一个内部显示一个 Forge Viewer 的官方扩展,但实现这一点是可能的。 您可以重用查看器的 UI 组件之一(例如DockingPanel ,也在本教程中进行了解释),并在其中托管第二个查看器。

以下是此类扩展的外观:

class MyExtension extends Autodesk.Viewing.Extension {
    constructor(viewer, options) {
        super(viewer, options);
        this._group = null;
        this._button = null;
        this._panel = null;
    }

    load() {
        return true;
    }

    unload() {
        return true;
    }

    onToolbarCreated() {
        this._group = new Autodesk.Viewing.UI.ControlGroup('allMyAwesomeExtensionsToolbar');
        this._button = new Autodesk.Viewing.UI.Button('MyExtensionButton');
        this._button.setToolTip('My Extension Button');
        this._group.addControl(this._button);
        this._panel = new MyPanel(this.viewer, this.viewer.container, 'MyPanel', 'My Panel Title');
        this._button.onClick = (ev) => {
            this._panel.setVisible(true);
        };
        this.viewer.toolbar.addControl(this._group);
    }
}

class MyPanel extends Autodesk.Viewing.UI.DockingPanel {
    constructor(viewer, container, id, title, options) {
        super(container, id, title, options);
        this.viewer = viewer;
        this.secondViewer = null;
        this.container.style.width = '640px';
        this.container.style.height = '480px';
        this.container.style.left = '1em';
        this.container.style.top = '1em';
    }

    setVisible(show) {
        super.setVisible(show);
        if (show && !this.secondViewer) {
            this.secondViewer = new Autodesk.Viewing.GuiViewer3D(this.container);
            this.secondViewer.start();
            Autodesk.Viewing.Document.load(
                'urn:<your model urn>',
                this.onDocumentLoadSuccess.bind(this),
                this.onDocumentLoadFailure.bind(this)
            );
        }
    }

    onDocumentLoadSuccess(doc) {
        const viewables = doc.getRoot().getDefaultGeometry();
        this.secondViewer.loadDocumentNode(doc, viewables);
    }

    onDocumentLoadFailure(viewerErrorCode) {
        console.error('onDocumentLoadFailure() - errorCode:' + viewerErrorCode);
    }
}

Autodesk.Viewing.theExtensionManager.registerExtension('MyExtension', MyExtension);

在此处输入图片说明

暂无
暂无

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

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