UNPKG

mylingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

51 lines 1.92 kB
import { Reactive } from "@lincode/reactivity"; import { debounceInstance } from "@lincode/utils"; import { onSceneGraphChange } from "../../events/onSceneGraphChange"; import CameraBase from "./CameraBase"; import { isMeshItem } from "./MeshItem"; const attachSet = new WeakSet(); export default class OrbitCameraBase extends CameraBase { constructor(camera) { super(camera); this.createEffect(() => { const target = this.targetState.get(); if (!target) return; const handle = onSceneGraphChange(() => target.parent !== this && this.retarget()); return () => { handle.cancel(); }; }, [this.targetState.get]); } manualTarget; targetState = new Reactive(undefined); static retaget = debounceInstance((instance) => { let target = instance.manualTarget; for (const child of instance.children ?? []) if (target) { if (child.outerObject3d.parent !== instance.camera) instance.camera[attachSet.has(child) ? "attach" : "add"](child.outerObject3d); } else if (isMeshItem(child)) { target = child; const { parent } = instance.outerObject3d; if (parent && child.outerObject3d.parent !== parent) parent[attachSet.has(target) ? "attach" : "add"](target.outerObject3d); } instance.targetState.set(target); }, 0, "trailing"); retarget() { OrbitCameraBase.retaget(this, this); } append(object) { this._append(object); attachSet.delete(object); this.retarget(); } attach(object) { this._append(object); attachSet.add(object); this.retarget(); } } //# sourceMappingURL=OrbitCameraBase.js.map