【问题标题】:Can not fetch instanceTree autodesk无法获取 instanceTree Autodesk
【发布时间】:2018-02-05 05:18:52
【问题描述】:

我收到此错误:未捕获的 TypeError:> 无法读取未定义的属性“getRootId” 即使我正在使用 Autodesk.Viewing.GEOMETRY_LOADED_EVENT.. 仍然没有效果。

【问题讨论】:

标签: javascript autodesk-forge autodesk autodesk-viewer


【解决方案1】:

当你想访问instanceTree时,你只需要等待Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT被触发:

viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {

  var instanceTree = model.getData().instanceTree //cool
})

【讨论】:

    【解决方案2】:

    您不应该使用instanceTree 数据结构,而是使用受支持的功能/操作。如果您需要枚举叶节点,请尝试类似于described here

    function getAllLeafComponents(viewer, callback) {
        var cbCount = 0; // count pending callbacks
        var components = []; // store the results
        var tree; // the instance tree
    
        function getLeafComponentsRec(parent) {
            cbCount++;
            if (tree.getChildCount(parent) != 0) {
                tree.enumNodeChildren(parent, function (children) {
                    getLeafComponentsRec(children);
                }, false);
            } else {
                components.push(parent);
            }
            if (--cbCount == 0) callback(components);
        }
        viewer.getObjectTree(function (objectTree) {
            tree = objectTree;
            var allLeafComponents = getLeafComponentsRec(tree.getRootId());
        });
    }
    

    【讨论】:

    • function waitForElement(){ if(instanceTree.getRootId() !== "undefined"){... } else{ setTimeout(waitForElement, 250); } };
    • Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT?
    • 问题就像javascript没有等到几何加载..我已经通过等待函数解决了它,就像我提到的那样,它已经解决了..我可以尝试你提供的解决方案..但是我的整个代码依赖于实例树,我现在不想更改它..谢谢。
    猜你喜欢
    • 2020-09-06
    • 2020-09-09
    • 2018-06-05
    • 2021-03-01
    • 2021-03-13
    • 2023-02-09
    • 2020-09-14
    • 2018-02-27
    • 2016-12-20
    相关资源
    最近更新 更多