@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
@@ -1316,11 +1316,6 @@ __name(_MeshGeometryComponent, "MeshGeometryComponent");
1316
1316
  var MeshGeometryComponent = _MeshGeometryComponent;
1317
1317
 
1318
1318
  // core/components/InstancedMesh.ts
1319
- var DEFAULT_INSTANCE_TRANSFORM = {
1320
- position: { x: 0, y: 0, z: 0 },
1321
- rotation: { x: 0, y: 0, z: 0 },
1322
- scale: { x: 1, y: 1, z: 1 }
1323
- };
1324
1319
  var DEFAULT_INSTANCED_MESH_PARAMETERS = {
1325
1320
  capsule: DEFAULT_MESH_GEOMETRY_PARAMETERS.capsule,
1326
1321
  cube: DEFAULT_MESH_GEOMETRY_PARAMETERS.cube,
@@ -1340,7 +1335,7 @@ var _InstancedMeshComponent = class _InstancedMeshComponent extends Component {
1340
1335
  };
1341
1336
  this.castShadow = options?.castShadow ?? false;
1342
1337
  this.receiveShadow = options?.receiveShadow ?? false;
1343
- this.instances = options?.instances && options.instances.length > 0 ? options.instances : [{ ...DEFAULT_INSTANCE_TRANSFORM }];
1338
+ this.instanceEntityIds = options?.instanceEntityIds ?? [];
1344
1339
  this.instancedMesh = null;
1345
1340
  }
1346
1341
  /** Sanitize and return a copy of the current mesh parameters with valid values. */
@@ -4197,14 +4192,14 @@ var _euler = new THREE13__namespace.Euler();
4197
4192
  var _scale = new THREE13__namespace.Vector3();
4198
4193
  var _matrix = new THREE13__namespace.Matrix4();
4199
4194
  var _modelMatrix = new THREE13__namespace.Matrix4();
4200
- function instanceTransformToMatrix4(inst, out) {
4201
- _position.set(inst.position.x, inst.position.y, inst.position.z);
4202
- _euler.set(inst.rotation.x, inst.rotation.y, inst.rotation.z, "XYZ");
4195
+ function instanceTransformFromComponent(transform, out) {
4196
+ _position.set(transform.position.x, transform.position.y, transform.position.z);
4197
+ _euler.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, "XYZ");
4203
4198
  _quaternion.setFromEuler(_euler);
4204
- _scale.set(inst.scale.x, inst.scale.y, inst.scale.z);
4199
+ _scale.set(transform.scale.x, transform.scale.y, transform.scale.z);
4205
4200
  out.compose(_position, _quaternion, _scale);
4206
4201
  }
