@relu-interactives/spatial-ecs 0.2.7 → 0.2.9
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/{System-CIiWteft.d.cts → System-AV2_87Zr.d.cts} +1 -1
- package/dist/{System-CIiWteft.d.ts → System-AV2_87Zr.d.ts} +1 -1
- package/dist/{Video-Dj4KBqQ1.d.cts → Video-Bn93p6XV.d.cts} +27 -5
- package/dist/{Video-B-qMljTn.d.ts → Video-D6mObK_5.d.ts} +27 -5
- package/dist/{chunk-R5D5PWXV.js → chunk-AZR6SLQN.js} +16 -4
- package/dist/chunk-AZR6SLQN.js.map +1 -0
- package/dist/{chunk-EIC5B3A7.js → chunk-LE6ARNYQ.js} +84 -13
- package/dist/chunk-LE6ARNYQ.js.map +1 -0
- package/dist/{chunk-FDWNCXU3.js → chunk-ODCWJHPS.js} +3 -3
- package/dist/{chunk-FDWNCXU3.js.map → chunk-ODCWJHPS.js.map} +1 -1
- package/dist/{chunk-G2DUXNTQ.js → chunk-PHIEXEKJ.js} +10 -3
- package/dist/chunk-PHIEXEKJ.js.map +1 -0
- package/dist/{chunk-2F6T3BVO.js → chunk-SABZQFSA.js} +47 -29
- package/dist/chunk-SABZQFSA.js.map +1 -0
- package/dist/components/index.cjs +13 -1
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/factories/index.cjs +92 -9
- package/dist/factories/index.cjs.map +1 -1
- package/dist/factories/index.d.cts +7 -4
- package/dist/factories/index.d.ts +7 -4
- package/dist/factories/index.js +3 -3
- package/dist/{index-Cf-PaKyN.d.ts → index-B4-ABchF.d.cts} +4 -3
- package/dist/{index-B12sx9yF.d.cts → index-BO49V8aS.d.ts} +4 -3
- package/dist/index.cjs +187 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +52 -14
- package/dist/index.js.map +1 -1
- package/dist/systems/index.cjs +44 -31
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +2 -2
- package/dist/systems/index.d.ts +2 -2
- package/dist/systems/index.js +3 -3
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/worldSnapshotUtils.cjs +8 -1
- package/dist/worldSnapshotUtils.cjs.map +1 -1
- package/dist/worldSnapshotUtils.d.cts +1 -1
- package/dist/worldSnapshotUtils.d.ts +1 -1
- package/dist/worldSnapshotUtils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2F6T3BVO.js.map +0 -1
- package/dist/chunk-EIC5B3A7.js.map +0 -1
- package/dist/chunk-G2DUXNTQ.js.map +0 -1
- package/dist/chunk-R5D5PWXV.js.map +0 -1
package/dist/systems/index.cjs
CHANGED
|
@@ -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.
|
|
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
|
|
4201
|
-
_position.set(
|
|
4202
|
-
_euler.set(
|
|
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(
|
|
4199
|
+
_scale.set(transform.scale.x, transform.scale.y, transform.scale.z);
|
|
4205
4200
|
out.compose(_position, _quaternion, _scale);
|
|
4206
4201
|
}
|
|
4207
|
-
__name(
|
|
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.
|
|
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;
|
|
@@ -4281,6 +4276,10 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4281
4276
|
this.loadingSignatures.delete(entityId);
|
|
4282
4277
|
this.modelMeshEntries.delete(entityId);
|
|
4283
4278
|
}
|
|
4279
|
+
if (instanceCount === 0) {
|
|
4280
|
+
this.geometrySignatures.set(entityId, geometrySignature);
|
|
4281
|
+
continue;
|
|
4282
|
+
}
|
|
4284
4283
|
if (comp.meshKind === "model") {
|
|
4285
4284
|
if (comp.modelPath && !this.loadingSignatures.has(entityId)) {
|
|
4286
4285
|
this.loadingSignatures.set(entityId, geometrySignature);
|
|
@@ -4299,7 +4298,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4299
4298
|
this.loadingSignatures.delete(targetEntityId);
|
|
4300
4299
|
return;
|
|
4301
4300
|
}
|
|
4302
|
-
const currentSig = `model:${currentComp.modelPath}:${currentComp.
|
|
4301
|
+
const currentSig = `model:${currentComp.modelPath}:${currentComp.instanceEntityIds.length}`;
|
|
4303
4302
|
if (currentSig !== targetSignature) {
|
|
4304
4303
|
this.loadingSignatures.delete(targetEntityId);
|
|
4305
4304
|
return;
|
|
@@ -4315,7 +4314,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4315
4314
|
disposeModelGroup(currentComp.instancedMesh);
|
|
4316
4315
|
currentComp.instancedMesh = null;
|
|
4317
4316
|
}
|
|
4318
|
-
const count2 = Math.max(1, currentComp.
|
|
4317
|
+
const count2 = Math.max(1, currentComp.instanceEntityIds.length);
|
|
4319
4318
|
const entries = [];
|
|
4320
4319
|
gltf.scene.updateWorldMatrix(true, true);
|
|
4321
4320
|
gltf.scene.traverse((child) => {
|
|
@@ -4333,12 +4332,13 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4333
4332
|
instancedMesh2.castShadow = currentComp.castShadow;
|
|
4334
4333
|
instancedMesh2.receiveShadow = currentComp.receiveShadow;
|
|
4335
4334
|
for (let i = 0; i < count2; i++) {
|
|
4336
|
-
const
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4335
|
+
const instanceEntityId = currentComp.instanceEntityIds[i];
|
|
4336
|
+
const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
|
|
4337
|
+
if (instTransform) {
|
|
4338
|
+
instanceTransformFromComponent(instTransform, _matrix);
|
|
4339
|
+
} else {
|
|
4340
|
+
_matrix.identity();
|
|
4341
|
+
}
|
|
4342
4342
|
_modelMatrix.multiplyMatrices(_matrix, localMatrix);
|
|
4343
4343
|
instancedMesh2.setMatrixAt(i, _modelMatrix);
|
|
4344
4344
|
}
|
|
@@ -4364,19 +4364,20 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4364
4364
|
}
|
|
4365
4365
|
continue;
|
|
4366
4366
|
}
|
|
4367
|
-
const count =
|
|
4367
|
+
const count = instanceCount;
|
|
4368
4368
|
const geometry = buildGeometry(comp);
|
|
4369
4369
|
const material = new THREE13__namespace.MeshStandardMaterial({ color: "#ffffff" });
|
|
4370
4370
|
const instancedMesh = new THREE13__namespace.InstancedMesh(geometry, material, count);
|
|
4371
4371
|
instancedMesh.castShadow = comp.castShadow;
|
|
4372
4372
|
instancedMesh.receiveShadow = comp.receiveShadow;
|
|
4373
4373
|
for (let i = 0; i < count; i++) {
|
|
4374
|
-
const
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
}
|
|
4379
|
-
|
|
4374
|
+
const instanceEntityId = comp.instanceEntityIds[i];
|
|
4375
|
+
const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
|
|
4376
|
+
if (instTransform) {
|
|
4377
|
+
instanceTransformFromComponent(instTransform, _matrix);
|
|
4378
|
+
} else {
|
|
4379
|
+
_matrix.identity();
|
|
4380
|
+
}
|
|
4380
4381
|
instancedMesh.setMatrixAt(i, _matrix);
|
|
4381
4382
|
}
|
|
4382
4383
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
@@ -4387,10 +4388,16 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4387
4388
|
if (comp.meshKind === "model") {
|
|
4388
4389
|
const entries = this.modelMeshEntries.get(entityId);
|
|
4389
4390
|
if (entries) {
|
|
4390
|
-
const count = comp.
|
|
4391
|
+
const count = comp.instanceEntityIds.length;
|
|
4391
4392
|
for (const entry of entries) {
|
|
4392
4393
|
for (let i = 0; i < count; i++) {
|
|
4393
|
-
|
|
4394
|
+
const instanceEntityId = comp.instanceEntityIds[i];
|
|
4395
|
+
const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
|
|
4396
|
+
if (instTransform) {
|
|
4397
|
+
instanceTransformFromComponent(instTransform, _matrix);
|
|
4398
|
+
} else {
|
|
4399
|
+
_matrix.identity();
|
|
4400
|
+
}
|
|
4394
4401
|
_modelMatrix.multiplyMatrices(_matrix, entry.localMatrix);
|
|
4395
4402
|
entry.instancedMesh.setMatrixAt(i, _modelMatrix);
|
|
4396
4403
|
}
|
|
@@ -4401,9 +4408,15 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
|
4401
4408
|
}
|
|
4402
4409
|
} else {
|
|
4403
4410
|
const im = comp.instancedMesh;
|
|
4404
|
-
const count = comp.
|
|
4411
|
+
const count = comp.instanceEntityIds.length;
|
|
4405
4412
|
for (let i = 0; i < count; i++) {
|
|
4406
|
-
|
|
4413
|
+
const instanceEntityId = comp.instanceEntityIds[i];
|
|
4414
|
+
const instTransform = instanceEntityId !== void 0 ? world.getComponent(instanceEntityId, TransformComponent) ?? null : null;
|
|
4415
|
+
if (instTransform) {
|
|
4416
|
+
instanceTransformFromComponent(instTransform, _matrix);
|
|
4417
|
+
} else {
|
|
4418
|
+
_matrix.identity();
|
|
4419
|
+
}
|
|
4407
4420
|
im.setMatrixAt(i, _matrix);
|
|
4408
4421
|
}
|
|
4409
4422
|
im.instanceMatrix.needsUpdate = true;
|