@relu-interactives/spatial-ecs 0.2.7 → 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-2F6T3BVO.js → chunk-TVBWYIGY.js} +42 -28
  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 +182 -39
  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 +39 -30
  34. package/dist/systems/index.cjs.map +1 -1
  35. package/dist/systems/index.d.cts +2 -2
  36. package/dist/systems/index.d.ts +2 -2
  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-2F6T3BVO.js.map +0 -1
  47. package/dist/chunk-EIC5B3A7.js.map +0 -1
  48. package/dist/chunk-G2DUXNTQ.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)) {
@@ -4263,7 +4258,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4263
4258
  const objectRef = world.getComponent(entityId, Object3DRef);
4264
4259
  const anchor = objectRef?.object ?? null;
4265
4260
  if (!anchor) continue;
4266
- const instanceCount = comp.instances.length;
4261
+ const instanceCount = comp.instanceEntityIds.length;
4267
4262
  const geometrySignature = comp.meshKind === "model" ? `model:${comp.modelPath}:${instanceCount}` : `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
4268
4263
  const pendingLoadSignature = this.loadingSignatures.get(entityId);
4269
4264
  const needsRebuild = (comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
@@ -4299,7 +4294,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4299
4294
  this.loadingSignatures.delete(targetEntityId);
4300
4295
  return;
4301
4296
  }
4302
- const currentSig = `model:${currentComp.modelPath}:${currentComp.instances.length}`;
4297
+ const currentSig = `model:${currentComp.modelPath}:${currentComp.instanceEntityIds.length}`;
4303
4298
  if (currentSig !== targetSignature) {
4304
4299
  this.loadingSignatures.delete(targetEntityId);
4305
4300
  return;
@@ -4315,7 +4310,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4315
4310
  disposeModelGroup(currentComp.instancedMesh);
4316
4311
  currentComp.instancedMesh = null;
4317
4312
  }
4318
- const count2 = Math.max(1, currentComp.instances.length);
4313
+ const count2 = Math.max(1, currentComp.instanceEntityIds.length);
4319
4314
  const entries = [];
4320
4315
  gltf.scene.updateWorldMatrix(true, true);
4321
4316
  gltf.scene.traverse((child) => {
@@ -4333,12 +4328,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4333
4328
  instancedMesh2.castShadow = currentComp.castShadow;
4334
4329
  instancedMesh2.receiveShadow = currentComp.receiveShadow;
4335
4330
  for (let i = 0; i < count2; i++) {
4336
- const inst = currentComp.instances[i] ?? {
4337
- position: { x: 0, y: 0, z: 0 },
4338
- rotation: { x: 0, y: 0, z: 0 },
4339
- scale: { x: 1, y: 1, z: 1 }
4340
- };
4341
- 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
+ }
4342
4338
  _modelMatrix.multiplyMatrices(_matrix, localMatrix);
4343
4339
  instancedMesh2.setMatrixAt(i, _modelMatrix);
4344
4340
  }
@@ -4371,12 +4367,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4371
4367
  instancedMesh.castShadow = comp.castShadow;
4372
4368
  instancedMesh.receiveShadow = comp.receiveShadow;
4373
4369
  for (let i = 0; i < count; i++) {
4374
- const inst = comp.instances[i] ?? {
4375
- position: { x: 0, y: 0, z: 0 },
4376
- rotation: { x: 0, y: 0, z: 0 },
4377
- scale: { x: 1, y: 1, z: 1 }
4378
- };
4379
- 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
+ }
4380
4377
  instancedMesh.setMatrixAt(i, _matrix);
4381
4378
  }
4382
4379
  instancedMesh.instanceMatrix.needsUpdate = true;
@@ -4387,10 +4384,16 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4387
4384
  if (comp.meshKind === "model") {
4388
4385
  const entries = this.modelMeshEntries.get(entityId);
4389
4386
  if (entries) {
4390
- const count = comp.instances.length;
4387
+ const count = comp.instanceEntityIds.length;
4391
4388
  for (const entry of entries) {
4392
4389
  for (let i = 0; i < count; i++) {
4393
- 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
+ }
4394
4397
  _modelMatrix.multiplyMatrices(_matrix, entry.localMatrix);
4395
4398
  entry.instancedMesh.setMatrixAt(i, _modelMatrix);
4396
4399
  }
@@ -4401,9 +4404,15 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4401
4404
  }
4402
4405
  } else {
4403
4406
  const im = comp.instancedMesh;
4404
- const count = comp.instances.length;
4407
+ const count = comp.instanceEntityIds.length;
4405
4408
  for (let i = 0; i < count; i++) {
4406
- 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
+ }
4407
4416
  im.setMatrixAt(i, _matrix);
4408
4417
  }
4409
4418
  im.instanceMatrix.needsUpdate = true;