mylingo3d
Version:
Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor
66 lines • 2.03 kB
JavaScript
import { Disposable } from "@lincode/promiselikes";
import { Object3D } from "three";
import { emitSceneGraphChange } from "../../events/onSceneGraphChange";
export const appendableRoot = new Set();
export const hiddenAppendables = new WeakSet();
export default class Appendable extends Disposable {
outerObject3d;
nativeObject3d;
constructor(outerObject3d = new Object3D()) {
super();
this.outerObject3d = outerObject3d;
outerObject3d.userData.manager = this;
this.nativeObject3d = outerObject3d;
appendableRoot.add(this);
emitSceneGraphChange();
}
get uuid() {
return this.outerObject3d.uuid;
}
parent;
children;
_append(child) {
appendableRoot.delete(child);
emitSceneGraphChange();
child.parent?.children?.delete(child);
child.parent = this;
(this.children ??= new Set()).add(child);
}
traverse(cb) {
for (const child of this.children ?? []) {
cb(child);
child.traverse(cb);
}
}
traverseSome(cb) {
for (const child of this.children ?? []) {
if (cb(child))
return true;
child.traverseSome(cb);
}
return false;
}
append(child) {
this._append(child);
this.outerObject3d.add(child.outerObject3d);
}
attach(child) {
this._append(child);
this.outerObject3d.attach(child.outerObject3d);
}
dispose() {
if (this.done)
return this;
super.dispose();
appendableRoot.delete(this);
emitSceneGraphChange();
this.parent?.children?.delete(this);
this.parent = undefined;
this.outerObject3d.parent?.remove(this.outerObject3d);
if (this.children)
for (const child of this.children)
child.dispose();
return this;
}
}
//# sourceMappingURL=Appendable.js.map