UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

84 lines (81 loc) 2.91 kB
import { EventDispatcher } from "three/src/Three"; import { Camera } from "./Camera"; export class DuckThreeCamera { Nt; constructor(t, e) { this.Nt = t.transform; const r = Object.getOwnPropertyNames(e); for (const t of r) { const r = e[t]; Object.defineProperty(this, t, { get: () => r, set: r => { e[t] = r; }, configurable: true }); } const o = new Map; this.tc(e, o); for (const [t, r] of o) { this[t] = r.bind(e); } this.ec(); } tc(t, e) { const r = t.__proto__; if (t !== EventDispatcher.prototype) { this.tc(r, e); } const o = Object.getOwnPropertyNames(r); for (const t of o) { if (t === "constructor") continue; if (t.startsWith("_")) continue; const o = r[t]; e.set(t, o); } } ec() { const t = this.Nt; const e = t.unsafeGetObject3D(); const r = [ "id", "uuid", "name", "parent", "children", "up", "position", "rotation", "quaternion", "scale", "matrix", "matrixWorld" ]; for (let t = 0; t < r.length; ++t) { const o = r[t]; Object.defineProperty(this, o, { get: () => e[o], set: t => { e[o] = t; } }); } const o = [ "add", "applyMatrix4", "applyQuaternion", "attach", "clear", "getWorldDirection", "getWorldPosition", "getWorldQuaternion", "getWorldScale", "localToWorld", "remove", "removeFromParent", "rotateOnAxis", "rotateOnWorldAxis", "rotateX", "rotateY", "rotateZ", "setRotationFromAxisAngle", "setRotationFromEuler", "setRotationFromMatrix", "setRotationFromQuaternion", "translateOnAxis", "translateX", "translateY", "translateZ", "updateMatrix", "updateMatrixWorld", "updateWorldMatrix", "worldToLocal" ]; for (let t = 0; t < o.length; ++t) { const r = o[t]; this[r] = e[r].bind(e); } this.lookAt = (t, r, o) => { e.isCamera = true; if (typeof t === "number") { e.lookAt(t, r, o); } else { e.lookAt(t); } e.isCamera = false; }; } static duckPool=new Map; static createInterface(t) { if (t.threeCamera === null) { throw new Error("DuckThreeCamera must be constructed after Camera onEnable message called"); } let e = this.duckPool.get(t.threeCamera); if (!e) { e = new DuckThreeCamera(t, t.threeCamera); this.duckPool.set(t.threeCamera, e); } return e; } } Camera.removeCameraFromDuckPool = function(t) { DuckThreeCamera.duckPool.delete(t); };