@thatopen/components 2.0.0-alpha.15 → 2.0.0-alpha.17

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/index.mjs CHANGED
@@ -3060,11 +3060,14 @@ class ia extends ar {
3060
3060
  I(this, "_parameters");
3061
3061
  I(this, "_resizeObserver", null);
3062
3062
  I(this, "onContainerUpdated", new U());
3063
+ I(this, "_resizing", !1);
3063
3064
  /** {@link Resizeable.resize} */
3064
3065
  I(this, "resize", (t) => {
3065
- this.onContainerUpdated.trigger();
3066
+ if (this._resizing)
3067
+ return;
3068
+ this._resizing = !0, this.onContainerUpdated.trigger();
3066
3069
  const e = t ? t.x : this.container.clientWidth, i = t ? t.y : this.container.clientHeight;
3067
- this.three.setSize(e, i), this.onResize.trigger(new g.Vector2(e, i));
3070
+ this.three.setSize(e, i), this.onResize.trigger(new g.Vector2(e, i)), this._resizing = !1;
3068
3071
  });
3069
3072
  I(this, "resizeEvent", () => {
3070
3073
  this.resize();
@@ -3111,7 +3114,7 @@ class ia extends ar {
3111
3114
  const e = this.three.domElement.parentElement;
3112
3115
  if (!e)
3113
3116
  throw new Error("This renderer needs to have an HTML container!");
3114
- this._resizeObserver && (this._resizeObserver.disconnect(), this._resizeObserver = null), window.removeEventListener("resize", this.resizeEvent), t && (this._resizeObserver = new ResizeObserver(this.resizeEvent), this._resizeObserver.observe(e), this._resizeObserver.observe(document.body), window.addEventListener("resize", this.resizeEvent));
3117
+ this._resizeObserver && (this._resizeObserver.disconnect(), this._resizeObserver = null), window.removeEventListener("resize", this.resizeEvent), t && (this._resizeObserver = new ResizeObserver(this.resizeEvent), this._resizeObserver.observe(e), window.addEventListener("resize", this.resizeEvent));
3115
3118
  }
3116
3119
  setupRenderer() {
3117
3120
  this.three.localClippingEnabled = !0, this.container && this.container.appendChild(this.three.domElement), this.onContainerUpdated.trigger();
@@ -4509,9 +4512,15 @@ class ke extends rr {
4509
4512
  */
4510
4513
  I(this, "updateAspect", () => {
4511
4514
  var t;
4512
- if (!(!this.currentWorld || !this.currentWorld.renderer) && !(this.three instanceof g.OrthographicCamera) && (t = this.currentWorld.renderer) != null && t.isResizeable()) {
4513
- const e = this.currentWorld.renderer.getSize();
4514
- this.three.aspect = e.width / e.height, this.three.updateProjectionMatrix(), this.onAspectUpdated.trigger();
4515
+ if (!(!this.currentWorld || !this.currentWorld.renderer)) {
4516
+ if (this.three instanceof g.OrthographicCamera) {
4517
+ this.onAspectUpdated.trigger();
4518
+ return;
4519
+ }
4520
+ if ((t = this.currentWorld.renderer) != null && t.isResizeable()) {
4521
+ const e = this.currentWorld.renderer.getSize();
4522
+ this.three.aspect = e.width / e.height, this.three.updateProjectionMatrix(), this.onAspectUpdated.trigger();
4523
+ }
4515
4524
  }
4516
4525
  });
4517
4526
  this.three = this.setupCamera(), this.setupEvents(!0), this.onWorldChanged.add(({ action: e, world: i }) => {
@@ -4592,13 +4601,44 @@ class ke extends rr {
4592
4601
  const gs = class gs extends J {
4593
4602
  constructor(t) {
4594
4603
  super(t);
4604
+ /**
4605
+ * Event triggered after the update process of all worlds.
4606
+ * Subscribers can listen to this event to perform actions post-update.
4607
+ */
4595
4608
  I(this, "onAfterUpdate", new U());
4609
+ /**
4610
+ * Event triggered before the update process of all worlds.
4611
+ * Subscribers can listen to this event to perform actions pre-update.
4612
+ */
4596
4613
  I(this, "onBeforeUpdate", new U());
4614
+ /**
4615
+ * Event triggered when the Worlds component is disposed.
4616
+ * Subscribers can listen to this event to perform cleanup actions.
4617
+ */
4597
4618
  I(this, "onDisposed", new U());
4619
+ /**
4620
+ * A collection of worlds managed by this component.
4621
+ * The key is the unique identifier (UUID) of the world, and the value is the World instance.
4622
+ */
4598
4623
  I(this, "list", /* @__PURE__ */ new Map());
4624
+ /**
4625
+ * A flag indicating whether the Worlds component is enabled.
4626
+ * If false, the update process will be skipped.
4627
+ */
4599
4628
  I(this, "enabled", !0);
4600
4629
  t.add(gs.uuid, this);
4601
4630
  }
4631
+ /**
4632
+ * Creates a new instance of a SimpleWorld and adds it to the list of worlds.
4633
+ *
4634
+ * @template T - The type of the scene, extending from BaseScene. Defaults to BaseScene.
4635
+ * @template U - The type of the camera, extending from BaseCamera. Defaults to BaseCamera.
4636
+ * @template S - The type of the renderer, extending from BaseRenderer. Defaults to BaseRenderer.
4637
+ *
4638
+ * @returns {SimpleWorld<T, U, S>} - The newly created SimpleWorld instance.
4639
+ *
4640
+ * @throws {Error} - Throws an error if a world with the same UUID already exists in the list.
4641
+ */
4602
4642
  create() {
4603
4643
  const t = new Ar(this.components), e = t.uuid;
4604
4644
  if (this.list.has(e))
@@ -4620,6 +4660,10 @@ const gs = class gs extends J {
4620
4660
  i.update(t);
4621
4661
  }
4622
4662
  };
4663
+ /**
4664
+ * A unique identifier for the component.
4665
+ * This UUID is used to register the component within the Components system.
4666
+ */
4623
4667
  I(gs, "uuid", "fdb61dc4-2ec1-4966-b83d-54ea795fad4a");
4624
4668
  let pi = gs;
4625
4669
  class _r {
@@ -5853,21 +5897,48 @@ class Vr extends Yr {
5853
5897
  const Ye = class Ye extends J {
5854
5898
  constructor(t) {
5855
5899
  super(t);
5900
+ /**
5901
+ * Indicates whether the Cullers component is enabled.
5902
+ */
5856
5903
  I(this, "_enabled", !0);
5904
+ /**
5905
+ * A map of MeshCullerRenderer instances, keyed by their world UUIDs.
5906
+ */
5857
5907
  I(this, "list", /* @__PURE__ */ new Map());
5858
- /** {@link Disposable.onDisposed} */
5908
+ /**
5909
+ * An event that is triggered when the Cullers component is disposed.
5910
+ */
5859
5911
  I(this, "onDisposed", new U());
5860
5912
  t.add(Ye.uuid, this);
5861
5913
  }
5862
- /** {@link Component.enabled} */
5914
+ /**
5915
+ * Gets the enabled state of the Cullers component.
5916
+ *
5917
+ * @returns The current enabled state.
5918
+ */
5863
5919
  get enabled() {
5864
5920
  return this._enabled;
5865
5921
  }
5922
+ /**
5923
+ * Sets the enabled state of the Cullers component.
5924
+ * Also sets the enabled state of all MeshCullerRenderer instances.
5925
+ *
5926
+ * @param value - The new enabled state.
5927
+ */
5866
5928
  set enabled(t) {
5867
5929
  this._enabled = t;
5868
5930
  for (const [e, i] of this.list)
5869
5931
  i.enabled = t;
5870
5932
  }
5933
+ /**
5934
+ * Creates a new MeshCullerRenderer for the given world.
5935
+ * If a MeshCullerRenderer already exists for the world, it will return the existing one.
5936
+ *
5937
+ * @param world - The world for which to create the MeshCullerRenderer.
5938
+ * @param config - Optional configuration settings for the MeshCullerRenderer.
5939
+ *
5940
+ * @returns The newly created or existing MeshCullerRenderer for the given world.
5941
+ */
5871
5942
  create(t, e) {
5872
5943
  if (this.list.has(t.uuid))
5873
5944
  return this.list.get(t.uuid);
@@ -5886,6 +5957,9 @@ const Ye = class Ye extends J {
5886
5957
  this.list.clear();
5887
5958
  }
5888
5959
  };
5960
+ /**
5961
+ * A unique identifier for the Cullers component.
5962
+ */
5889
5963
  I(Ye, "uuid", "69f2a50d-c266-44fc-b1bd-fa4d34be89e6");
5890
5964
  let Ci = Ye;
5891
5965
  class Gr {
@@ -6163,7 +6237,7 @@ class na extends ke {
6163
6237
  I(this, "_frustumSize", 50);
6164
6238
  I(this, "_navigationModes", /* @__PURE__ */ new Map());
6165
6239
  this.threePersp = this.three, this.threeOrtho = this.newOrthoCamera(), this.projection = new Wr(this), this.onAspectUpdated.add(() => {
6166
- this.setOrthoCameraAspect();
6240
+ this.setOrthoPerspCameraAspect();
6167
6241
  }), this.projection.onChanged.add(
6168
6242
  (e) => {
6169
6243
  this.three = e;
@@ -6240,11 +6314,17 @@ class na extends ke {
6240
6314
  1e3
6241
6315
  );
6242
6316
  }
6243
- setOrthoCameraAspect() {
6317
+ setOrthoPerspCameraAspect() {
6244
6318
  if (!this.currentWorld || !this.currentWorld.renderer)
6245
6319
  return;
6246
- const t = this.currentWorld.renderer.getSize(), e = t.x / t.y;
6247
- this.threeOrtho.left = -this._frustumSize * e / 2, this.threeOrtho.right = this._frustumSize * e / 2, this.threeOrtho.top = this._frustumSize / 2, this.threeOrtho.bottom = -this._frustumSize / 2, this.threeOrtho.updateProjectionMatrix();
6320
+ const t = this.currentWorld.renderer.getSize();
6321
+ this.threePersp.aspect = t.width / t.height, this.threePersp.updateProjectionMatrix();
6322
+ const e = new g.Vector3();
6323
+ this.threePersp.getWorldDirection(e);
6324
+ const i = new g.Vector3();
6325
+ this.controls.getTarget(i);
6326
+ const n = i.clone().sub(this.threePersp.position).dot(e), r = this.currentWorld.renderer.getSize(), a = r.x / r.y, l = this.threePersp, E = n * 2 * Math.atan(l.fov * (Math.PI / 180) / 2), d = E * a;
6327
+ this.threeOrtho.zoom = 1, this.threeOrtho.left = d / -2, this.threeOrtho.right = d / 2, this.threeOrtho.top = E / 2, this.threeOrtho.bottom = E / -2, this.threeOrtho.updateProjectionMatrix();
6248
6328
  }
6249
6329
  }
6250
6330
  const At = class At extends J {