@relu-interactives/spatial-ecs 0.2.6 → 0.2.7

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.
@@ -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);
@@ -2396,7 +2397,8 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2396
2397
  if (!anchor) continue;
2397
2398
  const instanceCount = comp.instances.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,20 +2428,25 @@ 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
2434
  const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.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
  }
2445
+ if (currentComp.instancedMesh) {
2446
+ currentAnchor.remove(currentComp.instancedMesh);
2447
+ disposeModelGroup(currentComp.instancedMesh);
2448
+ currentComp.instancedMesh = null;
2449
+ }
2441
2450
  const count2 = Math.max(1, currentComp.instances.length);
2442
2451
  const entries = [];
2443
2452
  gltf.scene.updateWorldMatrix(true, true);
@@ -2469,7 +2478,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2469
2478
  entries.push({ localMatrix, instancedMesh: instancedMesh2 });
2470
2479
  });
2471
2480
  if (entries.length === 0) {
2472
- this.loadingEntities.delete(targetEntityId);
2481
+ this.loadingSignatures.delete(targetEntityId);
2473
2482
  return;
2474
2483
  }
2475
2484
  const group = new THREE7.Group();
@@ -2480,9 +2489,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
2480
2489
  currentComp.instancedMesh = group;
2481
2490
  this.modelMeshEntries.set(targetEntityId, entries);
2482
2491
  this.geometrySignatures.set(targetEntityId, targetSignature);
2483
- this.loadingEntities.delete(targetEntityId);
2492
+ this.loadingSignatures.delete(targetEntityId);
2484
2493
  }).catch(() => {
2485
- this.loadingEntities.delete(targetEntityId);
2494
+ this.loadingSignatures.delete(targetEntityId);
2486
2495
  });
2487
2496
  }
2488
2497
  continue;
@@ -3570,5 +3579,5 @@ __name(_VideoSystem, "VideoSystem");
3570
3579
  var VideoSystem = _VideoSystem;
3571
3580
 
3572
3581
  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
3582
+ //# sourceMappingURL=chunk-2F6T3BVO.js.map
3583
+ //# sourceMappingURL=chunk-2F6T3BVO.js.map