@relu-interactives/spatial-ecs 0.2.4 → 0.2.5
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-BTyYvKVH.d.cts → System-CIiWteft.d.cts} +2 -2
- package/dist/{System-BTyYvKVH.d.ts → System-CIiWteft.d.ts} +2 -2
- package/dist/{Video-D2H5H-K3.d.cts → Video-ChVFs9Tl.d.cts} +139 -75
- package/dist/{Video-BWhbvVPg.d.ts → Video-DCMCLInA.d.ts} +139 -75
- package/dist/{chunk-XWIEEJ7Z.js → chunk-4A66FSFT.js} +128 -82
- package/dist/chunk-4A66FSFT.js.map +1 -0
- package/dist/{chunk-AYEF3X2P.js → chunk-CRP3W2GK.js} +3 -3
- package/dist/chunk-CRP3W2GK.js.map +1 -0
- package/dist/{chunk-MAWBTMCG.js → chunk-KRZLEPRI.js} +156 -88
- package/dist/chunk-KRZLEPRI.js.map +1 -0
- package/dist/{chunk-NFDTIYR4.js → chunk-NB6I5JJN.js} +17 -2
- package/dist/chunk-NB6I5JJN.js.map +1 -0
- package/dist/{chunk-P2YDX5DB.js → chunk-RXCUHGRB.js} +124 -5
- package/dist/chunk-RXCUHGRB.js.map +1 -0
- package/dist/components/index.cjs +161 -93
- 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 +217 -105
- package/dist/factories/index.cjs.map +1 -1
- package/dist/factories/index.d.cts +9 -3
- package/dist/factories/index.d.ts +9 -3
- package/dist/factories/index.js +3 -3
- package/dist/{index-KdEzEZox.d.cts → index-D1I5L7bA.d.cts} +8 -3
- package/dist/{index-Dm6zF1MY.d.ts → index-DGZDgt3p.d.ts} +8 -3
- package/dist/index.cjs +468 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +51 -12
- package/dist/index.js.map +1 -1
- package/dist/systems/index.cjs +248 -63
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +15 -3
- package/dist/systems/index.d.ts +15 -3
- 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 +15 -0
- 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-AYEF3X2P.js.map +0 -1
- package/dist/chunk-MAWBTMCG.js.map +0 -1
- package/dist/chunk-NFDTIYR4.js.map +0 -1
- package/dist/chunk-P2YDX5DB.js.map +0 -1
- package/dist/chunk-XWIEEJ7Z.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveDracoDecoderPath, applyTransform } from './chunk-
|
|
2
|
-
import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, ParentId, ScriptComponent, AudioComponent, VideoComponent } from './chunk-
|
|
1
|
+
import { resolveDracoDecoderPath, applyTransform } from './chunk-CRP3W2GK.js';
|
|
2
|
+
import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, AudioComponent, VideoComponent } from './chunk-KRZLEPRI.js';
|
|
3
3
|
import { __name } from './chunk-OY7ZODZP.js';
|
|
4
4
|
import * as THREE7 from 'three';
|
|
5
5
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
@@ -2269,6 +2269,125 @@ var _MeshGeometrySystem = class _MeshGeometrySystem {
|
|
|
2269
2269
|
};
|
|
2270
2270
|
__name(_MeshGeometrySystem, "MeshGeometrySystem");
|
|
2271
2271
|
var MeshGeometrySystem = _MeshGeometrySystem;
|
|
2272
|
+
function buildGeometry(component) {
|
|
2273
|
+
const p = component.getSanitizedParameters();
|
|
2274
|
+
switch (component.meshKind) {
|
|
2275
|
+
case "cube": {
|
|
2276
|
+
const params = p;
|
|
2277
|
+
return new THREE7.BoxGeometry(params.width, params.height, params.depth);
|
|
2278
|
+
}
|
|
2279
|
+
case "plane": {
|
|
2280
|
+
const params = p;
|
|
2281
|
+
return new THREE7.PlaneGeometry(params.width, params.height);
|
|
2282
|
+
}
|
|
2283
|
+
case "sphere": {
|
|
2284
|
+
const params = p;
|
|
2285
|
+
return new THREE7.SphereGeometry(params.radius, 24, 24);
|
|
2286
|
+
}
|
|
2287
|
+
case "cylinder": {
|
|
2288
|
+
const params = p;
|
|
2289
|
+
return new THREE7.CylinderGeometry(params.radius, params.radius, params.height, 20);
|
|
2290
|
+
}
|
|
2291
|
+
case "capsule": {
|
|
2292
|
+
const params = p;
|
|
2293
|
+
return new THREE7.CapsuleGeometry(params.radius, params.height, 4, 8);
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
__name(buildGeometry, "buildGeometry");
|
|
2298
|
+
var _position = new THREE7.Vector3();
|
|
2299
|
+
var _quaternion = new THREE7.Quaternion();
|
|
2300
|
+
var _euler = new THREE7.Euler();
|
|
2301
|
+
var _scale = new THREE7.Vector3();
|
|
2302
|
+
var _matrix = new THREE7.Matrix4();
|
|
2303
|
+
function instanceTransformToMatrix4(inst, out) {
|
|
2304
|
+
_position.set(inst.position.x, inst.position.y, inst.position.z);
|
|
2305
|
+
_euler.set(inst.rotation.x, inst.rotation.y, inst.rotation.z, "XYZ");
|
|
2306
|
+
_quaternion.setFromEuler(_euler);
|
|
2307
|
+
_scale.set(inst.scale.x, inst.scale.y, inst.scale.z);
|
|
2308
|
+
out.compose(_position, _quaternion, _scale);
|
|
2309
|
+
}
|
|
2310
|
+
__name(instanceTransformToMatrix4, "instanceTransformToMatrix4");
|
|
2311
|
+
var _InstancedMeshSystem = class _InstancedMeshSystem {
|
|
2312
|
+
constructor() {
|
|
2313
|
+
/** Signature tracking for geometry + instance count changes. */
|
|
2314
|
+
this.geometrySignatures = /* @__PURE__ */ new Map();
|
|
2315
|
+
}
|
|
2316
|
+
update(world) {
|
|
2317
|
+
const entityIds = world.query(InstancedMeshComponent);
|
|
2318
|
+
const alive = new Set(entityIds);
|
|
2319
|
+
for (const trackedId of this.geometrySignatures.keys()) {
|
|
2320
|
+
if (!alive.has(trackedId)) {
|
|
2321
|
+
this.geometrySignatures.delete(trackedId);
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
for (const entityId of entityIds) {
|
|
2325
|
+
const comp = world.getComponent(
|
|
2326
|
+
entityId,
|
|
2327
|
+
InstancedMeshComponent
|
|
2328
|
+
);
|
|
2329
|
+
if (!comp) {
|
|
2330
|
+
continue;
|
|
2331
|
+
}
|
|
2332
|
+
let anchor = null;
|
|
2333
|
+
const objectRef = world.getComponent(entityId, Object3DRef);
|
|
2334
|
+
if (objectRef?.object) {
|
|
2335
|
+
anchor = objectRef.object;
|
|
2336
|
+
}
|
|
2337
|
+
if (!anchor) {
|
|
2338
|
+
continue;
|
|
2339
|
+
}
|
|
2340
|
+
const instanceCount = comp.instances.length;
|
|
2341
|
+
const geometrySignature = `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
|
|
2342
|
+
const needsRebuild = comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature;
|
|
2343
|
+
if (needsRebuild) {
|
|
2344
|
+
if (comp.instancedMesh) {
|
|
2345
|
+
anchor.remove(comp.instancedMesh);
|
|
2346
|
+
comp.instancedMesh.geometry.dispose();
|
|
2347
|
+
if (Array.isArray(comp.instancedMesh.material)) {
|
|
2348
|
+
for (const m of comp.instancedMesh.material) {
|
|
2349
|
+
m.dispose();
|
|
2350
|
+
}
|
|
2351
|
+
} else {
|
|
2352
|
+
comp.instancedMesh.material.dispose();
|
|
2353
|
+
}
|
|
2354
|
+
comp.instancedMesh = null;
|
|
2355
|
+
}
|
|
2356
|
+
const count = Math.max(1, instanceCount);
|
|
2357
|
+
const geometry = buildGeometry(comp);
|
|
2358
|
+
const material = new THREE7.MeshStandardMaterial({ color: "#ffffff" });
|
|
2359
|
+
const instancedMesh = new THREE7.InstancedMesh(geometry, material, count);
|
|
2360
|
+
instancedMesh.castShadow = comp.castShadow;
|
|
2361
|
+
instancedMesh.receiveShadow = comp.receiveShadow;
|
|
2362
|
+
for (let i = 0; i < count; i++) {
|
|
2363
|
+
const inst = comp.instances[i] ?? {
|
|
2364
|
+
position: { x: 0, y: 0, z: 0 },
|
|
2365
|
+
rotation: { x: 0, y: 0, z: 0 },
|
|
2366
|
+
scale: { x: 1, y: 1, z: 1 }
|
|
2367
|
+
};
|
|
2368
|
+
instanceTransformToMatrix4(inst, _matrix);
|
|
2369
|
+
instancedMesh.setMatrixAt(i, _matrix);
|
|
2370
|
+
}
|
|
2371
|
+
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
2372
|
+
anchor.add(instancedMesh);
|
|
2373
|
+
comp.instancedMesh = instancedMesh;
|
|
2374
|
+
this.geometrySignatures.set(entityId, geometrySignature);
|
|
2375
|
+
} else {
|
|
2376
|
+
const im = comp.instancedMesh;
|
|
2377
|
+
const count = comp.instances.length;
|
|
2378
|
+
for (let i = 0; i < count; i++) {
|
|
2379
|
+
instanceTransformToMatrix4(comp.instances[i], _matrix);
|
|
2380
|
+
im.setMatrixAt(i, _matrix);
|
|
2381
|
+
}
|
|
2382
|
+
im.instanceMatrix.needsUpdate = true;
|
|
2383
|
+
im.castShadow = comp.castShadow;
|
|
2384
|
+
im.receiveShadow = comp.receiveShadow;
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
__name(_InstancedMeshSystem, "InstancedMeshSystem");
|
|
2390
|
+
var InstancedMeshSystem = _InstancedMeshSystem;
|
|
2272
2391
|
|
|
2273
2392
|
// core/systems/RenderSystem.ts
|
|
2274
2393
|
var _RenderSystem = class _RenderSystem {
|
|
@@ -3299,6 +3418,6 @@ var _VideoSystem = class _VideoSystem {
|
|
|
3299
3418
|
__name(_VideoSystem, "VideoSystem");
|
|
3300
3419
|
var VideoSystem = _VideoSystem;
|
|
3301
3420
|
|
|
3302
|
-
export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem };
|
|
3303
|
-
//# sourceMappingURL=chunk-
|
|
3304
|
-
//# sourceMappingURL=chunk-
|
|
3421
|
+
export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem };
|
|
3422
|
+
//# sourceMappingURL=chunk-RXCUHGRB.js.map
|
|
3423
|
+
//# sourceMappingURL=chunk-RXCUHGRB.js.map
|