@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.
- 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-NRSUYDBA.js → chunk-TVBWYIGY.js} +67 -44
- package/dist/chunk-TVBWYIGY.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 +207 -55
- 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 +64 -46
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +5 -4
- package/dist/systems/index.d.ts +5 -4
- 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-EIC5B3A7.js.map +0 -1
- package/dist/chunk-G2DUXNTQ.js.map +0 -1
- package/dist/chunk-NRSUYDBA.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)) {
|
|
@@ -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
|
-
/**
|
|
4240
|
-
|
|
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.
|
|
4251
|
-
if (!alive.has(trackedId)) this.
|
|
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.
|
|
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
|
|
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
|
-
|
|
4279
|
-
|
|
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.
|
|
4282
|
-
this.
|
|
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.
|
|
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.
|
|
4294
|
+
this.loadingSignatures.delete(targetEntityId);
|
|
4296
4295
|
return;
|
|
4297
4296
|
}
|
|
4298
|
-
const currentSig = `model:${currentComp.modelPath}:${currentComp.
|
|
4297
|
+
const currentSig = `model:${currentComp.modelPath}:${currentComp.instanceEntityIds.length}`;
|
|
4299
4298
|
if (currentSig !== targetSignature) {
|
|
4300
|
-
this.
|
|
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.
|
|
4305
|
+
this.loadingSignatures.delete(targetEntityId);
|
|
4307
4306
|
return;
|
|
4308
4307
|
}
|
|
4309
|
-
|
|
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
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
}
|
|
4332
|
-
|
|
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.
|
|
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.
|
|
4356
|
+
this.loadingSignatures.delete(targetEntityId);
|
|
4352
4357
|
}).catch(() => {
|
|
4353
|
-
this.
|
|
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
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
}
|
|
4370
|
-
|
|
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.
|
|
4387
|
+
const count = comp.instanceEntityIds.length;
|
|
4382
4388
|
for (const entry of entries) {
|
|
4383
4389
|
for (let i = 0; i < count; i++) {
|
|
4384
|
-
|
|
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.
|
|
4407
|
+
const count = comp.instanceEntityIds.length;
|
|
4396
4408
|
for (let i = 0; i < count; i++) {
|
|
4397
|
-
|
|
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;
|