依照需求將指定物件變色,並透過isolate物件強調物件與模型的相對關係
透過程式碼第二行綁定隔離事件和自訂函數
var instanceTree = _viewer.model.getData().instanceTree;
_viewer.addEventListener(Autodesk.Viewing.ISOLATE_EVENT,colorIsolate);
function colorIsolate(){
var rootId = this.rootId = instanceTree.getRootId();
var allobjects=getAlldbIds(rootId);
_viewer.restoreColorMaterial(allobjects);
_viewer.setColorMaterial(_viewer.getIsolatedNodes(),0xff0000);
}
function getAlldbIds (rootId) {
var alldbId = [];
if (!rootId) {
return alldbId;
}
var queue = [];
queue.push(rootId);
while (queue.length > 0) {
var node = queue.shift();
alldbId.push(node);
instanceTree.enumNodeChildren(node, function(childrenIds) {
queue.push(childrenIds);
});
}
return alldbId;
}
測試:綁定點擊事件與變色函數,將點選物件變色
NOP_VIEWER.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, Onselectchange);
function Onselectchange(){
var selected = NOP_VIEWER.getSelection();
NOP_VIEWER.restoreColorMaterial(selected);
NOP_VIEWER.setColorMaterial(selected,#bacfef);
}
參考:
遇到問題最可怕的不是被問倒,而是自己選擇逃避