UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

49 lines (48 loc) 1.37 kB
import {NodeEvent as NodeEvent2} from "../engine/poly/NodeEvent"; import {ArrayUtils as ArrayUtils2} from "./ArrayUtils"; export class CoreNodeSelection { constructor(_node) { this._node = _node; this._node_ids = []; this._json = []; } node() { return this._node; } nodes() { return this._node.scene().graph.nodes_from_ids(this._node_ids); } contains(node) { return this._node_ids.includes(node.graphNodeId()); } equals(nodes) { const node_ids = nodes.map((node) => node.graphNodeId()).sort(); return ArrayUtils2.isEqual(node_ids, this._node_ids); } clear() { this._node_ids = []; this.send_update_event(); } set(nodes) { this._node_ids = []; this.add(nodes); } add(nodes_to_add) { const node_ids_to_add = nodes_to_add.map((node) => node.graphNodeId()); this._node_ids = ArrayUtils2.union(this._node_ids, node_ids_to_add); this.send_update_event(); } remove(nodes_to_remove) { const node_ids_to_remove = nodes_to_remove.map((node) => node.graphNodeId()); this._node_ids = ArrayUtils2.difference(this._node_ids, node_ids_to_remove); this.send_update_event(); } send_update_event() { this._node.emit(NodeEvent2.SELECTION_UPDATED); } toJSON() { this._json = this._json || []; this._json = this._node_ids.map((id) => id); return this._json; } }