@relu-interactives/spatial-ecs 0.2.9 → 0.2.10

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-SABZQFSA.js';
2
- export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-SABZQFSA.js';
1
+ import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-Y7KXYSPD.js';
2
+ export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-Y7KXYSPD.js';
3
3
  import { registerDefaultFactories } from './chunk-LE6ARNYQ.js';
4
4
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-LE6ARNYQ.js';
5
5
  import { ObjectManagementSystem, applyTransform } from './chunk-ODCWJHPS.js';
@@ -7,7 +7,7 @@ export { ObjectManagementSystem } from './chunk-ODCWJHPS.js';
7
7
  import { SelectionTransformState, Object3DRef, Name, EntityType, ScriptComponent, InstancedMeshComponent, InstanceSlotComponent, AnimationComponent, TransformComponent, ModelComponent, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, CameraComponent, Environment, Postprocessing, ImageTarget, LightComponent, MaterialComponent, MeshGeometryComponent, Selectable, PhysicsComponent } from './chunk-AZR6SLQN.js';
8
8
  export { AnimationStateMachine, AnimationStateManager, components_exports as CoreComponents } from './chunk-AZR6SLQN.js';
9
9
  import './chunk-QHILSPT4.js';
10
- import { normalizeDebugValue, DEBUG_CHANGE_IGNORED_SYSTEMS, cloneHistoryValue } from './chunk-PHIEXEKJ.js';
10
+ import { normalizeDebugValue, DEBUG_CHANGE_IGNORED_SYSTEMS, cloneHistoryValue } from './chunk-R2WMVXZZ.js';
11
11
  import { __name } from './chunk-OY7ZODZP.js';
12
12
  export { Component } from './chunk-OY7ZODZP.js';
13
13
  import * as THREE from 'three';
@@ -4236,6 +4236,15 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4236
4236
  this.loadingSignatures = /* @__PURE__ */ new Map();
4237
4237
  /** Per-mesh data for model kind, populated after GLTF load. */
4238
4238
  this.modelMeshEntries = /* @__PURE__ */ new Map();
4239
+ /**
4240
+ * System-internal ref to the Three.js mesh/group most recently placed on
4241
+ * the anchor by this system. Used for cleanup on rebuild instead of
4242
+ * `comp.instancedMesh`, which can be stale (pointing to a disposed mesh)
4243
+ * after an undo/redo restores a history snapshot captured at an earlier
4244
+ * geometry configuration. Relying on the stale comp ref would skip removal
4245
+ * of the current live mesh → ghost mesh in the scene.
4246
+ */
4247
+ this.trackedMeshes = /* @__PURE__ */ new Map();
4239
4248
  }
4240
4249
  update(world) {
4241
4250
  const entityIds = world.query(InstancedMeshComponent);
@@ -4249,6 +4258,9 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4249
4258
  for (const trackedId of this.modelMeshEntries.keys()) {
4250
4259
  if (!alive.has(trackedId)) this.modelMeshEntries.delete(trackedId);
4251
4260
  }
4261
+ for (const trackedId of this.trackedMeshes.keys()) {
4262
+ if (!alive.has(trackedId)) this.trackedMeshes.delete(trackedId);
4263
+ }
4252
4264
  for (const entityId of entityIds) {
4253
4265
  const comp = world.getComponent(
4254
4266
  entityId,
@@ -4260,18 +4272,26 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4260
4272
  if (!anchor) continue;
4261
4273
  const instanceCount = comp.instanceEntityIds.length;
4262
4274
  const geometrySignature = comp.meshKind === "model" ? `model:${comp.modelPath}:${instanceCount}` : `${comp.meshKind}:${JSON.stringify(comp.meshParameters)}:${instanceCount}`;
4275
+ if (comp.instancedMesh === null) {
4276
+ const tracked = this.trackedMeshes.get(entityId);
4277
+ if (tracked) {
4278
+ comp.instancedMesh = tracked;
4279
+ }
4280
+ }
4263
4281
  const pendingLoadSignature = this.loadingSignatures.get(entityId);
4264
- const needsRebuild = (comp.instancedMesh === null || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
4282
+ const needsRebuild = (!this.trackedMeshes.has(entityId) || this.geometrySignatures.get(entityId) !== geometrySignature) && pendingLoadSignature !== geometrySignature;
4265
4283
  if (needsRebuild) {
4266
- if (comp.instancedMesh) {
4267
- anchor.remove(comp.instancedMesh);
4268
- if (comp.instancedMesh.isInstancedMesh) {
4269
- disposePrimitiveInstancedMesh(comp.instancedMesh);
4284
+ const trackedMesh = this.trackedMeshes.get(entityId);
4285
+ if (trackedMesh) {
4286
+ anchor.remove(trackedMesh);
4287
+ if (trackedMesh.isInstancedMesh) {
4288
+ disposePrimitiveInstancedMesh(trackedMesh);
4270
4289
  } else {
4271
- disposeModelGroup(comp.instancedMesh);
4290
+ disposeModelGroup(trackedMesh);
4272
4291
  }
4273
- comp.instancedMesh = null;
4292
+ this.trackedMeshes.delete(entityId);
4274
4293
  }
4294
+ comp.instancedMesh = null;
4275
4295
  if (pendingLoadSignature !== void 0 && pendingLoadSignature !== geometrySignature) {
4276
4296
  this.loadingSignatures.delete(entityId);
4277
4297
  this.modelMeshEntries.delete(entityId);
@@ -4357,6 +4377,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4357
4377
  currentComp.instancedMesh = group;
4358
4378
  this.modelMeshEntries.set(targetEntityId, entries);
4359
4379
  this.geometrySignatures.set(targetEntityId, targetSignature);
4380
+ this.trackedMeshes.set(targetEntityId, group);
4360
4381
  this.loadingSignatures.delete(targetEntityId);
4361
4382
  }).catch(() => {
4362
4383
  this.loadingSignatures.delete(targetEntityId);
@@ -4383,6 +4404,7 @@ var _InstancedMeshSystem = class _InstancedMeshSystem {
4383
4404
  instancedMesh.instanceMatrix.needsUpdate = true;
4384
4405
  anchor.add(instancedMesh);
4385
4406
  comp.instancedMesh = instancedMesh;
4407
+ this.trackedMeshes.set(entityId, instancedMesh);
4386
4408
  this.geometrySignatures.set(entityId, geometrySignature);
4387
4409
  } else {
4388
4410
  if (comp.meshKind === "model") {