@skewedaspect/sage 0.10.1 → 0.12.0

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.
package/dist/sage.es.js CHANGED
@@ -68,7 +68,7 @@ var He = class {
68
68
  configurable: !0
69
69
  });
70
70
  }
71
- }, j = "0.10.1", Ue = class e {
71
+ }, j = "0.12.0", Ue = class e {
72
72
  canvas;
73
73
  renderEngine;
74
74
  managers;
@@ -403,7 +403,7 @@ var B = class e extends Te {
403
403
  }), n.loadMesh(n.scene, this.name, this.state).catch((e) => {
404
404
  n.logger.error(`Loading the mesh for ${this.name} (${this.id}) failed. The entity keeps its node and carries no mesh.`, e);
405
405
  }).then((e) => {
406
- e !== void 0 && (e.parent = s.node, Xe(n, this.name, this.id, e)), s.mesh = e;
406
+ e !== void 0 && s.node.isDisposed() && (e.dispose(), e = void 0), e !== void 0 && (e.parent = s.node, Xe(n, this.name, this.id, e)), s.mesh = e;
407
407
  let t = L.get(s);
408
408
  L.delete(s), t?.();
409
409
  })) : L.has(s) ? L.set(s, () => {
@@ -838,6 +838,7 @@ var dt = class {
838
838
  _containers = /* @__PURE__ */ new Map();
839
839
  _sourceMeshes = /* @__PURE__ */ new Map();
840
840
  _pendingContainers = /* @__PURE__ */ new Map();
841
+ _sceneContainers = /* @__PURE__ */ new WeakMap();
841
842
  constructor(e, t, n) {
842
843
  this._bus = e, this._sceneEngine = t, this._log = n?.getLogger("AssetManager") ?? new H("AssetManager");
843
844
  }
@@ -872,6 +873,18 @@ var dt = class {
872
873
  this._pendingContainers.delete(e);
873
874
  }
874
875
  }
876
+ _containerForScene(e, t) {
877
+ let n = this._sceneContainers.get(t);
878
+ n || (n = /* @__PURE__ */ new Map(), this._sceneContainers.set(t, n));
879
+ let r = n.get(e);
880
+ if (r) return r;
881
+ let i = this._sceneEngine.loadModel(e, t);
882
+ n.set(e, i);
883
+ let a = n;
884
+ return i.catch(() => {
885
+ a.delete(e);
886
+ }), i;
887
+ }
875
888
  _findMeshInContainer(e, t, n) {
876
889
  let r = e.meshes.find((e) => e.name === t);
877
890
  if (!r) {
@@ -907,6 +920,16 @@ var dt = class {
907
920
  });
908
921
  return r.metadata = null, r;
909
922
  }
923
+ async instantiate(e, t) {
924
+ let { basePath: n, fragment: r } = this._parsePath(e);
925
+ if (r) throw Error(`Cannot instantiate '${e}': the fragment '${r}' is one mesh. clone() copies one mesh.`);
926
+ let i = (await this._containerForScene(n, t)).instantiateModelsToScene(void 0, !1, { doNotInstantiate: !0 });
927
+ for (let e of i.rootNodes) {
928
+ e.metadata = null;
929
+ for (let t of e.getDescendants()) t.metadata = null;
930
+ }
931
+ return i;
932
+ }
910
933
  async preload(e) {
911
934
  let t = e.length, n = [], r = 0, i = 0, a = async () => {
912
935
  for (; r < e.length;) {
@@ -1408,29 +1431,53 @@ function Mt(e) {
1408
1431
  function Nt(e, t) {
1409
1432
  return Math.abs(e) > jt || Math.abs(t) > jt;
1410
1433
  }
1411
- var Pt = class {
1434
+ function Pt(e, t) {
1435
+ let n = { ...e };
1436
+ for (let e of t) n[e] = !0;
1437
+ return n;
1438
+ }
1439
+ var Ft = /* @__PURE__ */ new Set([
1440
+ "button",
1441
+ "checkbox",
1442
+ "color",
1443
+ "file",
1444
+ "hidden",
1445
+ "image",
1446
+ "radio",
1447
+ "range",
1448
+ "reset",
1449
+ "submit"
1450
+ ]);
1451
+ function It(e) {
1452
+ if (!(e instanceof Element)) return !1;
1453
+ if (e instanceof HTMLTextAreaElement) return !0;
1454
+ if (e instanceof HTMLInputElement) return !Ft.has(e.type);
1455
+ let t = e.closest("[contenteditable]");
1456
+ return t !== null && t.getAttribute("contenteditable") !== "false";
1457
+ }
1458
+ var Lt = class {
1412
1459
  actions = new gt();
1413
1460
  contexts;
1414
1461
  #e = {};
1415
1462
  #t = {};
1416
- #n = {
1463
+ #n = /* @__PURE__ */ new Set();
1464
+ #r = /* @__PURE__ */ new Set();
1465
+ #i = {
1417
1466
  x: 0,
1418
1467
  y: 0
1419
1468
  };
1420
- #r = {
1469
+ #a = {
1421
1470
  deltaX: 0,
1422
1471
  deltaY: 0,
1423
1472
  deltaZ: 0
1424
1473
  };
1425
- #i = {
1474
+ #o = {
1426
1475
  x: 0,
1427
1476
  y: 0
1428
1477
  };
1429
- #a = /* @__PURE__ */ new Map();
1430
- #o = /* @__PURE__ */ new Set();
1431
1478
  #s = /* @__PURE__ */ new Map();
1432
- #c;
1433
- #l;
1479
+ #c = /* @__PURE__ */ new Set();
1480
+ #l = /* @__PURE__ */ new Map();
1434
1481
  #u;
1435
1482
  #d;
1436
1483
  #f;
@@ -1439,9 +1486,12 @@ var Pt = class {
1439
1486
  #h;
1440
1487
  #g;
1441
1488
  #_;
1489
+ #v;
1490
+ #y;
1491
+ #b;
1442
1492
  constructor(e) {
1443
- this.contexts = new ht(e), this.#f = (e) => {
1444
- this.#v("keyboard", "key", e.code) && e.preventDefault(), this.#e[e.code] = !0, this.#E("keyboard"), this.#k({
1493
+ this.contexts = new ht(e), this.#m = (e) => {
1494
+ It(e.composedPath()[0]) || (this.#x("keyboard", "key", e.code) && e.preventDefault(), this.#e[e.code] = !0, this.#n.add(e.code), this.#A("keyboard"), this.#N({
1445
1495
  device: {
1446
1496
  type: "keyboard",
1447
1497
  index: 0
@@ -1449,13 +1499,13 @@ var Pt = class {
1449
1499
  sourceType: "key",
1450
1500
  sourceKey: e.code,
1451
1501
  value: !0
1452
- });
1453
- }, this.#p = (e) => {
1502
+ }));
1503
+ }, this.#h = (e) => {
1454
1504
  this.#e[e.code] = !1;
1455
- }, this.#m = (e) => {
1505
+ }, this.#g = (e) => {
1456
1506
  if (e.pointerType !== "mouse") return;
1457
1507
  let t = String(e.button);
1458
- this.#v("mouse", "button", t) && e.preventDefault(), this.#t[t] = !0, this.#E("mouse"), this.#k({
1508
+ this.#x("mouse", "button", t) && e.preventDefault(), this.#t[t] = !0, this.#r.add(t), this.#A("mouse"), this.#N({
1459
1509
  device: {
1460
1510
  type: "mouse",
1461
1511
  index: 0
@@ -1464,22 +1514,25 @@ var Pt = class {
1464
1514
  sourceKey: t,
1465
1515
  value: !0
1466
1516
  });
1467
- }, this.#h = (e) => {
1468
- e.pointerType === "mouse" && (this.#t[String(e.button)] = !1);
1469
- }, this.#g = (e) => {
1470
- e.pointerType === "mouse" && (this.#n.x = e.clientX, this.#n.y = e.clientY, this.#i.x += e.movementX, this.#i.y += e.movementY, Nt(e.movementX, e.movementY) && (this.#c = "mouse"));
1471
1517
  }, this.#_ = (e) => {
