@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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-NRSUYDBA.js';
2
- export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-NRSUYDBA.js';
1
+ import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-2F6T3BVO.js';
2
+ export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-2F6T3BVO.js';
3
3
  import { registerDefaultFactories } from './chunk-EIC5B3A7.js';
4
4
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-EIC5B3A7.js';
5
5
  import { ObjectManagementSystem, applyTransform } from './chunk-FDWNCXU3.js';
@@ -4236,8 +4236,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4236
4236
  constructor() {
4237
4237
  /** Signature tracking for geometry + instance count changes. */
4238
4238
  this.geometrySignatures = /* @__PURE__ */ new Map();
4239
- /** Entities whose GLTF model is currently loading. Prevents duplicate load triggers. */
4240
- this.loadingEntities = /* @__PURE__ */ new Set();
4239
+ /** Signature being loaded per entity. Maps entityId → geometrySignature in-flight.
4240
+ * Prevents re-dispatching a load every frame while comp.instancedMesh is still null. */
4241
+ this.loadingSignatures = /* @__PURE__ */ new Map();
4241
4242
  /** Per-mesh data for model kind, populated after GLTF load. */
4242
4243
  this.modelMeshEntries = /* @__PURE__ */ new Map();
4243
4244
  }
@@ -4247,8 +4248,8 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4247
4248
  for (const trackedId of this.geometrySignatures.keys()) {
4248
4249
  if (!alive.has(trackedId)) this.geometrySignatures.delete(trackedId);
4249
4250
  }
4250
- for (const trackedId of this.loadingEntities) {
4251
- if (!alive.has(trackedId)) this.loadingEntities.delete(trackedId);
4251
+ for (const trackedId of this.loadingSignatures.keys()) {
4252
+ if (!alive.has(trackedId)) this.loadingSignatures.delete(trackedId);
4252
4253
  }
4253
4254
  for (const trackedId of this.modelMeshEntries.keys()) {
4254
4255
  if (!alive.has(trackedId)) this.modelMeshEntries.delete(trackedId);
@@ -4264,7 +4265,8 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4264
4265
  if (!anchor) continue;
4265
4266
  const instanceCount = comp.instances.length;
4266
4267
  const geometrySignature = comp.meshKind === "model" ? `model:${comp.modelPath}:${instanceCount}` : `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
4267
- const needsRebuild = comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature;
4268
+ const pendingLoadSignature = this.loadingSignatures.get(entityId);
4269
+ const needsRebuild = (comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
4268
4270
  if (needsRebuild) {
4269
4271
  if (comp.instancedMesh) {
4270
4272
  anchor.remove(comp.instancedMesh);
@@ -4275,16 +4277,18 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4275
4277
  }
4276
4278
  comp.instancedMesh = null;
4277
4279
  }
4278
- this.loadingEntities.delete(entityId);
4279
- this.modelMeshEntries.delete(entityId);
4280
+ if (pendingLoadSignature !== void 0 && pendingLoadSignature !== geometrySignature) {
4281
+ this.loadingSignatures.delete(entityId);
4282
+ this.modelMeshEntries.delete(entityId);
4283
+ }
4280
4284
  if (comp.meshKind === "model") {
4281
- if (comp.modelPath && !this.loadingEntities.has(entityId)) {
4282
- this.loadingEntities.add(entityId);
4285
+ if (comp.modelPath && !this.loadingSignatures.has(entityId)) {
4286
+ this.loadingSignatures.set(entityId, geometrySignature);
4283
4287
  const targetSignature = geometrySignature;
4284
4288
  const targetEntityId = entityId;
4285
4289
  loadGLTF(comp.modelPath).then((gltf) => {
4286
4290
  if (!world.hasEntity(targetEntityId)) {
4287
- this.loadingEntities.delete(targetEntityId);
4291
+ this.loadingSignatures.delete(targetEntityId);
4288
4292
  return;
4289
4293
  }
4290
4294
  const currentComp = world.getComponent(
@@ -4292,20 +4296,25 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4292
4296
  InstancedMeshComponent
4293
4297
  );
4294
4298
  if (!currentComp) {
4295
- this.loadingEntities.delete(targetEntityId);
4299
+ this.loadingSignatures.delete(targetEntityId);
4296
4300
  return;
4297
4301
  }
4298
4302
  const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.length}`;
4299
4303
  if (currentSig !== targetSignature) {
4300
- this.loadingEntities.delete(targetEntityId);
4304
+ this.loadingSignatures.delete(targetEntityId);
4301
4305
  return;
4302
4306
  }
4303
4307
  const currentRef = world.getComponent(targetEntityId, Object3DRef);
4304
4308
  const currentAnchor = currentRef?.object ?? null;
4305
4309
  if (!currentAnchor) {
4306
- this.loadingEntities.delete(targetEntityId);
4310
+ this.loadingSignatures.delete(targetEntityId);
4307
4311
  return;
4308
4312
  }
4313
+ if (currentComp.instancedMesh) {
4314
+ currentAnchor.remove(currentComp.instancedMesh);
4315
+ disposeModelGroup(currentComp.instancedMesh);
4316
+ currentComp.instancedMesh = null;
4317
+ }
4309
4318
  const count2 = Math.max(1, currentComp.instances.length);
4310
4319
  const entries = [];
4311
4320
  gltf.scene.updateWorldMatrix(true, true);
@@ -4337,7 +4346,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4337
4346
  entries.push({ localMatrix, instancedMesh: instancedMesh2 });
4338
4347
  });
4339
4348
  if (entries.length === 0) {
4340
- this.loadingEntities.delete(targetEntityId);
4349
+ this.loadingSignatures.delete(targetEntityId);
4341
4350
  return;
4342
4351
  }
4343
4352
  const group = new THREE13__namespace.Group();
@@ -4348,9 +4357,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4348
4357
  currentComp.instancedMesh = group;
4349
4358
  this.modelMeshEntries.set(targetEntityId, entries);
4350
4359
  this.geometrySignatures.set(targetEntityId, targetSignature);
4351
- this.loadingEntities.delete(targetEntityId);
4360
+ this.loadingSignatures.delete(targetEntityId);
4352
4361
  }).catch(() => {
4353
- this.loadingEntities.delete(targetEntityId);
4362
+ this.loadingSignatures.delete(targetEntityId);
4354
4363
  });
4355
4364
  }
4356
4365
  continue;