@skewedaspect/sage 0.10.0-beta.1 → 0.10.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/behaviors/sound.d.ts +22 -0
  2. package/dist/classes/gameEngine.d.ts +7 -0
  3. package/dist/classes/gameLevel.d.ts +6 -0
  4. package/dist/classes/level.d.ts +19 -0
  5. package/dist/debug/builtins.d.ts +0 -4
  6. package/dist/entities/entityPicking.d.ts +1 -0
  7. package/dist/entities/nodeEntity.d.ts +10 -0
  8. package/dist/entities/nodeSimulation.d.ts +9 -1
  9. package/dist/entities/nodeSimulationContext.d.ts +4 -0
  10. package/dist/events/payloads.d.ts +0 -12
  11. package/dist/input/actionContext.d.ts +2 -0
  12. package/dist/input/binding.d.ts +3 -1
  13. package/dist/input/bindings/delta.d.ts +23 -0
  14. package/dist/input/bindings/toggle.d.ts +5 -1
  15. package/dist/input/bindings/trigger.d.ts +5 -1
  16. package/dist/input/bindings/value.d.ts +7 -4
  17. package/dist/input/deliverAction.d.ts +3 -2
  18. package/dist/input/deviceReaders/mouse.d.ts +1 -1
  19. package/dist/input/deviceState.d.ts +5 -0
  20. package/dist/interfaces/game.d.ts +1 -1
  21. package/dist/interfaces/level.d.ts +2 -2
  22. package/dist/managers/asset.d.ts +17 -3
  23. package/dist/managers/game.d.ts +8 -1
  24. package/dist/managers/input.d.ts +34 -0
  25. package/dist/managers/level.d.ts +14 -0
  26. package/dist/managers/simulationSave.d.ts +10 -2
  27. package/dist/{postProcessingFrameGraph-rr2DbgPi.js → postProcessingFrameGraph-C3Og4kaS.js} +34 -26
  28. package/dist/postProcessingFrameGraph-C3Og4kaS.js.map +1 -0
  29. package/dist/sage.d.ts +13 -5
  30. package/dist/sage.es.js +919 -429
  31. package/dist/sage.es.js.map +1 -1
  32. package/dist/sage.umd.js +1 -1
  33. package/dist/sage.umd.js.map +1 -1
  34. package/dist/utils/bounds.d.ts +11 -0
  35. package/package.json +1 -1
  36. package/dist/postProcessingFrameGraph-rr2DbgPi.js.map +0 -1
package/dist/sage.es.js CHANGED
@@ -1,11 +1,11 @@
1
- import { AbstractMesh as e, ActionManager as t, ArcRotateCamera as n, Color3 as r, Color4 as i, CreateAudioEngineAsync as a, CubeTexture as o, DefaultRenderingPipeline as s, DirectionalLight as c, Engine as l, ExecuteCodeAction as u, FreeCamera as d, HDRCubeTexture as f, HavokPlugin as p, HemisphericLight as m, ImageProcessingConfiguration as h, ImportMeshAsync as ee, LoadAssetContainerAsync as g, Matrix as _, Mesh as v, MeshBuilder as y, NullEngine as b, PBRMaterial as x, PhysicsAggregate as te, PhysicsShapeType as S, PointLight as ne, Quaternion as C, RectAreaLight as w, SSAO2RenderingPipeline as re, Scene as ie, SelectionOutlineLayer as ae, SoundState as oe, SpotLight as se, StandardMaterial as T, Texture as ce, TransformNode as E, UniversalCamera as le, Vector3 as D, WebGPUEngine as ue } from "@babylonjs/core";
2
- import { registerBuiltInLoaders as de } from "@babylonjs/loaders/dynamic";
3
- import { GeospatialCamera as fe } from "@babylonjs/core/Cameras/geospatialCamera";
4
- import { ClusteredLightContainer as pe } from "@babylonjs/core/Lights/Clustered/clusteredLightContainer";
5
- import { PhysicsViewer as me } from "@babylonjs/core/Debug/physicsViewer";
6
- import he from "@babylonjs/havok";
1
+ import { AbstractMesh as e, ActionManager as t, ArcRotateCamera as n, Color3 as r, Color4 as i, CreateAudioEngineAsync as a, CubeTexture as o, DefaultRenderingPipeline as s, DirectionalLight as c, Engine as l, ExecuteCodeAction as u, FreeCamera as d, HDRCubeTexture as f, HavokPlugin as p, HemisphericLight as m, ImageProcessingConfiguration as h, ImportMeshAsync as g, LoadAssetContainerAsync as ee, Matrix as _, Mesh as v, MeshBuilder as y, NullEngine as b, PBRMaterial as x, PhysicsAggregate as S, PhysicsShapeType as C, PointLight as te, Quaternion as w, RectAreaLight as ne, SSAO2RenderingPipeline as re, Scene as ie, SelectionOutlineLayer as ae, SoundState as oe, SpotLight as T, StandardMaterial as E, Texture as se, TransformNode as D, UniversalCamera as ce, Vector3 as O, WebGPUEngine as le } from "@babylonjs/core";
2
+ import { registerBuiltInLoaders as ue } from "@babylonjs/loaders/dynamic";
3
+ import { GeospatialCamera as de } from "@babylonjs/core/Cameras/geospatialCamera";
4
+ import { ClusteredLightContainer as fe } from "@babylonjs/core/Lights/Clustered/clusteredLightContainer";
5
+ import { PhysicsViewer as pe } from "@babylonjs/core/Debug/physicsViewer";
6
+ import me from "@babylonjs/havok";
7
7
  //#region src/classes/debugConsole.ts
8
- var O = class {
8
+ var he = class {
9
9
  _namespaceName;
10
10
  _entries = /* @__PURE__ */ new Map();
11
11
  _disposed = !1;
@@ -62,7 +62,7 @@ var O = class {
62
62
  configurable: !0
63
63
  });
64
64
  }