4207
- __name(instanceTransformToMatrix4, "instanceTransformToMatrix4");
4202
+ __name(instanceTransformFromComponent, "instanceTransformFromComponent");
4208
4203
  function disposePrimitiveInstancedMesh(mesh) {
4209
4204
  mesh.geometry.dispose();
4210
4205
  if (Array.isArray(mesh.material)) {
@@ -4236,8 +4231,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4236
4231
  constructor() {
4237
4232
  /** Signature tracking for geometry + instance count changes. */
4238
4233
  this.geometrySignatures = /* @__PURE__ */ new Map();
4239
- /** Entities whose GLTF model is currently loading. Prevents duplicate load triggers. */
4240
- this.loadingEntities = /* @__PURE__ */ new Set();
4234
+ /** Signature being loaded per entity. Maps entityId → geometrySignature in-flight.
4235
+ * Prevents re-dispatching a load every frame while comp.instancedMesh is still null. */
4236
+ this.loadingSignatures = /* @__PURE__ */ new Map();
4241
4237
  /** Per-mesh data for model kind, populated after GLTF load. */
4242
4238
  this.modelMeshEntries = /* @__PURE__ */ new Map();
4243
4239
  }
@@ -4247,8 +4243,8 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4247
4243
  for (const trackedId of this.geometrySignatures.keys()) {
4248
4244
  if (!alive.has(trackedId)) this.geometrySignatures.delete(trackedId);
4249
4245
  }
4250
- for (const trackedId of this.loadingEntities) {
4251
- if (!alive.has(trackedId)) this.loadingEntities.delete(trackedId);
4246
+ for (const trackedId of this.loadingSignatures.keys()) {
4247
+ if (!alive.has(trackedId)) this.loadingSignatures.delete(trackedId);
4252
4248
  }
4253
4249
  for (const trackedId of this.modelMeshEntries.keys()) {
4254
4250
  if (!alive.has(trackedId)) this.modelMeshEntries.delete(trackedId);
@@ -4262,9 +4258,10 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4262
4258
  const objectRef = world.getComponent(entityId, Object3DRef);
4263
4259
  const anchor = objectRef?.object ?? null;
4264
4260
  if (!anchor) continue;
4265
- const instanceCount = comp.instances.length;
4261
+ const instanceCount = comp.instanceEntityIds.length;
4266
4262
  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;
4263
+ const pendingLoadSignature = this.loadingSignatures.get(entityId);
4264
+ const needsRebuild = (comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
4268
4265
  if (needsRebuild) {
4269
4266
  if (comp.instancedMesh) {
4270
4267
  anchor.remove(comp.instancedMesh);
@@ -4275,16 +4272,18 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4275
4272
  }
4276
4273
  comp.instancedMesh = null;
4277
4274
  }
4278
- this.loadingEntities.delete(entityId);
4279
- this.modelMeshEntries.delete(entityId);
4275
+ if (pendingLoadSignature !== void 0 && pendingLoadSignature !== geometrySignature) {
4276
+ this.loadingSignatures.delete(entityId);
4277
+ this.modelMeshEntries.delete(entityId);
4278
+ }
4280
4279
  if (comp.meshKind === "model") {
4281
- if (comp.modelPath && !this.loadingEntities.has(entityId)) {
4282
- this.loadingEntities.add(entityId);
4280
+ if (comp.modelPath && !this.loadingSignatures.has(entityId)) {
4281
+ this.loadingSignatures.set(entityId, geometrySignature);
4283
4282
  const targetSignature = geometrySignature;
4284
4283
  const targetEntityId = entityId;
4285
4284
  loadGLTF(comp.modelPath).then((gltf) => {
4286
4285
  if (!world.hasEntity(targetEntityId)) {
4287
- this.loadingEntities.delete(targetEntityId);
4286
+ this.loadingSignatures.delete(targetEntityId);
4288
4287
  return;
4289
4288
  }
4290
4289
  const currentComp = world.getComponent(
@@ -4292,21 +4291,26 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4292
4291
  InstancedMeshComponent
4293
4292
  );
4294
4293
  if (!currentComp) {
4295
- this.loadingEntities.delete(targetEntityId);
4294
+ this.loadingSignatures.delete(targetEntityId);
4296
4295
  return;
4297
4296
  }
4298
- const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.length}`;
4297
+ const currentSig = `model:${currentComp.modelPath}:${currentComp.instanceEntityIds.length}`;
4299
4298
  if (currentSig !== targetSignature) {
4300
- this.loadingEntities.delete(targetEntityId);
4299
+ this.loadingSignatures.delete(targetEntityId);
4301
4300
  return;
4302
4301
  }
4303
4302
  const currentRef = world.getComponent(targetEntityId, Object3DRef);
4304
4303
  const currentAnchor = currentRef?.object ?? null;
4305
4304
  if (!currentAnchor) {
4306
- this.loadingEntities.delete(targetEntityId);
4305
+ this.loadingSignatures.delete(targetEntityId);
4307
4306
  return;
4308
4307
  }
4309
- const count2 = Math.max(1, currentComp.instances.length);
4308
+ if (currentComp.instancedMesh) {
4309
+ currentAnchor.remove(currentComp.instancedMesh);
4310
+ disposeModelGroup(currentComp.instancedMesh);
4311
+ currentComp.instancedMesh = null;
4312
+ }
4313
+ const count2 = Math.max(1, currentComp.instanceEntityIds.length);
4310
4314
  const entries = [];
4311
4315
  gltf.scene.updateWorldMatrix(true, true);
4312
4316
  gltf.scene.traverse((child) => {
@@ -4324,12 +4328,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4324
4328
  instancedMesh2.castShadow = currentComp.castShadow;
4325
4329
  instancedMesh2.receiveShadow = currentComp.receiveShadow;
4326
4330
  for (let i = 0; i < count2; i++) {
4327
- const inst = currentComp.instances[i] ?? {
4328
- position: { x: 0, y: 0, z: 0 },
4329
- rotation: { x: 0, y: 0, z: 0 },
4330
- scale: { x: 1, y: 1, z: 1 }
4331
- };
4332
- instanceTransformToMatrix4(inst, _matrix);
4331
+ const instanceEntityId = currentComp.instanceEntityIds[i];
4332
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
4333
+ if (instTransform) {
4334
+ instanceTransformFromComponent(instTransform, _matrix);
4335
+ } else {
4336
+ _matrix.identity();
4337
+ }
4333
4338
  _modelMatrix.multiplyMatrices(_matrix, localMatrix);
4334
4339
  instancedMesh2.setMatrixAt(i, _modelMatrix);
4335
4340
  }
@@ -4337,7 +4342,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4337
4342
  entries.push({ localMatrix, instancedMesh: instancedMesh2 });
4338
4343
  });
4339
4344
  if (entries.length === 0) {
4340
- this.loadingEntities.delete(targetEntityId);
4345
+ this.loadingSignatures.delete(targetEntityId);
4341
4346
  return;
4342
4347
  }
4343
4348
  const group = new THREE13__namespace.Group();
@@ -4348,9 +4353,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4348
4353
  currentComp.instancedMesh = group;
4349
4354
  this.modelMeshEntries.set(targetEntityId, entries);
4350
4355
  this.geometrySignatures.set(targetEntityId, targetSignature);
4351
- this.loadingEntities.delete(targetEntityId);
4356
+ this.loadingSignatures.delete(targetEntityId);
4352
4357
  }).catch(() => {
4353
- this.loadingEntities.delete(targetEntityId);
4358
+ this.loadingSignatures.delete(targetEntityId);
4354
4359
  });
4355
4360
  }
4356
4361
  continue;
@@ -4362,12 +4367,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4362
4367
  instancedMesh.castShadow = comp.castShadow;
4363
4368
  instancedMesh.receiveShadow = comp.receiveShadow;
4364
4369
  for (let i = 0; i < count; i++) {
4365
- const inst = comp.instances[i] ?? {
4366
- position: { x: 0, y: 0, z: 0 },
4367
- rotation: { x: 0, y: 0, z: 0 },
4368
- scale: { x: 1, y: 1, z: 1 }
4369
- };
4370
- instanceTransformToMatrix4(inst, _matrix);
4370
+ const instanceEntityId = comp.instanceEntityIds[i];
4371
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
4372
+ if (instTransform) {
4373
+ instanceTransformFromComponent(instTransform, _matrix);
4374
+ } else {
4375
+ _matrix.identity();
4376
+ }
4371
4377
  instancedMesh.setMatrixAt(i, _matrix);
4372
4378
  }
4373
4379
  instancedMesh.instanceMatrix.needsUpdate = true;
@@ -4378,10 +4384,16 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4378
4384
  if (comp.meshKind === "model") {
4379
4385
  const entries = this.modelMeshEntries.get(entityId);
4380
4386
  if (entries) {
4381
- const count = comp.instances.length;
4387
+ const count = comp.instanceEntityIds.length;
4382
4388
  for (const entry of entries) {
4383
4389
  for (let i = 0; i < count; i++) {
4384
- instanceTransformToMatrix4(comp.instances[i], _matrix);
4390
+ const instanceEntityId = comp.instanceEntityIds[i];
4391
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
4392
+ if (instTransform) {
4393
+ instanceTransformFromComponent(instTransform, _matrix);
4394
+ } else {
4395
+ _matrix.identity();
4396
+ }
4385
4397
  _modelMatrix.multiplyMatrices(_matrix, entry.localMatrix);
4386
4398
  entry.instancedMesh.setMatrixAt(i, _modelMatrix);
4387
4399
  }
@@ -4392,9 +4404,15 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4392
4404
  }
4393
4405
  } else {
4394
4406
  const im = comp.instancedMesh;
4395
- const count = comp.instances.length;
4407
+ const count = comp.instanceEntityIds.length;
4396
4408
  for (let i = 0; i < count; i++) {
4397
- instanceTransformToMatrix4(comp.instances[i], _matrix);
4409
+ const instanceEntityId = comp.instanceEntityIds[i];
4410
+ const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
4411
+ if (instTransform) {
4412
+ instanceTransformFromComponent(instTransform, _matrix);
4413
+ } else {
4414
+ _matrix.identity();
4415
+ }
4398
4416
  im.setMatrixAt(i, _matrix);
4399
4417
  }
4400
4418
  im.instanceMatrix.needsUpdate = true;