模型聚合:在loadDocumentNode之后,扩展(选择)不起作用

时间:2020-01-30 07:08:54

标签: autodesk-forge autodesk-viewer

我正在使用以下代码使用Viewer3D.loadDocumentNode(API v7)加载其他模型,效果很好。但是我有两个问题:

Autodesk.Viewing.Document.load(`urn:${myURN}`, (doc) => {
                var viewables = doc.getRoot().getDefaultGeometry();
                viewer.loadDocumentNode(doc, viewables,{
                    placementTransform: (new THREE.Matrix4()).setPosition({x:0,y:0,z:0}),
                    keepCurrentModels: true,
                    globalOffset: {x:0,y:0,z:0}

                })
                .then( onLoadFinished );
            });

第一期:加载汇总模型后,不再触发我等待SELECTION_CHANGED_EVENT的扩展程序。

load() {
    this.onSelectionBinded = this.onSelectionEvent.bind(this);
    this.viewer.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, this.onSelectionBinded);
    console.log('ReactToEvents has been loaded');
    return true;
}

示例来自https://forge.autodesk.com/en/docs/viewer/v7/developers_guide/viewer_basics/events/

第二个问题:解析所选元素的另一个扩展未考虑聚合模型中的所选元素(选择数= 0)

onToolbarCreated() {
    // Create a new toolbar group if it doesn't exist
    this._group = this.viewer.toolbar.getControl('allMyAwesomeExtensionsToolbar');
    if (!this._group) {
        this._group = new Autodesk.Viewing.UI.ControlGroup('allMyAwesomeExtensionsToolbar');
        this.viewer.toolbar.addControl(this._group);
    }

    // Add a new button to the toolbar group
    this._button = new Autodesk.Viewing.UI.Button('handleSelectionExtensionButton');
    this._button.onClick = (ev) => {
        // Get current selection
        const selection = this.viewer.getSelection();
        this.viewer.clearSelection();
        // Anything selected?
        console.log("Clicked handleSelectionExtensionButton: ", selection.length);
        if (selection.length > 0) { ... }
    }
}

出于某种原因this.viewer.getSelection();忽略来自loadDocumentNode()的内容。

我尝试卸载/重新加载扩展,但仍然无法正常工作。

任何帮助,不胜感激!

1 个答案:

答案 0 :(得分:1)

稍后添加了对加载多个模型的支持,并且为了防止破坏向后兼容性,开发人员添加了应在多模型方案中使用的新API和事件名称。查找其中带有“聚合”字样的方法和事件,例如getAggregateSelectionAutodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENTAutodesk.Viewing.AGGREGATE_FIT_TO_VIEW_EVENT