@relu-interactives/spatial-ecs 0.2.6 → 0.2.8

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 (49) hide show
  1. package/dist/{System-CIiWteft.d.cts → System-AV2_87Zr.d.cts} +1 -1
  2. package/dist/{System-CIiWteft.d.ts → System-AV2_87Zr.d.ts} +1 -1
  3. package/dist/{Video-Dj4KBqQ1.d.cts → Video-Bn93p6XV.d.cts} +27 -5
  4. package/dist/{Video-B-qMljTn.d.ts → Video-D6mObK_5.d.ts} +27 -5
  5. package/dist/{chunk-R5D5PWXV.js → chunk-AZR6SLQN.js} +16 -4
  6. package/dist/chunk-AZR6SLQN.js.map +1 -0
  7. package/dist/{chunk-EIC5B3A7.js → chunk-LE6ARNYQ.js} +84 -13
  8. package/dist/chunk-LE6ARNYQ.js.map +1 -0
  9. package/dist/{chunk-FDWNCXU3.js → chunk-ODCWJHPS.js} +3 -3
  10. package/dist/{chunk-FDWNCXU3.js.map → chunk-ODCWJHPS.js.map} +1 -1
  11. package/dist/{chunk-G2DUXNTQ.js → chunk-PHIEXEKJ.js} +10 -3
  12. package/dist/chunk-PHIEXEKJ.js.map +1 -0
  13. package/dist/{chunk-NRSUYDBA.js → chunk-TVBWYIGY.js} +67 -44
  14. package/dist/chunk-TVBWYIGY.js.map +1 -0
  15. package/dist/components/index.cjs +13 -1
  16. package/dist/components/index.cjs.map +1 -1
  17. package/dist/components/index.d.cts +2 -2
  18. package/dist/components/index.d.ts +2 -2
  19. package/dist/components/index.js +1 -1
  20. package/dist/factories/index.cjs +92 -9
  21. package/dist/factories/index.cjs.map +1 -1
  22. package/dist/factories/index.d.cts +7 -4
  23. package/dist/factories/index.d.ts +7 -4
  24. package/dist/factories/index.js +3 -3
  25. package/dist/{index-Cf-PaKyN.d.ts → index-B4-ABchF.d.cts} +4 -3
  26. package/dist/{index-B12sx9yF.d.cts → index-BO49V8aS.d.ts} +4 -3
  27. package/dist/index.cjs +207 -55
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +6 -6
  30. package/dist/index.d.ts +6 -6
  31. package/dist/index.js +52 -14
  32. package/dist/index.js.map +1 -1
  33. package/dist/systems/index.cjs +64 -46
  34. package/dist/systems/index.cjs.map +1 -1
  35. package/dist/systems/index.d.cts +5 -4
  36. package/dist/systems/index.d.ts +5 -4
  37. package/dist/systems/index.js +3 -3
  38. package/dist/types.d.cts +1 -1
  39. package/dist/types.d.ts +1 -1
  40. package/dist/worldSnapshotUtils.cjs +8 -1
  41. package/dist/worldSnapshotUtils.cjs.map +1 -1
  42. package/dist/worldSnapshotUtils.d.cts +1 -1
  43. package/dist/worldSnapshotUtils.d.ts +1 -1
  44. package/dist/worldSnapshotUtils.js +1 -1
  45. package/package.json +1 -1
  46. package/dist/chunk-EIC5B3A7.js.map +0 -1
  47. package/dist/chunk-G2DUXNTQ.js.map +0 -1
  48. package/dist/chunk-NRSUYDBA.js.map +0 -1
  49. package/dist/chunk-R5D5PWXV.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { resolveDracoDecoderPath, applyTransform } from './chunk-FDWNCXU3.js';
2
- import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, AudioComponent, VideoComponent } from './chunk-R5D5PWXV.js';
1
+ import { resolveDracoDecoderPath, applyTransform } from './chunk-ODCWJHPS.js';
2
+ import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, AudioComponent, VideoComponent } from './chunk-AZR6SLQN.js';
3
3
  import { __name } from './chunk-OY7ZODZP.js';