65
- }, k = "0.10.0-beta.1", A = class {
65
+ }, k = "0.10.0-beta.2", ge = class {
66
66
  canvas;
67
67
  renderEngine;
68
68
  physics;
@@ -75,6 +75,7 @@ var O = class {
75
75
  debug;
76
76
  largeWorldRendering;
77
77
  started = !1;
78
+ _stopped = !1;
78
79
  _log;
79
80
  _buildSimulation;
80
81
  _beforeStartHook = null;
@@ -109,8 +110,9 @@ var O = class {
109
110
  this.started ? this._log.warn("Game engine is already started. Skipping start.") : (this._log.info(`Starting SkewedAspect Game Engine (Version: ${k})...`), this._beforeStartHook && (this._log.debug("Executing beforeStart hook..."), await this._beforeStartHook(this)), await this.managers.gameManager.start(), this._log.info("Game engine started successfully"), this._onStartHook && (this._log.debug("Executing onStart hook..."), await this._onStartHook(this)), this.started = !0);
110
111
  }
111
112
  async stop() {
112
- if (this.started) {
113
- this._log.info(`Stopping SkewedAspect Game Engine (Version: ${k})...`);
113
+ if (this._stopped) this._log.warn("Game engine is already stopped. Skipping stop.");
114
+ else {
115
+ this._stopped = !0, this._log.info(`Stopping SkewedAspect Game Engine (Version: ${k})...`);
114
116
  let e = null;
115
117
  if (this._onTeardownHook) try {
116
118
  this._log.debug("Executing onTeardown hook..."), await this._onTeardownHook(this);
@@ -135,9 +137,9 @@ var O = class {
135
137
  }
136
138
  }
137
139
  if (this.started = !1, this._log.info("Game engine stopped successfully"), e) throw e;
138
- } else this._log.warn("Game engine is not started. Skipping stop.");
140
+ }
139
141
  }
140
- }, j = class {
142
+ }, _e = class {
141
143
  timers;
142
144
  constructor() {
143
145
  this.timers = /* @__PURE__ */ new Map();
@@ -196,7 +198,7 @@ var O = class {
196
198
  console.info(`${a} Timer '${t}' completed in ${i.toFixed(2)}ms`, o, s, c);
197
199
  } else console.warn(`[${e}]: Timer '${t}' does not exist`);
198
200
  }
199
- }, M = class {
201
+ }, A = class {
200
202
  trace(e, t, ...n) {}
201
203
  debug(e, t, ...n) {}
202
204
  info(e, t, ...n) {}
@@ -204,11 +206,11 @@ var O = class {
204
206
  error(e, t, ...n) {}
205
207
  time(e, t) {}
206
208
  timeEnd(e, t) {}
207
- }, N = class {
209
+ }, j = class {
208
210
  category;
209
211
  backend;
210
212
  minLevel;
211
- constructor(e, t = "none", n = new M()) {
213
+ constructor(e, t = "none", n = new A()) {
212
214
  this.category = e, this.backend = n, this.minLevel = t;
213
215
  }
214
216
  updateSettings(e, t) {
@@ -246,21 +248,21 @@ var O = class {
246
248
  default: return !1;
247
249
  }
248
250
  }
249
- }, P = class {
251
+ }, M = class {
250
252
  backend;
251
253
  level;
252
254
  loggers;
253
- constructor(e = "debug", t = new j()) {
255
+ constructor(e = "debug", t = new _e()) {
254
256
  this.backend = t, this.level = e, this.loggers = /* @__PURE__ */ new Map();
255
257
  }
256
258
  setBackend(e) {
257
259
  this.backend = e, this.loggers.forEach((e) => {
258
- e instanceof N && e.updateSettings(this.backend, this.level);
260
+ e instanceof j && e.updateSettings(this.backend, this.level);
259
261
  });
260
262
  }
261
263
  setLevel(e) {
262
264
  this.level = e, this.loggers.forEach((e) => {
263
- e instanceof N && e.updateSettings(this.backend, this.level);
265
+ e instanceof j && e.updateSettings(this.backend, this.level);
264
266
  });
265
267
  }
266
268
  getLevel() {
@@ -268,14 +270,14 @@ var O = class {
268
270
  }
269
271
  getLogger(e) {
270
272
  let t = this.loggers.get(e);
271
- return t || (t = new N(e, this.level, this.backend), this.loggers.set(e, t)), t;
273
+ return t || (t = new j(e, this.level, this.backend), this.loggers.set(e, t)), t;
272
274
  }
273
- }, F = class {
275
+ }, N = class {
274
276
  directMap = /* @__PURE__ */ new Map();
275
277
  patternSubs = /* @__PURE__ */ new Set();
276
278
  _log;
277
279
  constructor(e) {
278
- this._log = e?.getLogger("EventBus") || new N("EventBus");
280
+ this._log = e?.getLogger("EventBus") || new j("EventBus");
279
281
  }
280
282
  subscribe(e, t) {
281
283
  return this._log.trace(`Subscribe request for: ${e.toString()}`), e instanceof RegExp || typeof e == "string" && e.includes("*") ? this.subscribePattern(e, t) : this.subscribeExact(e, t);
@@ -320,12 +322,30 @@ var O = class {
320
322
  async $teardown() {
321
323
  this._log.debug("Tearing down EventBus"), this.directMap.clear(), this.patternSubs.clear();
322
324
  }
323
- }, ge = class {};
325
+ }, P = class {}, F = class extends P {
326
+ defaults = { displayName: "" };
327
+ };
328
+ function ve(e, t) {
329
+ return t;
330
+ }
331
+ var ye = class extends P {
332
+ static ops = ["transitionTo"];
333
+ onUpdate(e) {
334
+ let t = this.state.currentState;
335
+ this.states[t].update?.call(this, e);
336
+ }
337
+ transitionTo(e) {
338
+ if (!(e in this.states)) throw Error(`StateMachineBehavior: no state named "${e}" is declared.`);
339
+ if (e === this.state.currentState) return;
340
+ let t = this.state.currentState;
341
+ this.states[t].exit?.call(this, e), this.state.currentState = e, this.states[e].enter?.call(this, t);
342
+ }
343
+ }, be = 32, xe = 64, Se = 5;
324
344
  function I(e) {
325
345
  let t = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\*/g, ".*");
326
346
  return RegExp(`^${t}$`);
327
347
  }
328
- var _e = class e {
348
+ var L = class e {
329
349
  #e = [];
330
350
  #t = [];
331
351
  #n = /* @__PURE__ */ new Map();
@@ -404,23 +424,31 @@ var _e = class e {
404
424
  }
405
425
  }
406
426
  };
407
- function L(e) {
427
+ function R(e, t) {
428
+ throw TypeError(`Entity "${e}" state holds a value that is not finite JSON-compatible data at "${t}".`);
429
+ }
430
+ function z(e, t, n, r) {
431
+ if (e === null || typeof e == "string" || typeof e == "boolean") return e;
432
+ if (typeof e == "number") return Number.isFinite(e) || R(t, n), e;
408
433
  if (Array.isArray(e)) {
409
- let t = [];
410
- for (let n of e) t.push(L(n));
411
- return t;
412
- }
413
- if (typeof e == "object" && e) {
414
- let t = Object.create(null);
415
- for (let [n, r] of Object.entries(e)) t[n] = L(r);
416
- return t;
417
- }
418
- return e;
434
+ r.has(e) && R(t, n), r.add(e);
435
+ let i = [];
436
+ for (let [a, o] of e.entries()) i.push(z(o, t, `${n}[${a}]`, r));
437
+ return r.delete(e), i;
438
+ }
439
+ if (typeof e == "object") {
440
+ let i = Object.getPrototypeOf(e);
441
+ (i !== Object.prototype && i !== null || r.has(e)) && R(t, n), r.add(e);
442
+ let a = Object.create(null);
443
+ for (let [i, o] of Object.entries(e)) a[i] = z(o, t, n === "" ? i : `${n}.${i}`, r);
444
+ return r.delete(e), a;
445
+ }
446
+ return R(t, n);
419
447
  }
420
- function R(e) {
421
- return L(e);
448
+ function B(e, t) {
449
+ return z(e, t, "", /* @__PURE__ */ new Set());
422
450
  }
423
- var z = class e {
451
+ var Ce = class e {
424
452
  id;
425
453
  name;
426
454
  context;
@@ -485,7 +513,7 @@ var z = class e {
485
513
  }
486
514
  receive(t) {
487
515
  let n = t;
488
- for (let r of this.#t) if (e.#g(r, n.type) && r.instance.onEvent?.(t) === !0) return !0;
516
+ for (let r of this.#t) if (e.#f(r, n.type) && r.instance.onEvent?.(t) === !0) return !0;
489
517
  return !1;
490
518
  }
491
519
  destroy() {
@@ -539,14 +567,10 @@ var z = class e {
539
567
  static #u(t, n, r) {
540
568
  let i = Object.create(null);
541
569
  i.tags = [];
542
- for (let n of t) Object.assign(i, e.#d(n.defaults, r));
543
- return Object.assign(i, e.#d(n, r)), e.#f(i, r), i;
570
+ for (let e of t) Object.assign(i, B(e.defaults, r));
571
+ return Object.assign(i, B(n, r)), e.#d(i, r), i;
544
572
  }
545
- static #d(t, n) {
546
- if (!e.#h(t, /* @__PURE__ */ new Set())) throw TypeError(`Entity "${n}" state holds a value that is not finite JSON-compatible data.`);
547
- return R(t);
548
- }
549
- static #f(e, t) {
573
+ static #d(e, t) {
550
574
  let n = e.tags;
551
575
  if (!Array.isArray(n)) throw TypeError(`Entity "${t}" tags must be a list of strings.`);
552
576
  let r = [];
@@ -556,29 +580,13 @@ var z = class e {
556
580
  r.push(e);
557
581
  }
558
582
  }
559
- static #p(t, n) {
560
- return t === null || typeof t == "string" || typeof t == "boolean" ? !0 : typeof t == "number" ? Number.isFinite(t) : Array.isArray(t) ? e.#m(t, n) : typeof t == "object" && e.#h(t, n);
561
- }
562
- static #m(t, n) {
563
- if (n.has(t)) return !1;
564
- n.add(t);
565
- for (let r of t) if (!e.#p(r, n)) return n.delete(t), !1;
566
- return n.delete(t), !0;
567
- }
568
- static #h(t, n) {
569
- let r = Object.getPrototypeOf(t);
570
- if (r !== Object.prototype && r !== null || n.has(t)) return !1;
571
- n.add(t);
572
- for (let r of Object.values(t)) if (!e.#p(r, n)) return n.delete(t), !1;
573
- return n.delete(t), !0;
574
- }
575
- static #g(e, t) {
583
+ static #f(e, t) {
576
584
  if (e.exact.includes(t)) return !0;
577
585
  for (let n of e.patterns) if (n.test(t)) return !0;
578
586
  return !1;
579
587
  }
580
- }, B = class e {
581
- #e = new _e();
588
+ }, we = class e {
589
+ #e = new L();
582
590
  #t;
583
591
  #n;
584
592
  #r;
@@ -630,7 +638,7 @@ var z = class e {
630
638
  for (let t of this.#s) e.push({
631
639
  id: t.id,
632
640
  name: t.name,
633
- state: R(t.state)
641
+ state: B(t.state, t.id)
634
642
  });
635
643
  return {
636
644
  tick: this.#i,
@@ -684,7 +692,7 @@ var z = class e {
684
692
  static #p(e) {
685
693
  return e.state;
686
694
  }
687
- }, V = class e extends z {
695
+ }, V = /* @__PURE__ */ new WeakMap(), H = class e extends Ce {
688
696
  static poolable = !1;
689
697
  static poolSize;
690
698
  static meshConfig;
@@ -699,6 +707,46 @@ var z = class e {
699
707
  set mesh(e) {
700
708
  this.#e.mesh = e;
701
709
  }
710
+ get audio() {
711
+ return this.context.audio;
712
+ }
713
+ showCollider(e, t) {
714
+ let n = this.context.colliders, r = this.#t();
715
+ if (e === void 0 || e === !0) {
716
+ for (let e of r) n.showColliderForNode(e);
717
+ return;
718
+ }
719
+ if (e !== !1) {
720
+ if (typeof e == "string") {
721
+ if (e.startsWith("#")) {
722
+ for (let t of r) n.showColliderForNode(t, e);
723
+ return;
724
+ }
725
+ let i = r.find((t) => t.name === e);
726
+ i && n.showColliderForNode(i, t);
727
+ return;
728
+ }
729
+ for (let t of r) {
730
+ let r = e[t.name];
731
+ r && n.showColliderForNode(t, r);
732
+ }
733
+ }
734
+ }
735
+ hideCollider(e) {
736
+ let t = this.context.colliders, n = this.#t();
737
+ if (e === void 0) {
738
+ for (let e of n) t.hideColliderForNode(e);
739
+ return;
740
+ }
741
+ let r = n.find((t) => t.name === e);
742
+ r && t.hideColliderForNode(r);
743
+ }
744
+ #t() {
745
+ let e = [];
746
+ this.node.physicsBody && e.push(this.node);
747
+ for (let t of this.node.getChildTransformNodes(!1)) t.physicsBody && e.push(t);
748
+ return e;
749
+ }
702
750
  constructor(t, n, r, i, a) {
703
751
  super(t, n, r, i, a);
704
752
  let o = n, s = new.target, c = this.state;
@@ -712,20 +760,26 @@ var z = class e {
712
760
  z: 0,
713
761
  w: 1
714
762
  }), c.nodeName !== void 0) this.#e = {
715
- node: e.#t(o, c.nodeName),
763
+ node: e.#o(o, c.nodeName),
716
764
  mesh: void 0
717
- };
765
+ }, this.#n();
718
766
  else {
719
767
  let e = s.poolable ? o.pool.take(this.name) : void 0;
720
- if (e !== void 0) this.#e = e, this.#e.node.setEnabled(!0);
768
+ if (e !== void 0) this.#e = e, this.#e.node.setEnabled(!0), this.#a(), V.has(e) ? V.set(e, () => {
769
+ this.#r();
770
+ }) : this.#n();
721
771
  else {
722
772
  this.#e = {
723
- node: new E(t, o.scene),
773
+ node: new D(t, o.scene),
724
774
  mesh: void 0
725
- };
775
+ }, this.#a();
726
776
  let e = this.#e;
727
- o.loadMesh(this.name, this.state).then((t) => {
777
+ V.set(e, () => {
778
+ this.#r();
779
+ }), o.loadMesh(this.name, this.state).then((t) => {
728
780
  t !== void 0 && (t.parent = e.node), e.mesh = t;
781
+ let n = V.get(e);
782
+ V.delete(e), n?.();
729
783
  });
730
784
  }
731
785
  }
@@ -734,66 +788,85 @@ var z = class e {
734
788
  t instanceof e && (this.node.parent = t.node);
735
789
  }
736
790
  }
791
+ #n() {
792
+ try {
793
+ this.#r();
794
+ } catch (e) {
795
+ throw super.destroy(), e;
796
+ }
797
+ }
798
+ #r() {
799
+ let e = this.state;
800
+ e.debugCollider !== void 0 && this.showCollider(e.debugCollider);
801
+ for (let e of this.attachedBehaviors()) e.onMeshLoaded?.();
802
+ }
803
+ #i() {
804
+ for (let e of this.attachedBehaviors()) e.onDestroy?.();
805
+ }
737
806
  update(e) {
738
- super.update(e);
739
- let t = this.state;
740
- t.nodeName === void 0 && (this.node.position = new D(t.position.x, t.position.y, t.position.z), this.node.rotationQuaternion = new C(t.rotation.x, t.rotation.y, t.rotation.z, t.rotation.w));
807
+ super.update(e), this.state.nodeName === void 0 && this.#a();
808
+ }
809
+ #a() {
810
+ let e = this.state;
811
+ this.node.position = new O(e.position.x, e.position.y, e.position.z), this.node.rotationQuaternion = new w(e.rotation.x, e.rotation.y, e.rotation.z, e.rotation.w);
741
812
  }
742
813
  destroy() {
743
- if (super.destroy(), this.state.nodeName !== void 0) return;
814
+ if (this.hideCollider(), this.#i(), super.destroy(), V.has(this.#e) && V.set(this.#e, () => {}), this.state.nodeName !== void 0) return;
744
815
  let e = this.constructor;
745
816
  e.poolable ? this.context.pool.give(this.name, this.#e, e.poolSize) : this.node.dispose();
746
817
  }
747
- static #t(e, t) {
818
+ static #o(e, t) {
748
819
  let n = e.scene.getNodeByName(t);
749
- if (!(n instanceof E)) throw Error(`NodeEntity: no authored node named "${t}" exists in the scene.`);
820
+ if (!(n instanceof D)) throw Error(`NodeEntity: no authored node named "${t}" exists in the scene.`);
750
821
  return n;
751
822
  }
752
823
  };
753
824
  //#endregion
754
825
  //#region src/entities/entityPicking.ts
755
- function ve(e, t) {
826
+ function Te(e, t) {
756
827
  let n = [];
757
- for (let t of e) t instanceof V && n.push(t);
828
+ for (let t of e) t instanceof H && n.push(t);
758
829
  let r = t;
759
830
  for (; r !== null;) {
760
831
  for (let e of n) if (e.node === r) return e;
761
832
  r = r.parent;
762
833
  }
763
834
  }
764
- function ye(e, t) {
835
+ function Ee(e, t) {
765
836
  if (t?.tags === void 0) return !0;
766
837
  let n = e.state.tags;
767
838
  for (let e of t.tags) if (!n.includes(e)) return !1;
768
839
  return !0;
769
840
  }
770
- function H(e, t, n) {
841
+ function De(e, t, n) {
771
842
  if (t === null || !t.hit || t.pickedMesh === null || t.pickedPoint === null) return;
772
- let r = ve(e, t.pickedMesh);
773
- if (r === void 0 || !ye(r, n)) return;
843
+ let r = Te(e, t.pickedMesh);
844
+ if (r === void 0 || !Ee(r, n)) return;
774
845
  let i = t.getNormal(!0, !0);
775
846
  return {
776
847
  entity: r,
777
848
  mesh: t.pickedMesh,
778
849
  point: t.pickedPoint,
779
850
  distance: t.distance,
780
- normal: i ?? D.Zero()
851
+ normal: i ?? O.Zero()
781
852
  };
782
853
  }
783
854
  //#endregion
784
855
  //#region src/entities/nodeSimulation.ts
785
- var U = class e extends B {
856
+ var Oe = class e extends we {
786
857
  scene;
787
858
  pool;
788
859
  loadMesh;
860
+ audio;
861
+ colliders;
789
862
  #e;
790
863
  constructor(e) {
791
- super(e), this.scene = e.scene, this.pool = e.pool, this.loadMesh = e.loadMesh, this.#e = e.entityClasses;
864
+ super(e), this.scene = e.scene, this.pool = e.pool, this.loadMesh = e.loadMesh, this.audio = e.audio, this.colliders = e.colliders, this.#e = e.entityClasses;
792
865
  }
793
866
  async prewarm(e, t, n = {}) {
794
867
  let r = this.#e[e], i = await Promise.all(Array.from({ length: t }, () => this.loadMesh(e, n)));
795
868
  for (let t of i) {
796
- let n = new E(e, this.scene);
869
+ let n = new D(e, this.scene);
797
870
  t !== void 0 && (t.parent = n), this.pool.give(e, {
798
871
  node: n,
799
872
  mesh: t
@@ -801,23 +874,28 @@ var U = class e extends B {
801
874
  }
802
875
  }
803
876
  pickEntityWithRay(e, t) {
804
- return H(this.entities, this.scene.pickWithRay(e), t);
877
+ return De(this.entities, this.scene.pickWithRay(e), t);
805
878
  }
806
879
  pickEntity(e, t, n) {
807
- return H(this.entities, this.scene.pick(e, t), n);
880
+ return De(this.entities, this.scene.pick(e, t), n);
808
881
  }
809
882
  pickEntityForward(e, t, n) {
810
883
  return this.pickEntityWithRay(e.getForwardRay(t), n);
811
884
  }
885
+ getEntityForMesh(e) {
886
+ return Te(this.entities, e);
887
+ }
812
888
  buildReplacementSimulation(t) {
813
889
  return new e({
814
890
  ...t,
815
891
  scene: this.scene,
816
892
  pool: this.pool,
817
- loadMesh: this.loadMesh
893
+ loadMesh: this.loadMesh,
894
+ audio: this.audio,
895
+ colliders: this.colliders
818
896
  });
819
897
  }
820
- }, be = class {
898
+ }, ke = class {
821
899
  #e = /* @__PURE__ */ new Map();
822
900
  take(e) {
823
901
  let t = this.#e.get(e);
@@ -842,7 +920,7 @@ var U = class e extends B {
842
920
  clearAll() {
843
921
  for (let e of [...this.#e.keys()]) this.clear(e);
844
922
  }
845
- }, xe = class {
923
+ }, Ae = class {
846
924
  _engine = null;
847
925
  _mainBus = null;
848
926
  _buses = /* @__PURE__ */ new Map();
@@ -886,8 +964,8 @@ var U = class e extends B {
886
964
  };
887
965
  //#endregion
888
966
  //#region src/engines/scene.ts
889
- de();
890
- var Se = class {
967
+ ue();
968
+ var je = class {
891
969
  _canvas;
892
970
  _engine;
893
971
  _havok;
@@ -898,14 +976,14 @@ var Se = class {
898
976
  createScene() {
899
977
  return new ie(this._engine);
900
978
  }
901
- enablePhysics(e, t = new D(0, -9.8, 0), n) {
979
+ enablePhysics(e, t = new O(0, -9.8, 0), n) {
902
980
  this._log.debug(`Enabling physics with gravity (${t.x}, ${t.y}, ${t.z})...`);
903
981
  let r = n === void 0 ? void 0 : { floatingOriginWorldRadius: n }, i = new p(!0, this._havok, r);
904
982
  e.enablePhysics(t, i);
905
983
  }
906
984
  createFreeCamera(e, t, n, r) {
907
985
  let i = new d(e, t, n);
908
- return i.setTarget(D.Zero()), r ??= this._canvas, r && i.attachControl(r, !0), i;
986
+ return i.setTarget(O.Zero()), r ??= this._canvas, r && i.attachControl(r, !0), i;
909
987
  }
910
988
  createHemisphericLight(e, t, n, r = .7) {
911
989
  let i = new m(e, t, n);
@@ -916,15 +994,15 @@ var Se = class {
916
994
  return i.intensity = r, i;
917
995
  }
918
996
  createPointLight(e, t, n, r = 1) {
919
- let i = new ne(e, t, n);
997
+ let i = new te(e, t, n);
920
998
  return i.intensity = r, i;
921
999
  }
922
1000
  createSpotLight(e, t, n, r, i, a, o = 1) {
923
- let s = new se(e, t, n, r, i, a);
1001
+ let s = new T(e, t, n, r, i, a);
924
1002
  return s.intensity = o, s;
925
1003
  }
926
1004
  createRectAreaLight(e, t, n, r, i, a = 1) {
927
- let o = new w(e, t, n, r, i);
1005
+ let o = new ne(e, t, n, r, i);
928
1006
  return o.intensity = a, o;
929
1007
  }
930
1008
  createSphere(e, t = {}, n) {
@@ -957,7 +1035,7 @@ var Se = class {
957
1035
  }, n);
958
1036
  }
959
1037
  addPhysics(e, t, n = {}, r) {
960
- return new te(e, t, {
1038
+ return new S(e, t, {
961
1039
  mass: 1,
962
1040
  restitution: .75,
963
1041
  friction: .5,
@@ -967,7 +1045,7 @@ var Se = class {
967
1045
  async loadModel(e, t) {
968
1046
  this._log.debug(`Loading model: ${e}`);
969
1047
  try {
970
- let n = await g(`${e}`, t);
1048
+ let n = await ee(`${e}`, t);
971
1049
  return this._log.debug(`Model loaded successfully: ${e}`), n;
972
1050
  } catch (t) {
973
1051
  throw this._log.error(`Failed to load model: ${e}`, t), t;
@@ -976,7 +1054,7 @@ var Se = class {
976
1054
  async importMeshes(e, t, n) {
977
1055
  this._log.debug(`Importing meshes from: ${t}`);
978
1056
  try {
979
- let r = e.length > 0 ? { meshNames: e } : void 0, i = await ee(`${t}`, n, r);
1057
+ let r = e.length > 0 ? { meshNames: e } : void 0, i = await g(`${t}`, n, r);
980
1058
  return this._log.debug(`Meshes imported successfully: ${e.length > 0 ? e.join(", ") : "all"}`), i;
981
1059
  } catch (e) {
982
1060
  throw this._log.error(`Failed to import meshes from: ${t}`, e), e;
@@ -985,14 +1063,15 @@ var Se = class {
985
1063
  async $teardown() {
986
1064
  this._log.info("Tearing down SceneEngine"), this._log.info("SceneEngine torn down successfully");
987
1065
  }
988
- }, Ce = class {
1066
+ }, Me = 6, Ne = class {
989
1067
  _eventBus;
990
1068
  _sceneEngine;
991
1069
  _log;
992
1070
  _containers = /* @__PURE__ */ new Map();
993
1071
  _sourceMeshes = /* @__PURE__ */ new Map();
1072
+ _pendingContainers = /* @__PURE__ */ new Map();
994
1073
  constructor(e, t, n) {
995
- this._eventBus = e, this._sceneEngine = t, this._log = n?.getLogger("AssetManager") ?? new N("AssetManager");
1074
+ this._eventBus = e, this._sceneEngine = t, this._log = n?.getLogger("AssetManager") ?? new j("AssetManager");
996
1075
  }
997
1076
  _parsePath(e) {
998
1077
  let t = e.indexOf("#");
@@ -1004,16 +1083,22 @@ var Se = class {
1004
1083
  async _loadContainer(e) {
1005
1084
  let t = this._containers.get(e);
1006
1085
  if (t) return t.refCount++, t.container;
1086
+ let n = this._pendingContainers.get(e);
1087
+ n || (n = this._fetchContainer(e), this._pendingContainers.set(e, n));
1088
+ let r = await n, i = this._containers.get(e);
1089
+ return i && i.refCount++, r;
1090
+ }
1091
+ async _fetchContainer(e) {
1007
1092
  this._log.debug(`Loading asset container: ${e}`);
1008
- let n = this._sceneEngine.createScene();
1093
+ let t = this._sceneEngine.createScene();
1009
1094
  try {
1010
- let t = await this._sceneEngine.loadModel(e, n);
1095
+ let n = await this._sceneEngine.loadModel(e, t);
1011
1096
  return this._containers.set(e, {
1012
- container: t,
1013
- refCount: 1
1014
- }), this._log.debug(`Cached asset container: ${e}`), t;
1097
+ container: n,
1098
+ refCount: 0
1099
+ }), this._log.debug(`Cached asset container: ${e}`), n;
1015
1100
  } finally {
1016
- n.dispose();
1101
+ t.dispose(), this._pendingContainers.delete(e);
1017
1102
  }
1018
1103
  }
1019
1104
  _findMeshInContainer(e, t, n) {
@@ -1048,15 +1133,34 @@ var Se = class {
1048
1133
  return t.clone(`${t.name}-clone`);
1049
1134
  }
1050
1135
  async preload(e) {
1051
- let t = e.length;
1052
- for (let n = 0; n < e.length; n++) await this.load(e[n]), this._eventBus.publish({
1053
- type: "asset:progress",
1054
- payload: {
1055
- path: e[n],
1056
- loaded: n + 1,
1057
- total: t
1136
+ let t = e.length, n = [], r = 0, i = 0, a = async () => {
1137
+ for (; r < e.length;) {
1138
+ let a = e[r];
1139
+ r++;
1140
+ let o = !0;
1141
+ try {
1142
+ await this.load(a);
1143
+ } catch (e) {
1144
+ o = !1, n.push({
1145
+ path: a,
1146
+ error: e
1147
+ });
1148
+ }
1149
+ o && (i++, this._eventBus.publish({
1150
+ type: "asset:progress",
1151
+ payload: {
1152
+ path: a,
1153
+ loaded: i,
1154
+ total: t
1155
+ }
1156
+ }));
1058
1157
  }
1059
- });
1158
+ }, o = [], s = Math.min(Me, t);
1159
+ for (let e = 0; e < s; e++) o.push(a());
1160
+ if (await Promise.all(o), n.length > 0) {
1161
+ let e = n.map((e) => e.path).join(", ");
1162
+ throw AggregateError(n.map((e) => e.error), `Preload failed for ${n.length} of ${t} assets: ${e}`);
1163
+ }
1060
1164
  this._eventBus.publish({
1061
1165
  type: "asset:complete",
1062
1166
  payload: { paths: e }
@@ -1081,18 +1185,19 @@ var Se = class {
1081
1185
  };
1082
1186
  //#endregion
1083
1187
  //#region src/utils/capabilities.ts
1084
- function W() {
1188
+ function U() {
1085
1189
  return typeof window < "u" && window.document !== void 0;
1086
1190
  }
1087
- function we() {
1088
- return W() && !!window.navigator.gpu;
1191
+ function Pe() {
1192
+ return U() && !!window.navigator.gpu;
1089
1193
  }
1090
1194
  //#endregion
1091
1195
  //#region src/managers/game.ts
1092
- var Te = class {
1196
+ var Fe = class {
1093
1197
  _engine;
1094
1198
  _eventBus;
1095
1199
  _gameEngine = null;
1200
+ _inputManager = null;
1096
1201
  _levelManager;
1097
1202
  _log;
1098
1203
  _boundRenderLoop;
@@ -1102,7 +1207,7 @@ var Te = class {
1102
1207
  _paused = !1;
1103
1208
  started = !1;
1104
1209
  constructor(e, t, n, r) {
1105
- this._engine = e, this._eventBus = t, this._levelManager = n, this._log = r?.getLogger("GameManager") || new N("GameManager"), this._boundRenderLoop = this._renderLoop.bind(this), this._boundResizeHandler = this._resizeHandler.bind(this), W() && window.addEventListener("resize", this._boundResizeHandler);
1210
+ this._engine = e, this._eventBus = t, this._levelManager = n, this._log = r?.getLogger("GameManager") || new j("GameManager"), this._boundRenderLoop = this._renderLoop.bind(this), this._boundResizeHandler = this._resizeHandler.bind(this), U() && window.addEventListener("resize", this._boundResizeHandler);
1106
1211
  }
1107
1212
  get currentScene() {
1108
1213
  return this._levelManager.currentLevel?.scene ?? null;
@@ -1110,29 +1215,33 @@ var Te = class {
1110
1215
  $setGameEngine(e) {
1111
1216
  this._gameEngine = e;
1112
1217
  }
1218
+ setInputManager(e) {
1219
+ this._inputManager = e;
1220
+ }
1113
1221
  get isPaused() {
1114
1222
  return this._paused;
1115
1223
  }
1116
- registerFrameCallback(e) {
1117
- let t = this._nextCallbackId++;
1224
+ registerFrameCallback(e, t) {
1225
+ let n = this._nextCallbackId++;
1118
1226
  return this._frameCallbacks.push({
1119
- id: t,
1120
- callback: e
1121
- }), this._log.debug(`Registered frame callback (id: ${t})`), () => {
1122
- let e = this._frameCallbacks.findIndex((e) => e.id === t);
1123
- e !== -1 && (this._frameCallbacks.splice(e, 1), this._log.debug(`Unregistered frame callback (id: ${t})`));
1227
+ id: n,
1228
+ callback: e,
1229
+ suspendedByPause: t?.suspendedByPause ?? !0
1230
+ }), this._log.debug(`Registered frame callback (id: ${n})`), () => {
1231
+ let e = this._frameCallbacks.findIndex((e) => e.id === n);
1232
+ e !== -1 && (this._frameCallbacks.splice(e, 1), this._log.debug(`Unregistered frame callback (id: ${n})`));
1124
1233
  };
1125
1234
  }
1126
1235
  _renderLoop() {
1127
1236
  let e = this._engine.getDeltaTime() / 1e3;
1128
1237
  if (!this._paused) {
1129
1238
  if (this._gameEngine === null) throw Error("GameManager: gameEngine not set. Call $setGameEngine() first.");
1130
- this._gameEngine.simulation !== null && this._gameEngine.simulation.runStepsForElapsedTime(e);
1131
- for (let { callback: t } of this._frameCallbacks) try {
1132
- t(e);
1133
- } catch (e) {
1134
- this._log.error("Error in frame callback:", e);
1135
- }
1239
+ this._gameEngine.simulation !== null && (this._inputManager !== null && this._inputManager.routeCapturedInput(this._gameEngine.simulation), this._gameEngine.simulation.runStepsForElapsedTime(e));
1240
+ }
1241
+ for (let { callback: t, suspendedByPause: n } of this._frameCallbacks) if (!(this._paused && n)) try {
1242
+ t(e);
1243
+ } catch (e) {
1244
+ this._log.error("Error in frame callback:", e);
1136
1245
  }
1137
1246
  this.currentScene && this.currentScene.render();
1138
1247
  }
@@ -1166,20 +1275,321 @@ var Te = class {
1166
1275
  });
1167
1276
  }
1168
1277
  async $teardown() {
1169
- this._log.info("Tearing down GameManager"), this.started && await this.stop(), W() && window.removeEventListener("resize", this._boundResizeHandler), this._frameCallbacks = [], this._log.info("GameManager torn down successfully");
1278
+ this._log.info("Tearing down GameManager"), this.started && await this.stop(), U() && window.removeEventListener("resize", this._boundResizeHandler), this._frameCallbacks = [], this._log.info("GameManager torn down successfully");
1279
+ }
1280
+ }, Ie = class {
1281
+ #e = /* @__PURE__ */ new Map();
1282
+ #t = [];
1283
+ registerContext(e, t = !0) {
1284
+ this.#e.set(e, {
1285
+ exclusive: t,
1286
+ active: !1
1287
+ });
1288
+ }
1289
+ activateContext(e, t) {
1290
+ let n = this.#n(e);
1291
+ if (n.exclusive) for (let [t, n] of this.#e) t !== e && n.exclusive && (n.active = !1);
1292
+ n.active = !0;
1293
+ for (let n of this.#t) n.context === e && n.prime(t(n));
1294
+ }
1295
+ deactivateContext(e) {
1296
+ this.#n(e).active = !1;
1297
+ }
1298
+ isActive(e) {
1299
+ return this.#e.get(e)?.active === !0;
1300
+ }
1301
+ isRegistered(e) {
1302
+ return this.#e.has(e);
1303
+ }
1304
+ addBinding(e) {
1305
+ this.#t.push(e);
1306
+ }
1307
+ removeBinding(e) {
1308
+ let t = this.#t.indexOf(e);
1309
+ t !== -1 && this.#t.splice(t, 1);
1310
+ }
1311
+ list() {
1312
+ return [...this.#t];
1313
+ }
1314
+ isLive(e) {
1315
+ return e.context === void 0 || this.isActive(e.context);
1316
+ }
1317
+ #n(e) {
1318
+ let t = this.#e.get(e);
1319
+ if (t === void 0) throw Error(`No context is registered under the name "${e}".`);
1320
+ return t;
1321
+ }
1322
+ }, Le = class {
1323
+ #e = /* @__PURE__ */ new Map();
1324
+ register(e) {
1325
+ if (this.#e.has(e.name)) throw Error(`An action is already registered under the name "${e.name}".`);
1326
+ if (e.type === "analog" && e.minValue !== void 0 && e.maxValue !== void 0 && e.minValue > e.maxValue) throw Error(`Action "${e.name}": minValue (${e.minValue}) is above maxValue (${e.maxValue}).`);
1327
+ this.#e.set(e.name, e);
1328
+ }
1329
+ get(e) {
1330
+ return this.#e.get(e);
1331
+ }
1332
+ list() {
1333
+ return [...this.#e.values()];
1334
+ }
1335
+ };
1336
+ //#endregion
1337
+ //#region src/input/deliverAction.ts
1338
+ function Re(e, t, n, r) {
1339
+ let i = e.process(t);
1340
+ if (i === void 0) return;
1341
+ let a = {
1342
+ type: `action:${e.action.name}`,
1343
+ senderID: r,
1344
+ payload: i.value
1345
+ };
1346
+ n.bus.emit(a);
1347
+ }
1348
+ function ze(e, t, n, r) {
1349
+ let i = {
1350
+ type: `action:${e.name}`,
1351
+ senderID: r,
1352
+ payload: t
1353
+ };
1354
+ n.bus.emit(i);
1355
+ }
1356
+ //#endregion
1357
+ //#region src/managers/input.ts
1358
+ var W = "sage-input", Be = .2, G = 0;
1359
+ function Ve(e) {
1360
+ return Math.abs(e - G) > Be;
1361
+ }
1362
+ function He(e, t) {
1363
+ return Math.abs(e - G) > 2 || Math.abs(t - G) > 2;
1364
+ }
1365
+ var Ue = class {
1366
+ actions = new Le();
1367
+ contexts = new Ie();
1368
+ #e = {};
1369
+ #t = {};
1370
+ #n = {
1371
+ x: 0,
1372
+ y: 0
1373
+ };
1374
+ #r = {
1375
+ deltaX: 0,
1376
+ deltaY: 0,
1377
+ deltaZ: 0
1378
+ };
1379
+ #i = {
1380
+ x: 0,
1381
+ y: 0
1382
+ };
1383
+ #a = /* @__PURE__ */ new Map();
1384
+ #o = /* @__PURE__ */ new Set();
1385
+ #s = /* @__PURE__ */ new Map();
1386
+ #c;
1387
+ #l;
1388
+ #u;
1389
+ #d;
1390
+ #f;
1391
+ #p;
1392
+ #m;
1393
+ #h;
1394
+ constructor() {
1395
+ this.#u = (e) => {
1396
+ this.#g("keyboard", "key", e.code) && e.preventDefault(), this.#e[e.code] = !0, this.#c = "keyboard", this.#T({
1397
+ device: {
1398
+ type: "keyboard",
1399
+ index: 0
1400
+ },
1401
+ sourceType: "key",
1402
+ sourceKey: e.code,
1403
+ value: !0
1404
+ });
1405
+ }, this.#d = (e) => {
1406
+ this.#e[e.code] = !1;
1407
+ }, this.#f = (e) => {
1408
+ if (e.pointerType !== "mouse") return;
1409
+ let t = String(e.button);
1410
+ this.#g("mouse", "button", t) && e.preventDefault(), this.#t[t] = !0, this.#c = "mouse", this.#T({
1411
+ device: {
1412
+ type: "mouse",
1413
+ index: 0
1414
+ },
1415
+ sourceType: "button",
1416
+ sourceKey: t,
1417
+ value: !0
1418
+ });
1419
+ }, this.#p = (e) => {
1420
+ e.pointerType === "mouse" && (this.#t[String(e.button)] = !1);
1421
+ }, this.#m = (e) => {
1422
+ e.pointerType === "mouse" && (this.#n.x = e.clientX, this.#n.y = e.clientY, this.#i.x += e.movementX, this.#i.y += e.movementY, He(e.movementX, e.movementY) && (this.#c = "mouse"));
1423
+ }, this.#h = (e) => {
1424
+ this.#g("mouse", "wheel") && e.preventDefault(), this.#r.deltaX = e.deltaX, this.#r.deltaY = e.deltaY, this.#r.deltaZ = e.deltaZ, (e.deltaX !== G || e.deltaY !== G || e.deltaZ !== G) && (this.#c = "mouse", this.#w(e));
1425
+ }, U() && (window.addEventListener("keydown", this.#u), window.addEventListener("keyup", this.#d), window.addEventListener("pointerdown", this.#f), window.addEventListener("pointerup", this.#p), window.addEventListener("pointermove", this.#m), window.addEventListener("wheel", this.#h, { passive: !1 }));
1426
+ }
1427
+ get lastActiveDeviceType() {
1428
+ return this.#c;
1429
+ }
1430
+ deviceState(e, t) {
1431
+ return this.#b(e, t);
1432
+ }
1433
+ registerCapture(e) {
1434
+ return this.#o.add(e), () => {
1435
+ this.#o.delete(e);
1436
+ };
1437
+ }
1438
+ getBindingsForAction(e, t, n) {
1439
+ let r = [];
1440
+ for (let i of this.contexts.list()) {
1441
+ let a = i.action.name === e, o = t === void 0 || i.device.type === t, s = n === void 0 || i.context === n;
1442
+ a && o && s && r.push(i);
1443
+ }
1444
+ return r;
1445
+ }
1446
+ routeCapturedInput(e) {
1447
+ this.#x();
1448
+ let t = /* @__PURE__ */ new Map();
1449
+ for (let n of this.contexts.list()) if (this.contexts.isLive(n)) {
1450
+ let r = this.#b(n.device.type, n.device.index);
1451
+ n.kind === "value" ? this.#_(t, n, r) : Re(n, r, e, W);
1452
+ }
1453
+ this.#v(t, e), this.#C(e), this.#i.x = G, this.#i.y = G, this.#r.deltaX = G, this.#r.deltaY = G, this.#r.deltaZ = G;
1454
+ }
1455
+ #g(e, t, n) {
1456
+ for (let r of this.contexts.list()) if (r.preventDefault && this.contexts.isLive(r)) {
1457
+ let { device: i, sourceType: a, sourceKey: o } = r.input;
1458
+ if (i.type === e && a === t && (n === void 0 || o === n)) return !0;
1459
+ }
1460
+ return !1;
1461
+ }
1462
+ async $teardown() {
1463
+ U() && (window.removeEventListener("keydown", this.#u), window.removeEventListener("keyup", this.#d), window.removeEventListener("pointerdown", this.#f), window.removeEventListener("pointerup", this.#p), window.removeEventListener("pointermove", this.#m), window.removeEventListener("wheel", this.#h));
1464
+ }
1465
+ #_(e, t, n) {
1466
+ let r = t.process(n);
1467
+ if (r === void 0) return;
1468
+ let i = Number(r.value), a = e.get(t.action.name);
1469
+ a === void 0 ? e.set(t.action.name, {
1470
+ action: t.action,
1471
+ value: i
1472
+ }) : a.value += i;
1473
+ }
1474
+ #v(e, t) {
1475
+ for (let [t, n] of this.#s) e.has(t) || e.set(t, {
1476
+ action: n,
1477
+ value: 0
1478
+ });
1479
+ for (let [n, r] of e) {
1480
+ let e = this.#y(r.action, r.value), i = e !== this.#y(r.action, G), a = this.#s.has(n);
1481
+ i ? this.#s.set(n, r.action) : this.#s.delete(n), (i || a) && ze(r.action, e, t, W);
1482
+ }
1483
+ }
1484
+ #y(e, t) {
1485
+ return e.type === "analog" ? e.minValue !== void 0 && t < e.minValue ? e.minValue : e.maxValue !== void 0 && t > e.maxValue ? e.maxValue : t : t;
1486
+ }
1487
+ #b(e, t) {
1488
+ if (e === "keyboard") return { keys: this.#e };
1489
+ if (e === "mouse") return {
1490
+ buttons: this.#t,
1491
+ position: this.#n,
1492
+ wheel: this.#r,
1493
+ movement: this.#i
1494
+ };
1495
+ let n = this.#a.get(t);
1496
+ return n === void 0 ? {
1497
+ buttons: {},
1498
+ axes: {}
1499
+ } : n;
1500
+ }
1501
+ #x() {
1502
+ if (typeof navigator > "u" || typeof navigator.getGamepads != "function") return;
1503
+ let e = navigator.getGamepads();
1504
+ for (let t = 0; t < e.length; t++) {
1505
+ let n = e[t];
1506
+ n !== null && this.#S(t, n);
1507
+ }
1508
+ }
1509
+ #S(e, t) {
1510
+ let n = {}, r = !1;
1511
+ for (let i = 0; i < t.buttons.length; i++) {
1512
+ let a = t.buttons[i].value, o = String(i);
1513
+ n[o] = a, Ve(a) && (r = !0, this.#T({
1514
+ device: {
1515
+ type: "gamepad",
1516
+ index: e
1517
+ },
1518
+ sourceType: "button",
1519
+ sourceKey: o,
1520
+ value: a
1521
+ }));
1522
+ }
1523
+ let i = {};
1524
+ for (let n = 0; n < t.axes.length; n++) {
1525
+ let a = t.axes[n], o = String(n);
1526
+ i[o] = a, Ve(a) && (r = !0, this.#T({
1527
+ device: {
1528
+ type: "gamepad",
1529
+ index: e
1530
+ },
1531
+ sourceType: "axis",
1532
+ sourceKey: o,
1533
+ value: a
1534
+ }));
1535
+ }
1536
+ this.#a.set(e, {
1537
+ buttons: n,
1538
+ axes: i
1539
+ }), r && (this.#c = "gamepad");
1540
+ }
1541
+ #C(e) {
1542
+ if (this.#c === this.#l) return;
1543
+ let t = this.#l;
1544
+ this.#l = this.#c, this.#c !== void 0 && e.bus.emit({
1545
+ type: "input:deviceChanged",
1546
+ senderID: W,
1547
+ payload: {
1548
+ deviceType: this.#c,
1549
+ previousDeviceType: t
1550
+ }
1551
+ });
1170
1552
  }
1171
- }, Ee = {
1553
+ #w(e) {
1554
+ let t = [
1555
+ {
1556
+ sourceKey: "deltaY",
1557
+ value: e.deltaY
1558
+ },
1559
+ {
1560
+ sourceKey: "deltaX",
1561
+ value: e.deltaX
1562
+ },
1563
+ {
1564
+ sourceKey: "deltaZ",
1565
+ value: e.deltaZ
1566
+ }
1567
+ ];
1568
+ for (let e of t) e.value !== G && this.#T({
1569
+ device: {
1570
+ type: "mouse",
1571
+ index: 0
1572
+ },
1573
+ sourceType: "wheel",
1574
+ sourceKey: e.sourceKey,
1575
+ value: e.value
1576
+ });
1577
+ }
1578
+ #T(e) {
1579
+ for (let t of this.#o) t.feed(e);
1580
+ }
1581
+ }, We = {
1172
1582
  hable: h.TONEMAPPING_STANDARD,
1173
1583
  reinhard: h.TONEMAPPING_STANDARD,
1174
1584
  hejidawson: h.TONEMAPPING_STANDARD,
1175
1585
  photographic: h.TONEMAPPING_STANDARD,
1176
1586
  aces: h.TONEMAPPING_ACES
1177
1587
  };
1178
- function De(e, t) {
1588
+ function Ge(e, t) {
1179
1589
  if (!e.activeCamera) return;
1180
1590
  t.volumetric && console.warn("[SAGE] Volumetric lighting requires renderer: \"frameGraph\". Ignored in pipeline mode.");
1181
1591
  let n = new s("sage-default", !0, e, e.cameras);
1182
- if (t.bloom && (n.bloomEnabled = !0, t.bloom.weight !== void 0 && (n.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (n.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (n.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (n.bloomKernel = t.bloom.kernel)), t.tonemap && (n.imageProcessingEnabled = !0, n.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (n.imageProcessing.toneMappingType = Ee[t.tonemap.operator] ?? h.TONEMAPPING_STANDARD)), t.grain && (n.grainEnabled = !0, t.grain.intensity !== void 0 && (n.grain.intensity = t.grain.intensity), t.grain.animated !== void 0 && (n.grain.animated = t.grain.animated)), t.vignette && (n.imageProcessingEnabled = !0, n.imageProcessing.vignetteEnabled = !0, t.vignette.weight !== void 0 && (n.imageProcessing.vignetteWeight = t.vignette.weight), t.vignette.stretch !== void 0 && (n.imageProcessing.vignetteStretch = t.vignette.stretch), t.vignette.color && (n.imageProcessing.vignetteColor = new i(t.vignette.color.r, t.vignette.color.g, t.vignette.color.b, 1))), t.sharpen && (n.sharpenEnabled = !0, t.sharpen.edge !== void 0 && (n.sharpen.edgeAmount = t.sharpen.edge), t.sharpen.color !== void 0 && (n.sharpen.colorAmount = t.sharpen.color)), t.chromaticAberration && (n.chromaticAberrationEnabled = !0, t.chromaticAberration.amount !== void 0 && (n.chromaticAberration.aberrationAmount = t.chromaticAberration.amount)), t.ssao) {
1592
+ if (t.bloom && (n.bloomEnabled = !0, t.bloom.weight !== void 0 && (n.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (n.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (n.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (n.bloomKernel = t.bloom.kernel)), t.tonemap && (n.imageProcessingEnabled = !0, n.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (n.imageProcessing.toneMappingType = We[t.tonemap.operator] ?? h.TONEMAPPING_STANDARD)), t.grain && (n.grainEnabled = !0, t.grain.intensity !== void 0 && (n.grain.intensity = t.grain.intensity), t.grain.animated !== void 0 && (n.grain.animated = t.grain.animated)), t.vignette && (n.imageProcessingEnabled = !0, n.imageProcessing.vignetteEnabled = !0, t.vignette.weight !== void 0 && (n.imageProcessing.vignetteWeight = t.vignette.weight), t.vignette.stretch !== void 0 && (n.imageProcessing.vignetteStretch = t.vignette.stretch), t.vignette.color && (n.imageProcessing.vignetteColor = new i(t.vignette.color.r, t.vignette.color.g, t.vignette.color.b, 1))), t.sharpen && (n.sharpenEnabled = !0, t.sharpen.edge !== void 0 && (n.sharpen.edgeAmount = t.sharpen.edge), t.sharpen.color !== void 0 && (n.sharpen.colorAmount = t.sharpen.color)), t.chromaticAberration && (n.chromaticAberrationEnabled = !0, t.chromaticAberration.amount !== void 0 && (n.chromaticAberration.aberrationAmount = t.chromaticAberration.amount)), t.ssao) {
1183
1593
  let n = new re("sage-ssao", e, {
1184
1594
  ssaoRatio: .5,
1185
1595
  blurRatio: 1
@@ -1189,25 +1599,25 @@ function De(e, t) {
1189
1599
  }
1190
1600
  //#endregion
1191
1601
  //#region src/handlers/postProcessing.ts
1192
- async function Oe(e, t) {
1602
+ async function Ke(e, t) {
1193
1603
  if (t.renderer === "frameGraph") {
1194
- let { applyFrameGraphPostProcessing: n } = await import("./postProcessingFrameGraph-rr2DbgPi.js");
1604
+ let { applyFrameGraphPostProcessing: n } = await import("./postProcessingFrameGraph-C3Og4kaS.js");
1195
1605
  await n(e, t);
1196
- } else De(e, t);
1606
+ } else Ge(e, t);
1197
1607
  }
1198
1608
  //#endregion
1199
1609
  //#region src/utils/vectors.ts
1200
- function ke(e) {
1610
+ function qe(e) {
1201
1611
  return {
1202
1612
  x: e.x,
1203
1613
  y: e.y,
1204
1614
  z: e.z
1205
1615
  };
1206
1616
  }
1207
- function G(e) {
1208
- return new D(e.x, e.y, e.z);
1209
- }
1210
1617
  function K(e) {
1618
+ return new O(e.x, e.y, e.z);
1619
+ }
1620
+ function Je(e) {
1211
1621
  return {
1212
1622
  x: e.x,
1213
1623
  y: e.y,
@@ -1215,10 +1625,10 @@ function K(e) {
1215
1625
  w: e.w
1216
1626
  };
1217
1627
  }
1218
- function Ae(e) {
1219
- return new C(e.x, e.y, e.z, e.w);
1628
+ function Ye(e) {
1629
+ return new w(e.x, e.y, e.z, e.w);
1220
1630
  }
1221
- function je(e) {
1631
+ function Xe(e) {
1222
1632
  e.computeWorldMatrix(!0);
1223
1633
  let t = e.getWorldMatrix().clone(), n = e.parent;
1224
1634
  for (; n;) {
@@ -1226,7 +1636,7 @@ function je(e) {
1226
1636
  let e = n.getWorldMatrix(), r = n.parent, i;
1227
1637
  r ? (r.computeWorldMatrix(!0), i = e.multiply(_.Invert(r.getWorldMatrix()))) : i = e, i.determinant() < 0 && (t = _.Invert(i).multiply(t)), n = r;
1228
1638
  }
1229
- let r = new D(), i = new C(), a = new D();
1639
+ let r = new O(), i = new w(), a = new O();
1230
1640
  return t.decompose(a, i, r), {
1231
1641
  position: r,
1232
1642
  rotation: i,
@@ -1235,16 +1645,17 @@ function je(e) {
1235
1645
  }
1236
1646
  //#endregion
1237
1647
  //#region src/classes/level.ts
1238
- var Me = class {
1648
+ var Ze = class {
1239
1649
  name;
1240
1650
  _log;
1241
1651
  _context;
1242
1652
  _scene = null;
1243
1653
  _forRestore = !1;
1654
+ _simulation = null;
1244
1655
  clusteredLights = null;
1245
1656
  outlines = null;
1246
1657
  constructor(e, t) {
1247
- this.name = e.name, this._context = t, this._log = t.logger?.getLogger(`Level:${e.name}`) ?? new N(`Level:${e.name}`, "info");
1658
+ this.name = e.name, this._context = t, this._log = t.logger?.getLogger(`Level:${e.name}`) ?? new j(`Level:${e.name}`, "info");
1248
1659
  }
1249
1660
  get scene() {
1250
1661
  return this._scene;
@@ -1258,6 +1669,12 @@ var Me = class {
1258
1669
  get propertyHandlers() {
1259
1670
  return this._context.propertyHandlers;
1260
1671
  }
1672
+ get $simulation() {
1673
+ return this._simulation;
1674
+ }
1675
+ $adoptSimulation(e) {
1676
+ this._simulation = e;
1677
+ }
1261
1678
  $emitProgress(e, t) {
1262
1679
  this.gameEngine.eventBus.publish({
1263
1680
  type: "level:progress",
@@ -1309,7 +1726,7 @@ var Me = class {
1309
1726
  async $dispose() {
1310
1727
  this._scene &&= (this._log.info(`Disposing level: ${this.name}`), this.outlines &&= (this.outlines.dispose(), null), this.clusteredLights &&= (this.clusteredLights.dispose(), null), this._scene.dispose(), null);
1311
1728
  }
1312
- }, Ne = class {
1729
+ }, Qe = class {
1313
1730
  _scene;
1314
1731
  _layers = /* @__PURE__ */ new Map();
1315
1732
  constructor(e, t) {
@@ -1353,7 +1770,7 @@ var Me = class {
1353
1770
  n.length > 0 && e.layer.addSelection(n);
1354
1771
  }
1355
1772
  }
1356
- }, Pe = class extends Me {
1773
+ }, $e = class extends Ze {
1357
1774
  _config;
1358
1775
  _spawnPoints = [];
1359
1776
  _entityNodes = [];
@@ -1369,15 +1786,19 @@ var Me = class {
1369
1786
  get spawnedEntities() {
1370
1787
  return this._spawnedEntities;
1371
1788
  }
1789
+ get simulation() {
1790
+ if (this._simulation === null) throw Error(`Level ${this.name}: rebuildSimulation has not run against this level's scene yet.`);
1791
+ return this._simulation;
1792
+ }
1372
1793
  async buildScene() {
1373
1794
  let { sceneEngine: e } = this.gameEngine.engines, { assetManager: t } = this.gameEngine.managers;
1374
1795
  this._config.preload && this._config.preload.length > 0 && (this.$emitProgress(2, "Preloading assets..."), await t.preload(this._config.preload));
1375
1796
  let n = e.createScene();
1376
- if (this._scene = n, this.gameEngine.rebuildSimulation(n, this._config.meshSource), this._config.physics && (this.$emitProgress(5, "Initializing physics..."), await this._enablePhysics(n)), this._config.scene && (this.$emitProgress(10, "Loading scene file..."), await this._loadSceneFile(n)), this._config.environment && (this.$emitProgress(15, "Setting up environment..."), this._processEnvironment(n)), this._processCameras(n), this._processLights(n), this._setupClustering(n), this._config.postProcessing) {
1797
+ if (this._scene = n, this._simulation = this.gameEngine.rebuildSimulation(n, this._config.meshSource), this._config.physics && (this.$emitProgress(5, "Initializing physics..."), await this._enablePhysics(n)), this._config.scene && (this.$emitProgress(10, "Loading scene file..."), await this._loadSceneFile(n)), this._config.environment && (this.$emitProgress(15, "Setting up environment..."), this._processEnvironment(n)), this._processCameras(n), this._processLights(n), this._setupClustering(n), this._config.postProcessing) {
1377
1798
  let e = this._config.postProcessing.renderer ?? "pipeline";
1378
- this._log.info(`Applying post-processing with ${e} renderer`), await Oe(n, this._config.postProcessing);
1799
+ this._log.info(`Applying post-processing with ${e} renderer`), await Ke(n, this._config.postProcessing);
1379
1800
  }
1380
- return this.outlines = new Ne(n, this._config.outlines), this.$emitProgress(50, "Processing scene properties..."), await this._processNodeProperties(n), this._forRestore || (this.$emitProgress(70, "Spawning entities..."), await this._processSpawnPoints(), this.$emitProgress(85, "Configuring entities..."), this._processEntityNodes()), this._config.sounds && (this.$emitProgress(95, "Loading sounds..."), await this._processLevelSounds()), n;
1801
+ return this.outlines = new Qe(n, this._config.outlines), this.$emitProgress(50, "Processing scene properties..."), await this._processNodeProperties(n), this._forRestore || (this.$emitProgress(70, "Spawning entities..."), await this._processSpawnPoints(), this.$emitProgress(85, "Configuring entities..."), this._processEntityNodes()), this._config.sounds && (this.$emitProgress(95, "Loading sounds..."), await this._processLevelSounds()), n;
1381
1802
  }
1382
1803
  async _loadSceneFile(e) {
1383
1804
  let t = this._getScenePath();
@@ -1411,8 +1832,8 @@ var Me = class {
1411
1832
  let n = t.skyboxSize ?? 1e3, r = y.CreateSphere("skybox", {
1412
1833
  diameter: n,
1413
1834
  segments: 32
1414
- }, e), i = new T("skybox-mat", e);
1415
- i.backFaceCulling = !1, i.disableLighting = !0, i.emissiveTexture = new ce(t.skybox, e), r.material = i, r.infiniteDistance = !0;
1835
+ }, e), i = new E("skybox-mat", e);
1836
+ i.backFaceCulling = !1, i.disableLighting = !0, i.emissiveTexture = new se(t.skybox, e), r.material = i, r.infiniteDistance = !0;
1416
1837
  }
1417
1838
  this._log.debug(`Skybox set from: ${t.skybox}`);
1418
1839
  }
@@ -1448,20 +1869,20 @@ var Me = class {
1448
1869
  }
1449
1870
  }
1450
1871
  _createCamera(e, t, r) {
1451
- let i = t.position ? G(t.position) : D.Zero(), a;
1872
+ let i = t.position ? K(t.position) : O.Zero(), a;
1452
1873
  switch (t.type) {
1453
1874
  case "arcRotate": {
1454
- let i = t.target ? G(t.target) : D.Zero();
1875
+ let i = t.target ? K(t.target) : O.Zero();
1455
1876
  a = new n(e, t.alpha ?? Math.PI / 2, t.beta ?? Math.PI / 3, t.radius ?? 10, i, r);
1456
1877
  break;
1457
1878
  }
1458
1879
  case "universal":
1459
- a = new le(e, i, r);
1880
+ a = new ce(e, i, r);
1460
1881
  break;
1461
1882
  case "geospatial": {
1462
- if (!t.planetRadius) return this._log.warn(`Geospatial camera "${e}" requires planetRadius -- skipping`), new d(e, D.Zero(), r);
1463
- let n = new fe(e, r, { planetRadius: t.planetRadius });
1464
- t.center && (n.center = G(t.center)), t.yaw !== void 0 && (n.yaw = t.yaw), t.pitch !== void 0 && (n.pitch = t.pitch), t.radius !== void 0 && (n.radius = t.radius), t.checkCollisions !== void 0 && (n.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (n.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (n.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (n.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (n.limits.pitchMax = t.pitchMax), t.yawMin !== void 0 && (n.limits.yawMin = t.yawMin), t.yawMax !== void 0 && (n.limits.yawMax = t.yawMax), a = n;
1883
+ if (!t.planetRadius) return this._log.warn(`Geospatial camera "${e}" requires planetRadius -- skipping`), new d(e, O.Zero(), r);
1884
+ let n = new de(e, r, { planetRadius: t.planetRadius });
1885
+ t.center && (n.center = K(t.center)), t.yaw !== void 0 && (n.yaw = t.yaw), t.pitch !== void 0 && (n.pitch = t.pitch), t.radius !== void 0 && (n.radius = t.radius), t.checkCollisions !== void 0 && (n.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (n.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (n.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (n.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (n.limits.pitchMax = t.pitchMax), t.yawMin !== void 0 && (n.limits.yawMin = t.yawMin), t.yawMax !== void 0 && (n.limits.yawMax = t.yawMax), a = n;
1465
1886
  break;
1466
1887
  }
1467
1888
  default: a = new d(e, i, r);
@@ -1469,7 +1890,7 @@ var Me = class {
1469
1890
  return this._applyCameraConfig(a, t), a;
1470
1891
  }
1471
1892
  _applyCameraConfig(e, t) {
1472
- t.fov !== void 0 && (e.fov = t.fov), t.position && (e.position = G(t.position)), t.minZ !== void 0 && (e.minZ = t.minZ), t.maxZ !== void 0 && (e.maxZ = t.maxZ), e instanceof d && (t.speed !== void 0 && (e.speed = t.speed), t.rotation && (e.rotation = G(t.rotation))), e instanceof n && (t.target && e.setTarget(G(t.target)), t.lowerRadiusLimit !== void 0 && (e.lowerRadiusLimit = t.lowerRadiusLimit), t.upperRadiusLimit !== void 0 && (e.upperRadiusLimit = t.upperRadiusLimit), t.lowerBetaLimit !== void 0 && (e.lowerBetaLimit = t.lowerBetaLimit), t.upperBetaLimit !== void 0 && (e.upperBetaLimit = t.upperBetaLimit), t.wheelPrecision !== void 0 && (e.wheelPrecision = t.wheelPrecision)), e instanceof fe && (t.yaw !== void 0 && (e.yaw = t.yaw), t.pitch !== void 0 && (e.pitch = t.pitch), t.radius !== void 0 && (e.radius = t.radius), t.center && (e.center = G(t.center)), t.checkCollisions !== void 0 && (e.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (e.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (e.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (e.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (e.limits.pitchMax = t.pitchMax));
1893
+ t.fov !== void 0 && (e.fov = t.fov), t.position && (e.position = K(t.position)), t.minZ !== void 0 && (e.minZ = t.minZ), t.maxZ !== void 0 && (e.maxZ = t.maxZ), e instanceof d && (t.speed !== void 0 && (e.speed = t.speed), t.rotation && (e.rotation = K(t.rotation))), e instanceof n && (t.target && e.setTarget(K(t.target)), t.lowerRadiusLimit !== void 0 && (e.lowerRadiusLimit = t.lowerRadiusLimit), t.upperRadiusLimit !== void 0 && (e.upperRadiusLimit = t.upperRadiusLimit), t.lowerBetaLimit !== void 0 && (e.lowerBetaLimit = t.lowerBetaLimit), t.upperBetaLimit !== void 0 && (e.upperBetaLimit = t.upperBetaLimit), t.wheelPrecision !== void 0 && (e.wheelPrecision = t.wheelPrecision)), e instanceof de && (t.yaw !== void 0 && (e.yaw = t.yaw), t.pitch !== void 0 && (e.pitch = t.pitch), t.radius !== void 0 && (e.radius = t.radius), t.center && (e.center = K(t.center)), t.checkCollisions !== void 0 && (e.checkCollisions = t.checkCollisions), t.radiusMin !== void 0 && (e.limits.radiusMin = t.radiusMin), t.radiusMax !== void 0 && (e.limits.radiusMax = t.radiusMax), t.pitchMin !== void 0 && (e.limits.pitchMin = t.pitchMin), t.pitchMax !== void 0 && (e.limits.pitchMax = t.pitchMax));
1473
1894
  }
1474
1895
  _processLights(e) {
1475
1896
  let t = this._config.lights;
@@ -1479,7 +1900,7 @@ var Me = class {
1479
1900
  }
1480
1901
  }
1481
1902
  _createLight(e, t, n) {
1482
- let r = t.direction ? G(t.direction) : new D(0, -1, 0), i = t.position ? G(t.position) : D.Zero();
1903
+ let r = t.direction ? K(t.direction) : new O(0, -1, 0), i = t.position ? K(t.position) : O.Zero();
1483
1904
  switch (t.type) {
1484
1905
  case "hemispheric": {
1485
1906
  let i = new m(e, r, n);
@@ -1492,20 +1913,20 @@ var Me = class {
1492
1913
  break;
1493
1914
  }
1494
1915
  case "point": {
1495
- let r = new ne(e, i, n);
1916
+ let r = new te(e, i, n);
1496
1917
  this._applyLightConfig(r, t);
1497
1918
  break;
1498
1919
  }
1499
1920
  case "spot": {
1500
- let a = new se(e, i, r, t.angle ?? Math.PI / 3, t.exponent ?? 2, n);
1921
+ let a = new T(e, i, r, t.angle ?? Math.PI / 3, t.exponent ?? 2, n);
1501
1922
  this._applyLightConfig(a, t);
1502
1923
  break;
1503
1924
  }
1504
1925
  case "rectarea": {
1505
- let a = new w(e, i, t.width ?? 1, t.height ?? 1, n);
1926
+ let a = new ne(e, i, t.width ?? 1, t.height ?? 1, n);
1506
1927
  if (this._applyLightConfig(a, t), t.direction) {
1507
- let t = new E(`${e}_pivot`, n);
1508
- t.position = a.position.clone(), a.position = D.Zero(), a.parent = t, t.lookAt(t.position.subtract(r));
1928
+ let t = new D(`${e}_pivot`, n);
1929
+ t.position = a.position.clone(), a.position = O.Zero(), a.parent = t, t.lookAt(t.position.subtract(r));
1509
1930
  }
1510
1931
  break;
1511
1932
  }
@@ -1517,19 +1938,19 @@ var Me = class {
1517
1938
  _setupClustering(e) {
1518
1939
  let t = this._config.clustering;
1519
1940
  if (!t?.enabled) return;
1520
- let n = e.lights.filter((e) => pe.IsLightSupported(e));
1941
+ let n = e.lights.filter((e) => fe.IsLightSupported(e));
1521
1942
  if (n.length === 0) {
1522
1943
  this._log.debug("Clustering enabled but no eligible lights found");
1523
1944
  return;
1524
1945
  }
1525
1946
  for (let t of n) e.removeLight(t);
1526
- let r = new pe("sage-clustered", n, e);
1947
+ let r = new fe("sage-clustered", n, e);
1527
1948
  t.horizontalTiles !== void 0 && (r.horizontalTiles = t.horizontalTiles), t.verticalTiles !== void 0 && (r.verticalTiles = t.verticalTiles), t.depthSlices !== void 0 && (r.depthSlices = t.depthSlices), t.maxRange !== void 0 && (r.maxRange = t.maxRange), this.clusteredLights = r, this._log.debug(`Clustered lighting enabled: ${n.length} lights, ${r.horizontalTiles}x${r.verticalTiles} tiles, ${r.depthSlices} depth slices`);
1528
1949
  for (let t of e.materials) t instanceof x && (t.useGLTFLightFalloff = !0);
1529
1950
  }
1530
1951
  async _enablePhysics(e) {
1531
- let t = this._config.physics, n = new D(0, -9.81, 0);
1532
- typeof t == "object" && t.gravity && (n = new D(t.gravity.x, t.gravity.y, t.gravity.z));
1952
+ let t = this._config.physics, n = new O(0, -9.81, 0);
1953
+ typeof t == "object" && t.gravity && (n = new O(t.gravity.x, t.gravity.y, t.gravity.z));
1533
1954
  let r = this.gameEngine.largeWorldRendering ? 1e5 : void 0;
1534
1955
  this._log.debug(`Enabling physics with gravity: ${n.toString()}`), await this.gameEngine.engines.sceneEngine.enablePhysics(e, n, r);
1535
1956
  }
@@ -1546,7 +1967,7 @@ var Me = class {
1546
1967
  }
1547
1968
  async _processNodeMetadata(e) {
1548
1969
  if ("spawn" in e.metadata) {
1549
- let { position: t, rotation: n, scaling: r } = je(e);
1970
+ let { position: t, rotation: n, scaling: r } = Xe(e);
1550
1971
  this._spawnPoints.push({
1551
1972
  name: e.metadata.spawn,
1552
1973
  position: t,
@@ -1578,12 +1999,12 @@ var Me = class {
1578
1999
  let n = {
1579
2000
  ...e.config,
1580
2001
  ...e.name === void 0 ? {} : { displayName: e.name },
2002
+ ...e.debugCollider === void 0 ? {} : { debugCollider: e.debugCollider },
1581
2003
  tags: e.tags ?? [],
1582
- position: ke(t.position),
1583
- rotation: K(t.rotation)
1584
- }, { simulation: r } = this.gameEngine;
1585
- if (r === null) throw Error("GameLevel: rebuildSimulation has not run against this level's scene yet.");
1586
- return r.spawn(e.entity, void 0, n);
2004
+ position: qe(t.position),
2005
+ rotation: Je(t.rotation)
2006
+ };
2007
+ return this.simulation.spawn(e.entity, void 0, n);
1587
2008
  }
1588
2009
  _processEntityNodes() {
1589
2010
  for (let e of this._entityNodes) {
@@ -1596,12 +2017,11 @@ var Me = class {
1596
2017
  let n = {
1597
2018
  ...e.config,
1598
2019
  ...e.name === void 0 ? {} : { displayName: e.name },
2020
+ ...e.debugCollider === void 0 ? {} : { debugCollider: e.debugCollider },
1599
2021
  tags: e.tags ?? [],
1600
2022
  nodeName: t.node.name
1601
- }, { simulation: r } = this.gameEngine;
1602
- if (r === null) throw Error("GameLevel: rebuildSimulation has not run against this level's scene yet.");
1603
- let i = r.spawn(e.entity, void 0, n);
1604
- this._spawnedEntities.push(i), this._log.debug(`Spawned entity '${e.entity}' adopting node '${t.node.name}'`);
2023
+ }, r = this.simulation.spawn(e.entity, void 0, n);
2024
+ this._spawnedEntities.push(r), this._log.debug(`Spawned entity '${e.entity}' adopting node '${t.node.name}'`);
1605
2025
  } catch (e) {
1606
2026
  this._log.error(`Failed to spawn entity adopting node '${t.node.name}':`, e);
1607
2027
  }
@@ -1635,13 +2055,12 @@ var Me = class {
1635
2055
  this._playingSoundsBeforeDeactivate.clear();
1636
2056
  }
1637
2057
  async $dispose() {
1638
- let { simulation: e } = this.gameEngine;
1639
- if (e !== null) for (let t of this._spawnedEntities) e.despawn(t.id);
1640
- this._spawnedEntities = [], this._spawnPoints = [], this._entityNodes = [];
2058
+ if (this._simulation !== null) for (let e of this._spawnedEntities) this._simulation.despawn(e.id);
2059
+ this._simulation = null, this._spawnedEntities = [], this._spawnPoints = [], this._entityNodes = [];
1641
2060
  for (let e of this._levelSounds.values()) e.dispose();
1642
2061
  this._levelSounds.clear(), this._playingSoundsBeforeDeactivate.clear(), await super.$dispose();
1643
2062
  }
1644
- }, Fe = class {
2063
+ }, et = class {
1645
2064
  _eventBus;
1646
2065
  _gameEngine = null;
1647
2066
  _log;
@@ -1663,7 +2082,7 @@ var Me = class {
1663
2082
  return this._propertyHandlers;
1664
2083
  }
1665
2084
  constructor(e, t) {
1666
- this._eventBus = e, this._logger = t, this._log = t?.getLogger("LevelManager") || new N("LevelManager"), this._eventUnsubscribers.push(this._eventBus.subscribe("level:progress", (e) => {
2085
+ this._eventBus = e, this._logger = t, this._log = t?.getLogger("LevelManager") || new j("LevelManager"), this._eventUnsubscribers.push(this._eventBus.subscribe("level:progress", (e) => {
1667
2086
  this._handleProgress(e.payload);
1668
2087
  })), this._eventUnsubscribers.push(this._eventBus.subscribe("level:complete", (e) => {
1669
2088
  this._handleComplete(e.payload);
@@ -1698,7 +2117,7 @@ var Me = class {
1698
2117
  if (!n) throw Error(`Level class '${e.class}' is not registered.`);
1699
2118
  return this._log.debug(`Creating level '${e.name}' using class '${e.class}'`), new n(e, t);
1700
2119
  }
1701
- return this._log.debug(`Creating level '${e.name}' using GameLevel`), new Pe(e, t);
2120
+ return this._log.debug(`Creating level '${e.name}' using GameLevel`), new $e(e, t);
1702
2121
  }
1703
2122
  registerLevelConfig(e) {
1704
2123
  this._levelConfigs.has(e.name) && this._log.warn(`Level config '${e.name}' is already registered. Overwriting.`), this._levelConfigs.set(e.name, e), this._log.info(`Registered level config: ${e.name}`);
@@ -1731,18 +2150,28 @@ var Me = class {
1731
2150
  let r = this._loadedLevels.get(n.name);
1732
2151
  if (r) return this._log.warn(`Level '${n.name}' is already loaded`), r;
1733
2152
  this._log.debug(`Loading level: ${n.name}`);
1734
- let i = this._createLevelInstance(n);
2153
+ let i = this._createLevelInstance(n), a = this._gameEngine?.simulation ?? null;
1735
2154
  this._loadingLevel = i;
1736
2155
  try {
1737
2156
  await i.load(t);
2157
+ let e = this._gameEngine?.simulation ?? null;
2158
+ i.$simulation === null && e !== null && e !== a && i.$adoptSimulation(e);
2159
+ } catch (e) {
2160
+ throw await i.$dispose(), e;
1738
2161
  } finally {
1739
- this._loadingLevel = null;
2162
+ this._loadingLevel = null, this._gameEngine !== null && (this._gameEngine.simulation = a);
1740
2163
  }
1741
2164
  return this._loadedLevels.set(n.name, i), i;
1742
2165
  }
2166
+ _bindSimulation(e) {
2167
+ this._gameEngine !== null && e.$simulation !== null && (this._gameEngine.simulation = e.$simulation);
2168
+ }
2169
+ $bindSimulation(e) {
2170
+ this._currentLevel !== null && this._currentLevel.$adoptSimulation(e), this._gameEngine !== null && (this._gameEngine.simulation = e);
2171
+ }
1743
2172
  async activateLevel(e) {
1744
2173
  let t = await this.loadLevel(e);
1745
- return this._currentLevel = t, this._log.info(`Activated level: ${t.name}`), t;
2174
+ return this._currentLevel = t, this._bindSimulation(t), this._log.info(`Activated level: ${t.name}`), t;
1746
2175
  }
1747
2176
  async unloadLevel(e) {
1748
2177
  let t = this._loadedLevels.get(e);
@@ -1752,7 +2181,7 @@ var Me = class {
1752
2181
  this._currentLevel ? await this.unloadLevel(this._currentLevel.name) : this._log.warn("No current level to unload");
1753
2182
  }
1754
2183
  async transition(e, t) {
1755
- let n = this._currentLevel;
2184
+ let n = this._currentLevel, r = this._gameEngine?.simulation ?? null;
1756
2185
  try {
1757
2186
  this._eventBus.publish({
1758
2187
  type: "level:transition:start",
@@ -1769,12 +2198,12 @@ var Me = class {
1769
2198
  });
1770
2199
  let r = await this.loadLevel(e, t);
1771
2200
  if (t?.preloadOnly) return;
1772
- n && !t?.keepAlive && await this.unloadLevel(n.name), this._currentLevel = r, r.onActivate && await r.onActivate(), this._eventBus.publish({
2201
+ n && !t?.keepAlive && await this.unloadLevel(n.name), this._currentLevel = r, this._bindSimulation(r), r.onActivate && await r.onActivate(), this._eventBus.publish({
1773
2202
  type: "level:transition:complete",
1774
2203
  payload: { levelName: e }
1775
2204
  });
1776
2205
  } catch (t) {
1777
- throw this._eventBus.publish({
2206
+ throw this._gameEngine !== null && (this._gameEngine.simulation = r), this._eventBus.publish({
1778
2207
  type: "level:transition:error",
1779
2208
  payload: {
1780
2209
  from: n?.name,
@@ -1790,7 +2219,7 @@ var Me = class {
1790
2219
  for (let e of this._loadedLevels.values()) await e.$dispose();
1791
2220
  this._loadedLevels.clear(), this._levelConfigs.clear(), this._currentLevel = null;
1792
2221
  }
1793
- }, Ie = class {
2222
+ }, tt = class {
1794
2223
  _audioEngine;
1795
2224
  _channels = /* @__PURE__ */ new Map();
1796
2225
  _masterMuted = !1;
@@ -1861,14 +2290,18 @@ var Me = class {
1861
2290
  getChannels() {
1862
2291
  return Array.from(this._channels.keys());
1863
2292
  }
1864
- }, Le = 1, Re = class {
2293
+ }, nt = 1, rt = class {
1865
2294
  #e;
1866
2295
  #t;
1867
2296
  #n;
1868
2297
  #r = [];
2298
+ #i = null;
1869
2299
  constructor(e, t, n = Date.now) {
1870
2300
  this.#e = e, this.#t = t, this.#n = n;
1871
2301
  }
2302
+ $setGameEngine(e) {
2303
+ this.#i = e;
2304
+ }
1872
2305
  onBeforeSave(e) {
1873
2306
  this.#r.push(e);
1874
2307
  }
@@ -1879,7 +2312,7 @@ var Me = class {
1879
2312
  ...e()
1880
2313
  };
1881
2314
  return {
1882
- saveFormatVersion: Le,
2315
+ saveFormatVersion: nt,
1883
2316
  engineVersion: this.#t,
1884
2317
  level: this.#e.currentLevel?.name ?? "",
1885
2318
  timestamp: this.#n(),
@@ -1887,17 +2320,22 @@ var Me = class {
1887
2320
  snapshot: e.snapshot()
1888
2321
  };
1889
2322
  }
1890
- async load(e, t) {
1891
- if (e.saveFormatVersion !== Le) throw Error(`The save format version "${e.saveFormatVersion}" is not one this engine knows how to load.`);
1892
- return await this.#e.transition(e.level, { forRestore: !0 }), {
1893
- simulation: t.fromSnapshot(e.snapshot),
2323
+ async load(e) {
2324
+ if (e.saveFormatVersion !== nt) throw Error(`The save format version "${e.saveFormatVersion}" is not one this engine knows how to load.`);
2325
+ if (this.#i === null) throw Error("SimulationSaveManager: gameEngine not set. Call $setGameEngine() first.");
2326
+ await this.#e.transition(e.level, { forRestore: !0 });
2327
+ let t = this.#i.simulation;
2328
+ if (t === null) throw Error("SimulationSaveManager: the transitioned level built no simulation to restore into.");
2329
+ let n = t.fromSnapshot(e.snapshot);
2330
+ return this.#e.$bindSimulation(n), {
2331
+ simulation: n,
1894
2332
  envelope: e
1895
2333
  };
1896
2334
  }
1897
2335
  async $teardown() {
1898
2336
  this.#r.length = 0;
1899
2337
  }
1900
- }, ze = class {
2338
+ }, it = class {
1901
2339
  _viewer = null;
1902
2340
  _shown = /* @__PURE__ */ new Map();
1903
2341
  _materials = /* @__PURE__ */ new Map();
@@ -1930,27 +2368,30 @@ var Me = class {
1930
2368
  this._materials.clear();
1931
2369
  }
1932
2370
  _getViewer(e) {
1933
- return this._viewer ||= new me(e.getScene()), this._viewer;
2371
+ return this._viewer ||= new pe(e.getScene()), this._viewer;
1934
2372
  }
1935
2373
  _getColorMaterial(e, t) {
1936
2374
  let n = this._materials.get(e);
1937
- return n || (n = new T(`sage-collider-debug-${e}`, t.getScene()), n.emissiveColor = r.FromHexString(e), n.disableLighting = !0, n.wireframe = !0, this._materials.set(e, n), n);
2375
+ return n || (n = new E(`sage-collider-debug-${e}`, t.getScene()), n.emissiveColor = r.FromHexString(e), n.disableLighting = !0, n.wireframe = !0, this._materials.set(e, n), n);
1938
2376
  }
1939
2377
  };
1940
2378
  //#endregion
1941
2379
  //#region src/utils/graphics.ts
1942
- async function Be(e, t) {
1943
- let n = new ue(e, t);
2380
+ async function at() {
2381
+ return Pe() ? le.IsSupportedAsync : !1;
2382
+ }
2383
+ async function ot(e, t) {
2384
+ let n = new le(e, t);
1944
2385
  return await n.initAsync(), n;
1945
2386
  }
1946
- function q(e, t) {
2387
+ function st(e, t) {
1947
2388
  return new l(e, t.antialias, t.options, t.adaptToDeviceRatio);
1948
2389
  }
1949
- function Ve(e) {
2390
+ function ct(e) {
1950
2391
  return new b(e);
1951
2392
  }
1952
- async function He(e, t, n = !1) {
1953
- if (e === null) return console.debug("Using Null Engine"), Ve(t);
2393
+ async function lt(e, t, n = !1) {
2394
+ if (e === null) return console.debug("Using Null Engine"), ct(t);
1954
2395
  if (n) {
1955
2396
  if ("options" in t) {
1956
2397
  let e = t;
@@ -1968,33 +2409,33 @@ async function He(e, t, n = !1) {
1968
2409
  }
1969
2410
  let r = t.engine || "auto";
1970
2411
  if (r === "webgpu") {
1971
- if (we()) try {
1972
- return console.debug("Using forced WebGPU engine"), await Be(e, t);
2412
+ if (await at()) try {
2413
+ return console.debug("Using forced WebGPU engine"), await ot(e, t);
1973
2414
  } catch (e) {
1974
2415
  throw console.error("Forced WebGPU initialization failed:", e), Error("Forced WebGPU failed to initialize. If WebGPU is required, check browser compatibility.", { cause: e });
1975
2416
  }
1976
2417
  throw Error("WebGPU was forced but is not available in this browser.");
1977
2418
  }
1978
- if (r === "webgl") return console.debug("Using forced WebGL engine"), q(e, t);
1979
- if (we()) try {
1980
- return console.debug("Using WebGPU"), Be(e, t).catch((n) => (console.warn("WebGPU initialization failed, falling back to WebGL:", n), q(e, t)));
2419
+ if (r === "webgl") return console.debug("Using forced WebGL engine"), st(e, t);
2420
+ if (await at()) try {
2421
+ return console.debug("Using WebGPU"), await ot(e, t);
1981
2422
  } catch (e) {
1982
2423
  console.warn("WebGPU initialization failed, falling back to WebGL:", e);
1983
2424
  }
1984
2425
  else console.warn("WebGPU not supported, falling back to WebGL.");
1985
- return console.debug("Using WebGL"), q(e, t);
2426
+ return console.debug("Using WebGL"), st(e, t);
1986
2427
  }
1987
2428
  //#endregion
1988
2429
  //#region src/utils/physics.ts
1989
- async function Ue(e) {
1990
- return await he(e ? { wasmBinary: e } : void 0);
2430
+ async function ut(e) {
2431
+ return await me(e ? { wasmBinary: e } : void 0);
1991
2432
  }
1992
- function We(e) {
2433
+ function dt(e) {
1993
2434
  return new p(!0, e);
1994
2435
  }
1995
2436
  //#endregion
1996
2437
  //#region src/utils/timer.ts
1997
- var Ge = class {
2438
+ var ft = class {
1998
2439
  _nextId = 0;
1999
2440
  _delays = [];
2000
2441
  _intervals = [];
@@ -2052,31 +2493,40 @@ var Ge = class {
2052
2493
  };
2053
2494
  //#endregion
2054
2495
  //#region src/debug/builtins.ts
2055
- function J(e) {
2496
+ function q(e) {
2056
2497
  if (e.simulation === null) {
2057
2498
  console.warn("[sage] No simulation yet -- nothing has given the engine a scene to build one against.");
2058
2499
  return;
2059
2500
  }
2060
2501
  return e.simulation;
2061
2502
  }
2062
- function Ke(e, t) {
2063
- return typeof e == "string" ? J(t)?.getEntity(e) : e;
2503
+ function pt(e, t) {
2504
+ return typeof e == "string" ? q(t)?.getEntity(e) : e;
2064
2505
  }
2065
- function qe(e, t) {
2506
+ function mt(e, t) {
2066
2507
  let n = t.managers.gameManager, r = t.managers.levelManager, i = [];
2067
- e.expose("engine", t), e.expose("events", t.eventBus), e.expose("physics", t.physics), e.expose("colliders", t.debug.colliders), e.expose("level", { get: () => r.currentLevel }), e.expose("scene", { get: () => r.currentLevel?.scene ?? null }), e.expose("tp", (e, n, r, i) => {
2068
- let a = Ke(e, t);
2508
+ e.expose("engine", t), e.expose("events", t.eventBus), e.expose("physics", t.physics), e.expose("colliders", t.debug.colliders), e.expose("entities", new Proxy({}, { get(e, n) {
2509
+ if (typeof n == "symbol") return;
2510
+ let r = q(t)?.getEntity(n);
2511
+ return r || console.warn(`[sage] Entity not found: ${n}`), r;
2512
+ } })), e.expose("level", { get: () => r.currentLevel }), e.expose("scene", { get: () => r.currentLevel?.scene ?? null }), e.expose("tp", (e, n, r, i) => {
2513
+ let a = pt(e, t);
2069
2514
  if (!a) {
2070
2515
  console.warn(`[sage] Entity not found: ${e}`);
2071
2516
  return;
2072
2517
  }
2073
- if (!(a instanceof V)) {
2518
+ if (!(a instanceof H)) {
2074
2519
  console.warn(`[sage] Entity "${a.id}" has no node`);
2075
2520
  return;
2076
2521
  }
2077
- a.node.position.x = n, a.node.position.y = r, a.node.position.z = i, console.log(`[sage] Teleported "${a.id}" to (${n}, ${r}, ${i})`);
2522
+ let o = a.state;
2523
+ o.nodeName === void 0 ? o.position = {
2524
+ x: n,
2525
+ y: r,
2526
+ z: i
2527
+ } : (a.node.position.x = n, a.node.position.y = r, a.node.position.z = i), console.log(`[sage] Teleported "${a.id}" to (${n}, ${r}, ${i})`);
2078
2528
  }), e.expose("spawn", (e, n, r, i) => {
2079
- let a = J(t);
2529
+ let a = q(t);
2080
2530
  if (!a) return;
2081
2531
  let o = a.spawn(e, void 0, { position: {
2082
2532
  x: n,
@@ -2084,16 +2534,22 @@ function qe(e, t) {
2084
2534
  z: i
2085
2535
  } });
2086
2536
  return console.log(`[sage] Spawned "${e}" (${o.id}) at (${n}, ${r}, ${i})`), o;
2087
- }), e.expose("list", () => {
2088
- let e = J(t);
2089
- if (!e) return [];
2090
- let n = e.entities, r = n.map((e) => ({
2091
- id: e.id,
2092
- node: e instanceof V ? e.node.name : "(no node)"
2093
- }));
2094
- return console.table(r), n;
2537
+ }), e.expose("list", (e, n) => {
2538
+ let r = q(t);
2539
+ if (!r) return [];
2540
+ let i = r.entities;
2541
+ e !== void 0 && (i = i.filter((t) => t.name === e)), n !== void 0 && (i = i.filter((e) => e.state.tags.includes(n)));
2542
+ let a = i.map((e) => {
2543
+ let t = {
2544
+ id: e.id,
2545
+ name: e.name,
2546
+ node: e instanceof H ? e.node.name : "(no node)"
2547
+ };
2548
+ return e.hasBehavior(F) && (t.displayName = e.state.displayName), t;
2549
+ });
2550
+ return console.table(a), [...i];
2095
2551
  }), e.expose("inspect", (e) => {
2096
- let n = Ke(e, t);
2552
+ let n = pt(e, t);
2097
2553
  if (!n) {
2098
2554
  console.warn(`[sage] Entity not found: ${e}`);
2099
2555
  return;
@@ -2101,8 +2557,8 @@ function qe(e, t) {
2101
2557
  let r = {
2102
2558
  id: n.id,
2103
2559
  state: n.state,
2104
- node: n instanceof V ? n.node.name : null,
2105
- position: n instanceof V ? n.node.position : null
2560
+ node: n instanceof H ? n.node.name : null,
2561
+ position: n instanceof H ? n.node.position : null
2106
2562
  };
2107
2563
  return console.log("[sage] Entity info:", r), r;
2108
2564
  }), e.expose("logEvents", (e) => {
@@ -2123,73 +2579,78 @@ function qe(e, t) {
2123
2579
  }
2124
2580
  //#endregion
2125
2581
  //#region src/interfaces/logger.ts
2126
- var Je = [
2582
+ var ht = [
2127
2583
  "trace",
2128
2584
  "debug",
2129
2585
  "info",
2130
2586
  "warn",
2131
2587
  "error",
2132
2588
  "none"
2133
- ], Y = new N("ColliderHandler");
2134
- function Ye(e) {
2135
- let { min: t, max: n } = e.getHierarchyBoundingVectors(!0), r = n.subtract(t), i = t.add(n).scale(.5).subtract(e.absolutePosition), a = e.absoluteRotationQuaternion, o = C.Inverse(a), s = new D();
2136
- return i.rotateByQuaternionToRef(o, s), {
2589
+ ];
2590
+ //#endregion
2591
+ //#region src/utils/bounds.ts
2592
+ function gt(e) {
2593
+ let { min: t, max: n } = e.getHierarchyBoundingVectors(!0), r = n.subtract(t), i = t.add(n).scale(.5).subtract(e.absolutePosition), a = w.Inverse(e.absoluteRotationQuaternion), o = new O();
2594
+ return i.rotateByQuaternionToRef(a, o), {
2137
2595
  extents: r,
2138
- center: s
2596
+ center: o
2139
2597
  };
2140
2598
  }
2141
- function X(e, t, n) {
2599
+ //#endregion
2600
+ //#region src/handlers/collider.ts
2601
+ var J = new j("ColliderHandler");
2602
+ function Y(e, t, n) {
2142
2603
  let r = e.getScene(), i = { mass: n };
2143
- if (!(e instanceof v) && (t === S.BOX || t === S.SPHERE)) {
2144
- let { extents: n, center: r } = Ye(e);
2145
- i.center = r, t === S.BOX ? i.extents = n : i.radius = Math.max(n.x, n.y, n.z) / 2;
2604
+ if (!(e instanceof v) && (t === C.BOX || t === C.SPHERE)) {
2605
+ let { extents: n, center: r } = gt(e);
2606
+ i.center = r, t === C.BOX ? i.extents = n : i.radius = Math.max(n.x, n.y, n.z) / 2;
2146
2607
  }
2147
- new te(e, t, i, r);
2608
+ new S(e, t, i, r);
2148
2609
  }
2149
- function Xe(e, t) {
2610
+ function _t(e, t) {
2150
2611
  let n = e.getChildMeshes().find((e) => e.metadata?.collider_mesh === !0);
2151
- n instanceof v ? (n.isVisible = !1, X(n, S.MESH, t)) : X(e, S.MESH, t);
2612
+ n instanceof v ? (n.isVisible = !1, Y(n, C.MESH, t)) : Y(e, C.MESH, t);
2152
2613
  }
2153
- function Ze(t) {
2614
+ function vt(t) {
2154
2615
  t.registerPropertyHandler("collider", (t, n, r, i) => {
2155
2616
  let a = n;
2156
- if (Y.debug(`Processing collider: ${t.name} -> ${a} (isMesh: ${t instanceof v})`), !r.scene) throw Error("Scene not available for collider handler");
2617
+ if (J.debug(`Processing collider: ${t.name} -> ${a} (isMesh: ${t instanceof v})`), !r.scene) throw Error("Scene not available for collider handler");
2157
2618
  if (!(t instanceof v) && a === "mesh") {
2158
- Y.warn(`Skipping mesh collider for ${t.name}: not a Mesh instance`);
2619
+ J.warn(`Skipping mesh collider for ${t.name}: not a Mesh instance`);
2159
2620
  return;
2160
2621
  }
2161
2622
  let o = t.metadata?.collider_mass ?? 0;
2162
2623
  switch (a) {
2163
2624
  case "box":
2164
- X(t, S.BOX, o);
2625
+ Y(t, C.BOX, o);
2165
2626
  break;
2166
2627
  case "sphere":
2167
- X(t, S.SPHERE, o);
2628
+ Y(t, C.SPHERE, o);
2168
2629
  break;
2169
2630
  case "mesh":
2170
- Xe(t, o);
2631
+ _t(t, o);
2171
2632
  break;
2172
2633
  case "none":
2173
2634
  t instanceof e && (t.checkCollisions = !1);
2174
2635
  break;
2175
- default: Y.warn(`Unknown collider type: ${a}`);
2636
+ default: J.warn(`Unknown collider type: ${a}`);
2176
2637
  }
2177
2638
  t.metadata?.collider_kinematic && t instanceof e && t.physicsBody && (t.physicsBody.disablePreStep = !1);
2178
2639
  });
2179
2640
  }
2180
2641
  //#endregion
2181
2642
  //#region src/handlers/lod.ts
2182
- var Qe = new N("LodHandler");
2183
- function $e(e) {
2643
+ var yt = new j("LodHandler");
2644
+ function bt(e) {
2184
2645
  return e.split(",").map((e) => parseFloat(e.trim())).filter((e) => !isNaN(e));
2185
2646
  }
2186
- function et(e) {
2647
+ function xt(e) {
2187
2648
  e.registerPropertyHandler("lod_distances", (e, t, n, r) => {
2188
2649
  let i = t;
2189
2650
  if (!(e instanceof v)) return;
2190
- let a = $e(i);
2651
+ let a = bt(i);
2191
2652
  if (a.length === 0) {
2192
- Qe.warn(`Invalid lod_distances value: ${i}`);
2653
+ yt.warn(`Invalid lod_distances value: ${i}`);
2193
2654
  return;
2194
2655
  }
2195
2656
  let o = e.getChildMeshes(!0), s = Math.min(a.length, o.length);
@@ -2200,14 +2661,14 @@ function et(e) {
2200
2661
  }
2201
2662
  //#endregion
2202
2663
  //#region src/handlers/occluder.ts
2203
- function tt(e) {
2664
+ function St(e) {
2204
2665
  e.registerPropertyHandler("occluder", (e, t, n, r) => {
2205
2666
  t && e instanceof v && (e.isOccluder = !0, e.isVisible = !1);
2206
2667
  });
2207
2668
  }
2208
2669
  //#endregion
2209
2670
  //#region src/utils/metadata.ts
2210
- function nt(e, t) {
2671
+ function Ct(e, t) {
2211
2672
  let n = {}, r = `${t}_`;
2212
2673
  for (let [t, i] of Object.entries(e)) if (t.startsWith(r)) {
2213
2674
  let e = t.slice(r.length);
@@ -2217,14 +2678,14 @@ function nt(e, t) {
2217
2678
  }
2218
2679
  //#endregion
2219
2680
  //#region src/handlers/sound.ts
2220
- var rt = new N("SoundHandler");
2221
- function it(e) {
2681
+ var wt = new j("SoundHandler");
2682
+ function Tt(e) {
2222
2683
  e.registerPropertyHandler("sound", (e, t, n, r) => {
2223
2684
  let i = t;
2224
2685
  if (!n.scene) throw Error("Scene not available for sound handler");
2225
- let a = nt(e.metadata, "sound"), o = a.volume ?? 1, s = a.loop ?? !0, c = a.spatial ?? !0, l = a.distance ?? 100, u = a.autoplay ?? !0, d = a.channel ?? "ambient", f = r.managers.audioManager;
2686
+ let a = Ct(e.metadata, "sound"), o = a.volume ?? 1, s = a.loop ?? !0, c = a.spatial ?? !0, l = a.distance ?? 100, u = a.autoplay ?? !0, d = a.channel ?? "ambient", f = r.managers.audioManager;
2226
2687
  if (!f) {
2227
- rt.warn(`No AudioManager available. Sound for "${e.name}" skipped.`);
2688
+ wt.warn(`No AudioManager available. Sound for "${e.name}" skipped.`);
2228
2689
  return;
2229
2690
  }
2230
2691
  f.createSound(`${e.name}_sound`, i, d, {
@@ -2237,13 +2698,13 @@ function it(e) {
2237
2698
  }).then((t) => {
2238
2699
  c && t.spatial.attach(e);
2239
2700
  }).catch((t) => {
2240
- rt.error(`Failed to create sound for node "${e.name}": ${t}`);
2701
+ wt.error(`Failed to create sound for node "${e.name}": ${t}`);
2241
2702
  });
2242
2703
  });
2243
2704
  }
2244
2705
  //#endregion
2245
2706
  //#region src/handlers/trigger.ts
2246
- function at(e, n, r, i, a) {
2707
+ function Et(e, n, r, i, a) {
2247
2708
  let o = a === "enter" ? t.OnIntersectionEnterTrigger : t.OnIntersectionExitTrigger, s = `trigger:${a}`;
2248
2709
  e.registerAction(new u({
2249
2710
  trigger: o,
@@ -2253,15 +2714,15 @@ function at(e, n, r, i, a) {
2253
2714
  type: s,
2254
2715
  payload: {
2255
2716
  trigger: n,
2256
- other: e.source
2717
+ other: e.additionalData
2257
2718
  }
2258
2719
  });
2259
2720
  }));
2260
2721
  }
2261
- function ot(e, t, n, r) {
2262
- at(e, t, n, r, "enter"), at(e, t, n, r, "exit");
2722
+ function Dt(e, t, n, r) {
2723
+ Et(e, t, n, r, "enter"), Et(e, t, n, r, "exit");
2263
2724
  }
2264
- function st(n) {
2725
+ function Ot(n) {
2265
2726
  n.registerPropertyHandler("trigger", (n, r, i, a) => {
2266
2727
  let o = r, s = i.scene;
2267
2728
  if (!s) throw Error("Scene not available for trigger handler");
@@ -2270,9 +2731,9 @@ function st(n) {
2270
2731
  n.isVisible = !1, n.checkCollisions = !0;
2271
2732
  let l = n.actionManager ?? new t(s);
2272
2733
  n.actionManager = l;
2273
- for (let e of s.meshes) e !== n && !e.metadata?.trigger && ot(l, o, c, e);
2734
+ for (let e of s.meshes) e !== n && !e.metadata?.trigger && Dt(l, o, c, e);
2274
2735
  let u = s.onNewMeshAddedObservable.add((e) => {
2275
- e !== n && !e.metadata?.trigger && ot(l, o, c, e);
2736
+ e !== n && !e.metadata?.trigger && Dt(l, o, c, e);
2276
2737
  });
2277
2738
  n.onDisposeObservable.add(() => {
2278
2739
  s.onNewMeshAddedObservable.remove(u);
@@ -2281,7 +2742,7 @@ function st(n) {
2281
2742
  }
2282
2743
  //#endregion
2283
2744
  //#region src/handlers/visible.ts
2284
- function ct(t) {
2745
+ function kt(t) {
2285
2746
  t.registerPropertyHandler("visible", (t, n, r, i) => {
2286
2747
  if (!(t instanceof e)) return;
2287
2748
  let a = !0;
@@ -2290,12 +2751,12 @@ function ct(t) {
2290
2751
  }
2291
2752
  //#endregion
2292
2753
  //#region src/handlers/index.ts
2293
- function lt(e) {
2294
- Ze(e), et(e), tt(e), it(e), st(e), ct(e);
2754
+ function At(e) {
2755
+ vt(e), xt(e), St(e), Tt(e), Ot(e), kt(e);
2295
2756
  }
2296
2757
  //#endregion
2297
2758
  //#region src/entities/defineEntity.ts
2298
- function ut(e, t) {
2759
+ function jt(e, t) {
2299
2760
  let n = t ?? {}, r = e.tags ?? [], i = n.tags ?? [];
2300
2761
  return {
2301
2762
  ...e.defaultState,
@@ -2303,13 +2764,13 @@ function ut(e, t) {
2303
2764
  tags: [.../* @__PURE__ */ new Set([...r, ...i])]
2304
2765
  };
2305
2766
  }
2306
- function dt(e) {
2307
- class t extends V {
2767
+ function Mt(e) {
2768
+ class t extends H {
2308
2769
  static behaviors = e.behaviors;
2309
2770
  static meshConfig = e.mesh;
2310
2771
  static actions = e.actions;
2311
2772
  static create(t, n, r, i) {
2312
- let a = ut(e, r);
2773
+ let a = jt(e, r);
2313
2774
  return super.create(t, n, a, i);
2314
2775
  }
2315
2776
  }
@@ -2317,84 +2778,72 @@ function dt(e) {
2317
2778
  }
2318
2779
  //#endregion
2319
2780
  //#region src/entities/standardMeshSource.ts
2320
- function Z(e) {
2781
+ function X(e) {
2321
2782
  return new r(e.r, e.g, e.b);
2322
2783
  }
2323
- function ft(e, t, n) {
2784
+ function Nt(e, t, n) {
2324
2785
  let r = `Create${t.charAt(0).toUpperCase()}${t.slice(1)}`, i = y[r];
2325
2786
  if (typeof i != "function") throw Error(`No Babylon mesh builder provides the primitive shape "${t}".`);
2326
2787
  return i(t, n ?? {}, e);
2327
2788
  }
2328
- function pt(e, t, n) {
2789
+ function Pt(e, t, n) {
2329
2790
  if (n.type === "pbr") {
2330
2791
  let r = new x(`${t.name}-material`, e);
2331
- n.color !== void 0 && (r.albedoColor = Z(n.color)), n.emissive !== void 0 && (r.emissiveColor = Z(n.emissive)), n.metallic !== void 0 && (r.metallic = n.metallic), n.roughness !== void 0 && (r.roughness = n.roughness), t.material = r;
2792
+ n.color !== void 0 && (r.albedoColor = X(n.color)), n.emissive !== void 0 && (r.emissiveColor = X(n.emissive)), n.metallic !== void 0 && (r.metallic = n.metallic), n.roughness !== void 0 && (r.roughness = n.roughness), t.material = r;
2332
2793
  } else {
2333
- let r = new T(`${t.name}-material`, e);
2334
- n.color !== void 0 && (r.diffuseColor = Z(n.color)), n.emissive !== void 0 && (r.emissiveColor = Z(n.emissive)), t.material = r;
2794
+ let r = new E(`${t.name}-material`, e);
2795
+ n.color !== void 0 && (r.diffuseColor = X(n.color)), n.emissive !== void 0 && (r.emissiveColor = X(n.emissive)), t.material = r;
2335
2796
  }
2336
2797
  }
2337
- async function mt(e, t, n) {
2798
+ async function Ft(e, t, n) {
2338
2799
  let r;
2339
- return t.source.includes("#") ? (await n.load(t.source), r = n.clone(t.source)) : r = ft(e, t.source, t.params), r.isVisible = t.visible ?? !0, t.material !== void 0 && pt(e, r, t.material), r;
2800
+ return t.source.includes("#") ? (await n.load(t.source), r = n.clone(t.source)) : r = Nt(e, t.source, t.params), r.isVisible = t.visible ?? !0, t.material !== void 0 && Pt(e, r, t.material), r;
2340
2801
  }
2341
- function ht(e, t) {
2802
+ function It(e, t) {
2342
2803
  return async (n, r) => {
2343
2804
  let i = e[r]?.meshConfig;
2344
- if (i !== void 0) return mt(n, i, t);
2805
+ if (i !== void 0) return Ft(n, i, t);
2345
2806
  };
2346
2807
  }
2347
2808
  //#endregion
2348
- //#region src/input/actionRegistry.ts
2349
- var gt = class {
2809
+ //#region src/behaviors/sound.ts
2810
+ var Lt = class extends P {
2811
+ static ops = ["play", "stop"];
2812
+ defaults = { sounds: {} };
2350
2813
  #e = /* @__PURE__ */ new Map();
2351
- register(e) {
2352
- if (this.#e.has(e.name)) throw Error(`An action is already registered under the name "${e.name}".`);
2353
- if (e.type === "analog" && e.minValue !== void 0 && e.maxValue !== void 0 && e.minValue > e.maxValue) throw Error(`Action "${e.name}": minValue (${e.minValue}) is above maxValue (${e.maxValue}).`);
2354
- this.#e.set(e.name, e);
2355
- }
2356
- get(e) {
2357
- return this.#e.get(e);
2358
- }
2359
- list() {
2360
- return [...this.#e.values()];
2361
- }
2362
- }, _t = class {
2363
- #e = /* @__PURE__ */ new Map();
2364
- #t = [];
2365
- registerContext(e, t = !0) {
2366
- this.#e.set(e, {
2367
- exclusive: t,
2368
- active: !1
2814
+ #t = !1;
2815
+ onMeshLoaded() {
2816
+ let e = this.entity, t = e.audio;
2817
+ if (t !== void 0) for (let [n, r] of Object.entries(this.state.sounds)) t.createSound(n, r.url, r.channel, {
2818
+ volume: r.volume ?? 1,
2819
+ loop: r.loop ?? !1
2820
+ }).then((t) => {
2821
+ this.#n(n, r, e, t);
2369
2822
  });
2370
2823
  }
2371
- activateContext(e, t) {
2372
- let n = this.#n(e);
2373
- if (n.exclusive) for (let [t, n] of this.#e) t !== e && n.exclusive && (n.active = !1);
2374
- n.active = !0;
2375
- for (let n of this.#t) n.context === e && n.prime(t(n));
2824
+ onDestroy() {
2825
+ this.#t = !0;
2826
+ for (let e of this.#e.values()) e.stop(), e.dispose();
2827
+ this.#e.clear();
2376
2828
  }
2377
- deactivateContext(e) {
2378
- this.#n(e).active = !1;
2379
- }
2380
- isActive(e) {
2381
- return this.#e.get(e)?.active === !0;
2382
- }
2383
- isRegistered(e) {
2384
- return this.#e.has(e);
2829
+ play(e) {
2830
+ this.#r(e)?.play();
2385
2831
  }
2386
- addBinding(e) {
2387
- this.#t.push(e);
2832
+ stop(e) {
2833
+ this.#r(e)?.stop();
2388
2834
  }
2389
- isLive(e) {
2390
- return e.context === void 0 || this.isActive(e.context);
2835
+ #n(e, t, n, r) {
2836
+ if (this.#t) {
2837
+ r.dispose();
2838
+ return;
2839
+ }
2840
+ (t.spatial ?? !1) && (r.spatial.attach(n.node), r.spatial.maxDistance = t.maxDistance ?? 100), this.#e.set(e, r), (t.loop ?? !1) && r.play();
2391
2841
  }
2392
- #n(e) {
2393
- let t = this.#e.get(e);
2394
- if (t === void 0) throw Error(`No context is registered under the name "${e}".`);
2395
- return t;
2842
+ #r(e) {
2843
+ if (!(e in this.state.sounds)) throw Error(`SoundBehavior: no sound named "${e}" is declared.`);
2844
+ return this.#e.get(e);
2396
2845
  }
2397
- }, vt = class {
2846
+ }, Rt = class {
2398
2847
  sourceType = "key";
2399
2848
  sourceKey;
2400
2849
  constructor(e) {
@@ -2403,7 +2852,7 @@ var gt = class {
2403
2852
  getValue(e) {
2404
2853
  return e.keys[this.sourceKey];
2405
2854
  }
2406
- }, yt = class {
2855
+ }, zt = class {
2407
2856
  sourceType;
2408
2857
  sourceKey;
2409
2858
  constructor(e, t) {
@@ -2411,10 +2860,11 @@ var gt = class {
2411
2860
  }
2412
2861
  getValue(e) {
2413
2862
  if (this.sourceType === "button") return e.buttons[this.sourceKey];
2863
+ if (this.sourceType === "movement") return this.sourceKey === "x" ? e.movement.x : this.sourceKey === "y" ? e.movement.y : void 0;
2414
2864
  if (this.sourceType === "position") return this.sourceKey === "x" ? e.position.x : this.sourceKey === "y" ? e.position.y : void 0;
2415
2865
  if (this.sourceType === "wheel") return this.sourceKey === "deltaX" ? e.wheel.deltaX : this.sourceKey === "deltaY" ? e.wheel.deltaY : this.sourceKey === "deltaZ" ? e.wheel.deltaZ : void 0;
2416
2866
  }
2417
- }, bt = class {
2867
+ }, Bt = class {
2418
2868
  sourceType;
2419
2869
  sourceKey;
2420
2870
  constructor(e, t) {
@@ -2424,17 +2874,25 @@ var gt = class {
2424
2874
  if (this.sourceType === "button") return e.buttons[this.sourceKey];
2425
2875
  if (this.sourceType === "axis") return e.axes[this.sourceKey];
2426
2876
  }
2427
- }, xt = class {
2877
+ }, Vt = class {
2428
2878
  kind = "trigger";
2429
2879
  action;
2430
2880
  device;
2431
2881
  context;
2882
+ preventDefault;
2432
2883
  #e;
2433
2884
  #t;
2434
2885
  #n;
2435
2886
  #r;
2436
2887
  constructor(e, t, n, r = {}, i) {
2437
- this.action = e, this.device = t, this.context = i, this.#e = n, this.#t = r.edge ?? "rising", this.#n = r.threshold;
2888
+ this.action = e, this.device = t, this.context = i, this.preventDefault = r.preventDefault ?? !1, this.#e = n, this.#t = r.edge ?? "rising", this.#n = r.threshold;
2889
+ }
2890
+ get input() {
2891
+ return {
2892
+ device: this.device,
2893
+ sourceType: this.#e.sourceType,
2894
+ sourceKey: this.#e.sourceKey
2895
+ };
2438
2896
  }
2439
2897
  process(e) {
2440
2898
  let t = this.#a(this.#e.getValue(e)), n = this.#r;
@@ -2445,14 +2903,10 @@ var gt = class {
2445
2903
  }
2446
2904
  toDefinition() {
2447
2905
  let e = { edge: this.#t };
2448
- return this.#n !== void 0 && (e.threshold = this.#n), {
2906
+ return this.#n !== void 0 && (e.threshold = this.#n), this.preventDefault && (e.preventDefault = !0), {
2449
2907
  kind: "trigger",
2450
2908
  action: this.action.name,
2451
- input: {
2452
- device: this.device,
2453
- sourceType: this.#e.sourceType,
2454
- sourceKey: this.#e.sourceKey
2455
- },
2909
+ input: this.input,
2456
2910
  context: this.context,
2457
2911
  options: e
2458
2912
  };
@@ -2466,11 +2920,12 @@ var gt = class {
2466
2920
  #o(e) {
2467
2921
  return typeof e == "number" ? e : +(e === !0);
2468
2922
  }
2469
- }, St = class {
2923
+ }, Ht = class {
2470
2924
  kind = "toggle";
2471
2925
  action;
2472
2926
  device;
2473
2927
  context;
2928
+ preventDefault;
2474
2929
  #e;
2475
2930
  #t;
2476
2931
  #n;
@@ -2479,7 +2934,14 @@ var gt = class {
2479
2934
  #a;
2480
2935
  #o;
2481
2936
  constructor(e, t, n, r = {}, i) {
2482
- this.action = e, this.device = t, this.context = i, this.#e = n, this.#t = r.onValue ?? !0, this.#n = r.offValue ?? !1, this.#r = r.threshold, this.#i = r.invert ?? !1, this.#a = r.initialState;
2937
+ this.action = e, this.device = t, this.context = i, this.preventDefault = r.preventDefault ?? !1, this.#e = n, this.#t = r.onValue ?? !0, this.#n = r.offValue ?? !1, this.#r = r.threshold, this.#i = r.invert ?? !1, this.#a = r.initialState;
2938
+ }
2939
+ get input() {
2940
+ return {
2941
+ device: this.device,
2942
+ sourceType: this.#e.sourceType,
2943
+ sourceKey: this.#e.sourceKey
2944
+ };
2483
2945
  }
2484
2946
  process(e) {
2485
2947
  let t = this.#s(this.#e.getValue(e)), n = this.#o;
@@ -2494,14 +2956,10 @@ var gt = class {
2494
2956
  offValue: this.#n,
2495
2957
  invert: this.#i
2496
2958
  };
2497
- return this.#r !== void 0 && (e.threshold = this.#r), this.#a !== void 0 && (e.initialState = this.#a), {
2959
+ return this.#r !== void 0 && (e.threshold = this.#r), this.#a !== void 0 && (e.initialState = this.#a), this.preventDefault && (e.preventDefault = !0), {
2498
2960
  kind: "toggle",
2499
2961
  action: this.action.name,
2500
- input: {
2501
- device: this.device,
2502
- sourceType: this.#e.sourceType,
2503
- sourceKey: this.#e.sourceKey
2504
- },
2962
+ input: this.input,
2505
2963
  context: this.context,
2506
2964
  options: e
2507
2965
  };
@@ -2513,11 +2971,12 @@ var gt = class {
2513
2971
  #c(e) {
2514
2972
  return typeof e == "boolean" ? e : typeof e == "number" ? this.#r === void 0 ? e !== 0 : e >= this.#r : !1;
2515
2973
  }
2516
- }, Ct = class {
2974
+ }, Z = class {
2517
2975
  kind = "value";
2518
2976
  action;
2519
2977
  device;
2520
2978
  context;
2979
+ preventDefault;
2521
2980
  #e;
2522
2981
  #t;
2523
2982
  #n;
@@ -2525,68 +2984,94 @@ var gt = class {
2525
2984
  #i;
2526
2985
  #a;
2527
2986
  #o;
2528
- #s;
2529
- #c;
2530
2987
  constructor(e, t, n, r = {}, i) {
2531
- this.action = e, this.device = t, this.context = i, this.#e = n, this.#t = r.scale ?? 1, this.#n = r.offset ?? 0, this.#r = r.invert ?? !1, this.#i = r.deadzone ?? 0, this.#a = r.min, this.#o = r.max, this.#s = r.emitOnChange ?? !0;
2988
+ this.action = e, this.device = t, this.context = i, this.preventDefault = r.preventDefault ?? !1, this.#e = n, this.#t = r.scale ?? 1, this.#n = r.offset ?? 0, this.#r = r.invert ?? !1, this.#i = r.deadzone ?? 0, this.#a = r.min, this.#o = r.max;
2532
2989
  }
2533
- process(e) {
2534
- let t = this.#l(e), n = this.#c;
2535
- if (this.#c = t, !(this.#s && t === n)) return { value: t };
2990
+ get input() {
2991
+ return {
2992
+ device: this.device,
2993
+ sourceType: this.#e.sourceType,
2994
+ sourceKey: this.#e.sourceKey
2995
+ };
2536
2996
  }
2537
- prime(e) {
2538
- this.#c = this.#l(e);
2997
+ process(e) {
2998
+ return { value: this.#s(e) };
2539
2999
  }
3000
+ prime(e) {}
2540
3001
  toDefinition() {
2541
3002
  let e = {
2542
3003
  scale: this.#t,
2543
3004
  offset: this.#n,
2544
3005
  invert: this.#r,
2545
- deadzone: this.#i,
2546
- emitOnChange: this.#s
3006
+ deadzone: this.#i
2547
3007
  };
2548
- return this.#a !== void 0 && (e.min = this.#a), this.#o !== void 0 && (e.max = this.#o), {
3008
+ return this.#a !== void 0 && (e.min = this.#a), this.#o !== void 0 && (e.max = this.#o), this.preventDefault && (e.preventDefault = !0), {
2549
3009
  kind: "value",
2550
3010
  action: this.action.name,
2551
- input: {
2552
- device: this.device,
2553
- sourceType: this.#e.sourceType,
2554
- sourceKey: this.#e.sourceKey
2555
- },
3011
+ input: this.input,
2556
3012
  context: this.context,
2557
3013
  options: e
2558
3014
  };
2559
3015
  }
2560
- #l(e) {
2561
- let t = this.#u(this.#e.getValue(e));
3016
+ #s(e) {
3017
+ let t = this.#c(this.#e.getValue(e));
2562
3018
  return t *= this.#t, t += this.#n, this.#a !== void 0 && t < this.#a && (t = this.#a), this.#o !== void 0 && t > this.#o && (t = this.#o), this.#r && (t = -t), Math.abs(t) < this.#i && (t = 0), t;
2563
3019
  }
2564
- #u(e) {
3020
+ #c(e) {
3021
+ return typeof e == "number" ? e : +(e === !0);
3022
+ }
3023
+ }, Ut = class {
3024
+ kind = "delta";
3025
+ action;
3026
+ device;
3027
+ context;
3028
+ preventDefault;
3029
+ #e;
3030
+ #t;
3031
+ #n;
3032
+ #r;
3033
+ constructor(e, t, n, r = {}, i) {
3034
+ this.action = e, this.device = t, this.context = i, this.preventDefault = r.preventDefault ?? !1, this.#e = n, this.#t = r.scale ?? 1, this.#n = r.invert ?? !1, this.#r = r.deadzone ?? 0;
3035
+ }
3036
+ get input() {
3037
+ return {
3038
+ device: this.device,
3039
+ sourceType: this.#e.sourceType,
3040
+ sourceKey: this.#e.sourceKey
3041
+ };
3042
+ }
3043
+ process(e) {
3044
+ let t = this.#i(this.#e.getValue(e));
3045
+ if (t *= this.#t, this.#n && (t = -t), Math.abs(t) < this.#r && (t = 0), t !== 0) return { value: t };
3046
+ }
3047
+ prime(e) {}
3048
+ toDefinition() {
3049
+ let e = {
3050
+ scale: this.#t,
3051
+ invert: this.#n,
3052
+ deadzone: this.#r
3053
+ };
3054
+ return this.preventDefault && (e.preventDefault = !0), {
3055
+ kind: "delta",
3056
+ action: this.action.name,
3057
+ input: this.input,
3058
+ context: this.context,
3059
+ options: e
3060
+ };
3061
+ }
3062
+ #i(e) {
2565
3063
  return typeof e == "number" ? e : +(e === !0);
2566
3064
  }
2567
3065
  };
2568
3066
  //#endregion
2569
3067
  //#region src/input/resolveBinding.ts
2570
- function wt(e, t, n) {
3068
+ function Wt(e, t, n) {
2571
3069
  let r = e.input.device, i = e.options ?? {};
2572
- return e.kind === "trigger" ? new xt(t, r, n, i, e.context) : e.kind === "toggle" ? new St(t, r, n, i, e.context) : new Ct(t, r, n, i, e.context);
2573
- }
2574
- //#endregion
2575
- //#region src/input/deliverAction.ts
2576
- function Tt(e, t, n, r, i) {
2577
- let a = e.process(t);
2578
- if (a === void 0) return;
2579
- let o = {
2580
- type: `action:${e.action.name}`,
2581
- senderID: r,
2582
- targetID: i,
2583
- payload: a.value
2584
- };
2585
- n.bus.emit(o);
3070
+ return e.kind === "trigger" ? new Vt(t, r, n, i, e.context) : e.kind === "toggle" ? new Ht(t, r, n, i, e.context) : e.kind === "delta" ? new Ut(t, r, n, i, e.context) : new Z(t, r, n, i, e.context);
2586
3071
  }
2587
3072
  //#endregion
2588
3073
  //#region src/input/inputCapture.ts
2589
- var Et = class {
3074
+ var Gt = class {
2590
3075
  #e;
2591
3076
  #t;
2592
3077
  #n;
@@ -2614,14 +3099,14 @@ var Et = class {
2614
3099
  };
2615
3100
  //#endregion
2616
3101
  //#region src/input/configuration.ts
2617
- function Dt(e, t, n) {
3102
+ function Kt(e, t, n) {
2618
3103
  return {
2619
3104
  actions: [...e],
2620
3105
  bindings: t.map((e) => e.toDefinition()),
2621
3106
  contexts: [...n]
2622
3107
  };
2623
3108
  }
2624
- function Ot(e, t, n) {
3109
+ function qt(e, t, n) {
2625
3110
  for (let n of e.actions) t.register(n);
2626
3111
  for (let t of e.contexts) n.registerContext(t.name, t.exclusive);
2627
3112
  return [...e.bindings];
@@ -2629,7 +3114,7 @@ function Ot(e, t, n) {
2629
3114
  //#endregion
2630
3115
  //#region ../../node_modules/hexoid/dist/index.mjs
2631
3116
  for (var Q = 256, $ = []; Q--;) $[Q] = (Q + 256).toString(16).substring(1);
2632
- function kt(e) {
3117
+ function Jt(e) {
2633
3118
  e ||= 16;
2634
3119
  var t = "", n = 0;
2635
3120
  return function() {
@@ -2642,7 +3127,7 @@ function kt(e) {
2642
3127
  }
2643
3128
  //#endregion
2644
3129
  //#region src/utils/id.ts
2645
- var At = kt(16), jt = class {
3130
+ var Yt = Jt(16), Xt = class {
2646
3131
  _currentState;
2647
3132
  transitions = /* @__PURE__ */ new Map();
2648
3133
  wildcardTransitions = /* @__PURE__ */ new Map();
@@ -2700,54 +3185,59 @@ var At = kt(16), jt = class {
2700
3185
  };
2701
3186
  //#endregion
2702
3187
  //#region src/sage.ts
2703
- async function Mt(e, t, n = {}) {
2704
- let r = new P(n.logLevel || "debug"), i = r.getLogger("SAGE");
3188
+ async function Zt(e, t, n = {}) {
3189
+ let r = new M(n.logLevel || "debug"), i = r.getLogger("SAGE");
2705
3190
  i.info(`Initializing SAGE Game Engine v${k}...`), i.debug("Creating rendering engine...");
2706
- let a = await He(e, {
3191
+ let a = await lt(e, {
2707
3192
  antialias: !0,
2708
3193
  adaptToDeviceRatio: !0,
2709
3194
  ...n.renderOptions
2710
3195
  }, n.largeWorldRendering ?? !1);
2711
3196
  i.debug("Creating physics engine...");
2712
- let o = await Ue(n.havokBinary), s = We(o);
3197
+ let o = await ut(n.havokBinary), s = dt(o);
2713
3198
  i.debug("Creating event bus...");
2714
- let c = new F(r);
3199
+ let c = new N(r);
2715
3200
  i.debug("Creating scene engine...");
2716
- let l = new Se(e, a, o, r);
3201
+ let l = new je(e, a, o, r);
2717
3202
  i.debug("Creating managers...");
2718
- let u = new Ce(c, l, r), d = new Fe(c, r), f = new Re(d, k), p = new Te(a, c, d, r), m = n.fixedStepDuration ?? 1 / 60, h = async () => void 0, ee = (e, n) => new U({
2719
- fixedStepDuration: m,
3203
+ let u = new Ne(c, l, r), d = new et(c, r), f = new rt(d, k), p = new Fe(a, c, d, r), m = new Ue();
3204
+ p.setInputManager(m);
3205
+ let h, g;
3206
+ n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."), h = new Ae(r), await h.initialize(), i.debug("Creating audio manager..."), g = new tt(h, r), await g.initialize(n.audioChannels));
3207
+ let ee = n.fixedStepDuration ?? 1 / 60, _ = async () => void 0;
3208
+ i.debug("Creating collider debug manager...");
3209
+ let v = new it(), y = (e, n) => new Oe({
3210
+ fixedStepDuration: ee,
2720
3211
  entityClasses: t,
2721
3212
  scene: e,
2722
- pool: new be(),
2723
- loadMesh: (t, r) => (n ?? h)(e, t, r)
2724
- }), g = null;
2725
- n.debug !== !1 && (i.debug("Creating debug console..."), g = new O((typeof n.debug == "object" ? n.debug.namespace : void 0) ?? "sage")), i.debug("Creating collider debug manager...");
2726
- let _ = new ze();
2727
- i.debug("Creating game timer...");
2728
- let v = new Ge();
2729
- p.registerFrameCallback((e) => v.tick(e * 1e3));
2730
- let y, b;
2731
- n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."), y = new xe(r), await y.initialize(), i.debug("Creating audio manager..."), b = new Ie(y, r), await b.initialize(n.audioChannels)), i.info(`SAGE Game Engine v${k} initialized successfully.`);
2732
- let x = new A(e, a, s, c, r, v, ee, {
3213
+ pool: new ke(),
3214
+ loadMesh: (t, r) => (n ?? _)(e, t, r),
3215
+ audio: g,
3216
+ colliders: v
3217
+ }), b = null;
3218
+ n.debug !== !1 && (i.debug("Creating debug console..."), b = new he((typeof n.debug == "object" ? n.debug.namespace : void 0) ?? "sage")), i.debug("Creating game timer...");
3219
+ let x = new ft();
3220
+ p.registerFrameCallback((e) => x.tick(e * 1e3)), i.info(`SAGE Game Engine v${k} initialized successfully.`);
3221
+ let S = new ge(e, a, s, c, r, x, y, {
2733
3222
  sceneEngine: l,
2734
- audioEngine: y
3223
+ audioEngine: h
2735
3224
  }, {
2736
3225
  assetManager: u,
2737
3226
  gameManager: p,
3227
+ inputManager: m,
2738
3228
  levelManager: d,
2739
3229
  saveManager: f,
2740
- audioManager: b
3230
+ audioManager: g
2741
3231
  }, n.largeWorldRendering ?? !1, {
2742
- colliders: _,
2743
- console: g,
3232
+ colliders: v,
3233
+ console: b,
2744
3234
  expose: (e, t) => {
2745
- g?.expose(e, t);
3235
+ b?.expose(e, t);
2746
3236
  }
2747
3237
  });
2748
- return d.$setGameEngine(x), p.$setGameEngine(x), g && qe(g, x), x;
3238
+ return d.$setGameEngine(S), p.$setGameEngine(S), f.$setGameEngine(S), b && mt(b, S), S;
2749
3239
  }
2750
3240
  //#endregion
2751
- export { _t as ActionContextRegistry, gt as ActionRegistry, Ce as AssetManager, xe as AudioEngine, Ie as AudioManager, ge as Behavior, ze as ColliderDebugManager, j as ConsoleBackend, O as DebugConsole, A as GameEngine, z as GameEntity, F as GameEventBus, Pe as GameLevel, B as GameSimulationManager, Ge as GameTimer, bt as GamepadReader, Et as InputCapture, vt as KeyboardReader, Me as Level, Je as LogLevels, P as LoggingUtility, yt as MouseReader, V as NodeEntity, be as NodePool, U as NodeSimulation, M as NullBackend, Ne as OutlineManager, N as SAGELogger, Se as SceneEngine, Re as SimulationSaveManager, jt as StateMachine, St as ToggleBinding, xt as TriggerBinding, k as VERSION, Ct as ValueBinding, Oe as applyPostProcessing, ht as buildStandardMeshSource, nt as collectPrefixedProperties, Mt as createGameEngine, dt as defineEntity, Tt as deliverAction, Dt as exportConfiguration, At as generateId, je as getCanonicalTransform, Ot as importConfiguration, lt as registerAllPropertyHandlers, Ze as registerColliderHandler, et as registerLodHandler, tt as registerOccluderHandler, it as registerSoundHandler, st as registerTriggerHandler, ct as registerVisibleHandler, wt as resolveBinding, K as toQuatObject, Ae as toQuaternion, ke as toVec3Object, G as toVector3 };
3241
+ export { Ie as ActionContextRegistry, Le as ActionRegistry, Ne as AssetManager, Ae as AudioEngine, tt as AudioManager, P as Behavior, it as ColliderDebugManager, _e as ConsoleBackend, he as DebugConsole, Ut as DeltaBinding, L as EventBus, ge as GameEngine, Ce as GameEntity, N as GameEventBus, $e as GameLevel, we as GameSimulationManager, ft as GameTimer, Bt as GamepadReader, Gt as InputCapture, Ue as InputManager, Rt as KeyboardReader, Ze as Level, ht as LogLevels, M as LoggingUtility, zt as MouseReader, F as NamedBehavior, H as NodeEntity, ke as NodePool, Oe as NodeSimulation, A as NullBackend, Qe as OutlineManager, W as ROUTING_LOOP_SENDER_ID, j as SAGELogger, je as SceneEngine, rt as SimulationSaveManager, Lt as SoundBehavior, Xt as StateMachine, ye as StateMachineBehavior, Ht as ToggleBinding, Vt as TriggerBinding, k as VERSION, Z as ValueBinding, Ke as applyPostProcessing, It as buildStandardMeshSource, Ct as collectPrefixedProperties, gt as computeHierarchyBounds, Zt as createGameEngine, Mt as defineEntity, ve as defineStates, Re as deliverAction, Se as dilationLimit, xe as drainPassLimit, Kt as exportConfiguration, Yt as generateId, Xe as getCanonicalTransform, qt as importConfiguration, be as operationCallDepthLimit, At as registerAllPropertyHandlers, vt as registerColliderHandler, xt as registerLodHandler, St as registerOccluderHandler, Tt as registerSoundHandler, Ot as registerTriggerHandler, kt as registerVisibleHandler, Wt as resolveBinding, Je as toQuatObject, Ye as toQuaternion, qe as toVec3Object, K as toVector3 };
2752
3242
 
2753
3243
  //# sourceMappingURL=sage.es.js.map