简体   繁体   English

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

[英]Forge Viewer as Extension for another viewer

We have a two forge viewers in one div.我们在一个 div 中有两个伪造查看器。 We has initialize those viewers same time and showing different models.我们同时初始化了这些查看器并显示了不同的模型。 Is it possible to initialize Autodesk Forge viewer as extension for another viewer and show in that viewers different models?是否可以将 Autodesk Forge 查看器初始化为另一个查看器的扩展并在该查看器中显示不同的模型?

There is no official extension for showing one Forge Viewer inside another, but implementing this is possible.没有用于在另一个内部显示一个 Forge Viewer 的官方扩展,但实现这一点是可能的。 You could reuse one of the UI components of the viewer (for example, DockingPanel , also explained in this tutorial ), and host the second viewer in it.您可以重用查看器的 UI 组件之一(例如DockingPanel ,也在本教程中进行了解释),并在其中托管第二个查看器。

Here's how such an extension might look like:以下是此类扩展的外观:

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