无法获取 instanceTree Autodesk
Can not fetch instanceTree autodesk
我收到这个错误:Uncaught TypeError:> Cannot read 属性 'getRootId' of undefined
即使我正在使用 Autodesk.Viewing.GEOMETRY_LOADED_EVENT..仍然没有效果。
您不应该使用 instanceTree
数据结构,而是 functions/operations,这是受支持的方式。如果您需要枚举叶节点,请尝试类似于 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());
});
}
您只需要等待 Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT
被触发即可访问 instanceTree
:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
var instanceTree = model.getData().instanceTree //cool
})
我收到这个错误:Uncaught TypeError:> Cannot read 属性 'getRootId' of undefined 即使我正在使用 Autodesk.Viewing.GEOMETRY_LOADED_EVENT..仍然没有效果。
您不应该使用 instanceTree
数据结构,而是 functions/operations,这是受支持的方式。如果您需要枚举叶节点,请尝试类似于 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());
});
}
您只需要等待 Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT
被触发即可访问 instanceTree
:
viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
var instanceTree = model.getData().instanceTree //cool
})