1472
- this.#v("mouse", "wheel") && e.preventDefault(), this.#r.deltaX += e.deltaX, this.#r.deltaY += e.deltaY, this.#r.deltaZ += e.deltaZ, (e.deltaX !== q || e.deltaY !== q || e.deltaZ !== q) && (this.#E("mouse"), this.#O(e));
1473
- }, A() && (window.addEventListener("keydown", this.#f), window.addEventListener("keyup", this.#p), window.addEventListener("pointerdown", this.#m), window.addEventListener("pointerup", this.#h), window.addEventListener("pointermove", this.#g), window.addEventListener("wheel", this.#_, { passive: !1 }));
1518
+ e.pointerType === "mouse" && (this.#t[String(e.button)] = !1);
1519
+ }, this.#v = (e) => {
1520
+ e.pointerType === "mouse" && (this.#i.x = e.clientX, this.#i.y = e.clientY, this.#o.x += e.movementX, this.#o.y += e.movementY, Nt(e.movementX, e.movementY) && (this.#u = "mouse"));
1521
+ }, this.#y = (e) => {
1522
+ this.#x("mouse", "wheel") && e.preventDefault(), this.#a.deltaX += e.deltaX, this.#a.deltaY += e.deltaY, this.#a.deltaZ += e.deltaZ, (e.deltaX !== q || e.deltaY !== q || e.deltaZ !== q) && (this.#A("mouse"), this.#M(e));
1523
+ }, this.#b = () => {
1524
+ for (let e of Object.keys(this.#e)) this.#e[e] = !1;
1525
+ for (let e of Object.keys(this.#t)) this.#t[e] = !1;
1526
+ }, A() && (window.addEventListener("blur", this.#b), window.addEventListener("keydown", this.#m), window.addEventListener("keyup", this.#h), window.addEventListener("pointerdown", this.#g), window.addEventListener("pointerup", this.#_), window.addEventListener("pointermove", this.#v), window.addEventListener("wheel", this.#y, { passive: !1 }));
1474
1527
  }
1475
1528
  get lastActiveDeviceType() {
1476
- return this.#c;
1529
+ return this.#u;
1477
1530
  }
1478
1531
  get activeScheme() {
1479
- return this.#l;
1532
+ return this.#d;
1480
1533
  }
1481
1534
  deviceState(e, t) {
1482
- return this.#S(e, t);
1535
+ return this.#E(e, t);
1483
1536
  }
1484
1537
  bind(e) {
1485
1538
  let t = this.actions.get(e.action);
@@ -1488,8 +1541,8 @@ var Pt = class {
1488
1541
  return this.contexts.addBinding(n), n;
1489
1542
  }
1490
1543
  registerCapture(e) {
1491
- return this.#o.add(e), () => {
1492
- this.#o.delete(e);
1544
+ return this.#c.add(e), () => {
1545
+ this.#c.delete(e);
1493
1546
  };
1494
1547
  }
1495
1548
  getBindingsForAction(e, t, n) {
@@ -1501,15 +1554,15 @@ var Pt = class {
1501
1554
  return r;
1502
1555
  }
1503
1556
  routeCapturedInput(e) {
1504
- this.#C();
1557
+ this.#D();
1505
1558
  let t = /* @__PURE__ */ new Map();
1506
1559
  for (let n of this.contexts.list()) if (this.contexts.isLive(n)) {
1507
- let r = this.#S(n.device.type, n.device.index);
1508
- n.kind === "value" ? this.#y(t, n, r) : _t(n, r, e, K);
1560
+ let r = this.#T(n.device.type, n.device.index);
1561
+ n.kind === "value" ? this.#S(t, n, r) : _t(n, r, e, K);
1509
1562
  }
1510
- this.#b(t, e), this.#T(e), this.#D(e), this.#i.x = q, this.#i.y = q, this.#r.deltaX = q, this.#r.deltaY = q, this.#r.deltaZ = q;
1563
+ this.#C(t, e), this.#k(e), this.#j(e), this.#o.x = q, this.#o.y = q, this.#a.deltaX = q, this.#a.deltaY = q, this.#a.deltaZ = q, this.#n.clear(), this.#r.clear();
1511
1564
  }
1512
- #v(e, t, n) {
1565
+ #x(e, t, n) {
1513
1566
  for (let r of this.contexts.list()) if (r.preventDefault && this.contexts.isLive(r)) {
1514
1567
  let { device: i, sourceType: a, sourceKey: o } = r.input;
1515
1568
  if (i.type === e && a === t && (n === void 0 || o === n)) return !0;
@@ -1517,9 +1570,9 @@ var Pt = class {
1517
1570
  return !1;
1518
1571
  }
1519
1572
  async dispose() {
1520
- A() && (window.removeEventListener("keydown", this.#f), window.removeEventListener("keyup", this.#p), window.removeEventListener("pointerdown", this.#m), window.removeEventListener("pointerup", this.#h), window.removeEventListener("pointermove", this.#g), window.removeEventListener("wheel", this.#_));
1573
+ A() && (window.removeEventListener("blur", this.#b), window.removeEventListener("keydown", this.#m), window.removeEventListener("keyup", this.#h), window.removeEventListener("pointerdown", this.#g), window.removeEventListener("pointerup", this.#_), window.removeEventListener("pointermove", this.#v), window.removeEventListener("wheel", this.#y));
1521
1574
  }
1522
- #y(e, t, n) {
1575
+ #S(e, t, n) {
1523
1576
  let r = t.process(n);
1524
1577
  if (r === void 0) return;
1525
1578
  let i = Number(r.value), a = e.get(t.action.name);
@@ -1528,46 +1581,54 @@ var Pt = class {
1528
1581
  value: i
1529
1582
  }) : a.value += i;
1530
1583
  }
1531
- #b(e, t) {
1532
- for (let [t, n] of this.#s) e.has(t) || e.set(t, {
1584
+ #C(e, t) {
1585
+ for (let [t, n] of this.#l) e.has(t) || e.set(t, {
1533
1586
  action: n,
1534
1587
  value: 0
1535
1588
  });
1536
1589
  for (let [n, r] of e) {
1537
- let e = this.#x(r.action, r.value), i = e !== this.#x(r.action, q), a = this.#s.has(n);
1538
- i ? this.#s.set(n, r.action) : this.#s.delete(n), (i || a) && vt(r.action, e, t, K);
1590
+ let e = this.#w(r.action, r.value), i = e !== this.#w(r.action, q), a = this.#l.has(n);
1591
+ i ? this.#l.set(n, r.action) : this.#l.delete(n), (i || a) && vt(r.action, e, t, K);
1539
1592
  }
1540
1593
  }
1541
- #x(e, t) {
1594
+ #w(e, t) {
1542
1595
  return e.type === "analog" ? e.minValue !== void 0 && t < e.minValue ? e.minValue : e.maxValue !== void 0 && t > e.maxValue ? e.maxValue : t : t;
1543
1596
  }
1544
- #S(e, t) {
1597
+ #T(e, t) {
1598
+ return e === "keyboard" ? { keys: Pt(this.#e, this.#n) } : e === "mouse" ? {
1599
+ buttons: Pt(this.#t, this.#r),
1600
+ position: this.#i,
1601
+ wheel: this.#a,
1602
+ movement: this.#o
1603
+ } : this.#E(e, t);
1604
+ }
1605
+ #E(e, t) {
1545
1606
  if (e === "keyboard") return { keys: this.#e };
1546
1607
  if (e === "mouse") return {
1547
1608
  buttons: this.#t,
1548
- position: this.#n,
1549
- wheel: this.#r,
1550
- movement: this.#i
1609
+ position: this.#i,
1610
+ wheel: this.#a,
1611
+ movement: this.#o
1551
1612
  };
1552
- let n = this.#a.get(t);
1613
+ let n = this.#s.get(t);
1553
1614
  return n === void 0 ? {
1554
1615
  buttons: {},
1555
1616
  axes: {}
1556
1617
  } : n;
1557
1618
  }
1558
- #C() {
1619
+ #D() {
1559
1620
  if (typeof navigator > "u" || typeof navigator.getGamepads != "function") return;
1560
1621
  let e = navigator.getGamepads();
1561
1622
  for (let t = 0; t < e.length; t++) {
1562
1623
  let n = e[t];
1563
- n !== null && this.#w(t, n);
1624
+ n !== null && this.#O(t, n);
1564
1625
  }
1565
1626
  }
1566
- #w(e, t) {
1627
+ #O(e, t) {
1567
1628
  let n = {}, r = !1;
1568
1629
  for (let i = 0; i < t.buttons.length; i++) {
1569
1630
  let a = t.buttons[i].value, o = String(i);
1570
- n[o] = a, Mt(a) && (r = !0, this.#k({
1631
+ n[o] = a, Mt(a) && (r = !0, this.#N({
1571
1632
  device: {
1572
1633
  type: "gamepad",
1573
1634
  index: e
@@ -1580,7 +1641,7 @@ var Pt = class {
1580
1641
  let i = {};
1581
1642
  for (let n = 0; n < t.axes.length; n++) {
1582
1643
  let a = t.axes[n], o = String(n);
1583
- i[o] = a, Mt(a) && (r = !0, this.#k({
1644
+ i[o] = a, Mt(a) && (r = !0, this.#N({
1584
1645
  device: {
1585
1646
  type: "gamepad",
1586
1647
  index: e
@@ -1590,39 +1651,39 @@ var Pt = class {
1590
1651
  value: a
1591
1652
  }));
1592
1653
  }
1593
- this.#a.set(e, {
1654
+ this.#s.set(e, {
1594
1655
  buttons: n,
1595
1656
  axes: i
1596
- }), r && this.#E("gamepad");
1657
+ }), r && this.#A("gamepad");
1597
1658
  }
1598
- #T(e) {
1599
- if (this.#c === this.#u) return;
1600
- let t = this.#u;
1601
- this.#u = this.#c, this.#c !== void 0 && e.bus.emit({
1659
+ #k(e) {
1660
+ if (this.#u === this.#f) return;
1661
+ let t = this.#f;
1662
+ this.#f = this.#u, this.#u !== void 0 && e.bus.emit({
1602
1663
  type: "input:deviceChanged",
1603
1664
  senderID: K,
1604
1665
  payload: {
1605
- deviceType: this.#c,
1666
+ deviceType: this.#u,
1606
1667
  previousDeviceType: t
1607
1668
  }
1608
1669
  });
1609
1670
  }
1610
- #E(e) {
1611
- this.#c = e, this.#l = G(e);
1671
+ #A(e) {
1672
+ this.#u = e, this.#d = G(e);
1612
1673
  }
1613
- #D(e) {
1614
- if (this.#l === this.#d) return;
1615
- let t = this.#d;
1616
- this.#d = this.#l, this.#l !== void 0 && e.bus.emit({
1674
+ #j(e) {
1675
+ if (this.#d === this.#p) return;
1676
+ let t = this.#p;
1677
+ this.#p = this.#d, this.#d !== void 0 && e.bus.emit({
1617
1678
  type: "input:schemeChanged",
1618
1679
  senderID: K,
1619
1680
  payload: {
1620
- scheme: this.#l,
1681
+ scheme: this.#d,
1621
1682
  previousScheme: t
1622
1683
  }
1623
1684
  });
1624
1685
  }
1625
- #O(e) {
1686
+ #M(e) {
1626
1687
  let t = [
1627
1688
  {
1628
1689
  sourceKey: "deltaY",
@@ -1637,7 +1698,7 @@ var Pt = class {
1637
1698
  value: e.deltaZ
1638
1699
  }
1639
1700
  ];
1640
- for (let e of t) e.value !== q && this.#k({
1701
+ for (let e of t) e.value !== q && this.#N({
1641
1702
  device: {
1642
1703
  type: "mouse",
1643
1704
  index: 0
@@ -1647,21 +1708,21 @@ var Pt = class {
1647
1708
  value: e.value
1648
1709
  });
1649
1710
  }
1650
- #k(e) {
1651
- for (let t of this.#o) t.feed(e);
1711
+ #N(e) {
1712
+ for (let t of this.#c) t.feed(e);
1652
1713
  }
1653
- }, Ft = {
1714
+ }, Rt = {
1654
1715
  hable: g.TONEMAPPING_STANDARD,
1655
1716
  reinhard: g.TONEMAPPING_STANDARD,
1656
1717
  hejidawson: g.TONEMAPPING_STANDARD,
1657
1718
  photographic: g.TONEMAPPING_STANDARD,
1658
1719
  aces: g.TONEMAPPING_ACES
1659
1720
  };
1660
- function It(e, t, n) {
1721
+ function zt(e, t, n) {
1661
1722
  if (!e.activeCamera) return;
1662
1723
  t.volumetric && n.warn("Volumetric lighting is recognized and applied by neither backend. Ignored.");
1663
1724
  let r = new c("sage-default", !0, e, e.cameras);
1664
- if (t.bloom && (r.bloomEnabled = !0, t.bloom.weight !== void 0 && (r.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (r.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (r.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (r.bloomKernel = t.bloom.kernel)), t.tonemap && (r.imageProcessingEnabled = !0, r.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (r.imageProcessing.toneMappingType = Ft[t.tonemap.operator] ?? g.TONEMAPPING_STANDARD)), t.grain && (r.grainEnabled = !0, t.grain.intensity !== void 0 && (r.grain.intensity = t.grain.intensity), t.grain.animated !== void 0 && (r.grain.animated = t.grain.animated)), t.vignette && (r.imageProcessingEnabled = !0, r.imageProcessing.vignetteEnabled = !0, t.vignette.weight !== void 0 && (r.imageProcessing.vignetteWeight = t.vignette.weight), t.vignette.stretch !== void 0 && (r.imageProcessing.vignetteStretch = t.vignette.stretch), t.vignette.color && (r.imageProcessing.vignetteColor = new a(t.vignette.color.r, t.vignette.color.g, t.vignette.color.b, 1))), t.sharpen && (r.sharpenEnabled = !0, t.sharpen.edge !== void 0 && (r.sharpen.edgeAmount = t.sharpen.edge), t.sharpen.color !== void 0 && (r.sharpen.colorAmount = t.sharpen.color)), t.chromaticAberration && (r.chromaticAberrationEnabled = !0, t.chromaticAberration.amount !== void 0 && (r.chromaticAberration.aberrationAmount = t.chromaticAberration.amount)), t.ssao) {
1725
+ if (t.bloom && (r.bloomEnabled = !0, t.bloom.weight !== void 0 && (r.bloomWeight = t.bloom.weight), t.bloom.threshold !== void 0 && (r.bloomThreshold = t.bloom.threshold), t.bloom.scale !== void 0 && (r.bloomScale = t.bloom.scale), t.bloom.kernel !== void 0 && (r.bloomKernel = t.bloom.kernel)), t.tonemap && (r.imageProcessingEnabled = !0, r.imageProcessing.toneMappingEnabled = !0, t.tonemap.operator && (r.imageProcessing.toneMappingType = Rt[t.tonemap.operator] ?? g.TONEMAPPING_STANDARD)), t.grain && (r.grainEnabled = !0, t.grain.intensity !== void 0 && (r.grain.intensity = t.grain.intensity), t.grain.animated !== void 0 && (r.grain.animated = t.grain.animated)), t.vignette && (r.imageProcessingEnabled = !0, r.imageProcessing.vignetteEnabled = !0, t.vignette.weight !== void 0 && (r.imageProcessing.vignetteWeight = t.vignette.weight), t.vignette.stretch !== void 0 && (r.imageProcessing.vignetteStretch = t.vignette.stretch), t.vignette.color && (r.imageProcessing.vignetteColor = new a(t.vignette.color.r, t.vignette.color.g, t.vignette.color.b, 1))), t.sharpen && (r.sharpenEnabled = !0, t.sharpen.edge !== void 0 && (r.sharpen.edgeAmount = t.sharpen.edge), t.sharpen.color !== void 0 && (r.sharpen.colorAmount = t.sharpen.color)), t.chromaticAberration && (r.chromaticAberrationEnabled = !0, t.chromaticAberration.amount !== void 0 && (r.chromaticAberration.aberrationAmount = t.chromaticAberration.amount)), t.ssao) {
1665
1726
  let n = new fe("sage-ssao", e, {
1666
1727
  ssaoRatio: .5,
1667
1728
  blurRatio: 1
@@ -1671,11 +1732,11 @@ function It(e, t, n) {
1671
1732
  }
1672
1733
  //#endregion
1673
1734
  //#region src/handlers/postProcessing.ts
1674
- async function Lt(e, t, n) {
1735
+ async function Bt(e, t, n) {
1675
1736
  if (t.renderer === "frameGraph") {
1676
1737
  let { applyFrameGraphPostProcessing: r } = await import("./postProcessingFrameGraph-Dx3e6D33.js");
1677
1738
  await r(e, t, n);
1678
- } else It(e, t, n);
1739
+ } else zt(e, t, n);
1679
1740
  }
1680
1741
  //#endregion
1681
1742
  //#region src/utils/bounds.ts
@@ -1688,22 +1749,22 @@ function J(e) {
1688
1749
  }
1689
1750
  //#endregion
1690
1751
  //#region src/handlers/collider.ts
1691
- var Y = 1, Rt = [
1752
+ var Y = 1, Vt = [
1692
1753
  "box",
1693
1754
  "sphere",
1694
1755
  "mesh",
1695
1756
  "none"
1696
1757
  ];
1697
- function zt(e, t, n) {
1698
- for (let e of Rt) if (t === e) return e;
1699
- n.warn(`Unusable collider on "${e.name}": ${JSON.stringify(t)}. The collider property takes ${Rt.join(", ")}. Building nothing.`);
1758
+ function Ht(e, t, n) {
1759
+ for (let e of Vt) if (t === e) return e;
1760
+ n.warn(`Unusable collider on "${e.name}": ${JSON.stringify(t)}. The collider property takes ${Vt.join(", ")}. Building nothing.`);
1700
1761
  }
1701
- function Bt(e, t) {
1762
+ function Ut(e, t) {
1702
1763
  let n = e.metadata?.collider_mass;
1703
1764
  return n == null ? Y : typeof n != "number" || !Number.isFinite(n) ? (t.warn(`Unusable collider_mass on ${e.name}: ${JSON.stringify(n)}. Using the default of ${Y}.`), Y) : n;
1704
1765
  }
1705
- function Vt(e, t) {
1706
- let n = Bt(e, t), r = e.metadata?.collider_motion;
1766
+ function Wt(e, t) {
1767
+ let n = Ut(e, t), r = e.metadata?.collider_motion;
1707
1768
  return r === "dynamic" ? {
1708
1769
  type: S.DYNAMIC,
1709
1770
  mass: n
@@ -1715,10 +1776,10 @@ function Vt(e, t) {
1715
1776
  mass: n
1716
1777
  });
1717
1778
  }
1718
- function Ht(e) {
1779
+ function Gt(e) {
1719
1780
  return e instanceof y && e.getTotalVertices() > 0;
1720
1781
  }
1721
- function Ut(e) {
1782
+ function Kt(e) {
1722
1783
  for (let t of e.getChildMeshes(!1)) if (t.getTotalVertices() > 0) return !0;
1723
1784
  return !1;
1724
1785
  }
@@ -1735,35 +1796,35 @@ function X(e, t, n, r) {
1735
1796
  let o = new x(e, t, a, e.getScene());
1736
1797
  o.body.setMotionType(n.type), n.type === S.ANIMATED && o.body.setPrestepType(C.TELEPORT);
1737
1798
  }
1738
- function Wt(e, t, n) {
1739
- if (Ht(e)) {
1799
+ function qt(e, t, n) {
1800
+ if (Gt(e)) {
1740
1801
  X(e, t, n, void 0);
1741
1802
  return;
1742
1803
  }
1743
- if (!Ut(e)) throw Error(`Cannot build a collider on "${e.name}": it has neither a mesh nor anything under it to size a body from.`);
1804
+ if (!Kt(e)) throw Error(`Cannot build a collider on "${e.name}": it has neither a mesh nor anything under it to size a body from.`);
1744
1805
  X(e, t, n, J(e));
1745
1806
  }
1746
- function Gt(e, t) {
1807
+ function Jt(e, t) {
1747
1808
  let n = e;
1748
1809
  for (let t of e.getChildMeshes(!1)) if (t.metadata?.collider_mesh === !0 && t instanceof y) {
1749
1810
  t.isVisible = !1, n = t;
1750
1811
  break;
1751
1812
  }
1752
- if (!Ht(n)) throw Error(`Cannot build a "mesh" collider on "${n.name}": a triangle mesh reads vertices, and this node has none of its own.`);
1813
+ if (!Gt(n)) throw Error(`Cannot build a "mesh" collider on "${n.name}": a triangle mesh reads vertices, and this node has none of its own.`);
1753
1814
  X(n, w.MESH, t, void 0);
1754
1815
  }
1755
- function Kt(e) {
1816
+ function Yt(e) {
1756
1817
  e.registerPropertyHandler("collider", (e, t, n, r) => {
1757
1818
  if (!n.scene) throw Error("Scene not available for collider handler");
1758
- let i = zt(e, t, r.logger);
1819
+ let i = Ht(e, t, r.logger);
1759
1820
  if (i === void 0 || i === "none") return;
1760
- let a = Vt(e, r.logger);
1761
- i === "mesh" ? Gt(e, a) : i === "sphere" ? Wt(e, w.SPHERE, a) : Wt(e, w.BOX, a);
1821
+ let a = Wt(e, r.logger);
1822
+ i === "mesh" ? Jt(e, a) : i === "sphere" ? qt(e, w.SPHERE, a) : qt(e, w.BOX, a);
1762
1823
  });
1763
1824
  }
1764
1825
  //#endregion
1765
1826
  //#region src/handlers/lod.ts
1766
- function qt(e) {
1827
+ function Xt(e) {
1767
1828
  let t = [];
1768
1829
  for (let n of e.split(",")) {
1769
1830
  let e = parseFloat(n.trim());
@@ -1771,10 +1832,10 @@ function qt(e) {
1771
1832
  }
1772
1833
  return t;
1773
1834
  }
1774
- function Jt(e) {
1835
+ function Zt(e) {
1775
1836
  e.registerPropertyHandler("lod_distances", (e, t, n, r) => {
1776
1837
  if (!(e instanceof y)) return;
1777
- let i = qt(String(t));
1838
+ let i = Xt(String(t));
1778
1839
  if (i.length === 0) {
1779
1840
  r.logger.warn(`Unusable lod_distances on "${e.name}": ${JSON.stringify(t)}. No level added.`);
1780
1841
  return;
@@ -1789,14 +1850,14 @@ function Jt(e) {
1789
1850
  }
1790
1851
  //#endregion
1791
1852
  //#region src/handlers/occlusion.ts
1792
- function Yt(e) {
1853
+ function Qt(e) {
1793
1854
  e.registerPropertyHandler("occlusion", (e, t, n, r) => {
1794
1855
  e instanceof y && (t === "optimistic" ? e.occlusionType = y.OCCLUSION_TYPE_OPTIMISTIC : t === "strict" ? e.occlusionType = y.OCCLUSION_TYPE_STRICT : r.logger.warn(`Unknown occlusion on "${e.name}": ${JSON.stringify(t)}. The occlusion property takes "optimistic" or "strict".`));
1795
1856
  });
1796
1857
  }
1797
1858
  //#endregion
1798
1859
  //#region src/utils/metadata.ts
1799
- function Xt(e, t) {
1860
+ function $t(e, t) {
1800
1861
  let n = {}, r = `${t}_`;
1801
1862
  for (let [t, i] of Object.entries(e)) if (t.startsWith(r)) {
1802
1863
  let e = t.slice(r.length);
@@ -1806,11 +1867,11 @@ function Xt(e, t) {
1806
1867
  }
1807
1868
  //#endregion
1808
1869
  //#region src/handlers/sound.ts
1809
- function Zt(e) {
1870
+ function en(e) {
1810
1871
  e.registerPropertyHandler("sound", async (e, t, n, r) => {
1811
1872
  let i = t;
1812
1873
  if (!n.scene) throw Error("Scene not available for sound handler");
1813
- let a = Xt(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.audioManager;
1874
+ let a = $t(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.audioManager;
1814
1875
  if (!f) {
1815
1876
  r.logger.warn(`No AudioManager available. Sound for "${e.name}" skipped.`);
1816
1877
  return;
@@ -1828,7 +1889,7 @@ function Zt(e) {
1828
1889
  }
1829
1890
  //#endregion
1830
1891
  //#region src/handlers/trigger.ts
1831
- function Qt(e, n, r, i, a) {
1892
+ function tn(e, n, r, i, a) {
1832
1893
  let o = t.OnIntersectionExitTrigger;
1833
1894
  a === "enter" && (o = t.OnIntersectionEnterTrigger);
1834
1895
  let s = `trigger:${a}`;
@@ -1846,7 +1907,7 @@ function Qt(e, n, r, i, a) {
1846
1907
  });
1847
1908
  }));
1848
1909
  }
1849
- function $t(n) {
1910
+ function nn(n) {
1850
1911
  n.registerPropertyHandler("trigger", (n, r, i, a) => {
1851
1912
  let o = r, s = i.scene;
1852
1913
  if (!s) throw Error("Scene not available for trigger handler");
@@ -1860,7 +1921,7 @@ function $t(n) {
1860
1921
  if (e === n || e.metadata?.trigger) return;
1861
1922
  let t = [];
1862
1923
  for (let n of ["enter", "exit"]) {
1863
- let r = Qt(u, o, c, e, n);
1924
+ let r = tn(u, o, c, e, n);
1864
1925
  r && t.push(r);
1865
1926
  }
1866
1927
  let r = e.onDisposeObservable.add(() => {
@@ -1880,7 +1941,7 @@ function $t(n) {
1880
1941
  }
1881
1942
  //#endregion
1882
1943
  //#region src/handlers/visible.ts
1883
- function en(t) {
1944
+ function rn(t) {
1884
1945
  t.registerPropertyHandler("visible", (t, n) => {
1885
1946
  if (!(t instanceof e)) return;
1886
1947
  let r = !0;
@@ -1889,7 +1950,7 @@ function en(t) {
1889
1950
  }
1890
1951
  //#endregion
1891
1952
  //#region src/handlers/index.ts
1892
- var tn = [
1953
+ var an = [
1893
1954
  "collider",
1894
1955
  "lod_distances",
1895
1956
  "occlusion",
@@ -1897,12 +1958,12 @@ var tn = [
1897
1958
  "trigger",
1898
1959
  "visible"
1899
1960
  ];
1900
- function nn(e) {
1901
- Kt(e), Jt(e), Yt(e), Zt(e), $t(e), en(e);
1961
+ function on(e) {
1962
+ Yt(e), Zt(e), Qt(e), en(e), nn(e), rn(e);
1902
1963
  }
1903
1964
  //#endregion
1904
1965
  //#region src/classes/level.ts
1905
- var rn = class {
1966
+ var sn = class {
1906
1967
  name;
1907
1968
  _log;
1908
1969
  _context;
@@ -1932,6 +1993,10 @@ var rn = class {
1932
1993
  $adoptSimulation(e) {
1933
1994
  this._simulation = e;
1934
1995
  }
1996
+ createScene() {
1997
+ let e = this._context.sceneEngine.createScene();
1998
+ return this._scene = e, e;
1999
+ }
1935
2000
  rebuildSimulation(e, t) {
1936
2001
  return this._simulation = this._context.rebuildSimulation(e, t), this._simulation;
1937
2002
  }
@@ -2002,7 +2067,7 @@ var rn = class {
2002
2067
  async dispose() {
2003
2068
  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);
2004
2069
  }
2005
- }, an = class {
2070
+ }, cn = class {
2006
2071
  _scene;
2007
2072
  _layers = /* @__PURE__ */ new Map();
2008
2073
  constructor(e, t) {
@@ -2046,7 +2111,7 @@ var rn = class {
2046
2111
  n.length > 0 && e.layer.addSelection(n);
2047
2112
  }
2048
2113
  }
2049
- }, on = class extends rn {
2114
+ }, ln = class extends sn {
2050
2115
  _config;
2051
2116
  _spawnPoints = [];
2052
2117
  _entityNodes = [];
@@ -2072,14 +2137,14 @@ var rn = class {
2072
2137
  return n;
2073
2138
  }
2074
2139
  async buildScene() {
2075
- let { sceneEngine: e, assetManager: t } = this.context;
2076
- this._config.preload && this._config.preload.length > 0 && (this.$emitProgress(2, "Preloading assets..."), await t.preload(this._config.preload));
2077
- let n = e.createScene();
2078
- if (this._scene = n, this.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) {
2140
+ let { assetManager: e } = this.context;
2141
+ this._config.preload && this._config.preload.length > 0 && (this.$emitProgress(2, "Preloading assets..."), await e.preload(this._config.preload));
2142
+ let t = this.createScene();
2143
+ if (this.rebuildSimulation(t, this._config.meshSource), this._config.physics && (this.$emitProgress(5, "Initializing physics..."), await this._enablePhysics(t)), this._config.scene && (this.$emitProgress(10, "Loading scene file..."), await this._loadSceneFile(t)), this._config.environment && (this.$emitProgress(15, "Setting up environment..."), this._processEnvironment(t)), this._processCameras(t), this._processLights(t), this._setupClustering(t), this._config.postProcessing) {
2079
2144
  let e = this._config.postProcessing.renderer ?? "pipeline";
2080
- this._log.info(`Applying post-processing with ${e} renderer`), await Lt(n, this._config.postProcessing, this._log);
2145
+ this._log.info(`Applying post-processing with ${e} renderer`), await Bt(t, this._config.postProcessing, this._log);
2081
2146
  }
2082
- return this.outlines = new an(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;
2147
+ return this.outlines = new cn(t, this._config.outlines), this.$emitProgress(50, "Processing scene properties..."), await this._processNodeProperties(t), 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()), t;
2083
2148
  }
2084
2149
  async _loadSceneFile(e) {
2085
2150
  let t = this._getScenePath();
@@ -2255,7 +2320,7 @@ var rn = class {
2255
2320
  }
2256
2321
  _warnUnhandledProperties(e) {
2257
2322
  let t = e.metadata;
2258
- for (let n of tn) n in t && !this.propertyHandlers.has(n) && this._log.warn(`Node '${e.name}' carries '${n}' and no handler is registered for it. Call registerAllPropertyHandlers on the level manager to install the built-in handlers.`);
2323
+ for (let n of an) n in t && !this.propertyHandlers.has(n) && this._log.warn(`Node '${e.name}' carries '${n}' and no handler is registered for it. Call registerAllPropertyHandlers on the level manager to install the built-in handlers.`);
2259
2324
  }
2260
2325
  async _processNodeMetadata(e) {
2261
2326
  if ("spawn" in e.metadata) {
@@ -2352,7 +2417,7 @@ var rn = class {
2352
2417
  for (let e of this._levelSounds.values()) e.dispose();
2353
2418
  this._levelSounds.clear(), this._playingSoundsBeforeDeactivate.clear(), await super.dispose();
2354
2419
  }
2355
- }, sn = class {
2420
+ }, un = class {
2356
2421
  _bus;
2357
2422
  _gameEngine = null;
2358
2423
  _log;
@@ -2402,7 +2467,10 @@ var rn = class {
2402
2467
  sceneEngine: t.engines.sceneEngine,
2403
2468
  assetManager: t.managers.assetManager,
2404
2469
  audioManager: t.managers.audioManager,
2405
- rebuildSimulation: (n, r) => t.rebuildSimulation(n, e.name, r),
2470
+ rebuildSimulation: (n, r) => t.rebuildSimulation(n, e.name, {
2471
+ meshSource: r,
2472
+ fixedStepDuration: e.fixedStepDuration
2473
+ }),
2406
2474
  canvas: t.canvas,
2407
2475
  largeWorldRendering: t.largeWorldRendering,
2408
2476
  propertyHandlers: this._propertyHandlers,
@@ -2416,7 +2484,7 @@ var rn = class {
2416
2484
  if (!n) throw Error(`Level class '${e.class}' is not registered.`);
2417
2485
  return this._log.debug(`Creating level '${e.name}' using class '${e.class}'`), new n(e, t);
2418
2486
  }
2419
- return this._log.debug(`Creating level '${e.name}' using GameLevel`), new on(e, t);
2487
+ return this._log.debug(`Creating level '${e.name}' using GameLevel`), new ln(e, t);
2420
2488
  }
2421
2489
  registerLevelConfig(e) {
2422
2490
  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}`);
@@ -2436,6 +2504,9 @@ var rn = class {
2436
2504
  getLevel(e) {
2437
2505
  return this._loadedLevels.get(e) || null;
2438
2506
  }
2507
+ async unregisterLevelConfig(e) {
2508
+ await this.unloadLevel(e), this._levelConfigs.delete(e) && this._log.info(`Unregistered level config: ${e}`);
2509
+ }
2439
2510
  getLevelConfig(e) {
2440
2511
  return this._levelConfigs.get(e) || null;
2441
2512
  }
@@ -2525,7 +2596,7 @@ var rn = class {
2525
2596
  for (let e of this._loadedLevels.values()) await e.dispose();
2526
2597
  this._loadedLevels.clear(), this._levelConfigs.clear(), this._currentLevel = null;
2527
2598
  }
2528
- }, cn = class {
2599
+ }, dn = class {
2529
2600
  #e;
2530
2601
  #t = /* @__PURE__ */ new Map();
2531
2602
  #n = !1;
@@ -2594,7 +2665,7 @@ var rn = class {
2594
2665
  if (!t) throw Error(`AudioManager: no channel named "${e}" is declared.`);
2595
2666
  return t;
2596
2667
  }
2597
- }, ln = 1, un = class {
2668
+ }, fn = 2, pn = class {
2598
2669
  #e;
2599
2670
  #t;
2600
2671
  #n;
@@ -2619,7 +2690,7 @@ var rn = class {
2619
2690
  t[n] = r;
2620
2691
  }
2621
2692
  return {
2622
- saveFormatVersion: ln,
2693
+ saveFormatVersion: fn,
2623
2694
  engineVersion: this.#t,
2624
2695
  level: this.#e.currentLevel?.name ?? "",
2625
2696
  timestamp: this.#n(),
@@ -2628,7 +2699,7 @@ var rn = class {
2628
2699
  };
2629
2700
  }
2630
2701
  async load(e) {
2631
- if (e.saveFormatVersion !== ln) throw Error(`The save format version "${e.saveFormatVersion}" is not one this engine knows how to load.`);
2702
+ if (e.saveFormatVersion !== fn) throw Error(`The save format version "${e.saveFormatVersion}" is not one this engine knows how to load.`);
2632
2703
  this.#a(), await this.#e.transition(e.level, { forRestore: !0 });
2633
2704
  let t = this.#o().buildFromSnapshot(e.snapshot);
2634
2705
  return this.#e.$bindSimulation(t), {
@@ -2648,7 +2719,7 @@ var rn = class {
2648
2719
  if (e === null) throw Error("SimulationSaveManager: the engine holds no simulation.");
2649
2720
  return e;
2650
2721
  }
2651
- }, dn = class {
2722
+ }, mn = class {
2652
2723
  _viewer = null;
2653
2724
  _shown = /* @__PURE__ */ new Map();
2654
2725
  _materials = /* @__PURE__ */ new Map();
@@ -2687,21 +2758,21 @@ var rn = class {
2687
2758
  };
2688
2759
  //#endregion
2689
2760
  //#region src/utils/graphics.ts
2690
- async function fn() {
2761
+ async function hn() {
2691
2762
  return Ve() ? be.IsSupportedAsync : !1;
2692
2763
  }
2693
- async function pn(e, t) {
2764
+ async function gn(e, t) {
2694
2765
  let n = new be(e, t);
2695
2766
  return await n.initAsync(), n;
2696
2767
  }
2697
- function mn(e, t) {
2768
+ function _n(e, t) {
2698
2769
  return new u(e, t.antialias, t.options, t.adaptToDeviceRatio);
2699
2770
  }
2700
- function hn(e) {
2771
+ function vn(e) {
2701
2772
  return new te(e);
2702
2773
  }
2703
- async function gn(e, t, n = !1, r = new H("Boot")) {
2704
- if (e === null) return r.debug("Using Null Engine"), hn(t);
2774
+ async function yn(e, t, n = !1, r = new H("Boot")) {
2775
+ if (e === null) return r.debug("Using Null Engine"), vn(t);
2705
2776
  if (n) {
2706
2777
  if ("options" in t) {
2707
2778
  let e = t;
@@ -2719,25 +2790,25 @@ async function gn(e, t, n = !1, r = new H("Boot")) {
2719
2790
  }
2720
2791
  let i = t.engine || "auto";
2721
2792
  if (i === "webgpu") {
2722
- if (await fn()) try {
2723
- return r.debug("Using forced WebGPU engine"), await pn(e, t);
2793
+ if (await hn()) try {
2794
+ return r.debug("Using forced WebGPU engine"), await gn(e, t);
2724
2795
  } catch (e) {
2725
2796
  throw r.error("Forced WebGPU initialization failed:", e), Error("Forced WebGPU failed to initialize. If WebGPU is required, check browser compatibility.", { cause: e });
2726
2797
  }
2727
2798
  throw Error("WebGPU was forced but is not available in this browser.");
2728
2799
  }
2729
- if (i === "webgl") return r.debug("Using forced WebGL engine"), mn(e, t);
2730
- if (await fn()) try {
2731
- return r.debug("Using WebGPU"), await pn(e, t);
2800
+ if (i === "webgl") return r.debug("Using forced WebGL engine"), _n(e, t);
2801
+ if (await hn()) try {
2802
+ return r.debug("Using WebGPU"), await gn(e, t);
2732
2803
  } catch (e) {
2733
2804
  r.warn("WebGPU initialization failed, falling back to WebGL:", e);
2734
2805
  }
2735
2806
  else r.warn("WebGPU not supported, falling back to WebGL.");
2736
- return r.debug("Using WebGL"), mn(e, t);
2807
+ return r.debug("Using WebGL"), _n(e, t);
2737
2808
  }
2738
2809
  //#endregion
2739
2810
  //#region src/utils/timer.ts
2740
- var _n = class {
2811
+ var bn = class {
2741
2812
  _nextId = 0;
2742
2813
  _delays = [];
2743
2814
  _intervals = [];
@@ -2801,17 +2872,17 @@ function Z(e) {
2801
2872
  }
2802
2873
  return e.simulation;
2803
2874
  }
2804
- function vn(e, t) {
2875
+ function xn(e, t) {
2805
2876
  return typeof e == "string" ? Z(t)?.getEntity(e) : e;
2806
2877
  }
2807
- function yn(e, t) {
2878
+ function Sn(e, t) {
2808
2879
  let n = t.managers.gameManager, r = t.managers.levelManager, i = [];
2809
2880
  e.expose("engine", t), e.expose("events", t.bus), e.expose("physics", { get: () => r.currentLevel?.scene?.getPhysicsEngine() ?? null }), e.expose("colliders", t.debug.colliders), e.expose("entities", new Proxy({}, { get(e, n) {
2810
2881
  if (typeof n == "symbol") return;
2811
2882
  let r = Z(t)?.getEntity(n);
2812
2883
  return r || console.warn(`[sage] Entity not found: ${n}`), r;
2813
2884
  } })), e.expose("level", { get: () => r.currentLevel }), e.expose("scene", { get: () => r.currentLevel?.scene ?? null }), e.expose("tp", (e, n, r, i) => {
2814
- let a = vn(e, t);
2885
+ let a = xn(e, t);
2815
2886
  if (!a) {
2816
2887
  console.warn(`[sage] Entity not found: ${e}`);
2817
2888
  return;
@@ -2852,7 +2923,7 @@ function yn(e, t) {
2852
2923
  });
2853
2924
  return console.table(a), [...i];
2854
2925
  }), e.expose("inspect", (e) => {
2855
- let n = vn(e, t);
2926
+ let n = xn(e, t);
2856
2927
  if (!n) {
2857
2928
  console.warn(`[sage] Entity not found: ${e}`);
2858
2929
  return;
@@ -2885,7 +2956,7 @@ function yn(e, t) {
2885
2956
  }
2886
2957
  //#endregion
2887
2958
  //#region src/interfaces/logger.ts
2888
- var bn = [
2959
+ var Cn = [
2889
2960
  "trace",
2890
2961
  "debug",
2891
2962
  "info",
@@ -2895,7 +2966,7 @@ var bn = [
2895
2966
  ];
2896
2967
  //#endregion
2897
2968
  //#region src/entities/defineEntity.ts
2898
- function xn(e, t) {
2969
+ function wn(e, t) {
2899
2970
  let n = t ?? {}, r = e.tags ?? [], i = n.tags ?? [];
2900
2971
  return {
2901
2972
  ...e.defaultState,
@@ -2903,13 +2974,13 @@ function xn(e, t) {
2903
2974
  tags: [.../* @__PURE__ */ new Set([...r, ...i])]
2904
2975
  };
2905
2976
  }
2906
- function Sn(e) {
2977
+ function Tn(e) {
2907
2978
  class t extends B {
2908
2979
  static behaviors = e.behaviors;
2909
2980
  static meshConfig = e.mesh;
2910
2981
  static actions = e.actions;
2911
2982
  static create(t, n, r, i) {
2912
- let a = xn(e, r);
2983
+ let a = wn(e, r);
2913
2984
  return super.create(t, n, a, i);
2914
2985
  }
2915
2986
  }
@@ -2920,12 +2991,12 @@ function Sn(e) {
2920
2991
  function Q(e) {
2921
2992
  return new i(e.r, e.g, e.b);
2922
2993
  }
2923
- function Cn(e, t, n) {
2994
+ function En(e, t, n) {
2924
2995
  let r = `Create${t.charAt(0).toUpperCase()}${t.slice(1)}`, i = b[r];
2925
2996
  if (typeof i != "function") throw Error(`No Babylon mesh builder provides the primitive shape "${t}".`);
2926
2997
  return i(t, n ?? {}, e);
2927
2998
  }
2928
- function wn(e, t, n) {
2999
+ function Dn(e, t, n) {
2929
3000
  if (n.type === "pbr") {
2930
3001
  let r = new ne(`${t.name}-material`, e);
2931
3002
  n.color !== void 0 && (r.albedoColor = Q(n.color)), n.emissive !== void 0 && (r.emissiveColor = Q(n.emissive)), n.metallic !== void 0 && (r.metallic = n.metallic), n.roughness !== void 0 && (r.roughness = n.roughness), t.material = r;
@@ -2934,19 +3005,19 @@ function wn(e, t, n) {
2934
3005
  n.color !== void 0 && (r.diffuseColor = Q(n.color)), n.emissive !== void 0 && (r.emissiveColor = Q(n.emissive)), t.material = r;
2935
3006
  }
2936
3007
  }
2937
- async function Tn(e, t, n) {
3008
+ async function On(e, t, n) {
2938
3009
  let r;
2939
- return t.source.includes("#") ? (await n.load(t.source), r = n.clone(t.source, e)) : r = Cn(e, t.source, t.params), r.isVisible = t.visible ?? !0, t.material !== void 0 && wn(e, r, t.material), r;
3010
+ return t.source.includes("#") ? (await n.load(t.source), r = n.clone(t.source, e)) : r = En(e, t.source, t.params), r.isVisible = t.visible ?? !0, t.material !== void 0 && Dn(e, r, t.material), r;
2940
3011
  }
2941
- function En(e, t) {
3012
+ function kn(e, t) {
2942
3013
  return async (n, r) => {
2943
3014
  let i = e[r]?.meshConfig;
2944
- if (i !== void 0) return Tn(n, i, t);
3015
+ if (i !== void 0) return On(n, i, t);
2945
3016
  };
2946
3017
  }
2947
3018
  //#endregion
2948
3019
  //#region src/behaviors/sound.ts
2949
- var Dn = class extends k {
3020
+ var An = class extends k {
2950
3021
  static ops = ["play", "stop"];
2951
3022
  defaults = { sounds: {} };
2952
3023
  #e = /* @__PURE__ */ new Map();
@@ -2988,10 +3059,10 @@ var Dn = class extends k {
2988
3059
  };
2989
3060
  //#endregion
2990
3061
  //#region src/behaviors/physicsBody.ts
2991
- function On(e) {
3062
+ function jn(e) {
2992
3063
  return e === "sphere" ? w.SPHERE : e === "cylinder" ? w.CYLINDER : e === "convex" ? w.CONVEX_HULL : e === "mesh" ? w.MESH : w.BOX;
2993
3064
  }
2994
- function kn(e, t) {
3065
+ function Mn(e, t) {
2995
3066
  let { extents: n, center: r } = t;
2996
3067
  return e === "sphere" ? {
2997
3068
  radius: Math.max(n.x, n.y, n.z) / 2,
@@ -3005,7 +3076,7 @@ function kn(e, t) {
3005
3076
  center: r
3006
3077
  };
3007
3078
  }
3008
- function An(e, t) {
3079
+ function Nn(e, t) {
3009
3080
  let { extents: n } = e;
3010
3081
  if (e.shape === "sphere") return new ce(O.Zero(), n.x / 2, t);
3011
3082
  if (e.shape === "cylinder") {
@@ -3017,17 +3088,17 @@ function An(e, t) {
3017
3088
  function $(e) {
3018
3089
  return e === "static" ? S.STATIC : e === "kinematic" ? S.ANIMATED : S.DYNAMIC;
3019
3090
  }
3020
- function jn(e) {
3091
+ function Pn(e) {
3021
3092
  return e === S.STATIC ? "static" : e === S.ANIMATED ? "kinematic" : "dynamic";
3022
3093
  }
3023
- function Mn(e) {
3094
+ function Fn(e) {
3024
3095
  return e === "kinematic" ? C.ACTION : C.TELEPORT;
3025
3096
  }
3026
- function Nn(e) {
3097
+ function In(e) {
3027
3098
  for (let t of e.getChildMeshes(!1)) if (t.getTotalVertices() > 0) return !0;
3028
3099
  return !1;
3029
3100
  }
3030
- var Pn = class extends k {
3101
+ var Ln = class extends k {
3031
3102
  static ops = ["applyImpulse"];
3032
3103
  defaults = {
3033
3104
  shape: "box",
@@ -3088,13 +3159,13 @@ var Pn = class extends k {
3088
3159
  if (r === "convex" || r === "mesh") {
3089
3160
  let a = e.mesh;
3090
3161
  if (!(a instanceof y) || a.getTotalVertices() === 0) throw Error(`HavokPhysicsBodyBehavior: entity "${e.id}" asked for a "${r}" body, which reads vertices, and it has no mesh geometry to read.`);
3091
- return new x(n, On(r), {
3162
+ return new x(n, jn(r), {
3092
3163
  mass: i,
3093
3164
  mesh: a
3094
3165
  }, t);
3095
3166
  }
3096
- let a = kn(r, this.#s(e));
3097
- return new x(n, On(r), {
3167
+ let a = Mn(r, this.#s(e));
3168
+ return new x(n, jn(r), {
3098
3169
  mass: i,
3099
3170
  ...a
3100
3171
  }, t);
@@ -3108,13 +3179,13 @@ var Pn = class extends k {
3108
3179
  center: e.center.clone()
3109
3180
  };
3110
3181
  }
3111
- if (!Nn(e.node)) throw Error(`HavokPhysicsBodyBehavior: entity "${e.id}" has neither a mesh nor anything under its node to size a body from.`);
3182
+ if (!In(e.node)) throw Error(`HavokPhysicsBodyBehavior: entity "${e.id}" has neither a mesh nor anything under its node to size a body from.`);
3112
3183
  return J(e.node);
3113
3184
  }
3114
3185
  #c(e) {
3115
3186
  let t = new oe(e);
3116
3187
  for (let n of this.state.parts) {
3117
- let r = An(n, e);
3188
+ let r = Nn(n, e);
3118
3189
  t.addChild(r, N(n.position), F(n.rotation)), this.#a.push(r);
3119
3190
  }
3120
3191
  return this.#a.push(t), t;
@@ -3149,7 +3220,7 @@ var Pn = class extends k {
3149
3220
  get: () => s,
3150
3221
  set: r
3151
3222
  }), this.computed("motion", {
3152
- get: () => this.#n ? jn(this.#r) : jn(this.#y().getMotionType()),
3223
+ get: () => this.#n ? Pn(this.#r) : Pn(this.#y().getMotionType()),
3153
3224
  set: (e) => {
3154
3225
  if (this.#n) {
3155
3226
  this.#r = $(e);
@@ -3187,7 +3258,7 @@ var Pn = class extends k {
3187
3258
  }
3188
3259
  #d(e, t) {
3189
3260
  let n = this.#y(), r = n.transformNode;
3190
- r.position = N(e), r.rotationQuaternion = F(t), !this.#n && (n.setPrestepType(Mn(jn(n.getMotionType()))), this.#b().setPhysicsBodyTransformation(n, r), n.setPrestepType(C.DISABLED));
3261
+ r.position = N(e), r.rotationQuaternion = F(t), !this.#n && (n.setPrestepType(Fn(Pn(n.getMotionType()))), this.#b().setPhysicsBodyTransformation(n, r), n.setPrestepType(C.DISABLED));
3191
3262
  }
3192
3263
  #f(e) {
3193
3264
  if (e !== this.#n) {
@@ -3240,12 +3311,12 @@ var Pn = class extends k {
3240
3311
  if (this.#t === void 0) throw Error(`HavokPhysicsBodyBehavior: entity "${this.entity.id}" has no physics plugin to answer for.`);
3241
3312
  return this.#t;
3242
3313
  }
3243
- }, Fn = new O(0, -1, 0), In = "standing";
3244
- function Ln(e) {
3314
+ }, Rn = new O(0, -1, 0), zn = "standing";
3315
+ function Bn(e) {
3245
3316
  let t = Object.keys(e);
3246
3317
  return t.sort((t, n) => e[n].height - e[t].height), t;
3247
3318
  }
3248
- var Rn = class extends k {
3319
+ var Vn = class extends k {
3249
3320
  defaults = {
3250
3321
  moveX: 0,
3251
3322
  moveZ: 0,
@@ -3280,7 +3351,7 @@ var Rn = class extends k {
3280
3351
  z: 0
3281
3352
  },
3282
3353
  grounded: !1,
3283
- stance: In
3354
+ stance: zn
3284
3355
  };
3285
3356
  #e;
3286
3357
  #t;
@@ -3290,7 +3361,7 @@ var Rn = class extends k {
3290
3361
  #a = /* @__PURE__ */ new Map();
3291
3362
  #o = W();
3292
3363
  #s = !1;
3293
- #c = In;
3364
+ #c = zn;
3294
3365
  #l = !1;
3295
3366
  #u;
3296
3367
  #d = O.Zero();
@@ -3310,7 +3381,7 @@ var Rn = class extends k {
3310
3381
  onUpdate(e) {
3311
3382
  let t = this.#e;
3312
3383
  if (t === void 0) return;
3313
- let n = t.checkSupport(e, Fn);
3384
+ let n = t.checkSupport(e, Rn);
3314
3385
  this.#l = n.supportedState === r.SUPPORTED, this.#l ? this.#h = 0 : this.#h += 1, this.#S(), this.#u = this.#O(), this.#E().y <= 0 && (this.#g = !1);
3315
3386
  let i = this.desiredVelocity(e, n);
3316
3387
  this.#w(n) && (this.#g = !0, i.y = this.state.jumpSpeed), this.#d = this.#D(), i.addInPlace(this.#d), t.setVelocity(i), t.integrate(e, n, this.#o), this.entity.node.setAbsolutePosition(this.#B(t.getPosition())), this.state.velocity = M(t.getVelocity());
@@ -3356,7 +3427,7 @@ var Rn = class extends k {
3356
3427
  this.#v(this.state.wantsStance);
3357
3428
  let e = this.#c;
3358
3429
  if (this.stanceFits(this.state.wantsStance)) e = this.state.wantsStance;
3359
- else for (let t of Ln(this.state.stances)) if (this.#_(this.state.stances[t]) && this.stanceFits(t)) {
3430
+ else for (let t of Bn(this.state.stances)) if (this.#_(this.state.stances[t]) && this.stanceFits(t)) {
3360
3431
  e = t;
3361
3432
  break;
3362
3433
  }
@@ -3454,7 +3525,7 @@ var Rn = class extends k {
3454
3525
  return t;
3455
3526
  }
3456
3527
  #R() {
3457
- let e = Ln(this.state.stances);
3528
+ let e = Bn(this.state.stances);
3458
3529
  if (e.length === 0) throw Error(`CharacterControllerBehavior: entity "${this.entity.id}" has no stances to be in, and a character is always in one.`);
3459
3530
  return e[0];
3460
3531
  }
@@ -3472,7 +3543,7 @@ var Rn = class extends k {
3472
3543
  if (this.#e === void 0) throw Error(`CharacterControllerBehavior: entity "${this.entity.id}" has no capsule to answer for.`);
3473
3544
  return this.#e;
3474
3545
  }
3475
- }, zn = class {
3546
+ }, Hn = class {
3476
3547
  #e;
3477
3548
  #t;
3478
3549
  #n;
@@ -3500,24 +3571,24 @@ var Rn = class extends k {
3500
3571
  };
3501
3572
  //#endregion
3502
3573
  //#region src/input/configuration.ts
3503
- function Bn(e, t, n) {
3574
+ function Un(e, t, n) {
3504
3575
  return {
3505
3576
  actions: [...e],
3506
3577
  bindings: t.map((e) => e.toDefinition()),
3507
3578
  contexts: [...n]
3508
3579
  };
3509
3580
  }
3510
- function Vn(e, t, n) {
3581
+ function Wn(e, t, n) {
3511
3582
  for (let n of e.actions) t.register(n);
3512
3583
  for (let t of e.contexts) n.registerContext(t.name, t.exclusive);
3513
3584
  return [...e.bindings];
3514
3585
  }
3515
3586
  //#endregion
3516
3587
  //#region src/sage.ts
3517
- async function Hn(e, t, n = {}) {
3588
+ async function Gn(e, t, n = {}) {
3518
3589
  let r = new U(n.logLevel || "debug"), i = r.getLogger("SAGE");
3519
3590
  i.info(`Initializing SAGE Game Engine v${j}...`), i.debug("Creating rendering engine...");
3520
- let a = await gn(e, {
3591
+ let a = await yn(e, {
3521
3592
  antialias: !0,
3522
3593
  adaptToDeviceRatio: !0,
3523
3594
  enableAllFeatures: !0,
@@ -3528,20 +3599,20 @@ async function Hn(e, t, n = {}) {
3528
3599
  i.debug("Creating scene engine...");
3529
3600
  let s = new dt(a, r, n.havokBinary);
3530
3601
  i.debug("Creating managers...");
3531
- let c = new pt(o, s, r), l = new sn(o, r), u = new un(l, j), d = new mt(a, o, l, r), f = new Pt(r);
3602
+ let c = new pt(o, s, r), l = new un(o, r), u = new pn(l, j), d = new mt(a, o, l, r), f = new Lt(r);
3532
3603
  d.setInputManager(f);
3533
3604
  let p, m;
3534
- n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."), p = new lt(r), await p.initialize(), i.debug("Creating audio manager..."), m = new cn(p, r), await m.initialize(n.audioChannels));
3605
+ n.audioChannels && n.audioChannels.length > 0 && (i.debug("Creating audio engine..."), p = new lt(r), await p.initialize(), i.debug("Creating audio manager..."), m = new dn(p, r), await m.initialize(n.audioChannels));
3535
3606
  let h = n.fixedStepDuration ?? 1 / 60, g = async () => void 0;
3536
3607
  i.debug("Creating collider debug manager...");
3537
- let _ = new dn(), ee = (e, n, i) => new ot({
3608
+ let _ = new mn(), ee = (e, n, i) => new ot({
3538
3609
  id: n,
3539
3610
  bus: o,
3540
- fixedStepDuration: h,
3611
+ fixedStepDuration: i?.fixedStepDuration ?? h,
3541
3612
  entityClasses: t,
3542
3613
  scene: e,
3543
3614
  pool: new ct(),
3544
- loadMesh: i ?? g,
3615
+ loadMesh: i?.meshSource ?? g,
3545
3616
  audio: m,
3546
3617
  colliders: _,
3547
3618
  logger: r.getLogger("NodeSimulation")
@@ -3552,7 +3623,7 @@ async function Hn(e, t, n = {}) {
3552
3623
  typeof n.debug == "object" && n.debug.namespace !== void 0 && (e = n.debug.namespace), v = new He(e);
3553
3624
  }
3554
3625
  i.debug("Creating game timer...");
3555
- let y = new _n();
3626
+ let y = new bn();
3556
3627
  d.registerFrameCallback((e) => y.tick(e * 1e3)), i.info(`SAGE Game Engine v${j} initialized successfully.`);
3557
3628
  let b = new Ue(e, a, o, r, y, ee, {
3558
3629
  sceneEngine: s,
@@ -3571,9 +3642,9 @@ async function Hn(e, t, n = {}) {
3571
3642
  v?.expose(e, t);
3572
3643
  }
3573
3644
  });
3574
- return l.$setGameEngine(b), d.$setGameEngine(b), u.$setGameEngine(b), v && yn(v, b), b;
3645
+ return l.$setGameEngine(b), d.$setGameEngine(b), u.$setGameEngine(b), v && Sn(v, b), b;
3575
3646
  }
3576
3647
  //#endregion
3577
- export { ht as ActionContextRegistry, gt as ActionRegistry, pt as AssetManager, lt as AudioEngine, cn as AudioManager, tn as BUILT_IN_PROPERTIES, xe as Behavior, Rn as CharacterControllerBehavior, dn as ColliderDebugManager, at as ConsoleBackend, He as DebugConsole, Ot as DeltaBinding, Se as EventBus, Ue as GameEngine, we as GameEntity, on as GameLevel, mt as GameManager, Ee as GameRandom, De as GameSimulation, _n as GameTimer, yt as GamepadReader, Pn as HavokPhysicsBodyBehavior, zn as InputCapture, Pt as InputManager, bt as KeyboardReader, rn as Level, sn as LevelManager, bn as LogLevels, U as LoggingUtility, xt as MouseReader, ke as NamedBehavior, B as NodeEntity, ct as NodePool, ot as NodeSimulation, V as NullBackend, an as OutlineManager, K as ROUTING_LOOP_SENDER_ID, H as SAGELogger, dt as SceneEngine, un as SimulationSaveManager, Dn as SoundBehavior, je as StateMachineBehavior, Et as ToggleBinding, Tt as TriggerBinding, j as VERSION, Dt as ValueBinding, Lt as applyPostProcessing, En as buildStandardMeshSource, J as computeHierarchyBounds, Hn as createGameEngine, Sn as defineEntity, Me as defineStates, _t as deliverAction, Ne as dilationLimit, Pe as drainPassLimit, Bn as exportConfiguration, qe as getCanonicalTransform, Vn as importConfiguration, A as isBrowser, Fe as operationCallDepthLimit, st as poolSizeLimit, wt as readerFor, nn as registerAllPropertyHandlers, yn as registerBuiltins, Kt as registerColliderHandler, Jt as registerLodHandler, Yt as registerOcclusionHandler, Zt as registerSoundHandler, $t as registerTriggerHandler, en as registerVisibleHandler, kt as resolveBinding, G as schemeOf, P as toQuatObject, F as toQuaternion, M as toVec3Object, N as toVector3 };
3648
+ export { ht as ActionContextRegistry, gt as ActionRegistry, pt as AssetManager, lt as AudioEngine, dn as AudioManager, an as BUILT_IN_PROPERTIES, xe as Behavior, Vn as CharacterControllerBehavior, mn as ColliderDebugManager, at as ConsoleBackend, He as DebugConsole, Ot as DeltaBinding, Se as EventBus, Ue as GameEngine, we as GameEntity, ln as GameLevel, mt as GameManager, Ee as GameRandom, De as GameSimulation, bn as GameTimer, yt as GamepadReader, Ln as HavokPhysicsBodyBehavior, Hn as InputCapture, Lt as InputManager, bt as KeyboardReader, sn as Level, un as LevelManager, Cn as LogLevels, U as LoggingUtility, xt as MouseReader, ke as NamedBehavior, B as NodeEntity, ct as NodePool, ot as NodeSimulation, V as NullBackend, cn as OutlineManager, K as ROUTING_LOOP_SENDER_ID, H as SAGELogger, dt as SceneEngine, pn as SimulationSaveManager, An as SoundBehavior, je as StateMachineBehavior, Et as ToggleBinding, Tt as TriggerBinding, j as VERSION, Dt as ValueBinding, Bt as applyPostProcessing, kn as buildStandardMeshSource, J as computeHierarchyBounds, Gn as createGameEngine, Tn as defineEntity, Me as defineStates, _t as deliverAction, Ne as dilationLimit, Pe as drainPassLimit, Un as exportConfiguration, qe as getCanonicalTransform, Wn as importConfiguration, A as isBrowser, Fe as operationCallDepthLimit, st as poolSizeLimit, wt as readerFor, on as registerAllPropertyHandlers, Sn as registerBuiltins, Yt as registerColliderHandler, Zt as registerLodHandler, Qt as registerOcclusionHandler, en as registerSoundHandler, nn as registerTriggerHandler, rn as registerVisibleHandler, kt as resolveBinding, G as schemeOf, P as toQuatObject, F as toQuaternion, M as toVec3Object, N as toVector3 };
3578
3649
 
3579
3650
  //# sourceMappingURL=sage.es.js.map