4
4
  import * as THREE7 from 'three';
5
5
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
@@ -2329,14 +2329,14 @@ var _euler = new THREE7.Euler();
2329
2329
  var _scale = new THREE7.Vector3();
2330
2330
  var _matrix = new THREE7.Matrix4();
2331
2331
  var _modelMatrix = new THREE7.Matrix4();
2332
- function instanceTransformToMatrix4(inst, out) {
2333
- _position.set(inst.position.x, inst.position.y, inst.position.z);
2334
- _euler.set(inst.rotation.x, inst.rotation.y, inst.rotation.z, "XYZ");
2332
+ function instanceTransformFromComponent(transform, out) {
2333
+ _position.set(transform.position.x, transform.position.y, transform.position.z);
2334
+ _euler.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, "XYZ");
2335
2335
  _quaternion.setFromEuler(_euler);
2336
- _scale.set(inst.scale.x, inst.scale.y, inst.scale.z);
2336
+ _scale.set(transform.scale.x, transform.scale.y, transform.scale.z);
2337
2337
  out.compose(_position, _quaternion, _scale);
2338
2338
  }
2339
- __name(instanceTransformToMatrix4, "instanceTransformToMatrix4");
2339
+ __name(instanceTransformFromComponent, "instanceTransformFromComponent");
2340
2340
  function disposePrimitiveInstancedMesh(mesh) {
2341
2341
  mesh.geometry.dispose();
2342
2342
  if (Array.isArray(mesh.material)) {
@@ -2368,8 +2368,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2368
2368
  constructor() {
2369
2369
  /** Signature tracking for geometry + instance count changes. */
2370
2370
  this.geometrySignatures = /* @__PURE__ */ new Map();
2371
- /** Entities whose GLTF model is currently loading. Prevents duplicate load triggers. */
2372
- this.loadingEntities = /* @__PURE__ */ new Set();
2371
+ /** Signature being loaded per entity. Maps entityId → geometrySignature in-flight.
2372
+ * Prevents re-dispatching a load every frame while comp.instancedMesh is still null. */
2373
+ this.loadingSignatures = /* @__PURE__ */ new Map();
2373
2374
  /** Per-mesh data for model kind, populated after GLTF load. */
2374
2375
  this.modelMeshEntries = /* @__PURE__ */ new Map();
2375
2376
  }
@@ -2379,8 +2380,8 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2379
2380
  for (const trackedId of this.geometrySignatures.keys()) {
2380
2381
  if (!alive.has(trackedId)) this.geometrySignatures.delete(trackedId);
2381
2382
  }
2382
- for (const trackedId of this.loadingEntities) {
2383
- if (!alive.has(trackedId)) this.loadingEntities.delete(trackedId);
2383
+ for (const trackedId of this.loadingSignatures.keys()) {
2384
+ if (!alive.has(trackedId)) this.loadingSignatures.delete(trackedId);
2384
2385
  }
2385
2386
  for (const trackedId of this.modelMeshEntries.keys()) {
2386
2387
  if (!alive.has(trackedId)) this.modelMeshEntries.delete(trackedId);
@@ -2394,9 +2395,10 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2394
2395
  const objectRef = world.getComponent(entityId, Object3DRef);
2395
2396
  const anchor = objectRef?.object ?? null;
2396
2397
  if (!anchor) continue;
2397
- const instanceCount = comp.instances.length;
2398
+ const instanceCount = comp.instanceEntityIds.length;
2398
2399
  const geometrySignature = comp.meshKind === "model" ? `model:${comp.modelPath}:${instanceCount}` : `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
2399
- const needsRebuild = comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature;
2400
+ const pendingLoadSignature = this.loadingSignatures.get(entityId);
2401
+ const needsRebuild = (comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
2400
2402
  if (needsRebuild) {
2401
2403
  if (comp.instancedMesh) {
2402
2404
  anchor.remove(comp.instancedMesh);
@@ -2407,16 +2409,18 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2407
2409
  }
2408
2410
  comp.instancedMesh = null;
2409
2411
  }
2410
- this.loadingEntities.delete(entityId);
2411
- this.modelMeshEntries.delete(entityId);
2412
+ if (pendingLoadSignature !== void 0 && pendingLoadSignature !== geometrySignature) {
2413
+ this.loadingSignatures.delete(entityId);
2414
+ this.modelMeshEntries.delete(entityId);
2415
+ }
2412
2416
  if (comp.meshKind === "model") {
2413
- if (comp.modelPath && !this.loadingEntities.has(entityId)) {
2414
- this.loadingEntities.add(entityId);
2417
+ if (comp.modelPath && !this.loadingSignatures.has(entityId)) {
2418
+ this.loadingSignatures.set(entityId, geometrySignature);
2415
2419
  const targetSignature = geometrySignature;
2416
2420
  const targetEntityId = entityId;
2417
2421
  loadGLTF(comp.modelPath).then((gltf) => {
2418
2422
  if (!world.hasEntity(targetEntityId)) {
2419
- this.loadingEntities.delete(targetEntityId);
2423
+ this.loadingSignatures.delete(targetEntityId);
2420
2424
  return;
2421
2425
  }
2422
2426
  const currentComp = world.getComponent(
@@ -2424,21 +2428,26 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2424
2428
  InstancedMeshComponent
2425
2429
  );
2426
2430
  if (!currentComp) {
2427
- this.loadingEntities.delete(targetEntityId);
2431
+ this.loadingSignatures.delete(targetEntityId);
2428
2432
  return;
2429
2433
  }
2430
- const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.length}`;
2434
+ const currentSig = `model:${currentComp.modelPath}:${currentComp.instanceEntityIds.length}`;
2431
2435
  if (currentSig !== targetSignature) {
2432
- this.loadingEntities.delete(targetEntityId);
2436
+ this.loadingSignatures.delete(targetEntityId);
2433
2437
  return;
2434
2438
  }
2435
2439
  const currentRef = world.getComponent(targetEntityId, Object3DRef);
2436
2440
  const currentAnchor = currentRef?.object ?? null;
2437
2441
  if (!currentAnchor) {
2438
- this.loadingEntities.delete(targetEntityId);
2442
+ this.loadingSignatures.delete(targetEntityId);
2439
2443
  return;
2440
2444
  }
2441
- const count2 = Math.max(1, currentComp.instances.length);
2445
+ if (currentComp.instancedMesh) {
2446
+ currentAnchor.remove(currentComp.instancedMesh);
2447
+ disposeModelGroup(currentComp.instancedMesh);
2448
+ currentComp.instancedMesh = null;
2449
+ }
2450
+ const count2 = Math.max(1, currentComp.instanceEntityIds.length);
2442
2451
  const entries = [];
2443
2452
  gltf.scene.updateWorldMatrix(true, true);
2444
2453
  gltf.scene.traverse((child) => {
@@ -2456,12 +2465,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2456
2465
  instancedMesh2.castShadow = currentComp.castShadow;
2457
2466
  instancedMesh2.receiveShadow = currentComp.receiveShadow;
2458
2467
  for (let i = 0; i < count2; i++) {
2459
- const inst = currentComp.instances[i] ?? {
2460
- position: { x: 0, y: 0, z: 0 },
2461
- rotation: { x: 0, y: 0, z: 0 },
2462
- scale: { x: 1, y: 1, z: 1 }
2463
- };
2464
- instanceTransformToMatrix4(inst, _matrix);
2468
+ const instanceEntityId = currentComp.instanceEntityIds[i];
2469
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
2470
+ if (instTransform) {
2471
+ instanceTransformFromComponent(instTransform, _matrix);
2472
+ } else {
2473
+ _matrix.identity();
2474
+ }
2465
2475
  _modelMatrix.multiplyMatrices(_matrix, localMatrix);
2466
2476
  instancedMesh2.setMatrixAt(i, _modelMatrix);
2467
2477
  }
@@ -2469,7 +2479,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2469
2479
  entries.push({ localMatrix, instancedMesh: instancedMesh2 });
2470
2480
  });
2471
2481
  if (entries.length === 0) {
2472
- this.loadingEntities.delete(targetEntityId);
2482
+ this.loadingSignatures.delete(targetEntityId);
2473
2483
  return;
2474
2484
  }
2475
2485
  const group = new THREE7.Group();
@@ -2480,9 +2490,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2480
2490
  currentComp.instancedMesh = group;
2481
2491
  this.modelMeshEntries.set(targetEntityId, entries);
2482
2492
  this.geometrySignatures.set(targetEntityId, targetSignature);
2483
- this.loadingEntities.delete(targetEntityId);
2493
+ this.loadingSignatures.delete(targetEntityId);
2484
2494
  }).catch(() => {
2485
- this.loadingEntities.delete(targetEntityId);
2495
+ this.loadingSignatures.delete(targetEntityId);
2486
2496
  });
2487
2497
  }
2488
2498
  continue;
@@ -2494,12 +2504,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2494
2504
  instancedMesh.castShadow = comp.castShadow;
2495
2505
  instancedMesh.receiveShadow = comp.receiveShadow;
2496
2506
  for (let i = 0; i < count; i++) {
2497
- const inst = comp.instances[i] ?? {
2498
- position: { x: 0, y: 0, z: 0 },
2499
- rotation: { x: 0, y: 0, z: 0 },
2500
- scale: { x: 1, y: 1, z: 1 }
2501
- };
2502
- instanceTransformToMatrix4(inst, _matrix);
2507
+ const instanceEntityId = comp.instanceEntityIds[i];
2508
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
2509
+ if (instTransform) {
2510
+ instanceTransformFromComponent(instTransform, _matrix);
2511
+ } else {
2512
+ _matrix.identity();
2513
+ }
2503
2514
  instancedMesh.setMatrixAt(i, _matrix);
2504
2515
  }
2505
2516
  instancedMesh.instanceMatrix.needsUpdate = true;
@@ -2510,10 +2521,16 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2510
2521
  if (comp.meshKind === "model") {
2511
2522
  const entries = this.modelMeshEntries.get(entityId);
2512
2523
  if (entries) {
2513
- const count = comp.instances.length;
2524
+ const count = comp.instanceEntityIds.length;
2514
2525
  for (const entry of entries) {
2515
2526
  for (let i = 0; i < count; i++) {
2516
- instanceTransformToMatrix4(comp.instances[i], _matrix);
2527
+ const instanceEntityId = comp.instanceEntityIds[i];
2528
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
2529
+ if (instTransform) {
2530
+ instanceTransformFromComponent(instTransform, _matrix);
2531
+ } else {
2532
+ _matrix.identity();
2533
+ }
2517
2534
  _modelMatrix.multiplyMatrices(_matrix, entry.localMatrix);
2518
2535
  entry.instancedMesh.setMatrixAt(i, _modelMatrix);
2519
2536
  }
@@ -2524,9 +2541,15 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2524
2541
  }
2525
2542
  } else {
2526
2543
  const im = comp.instancedMesh;
2527
- const count = comp.instances.length;
2544
+ const count = comp.instanceEntityIds.length;
2528
2545
  for (let i = 0; i < count; i++) {
2529
- instanceTransformToMatrix4(comp.instances[i], _matrix);
2546
+ const instanceEntityId = comp.instanceEntityIds[i];
2547
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
2548
+ if (instTransform) {
2549
+ instanceTransformFromComponent(instTransform, _matrix);
2550
+ } else {
2551
+ _matrix.identity();
2552
+ }
2530
2553
  im.setMatrixAt(i, _matrix);
2531
2554
  }
2532
2555
  im.instanceMatrix.needsUpdate = true;
@@ -3570,5 +3593,5 @@ __name(_VideoSystem, "VideoSystem");
3570
3593
  var VideoSystem = _VideoSystem;
3571
3594
 
3572
3595
  export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem };
3573
- //# sourceMappingURL=chunk-NRSUYDBA.js.map
3574
- //# sourceMappingURL=chunk-NRSUYDBA.js.map
3596
+ //# sourceMappingURL=chunk-TVBWYIGY.js.map
3597
+ //# sourceMappingURL=chunk-TVBWYIGY.js.map