遍历Autodesk Forge中模型的所有对象

问题描述

如何确定模型的所有对象以及如何在Forge Viewer中存储和以编程方式表示3D对象?

解决方法

要在Forge Viewer中迭代模型的场景层次结构,可以使用“实例树”,例如:

const instanceTree = viewer.model.getInstanceTree();
const rootNodeId = instanceTree.getRootId();
const traverseRecursively = true;
function callback(dbid) {
    console.log('Found object ID',dbid);
}
instanceTree.enumNodeChildren(rootNodeId,callback,traverseRecursively);

有关更多信息,请查看此博客文章:https://forge.autodesk.com/blog/working-2d-and-3d-scenes-and-geometry-forge-viewer