【问题标题】:Forge Viewer as Extension for another viewerForge Viewer 作为另一个查看器的扩展
【发布时间】:2020-05-31 00:32:14
【问题描述】:

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

【问题讨论】:

    标签: autodesk-forge


    【解决方案1】:

    没有官方扩展可以在另一个中显示一个 Forge 查看器,但可以实现这一点。您可以重用查看器的其中一个 UI 组件(例如,DockingPanel,在此 tutorial 中也进行了说明),并在其中托管第二个查看器。

    以下是此类扩展程序的外观:

    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);
    

    【讨论】:

    • 好的,谢谢。但这不是我的问题的解决方案。我有一些问题,如果你能回答他们就太好了。
    • 我相信我的回答确实解决了最初的问题。随时编辑您的问题并添加更多详细信息,或向我们发送电子邮件至forge (dot) help (at) autodesk (dot) com,我们可以从那里获取。
    • 你是对的,事实上你的答案是我问题的解决方案,但我意识到这不是我问题的解决方案。我添加了另一个关于我的问题的问题。请看他。 stackoverflow.com/questions/60225809/…
    猜你喜欢
    • 2021-09-18
    • 2020-10-30
    • 2021-10-02
    • 2021-03-21
    • 2019-11-20
    • 2021-02-23
    • 1970-01-01
    • 2021-01-10
    • 2017-12-31
    相关资源
    最近更新 更多