【问题标题】:How to get dbId of only visible objects in Viewer?如何在查看器中仅获取可见对象的 dbId?
【发布时间】:2023-04-07 13:30:01
【问题描述】:

我可以通过

获取查看器中所有项目的dbId
const tree = viewerApp.myCurrentViewer.model.getData().instanceTree;
const dbIndices = Object.values(tree.nodeAccess.dbIdToIndex).slice(1);

但对于从 Revit 导入的模型,它们的数量远大于查看器中实际可见的对象(例如,对于仅包含三面墙的项目,此数量约为 3,500)。如何获得只有可见对象的 dbId?

【问题讨论】:

    标签: javascript autodesk-forge autodesk-viewer


    【解决方案1】:

    默认情况下,加载模型时所有节点(要为查看器渲染的资产)都是可见的。除了对应于 Revit 组件的 UniqueIDexternalId 之外,每个节点都可以由唯一的 dbid 唯一标识。

    所以您观察到的额外dbids 实际上是父节点。要隔离它们,请参阅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());
        });
    }
    

    【讨论】:

    • 它工作正常。唯一的一点是仅在加载可视化树后调用此方法。为此我使用viewer.addEventListener(window.Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, callBack)
    猜你喜欢
    • 2017-02-13
    • 2020-07-05
    • 2015-07-25
    • 2021-09-06
    • 2019-07-31
    • 1970-01-01
    • 2018-05-05
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多