@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
29 lines (28 loc) • 819 B
JavaScript
;
export class SelectionController {
constructor() {
this._map = /* @__PURE__ */ new Map();
this._resolvedObjects = [];
}
updateSelection(scene, objectsMask, selection) {
const foundObjects = scene.objectsByMask(objectsMask);
this._map.clear();
for (const object of foundObjects) {
this._map.set(object.uuid, object);
}
const isAncestorNotInList = (object) => {
let isAncestorInList = false;
object.traverseAncestors((ancestor) => {
if (this._map.has(ancestor.uuid)) {
isAncestorInList = true;
}
});
return !isAncestorInList;
};
this._resolvedObjects = foundObjects.filter(isAncestorNotInList);
selection.clear();
for (const object of this._resolvedObjects) {
selection.add(object);
}
}
}