@relu-interactives/spatial-ecs 0.2.17 → 0.2.20

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 (54) hide show
  1. package/dist/{System-BeuJ1xt5.d.cts → System-BjwOBx81.d.cts} +146 -1
  2. package/dist/{System-BeuJ1xt5.d.ts → System-BjwOBx81.d.ts} +146 -1
  3. package/dist/{Video-D4B-z74P.d.cts → Video-B8yVI1tF.d.cts} +17 -3
  4. package/dist/{Video-Cym2C52L.d.ts → Video-B9z5AtIf.d.ts} +17 -3
  5. package/dist/{chunk-EPK6MA7X.js → chunk-67MFQDHX.js} +1646 -8
  6. package/dist/chunk-67MFQDHX.js.map +1 -0
  7. package/dist/{chunk-GRUK5TNL.js → chunk-DY4ETMP2.js} +3 -3
  8. package/dist/{chunk-GRUK5TNL.js.map → chunk-DY4ETMP2.js.map} +1 -1
  9. package/dist/{chunk-CJW6K3CL.js → chunk-HUHN6IFD.js} +62 -5
  10. package/dist/chunk-HUHN6IFD.js.map +1 -0
  11. package/dist/{chunk-FTIQQK62.js → chunk-Z6OMYEXU.js} +42 -3
  12. package/dist/chunk-Z6OMYEXU.js.map +1 -0
  13. package/dist/{chunk-R2WMVXZZ.js → chunk-ZXGHKX7N.js} +5 -3
  14. package/dist/chunk-ZXGHKX7N.js.map +1 -0
  15. package/dist/components/index.cjs +39 -0
  16. package/dist/components/index.cjs.map +1 -1
  17. package/dist/components/index.d.cts +3 -2
  18. package/dist/components/index.d.ts +3 -2
  19. package/dist/components/index.js +1 -1
  20. package/dist/docs/guide/components/material.md +4 -0
  21. package/dist/docs/guide/components/physics.md +10 -0
  22. package/dist/docs/guide/getting-started/editor/assets-browser.md +1 -1
  23. package/dist/docs/guide/prefabs.md +133 -0
  24. package/dist/docs/guide/world-api.md +1 -1
  25. package/dist/factories/index.cjs +136 -64
  26. package/dist/factories/index.cjs.map +1 -1
  27. package/dist/factories/index.d.cts +5 -4
  28. package/dist/factories/index.d.ts +5 -4
  29. package/dist/factories/index.js +3 -3
  30. package/dist/{index-BoJ3_6a3.d.ts → index-BBI2YdCu.d.ts} +60 -4
  31. package/dist/{index-BfoOC2CG.d.cts → index-LHLKpJhZ.d.cts} +60 -4
  32. package/dist/index.cjs +5978 -4972
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +215 -7
  35. package/dist/index.d.ts +215 -7
  36. package/dist/index.js +203 -960
  37. package/dist/index.js.map +1 -1
  38. package/dist/systems/index.cjs +1367 -0
  39. package/dist/systems/index.cjs.map +1 -1
  40. package/dist/systems/index.d.cts +2 -2
  41. package/dist/systems/index.d.ts +2 -2
  42. package/dist/systems/index.js +3 -3
  43. package/dist/types.d.cts +1 -1
  44. package/dist/types.d.ts +1 -1
  45. package/dist/worldSnapshotUtils.cjs +3 -1
  46. package/dist/worldSnapshotUtils.cjs.map +1 -1
  47. package/dist/worldSnapshotUtils.d.cts +1 -1
  48. package/dist/worldSnapshotUtils.d.ts +1 -1
  49. package/dist/worldSnapshotUtils.js +1 -1
  50. package/package.json +4 -2
  51. package/dist/chunk-CJW6K3CL.js.map +0 -1
  52. package/dist/chunk-EPK6MA7X.js.map +0 -1
  53. package/dist/chunk-FTIQQK62.js.map +0 -1
  54. package/dist/chunk-R2WMVXZZ.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, m as ComponentClass, n as ParentLookup, o as EcsEntityKind, O as ObjectManagementSystem } from './System-BeuJ1xt5.cjs';
2
- export { A as AssetInput, p as CheckboxInput, q as ColorInput, r as ComponentFactory, s as ComponentInput, t as ComponentKind, u as DropdownInput, v as DropdownOption, w as EcsComponentFactoryKind, x as EcsEntityEditorKind, y as EntityId, z as EntityInput, F as FloatInput, I as InputSystem, B as IntersectionResult, K as KeyboardKey, G as KeyboardKeys, M as MouseButton, R as RenderSystem, S as SelectionListener, H as SliderInput, J as TextInput, L as ToggleInput, N as TransformSyncSystem, Q as Vec3, U as Vector2Input, X as Vector3Input } from './System-BeuJ1xt5.cjs';
1
+ import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, S as SpawnPrefabSource, m as SpawnPrefabOptions, n as ComponentClass, o as ParentLookup, p as EcsEntityKind, O as ObjectManagementSystem, q as EntityId, r as SubtreeSnapshot, s as ExternalRefWarning } from './System-BjwOBx81.cjs';
2
+ export { A as AssetInput, t as CheckboxInput, u as ColorInput, v as ComponentFactory, w as ComponentInput, x as ComponentKind, y as DropdownInput, z as DropdownOption, B as EcsComponentFactoryKind, F as EcsEntityEditorKind, G as EntityInput, H as FloatInput, I as InputSystem, J as IntersectionResult, K as KeyboardKey, L as KeyboardKeys, M as MouseButton, N as PREFAB_FILE_VERSION, Q as PrefabAsset, R as RemapSnapshotOptions, U as RenderSystem, X as SelectionListener, Y as SliderInput, Z as TextInput, _ as ToggleInput, $ as TransformSyncSystem, a0 as Vec3, a1 as Vector2Input, a2 as Vector3Input, a3 as clearPrefabCache, a4 as despawnPrefab, a5 as loadPrefab, a6 as parsePrefabAsset, a7 as remapSnapshotEntityIds, a8 as setPrefabAssetUrlResolver, a9 as spawnPrefab } from './System-BjwOBx81.cjs';
3
3
  import * as THREE from 'three';
4
- import { O as Object3DRef } from './Video-D4B-z74P.cjs';
5
- export { a2 as AnimationStateCallbacks, a3 as AnimationStateMachine, a4 as AnimationStateManager, a5 as StateMachine } from './Video-D4B-z74P.cjs';
6
- export { i as CoreComponents } from './index-BfoOC2CG.cjs';
4
+ import { O as Object3DRef } from './Video-B8yVI1tF.cjs';
5
+ export { a3 as AnimationStateCallbacks, a4 as AnimationStateMachine, a5 as AnimationStateManager, a6 as StateMachine } from './Video-B8yVI1tF.cjs';
6
+ export { i as CoreComponents } from './index-LHLKpJhZ.cjs';
7
7
  export { AnimationSystem, AudioSystem, CameraSyncSystem, EnvironmentSyncSystem, InstancedMeshSystem, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, ScriptBehaviourSystem, SelectionContext, VideoSystem } from './systems/index.cjs';
8
8
  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 './factories/index.cjs';
9
9
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
@@ -136,6 +136,31 @@ declare class Behaviour implements CustomEcsSystem {
136
136
  * @param world - The owning world at disposal time.
137
137
  */
138
138
  dispose?(world: World): void;
139
+ /**
140
+ * Instantiate a prefab asset into the world at runtime.
141
+ *
142
+ * `source` is typically an `AssetInput` field from this script's `data`
143
+ * (drag a `.prefab` from the asset browser onto the field in the editor),
144
+ * a URL string, or a pre-loaded `PrefabAsset`. Resolves with the new root
145
+ * entity id.
146
+ *
147
+ * ```ts
148
+ * data = { enemyPrefab: { path: "", type: "prefab" } };
149
+ * async onUpdate() {
150
+ * if (shouldSpawn) {
151
+ * const id = await this.spawnPrefab(this.data.enemyPrefab, {
152
+ * position: { x: 0, y: 0, z: -5 },
153
+ * });
154
+ * }
155
+ * }
156
+ * ```
157
+ */
158
+ spawnPrefab(source: SpawnPrefabSource, options?: SpawnPrefabOptions): Promise<number>;
159
+ /**
160
+ * Remove a spawned prefab instance (the root entity and all descendants).
161
+ * Returns the number of entities removed.
162
+ */
163
+ despawn(rootEntityId: number): number;
139
164
  /**
140
165
  * Returns the entity's world-space position as a new `THREE.Vector3`, or
141
166
  * `null` if the entity has no scene presence.
@@ -260,6 +285,32 @@ declare class Behaviour implements CustomEcsSystem {
260
285
  onTargetLost(target: WorldEntityView): void;
261
286
  }
262
287
 
288
+ type ComponentValueMaps = {
289
+ object3DRefValues: Map<number, unknown>;
290
+ nameValues: Map<number, unknown>;
291
+ transformValues: Map<number, unknown>;
292
+ modelValues: Map<number, unknown>;
293
+ imageValues: Map<number, unknown>;
294
+ spriteValues: Map<number, unknown>;
295
+ videoValues: Map<number, unknown>;
296
+ cameraValues: Map<number, unknown>;
297
+ environmentValues: Map<number, unknown>;
298
+ postprocessingValues: Map<number, unknown>;
299
+ audioValues: Map<number, unknown>;
300
+ imageTargetValues: Map<number, unknown>;
301
+ lightValues: Map<number, unknown>;
302
+ materialValues: Map<number, unknown>;
303
+ meshGeometryValues: Map<number, unknown>;
304
+ selectableValues: Map<number, unknown>;
305
+ physicsValues: Map<number, unknown>;
306
+ animationValues: Map<number, unknown>;
307
+ imageTargetAnchorValues: Map<number, unknown>;
308
+ scriptValues: Map<number, unknown>;
309
+ instancedMeshValues: Map<number, unknown>;
310
+ instanceSlotValues: Map<number, unknown>;
311
+ prefabNodeValues: Map<number, unknown>;
312
+ prefabInstanceValues: Map<number, unknown>;
313
+ };
263
314
  type EcsWorldComponentSnapshot = {
264
315
  component: string;
265
316
  entries: Array<{
@@ -275,12 +326,40 @@ type EcsWorldStateSnapshotLike = {
275
326
  type HydrateWorldFromSnapshotResult = {
276
327
  restoredCount: number;
277
328
  selectedEntityId: number | null;
329
+ /** Snapshot entity id → created live entity id for every hydrated entity. */
330
+ idMap: Map<number, number>;
331
+ };
332
+ /**
333
+ * Optional behavior tweaks for {@link hydrateWorldFromSnapshotDetailed}.
334
+ * Defaults preserve the historical full-world-load behavior; prefab/subtree
335
+ * instantiation passes stricter options.
336
+ */
337
+ type HydrateOptions = {
338
+ /**
339
+ * When false, no camera in the snapshot is promoted to the world camera.
340
+ * Defaults to true (full scene loads want their default camera active);
341
+ * prefab spawns pass false so a spawned camera never hijacks the view.
342
+ */
343
+ assignPrimaryCamera?: boolean;
344
+ /**
345
+ * "world" (default) re-applies local transforms for every entity in the
346
+ * world after parent links restore — correct for full scene loads.
347
+ * "created" limits the pass to entities created by THIS hydrate call, so
348
+ * mid-session spawns don't touch unrelated live entities.
349
+ */
350
+ applyTransformsScope?: "world" | "created";
278
351
  };
279
352
  declare const HYDRATABLE_ENTITY_KINDS: Set<EcsEntityKind>;
280
353
 
281
- declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): HydrateWorldFromSnapshotResult;
354
+ declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem, options?: HydrateOptions): HydrateWorldFromSnapshotResult;
282
355
  declare function hydrateWorldFromSnapshot(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): number;
283
356
 
357
+ declare function buildComponentValueMaps(snapshot: EcsWorldStateSnapshotLike): ComponentValueMaps;
358
+
359
+ declare function restoreComponentState(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps): void;
360
+
361
+ declare function restorePostCreateComponents(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps, idMap: Map<number, number>): void;
362
+
284
363
  /**
285
364
  * Override where the DRACO decoder files (draco_wasm_wrapper.js,
286
365
  * draco_decoder.wasm, draco_decoder.js) are fetched from. Embedding apps
@@ -311,4 +390,133 @@ declare function loadSharedGltf(url: string, load: () => Promise<GLTF>): Promise
311
390
  */
312
391
  declare function clearModelCache(url?: string): void;
313
392
 
314
- export { Behaviour, Component, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, HYDRATABLE_ENTITY_KINDS, type HydrateWorldFromSnapshotResult, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, World, WorldEntityView, clearModelCache, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, loadSharedGltf, resolveDracoDecoderPath, setDracoDecoderPath };
393
+ /**
394
+ * Collect the given roots plus every descendant, BFS parent-first, using the
395
+ * `ParentId` component edges. Parent-first ordering matters: serialization
396
+ * renumbers ids in this order and instantiation creates entities in file
397
+ * order, so parents always exist before their children are linked.
398
+ */
399
+ declare function collectEntitySubtree(world: World, rootIds: EntityId[]): EntityId[];
400
+
401
+ type InstantiateSubtreeResult = {
402
+ /** Live entity id of the subtree root, or null when nothing hydrated. */
403
+ rootId: EntityId | null;
404
+ /** Snapshot entity id → live entity id. */
405
+ idMap: Map<number, number>;
406
+ };
407
+ /**
408
+ * Hydrate a self-contained subtree snapshot (a prefab file's `snapshot`)
409
+ * into a LIVE world: fresh entity ids, internal references remapped, no
410
+ * camera promotion, transform pass scoped to the created entities.
411
+ */
412
+ declare function instantiateSubtree(world: World, objectManagementSystem: ObjectManagementSystem, snapshot: SubtreeSnapshot): InstantiateSubtreeResult;
413
+
414
+ /**
415
+ * Per-property prefab override model — pure JSON-space functions shared by
416
+ * the editor (diff/merge at apply time) and future `.scene` tooling.
417
+ *
418
+ * The core problem: an instance's entity ids differ from the prefab file's
419
+ * ids by construction, so raw values can't be compared. Both sides are first
420
+ * CANONICALIZED into nodeId-space: every entity-id-bearing field (kept in
421
+ * sync with `snapshotIdUtils.ts`) becomes `{ $node: "<nodeId>" }` when the id
422
+ * maps to a node inside the same document, or stays a raw id when external.
423
+ * Two canonical values are equal iff they describe the same state relative
424
+ * to their own subtree.
425
+ *
426
+ * Override encoding (stored in `PrefabInstance.overrides`):
427
+ * "<nodeId>|<ComponentName>|<slash/separated/path>"
428
+ * "<nodeId>|<ComponentName>|" // empty path = whole component overridden
429
+ */
430
+
431
+ /** Components that never participate in override diffing/merging. */
432
+ declare const OVERRIDE_DIFF_EXCLUDED_COMPONENTS: Set<string>;
433
+ /**
434
+ * Components excluded ONLY on the instance ROOT node — these are per-instance
435
+ * by definition (where the instance sits in the scene and what it's called).
436
+ */
437
+ declare const OVERRIDE_ROOT_EXCLUDED_COMPONENTS: Set<string>;
438
+ type NodeMaps = {
439
+ idToNode: Map<number, string>;
440
+ nodeToId: Map<string, number>;
441
+ /** nodeId of the subtree root (entity whose ParentId is null/absent). */
442
+ rootNodeId: string | null;
443
+ };
444
+ /** Entity ids of entities whose ParentId is null or absent. */
445
+ declare function findSnapshotRootEntityIds(snapshot: SubtreeSnapshot): number[];
446
+ declare function buildNodeMapsFromSnapshot(snapshot: SubtreeSnapshot): NodeMaps;
447
+ /** Invert the columnar snapshot into entityId → (componentName → value). */
448
+ declare function indexSnapshotByEntity(snapshot: SubtreeSnapshot): Map<number, Map<string, unknown>>;
449
+ /**
450
+ * Canonicalize a serialized component value into nodeId-space:
451
+ * - entity-id fields → `{$node}` (internal) or raw id (external)
452
+ * - ScriptComponent entries keep only `{className, scriptUrl, enabled, data}`
453
+ * (entityId/runtimeState/runtimeMessage are per-instance transients)
454
+ * - Object3DRef keeps only `{visibility}` (the rest is a live object ref)
455
+ *
456
+ * Keep the id-bearing field list in sync with `snapshotIdUtils.ts`.
457
+ */
458
+ declare function canonicalizeComponentValue(componentName: string, value: unknown, idToNode: Map<number, string>): unknown;
459
+ /**
460
+ * Replace every `{$node}` marker (at any depth) with the mapped entity id
461
+ * from `nodeToId`, or null when the node no longer exists. Exact inverse of
462
+ * canonicalization for the id-bearing positions.
463
+ */
464
+ declare function decanonicalizeComponentValue(value: unknown, nodeToId: Map<string, number>): unknown;
465
+ declare const encodeOverride: (nodeId: string, componentName: string, path: string) => string;
466
+ declare function parseOverride(encoded: string): {
467
+ nodeId: string;
468
+ componentName: string;
469
+ path: string;
470
+ } | null;
471
+ /** nodeId → componentName → set of overridden paths. */
472
+ declare function groupOverridePaths(overrides: string[]): Map<string, Map<string, Set<string>>>;
473
+ /**
474
+ * Collect leaf paths where two canonical values differ. Semantics:
475
+ * - `{$node}` refs compare atomically by nodeId
476
+ * - arrays of differing length are ONE atomic override (the array path);
477
+ * equal lengths recurse per index
478
+ * - object key present on one side only marks that key's path
479
+ * - type mismatches mark the current path
480
+ * An empty-string path means the values differ at the top level.
481
+ */
482
+ declare function collectDiffPaths(base: unknown, current: unknown, prefix?: string, out?: string[]): string[];
483
+ /**
484
+ * Diff a live instance subtree against its prefab base (both as serialized
485
+ * subtree snapshots carrying PrefabNode identity) and return the encoded
486
+ * override list: every path where the instance deviates from the base.
487
+ *
488
+ * v1 policies: components missing on the instance produce no override
489
+ * (apply re-adds them); components/nodes only on the instance are local
490
+ * additions and produce no override (apply never touches them).
491
+ */
492
+ declare function computeInstanceOverrides(baseSnapshot: SubtreeSnapshot, instanceSnapshot: SubtreeSnapshot): string[];
493
+ /**
494
+ * Merge a component's NEW canonical file value with an instance's canonical
495
+ * value, preserving the instance side at every overridden path. An empty
496
+ * path ("") means the whole component is overridden → instance wins.
497
+ */
498
+ declare function mergeComponentValue(newFileCanonical: unknown, instanceCanonical: unknown, overridePaths: Set<string> | undefined): unknown;
499
+
500
+ type SerializeEntitySubtreeResult = {
501
+ snapshot: SubtreeSnapshot;
502
+ /**
503
+ * References that pointed OUTSIDE the subtree and were nulled out
504
+ * (ids are LIVE world ids so callers can name the offending entities).
505
+ * The root's own external parent link is nulled silently — it is expected.
506
+ */
507
+ warnings: ExternalRefWarning[];
508
+ /** Component types stripped because they are scene singletons. */
509
+ strippedComponents: string[];
510
+ };
511
+ /**
512
+ * Serialize `rootId` + all descendants into a self-contained snapshot:
513
+ * entity ids renumbered 1..N in BFS parent-first order, all internal id
514
+ * references remapped, external references nulled + reported, root ParentId
515
+ * forced to null. The result is directly consumable by
516
+ * `hydrateWorldFromSnapshotDetailed` / `instantiateSubtree`.
517
+ */
518
+ declare function serializeEntitySubtree(world: World, rootId: EntityId, options?: {
519
+ maxDepth?: number;
520
+ }): SerializeEntitySubtreeResult;
521
+
522
+ export { Behaviour, Component, type ComponentValueMaps, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, EntityId, ExternalRefWarning, HYDRATABLE_ENTITY_KINDS, type HydrateOptions, type HydrateWorldFromSnapshotResult, type InstantiateSubtreeResult, type NodeMaps, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, type SerializeEntitySubtreeResult, SpawnPrefabOptions, SpawnPrefabSource, SubtreeSnapshot, World, WorldEntityView, buildComponentValueMaps, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearModelCache, collectDiffPaths, collectEntitySubtree, computeInstanceOverrides, decanonicalizeComponentValue, encodeOverride, findSnapshotRootEntityIds, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadSharedGltf, mergeComponentValue, parseOverride, resolveDracoDecoderPath, restoreComponentState, restorePostCreateComponents, serializeEntitySubtree, setDracoDecoderPath };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, m as ComponentClass, n as ParentLookup, o as EcsEntityKind, O as ObjectManagementSystem } from './System-BeuJ1xt5.js';
2
- export { A as AssetInput, p as CheckboxInput, q as ColorInput, r as ComponentFactory, s as ComponentInput, t as ComponentKind, u as DropdownInput, v as DropdownOption, w as EcsComponentFactoryKind, x as EcsEntityEditorKind, y as EntityId, z as EntityInput, F as FloatInput, I as InputSystem, B as IntersectionResult, K as KeyboardKey, G as KeyboardKeys, M as MouseButton, R as RenderSystem, S as SelectionListener, H as SliderInput, J as TextInput, L as ToggleInput, N as TransformSyncSystem, Q as Vec3, U as Vector2Input, X as Vector3Input } from './System-BeuJ1xt5.js';
1
+ import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, S as SpawnPrefabSource, m as SpawnPrefabOptions, n as ComponentClass, o as ParentLookup, p as EcsEntityKind, O as ObjectManagementSystem, q as EntityId, r as SubtreeSnapshot, s as ExternalRefWarning } from './System-BjwOBx81.js';
2
+ export { A as AssetInput, t as CheckboxInput, u as ColorInput, v as ComponentFactory, w as ComponentInput, x as ComponentKind, y as DropdownInput, z as DropdownOption, B as EcsComponentFactoryKind, F as EcsEntityEditorKind, G as EntityInput, H as FloatInput, I as InputSystem, J as IntersectionResult, K as KeyboardKey, L as KeyboardKeys, M as MouseButton, N as PREFAB_FILE_VERSION, Q as PrefabAsset, R as RemapSnapshotOptions, U as RenderSystem, X as SelectionListener, Y as SliderInput, Z as TextInput, _ as ToggleInput, $ as TransformSyncSystem, a0 as Vec3, a1 as Vector2Input, a2 as Vector3Input, a3 as clearPrefabCache, a4 as despawnPrefab, a5 as loadPrefab, a6 as parsePrefabAsset, a7 as remapSnapshotEntityIds, a8 as setPrefabAssetUrlResolver, a9 as spawnPrefab } from './System-BjwOBx81.js';
3
3
  import * as THREE from 'three';
4
- import { O as Object3DRef } from './Video-Cym2C52L.js';
5
- export { a2 as AnimationStateCallbacks, a3 as AnimationStateMachine, a4 as AnimationStateManager, a5 as StateMachine } from './Video-Cym2C52L.js';
6
- export { i as CoreComponents } from './index-BoJ3_6a3.js';
4
+ import { O as Object3DRef } from './Video-B9z5AtIf.js';
5
+ export { a3 as AnimationStateCallbacks, a4 as AnimationStateMachine, a5 as AnimationStateManager, a6 as StateMachine } from './Video-B9z5AtIf.js';
6
+ export { i as CoreComponents } from './index-BBI2YdCu.js';
7
7
  export { AnimationSystem, AudioSystem, CameraSyncSystem, EnvironmentSyncSystem, InstancedMeshSystem, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, ScriptBehaviourSystem, SelectionContext, VideoSystem } from './systems/index.js';
8
8
  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 './factories/index.js';
9
9
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
@@ -136,6 +136,31 @@ declare class Behaviour implements CustomEcsSystem {
136
136
  * @param world - The owning world at disposal time.
137
137
  */
138
138
  dispose?(world: World): void;
139
+ /**
140
+ * Instantiate a prefab asset into the world at runtime.
141
+ *
142
+ * `source` is typically an `AssetInput` field from this script's `data`
143
+ * (drag a `.prefab` from the asset browser onto the field in the editor),
144
+ * a URL string, or a pre-loaded `PrefabAsset`. Resolves with the new root
145
+ * entity id.
146
+ *
147
+ * ```ts
148
+ * data = { enemyPrefab: { path: "", type: "prefab" } };
149
+ * async onUpdate() {
150
+ * if (shouldSpawn) {
151
+ * const id = await this.spawnPrefab(this.data.enemyPrefab, {
152
+ * position: { x: 0, y: 0, z: -5 },
153
+ * });
154
+ * }
155
+ * }
156
+ * ```
157
+ */
158
+ spawnPrefab(source: SpawnPrefabSource, options?: SpawnPrefabOptions): Promise<number>;
159
+ /**
160
+ * Remove a spawned prefab instance (the root entity and all descendants).
161
+ * Returns the number of entities removed.
162
+ */
163
+ despawn(rootEntityId: number): number;
139
164
  /**
140
165
  * Returns the entity's world-space position as a new `THREE.Vector3`, or
141
166
  * `null` if the entity has no scene presence.
@@ -260,6 +285,32 @@ declare class Behaviour implements CustomEcsSystem {
260
285
  onTargetLost(target: WorldEntityView): void;
261
286
  }
262
287
 
288
+ type ComponentValueMaps = {
289
+ object3DRefValues: Map<number, unknown>;
290
+ nameValues: Map<number, unknown>;
291
+ transformValues: Map<number, unknown>;
292
+ modelValues: Map<number, unknown>;
293
+ imageValues: Map<number, unknown>;
294
+ spriteValues: Map<number, unknown>;
295
+ videoValues: Map<number, unknown>;
296
+ cameraValues: Map<number, unknown>;
297
+ environmentValues: Map<number, unknown>;
298
+ postprocessingValues: Map<number, unknown>;
299
+ audioValues: Map<number, unknown>;
300
+ imageTargetValues: Map<number, unknown>;
301
+ lightValues: Map<number, unknown>;
302
+ materialValues: Map<number, unknown>;
303
+ meshGeometryValues: Map<number, unknown>;
304
+ selectableValues: Map<number, unknown>;
305
+ physicsValues: Map<number, unknown>;
306
+ animationValues: Map<number, unknown>;
307
+ imageTargetAnchorValues: Map<number, unknown>;
308
+ scriptValues: Map<number, unknown>;
309
+ instancedMeshValues: Map<number, unknown>;
310
+ instanceSlotValues: Map<number, unknown>;
311
+ prefabNodeValues: Map<number, unknown>;
312
+ prefabInstanceValues: Map<number, unknown>;
313
+ };
263
314
  type EcsWorldComponentSnapshot = {
264
315
  component: string;
265
316
  entries: Array<{
@@ -275,12 +326,40 @@ type EcsWorldStateSnapshotLike = {
275
326
  type HydrateWorldFromSnapshotResult = {
276
327
  restoredCount: number;
277
328
  selectedEntityId: number | null;
329
+ /** Snapshot entity id → created live entity id for every hydrated entity. */
330
+ idMap: Map<number, number>;
331
+ };
332
+ /**
333
+ * Optional behavior tweaks for {@link hydrateWorldFromSnapshotDetailed}.
334
+ * Defaults preserve the historical full-world-load behavior; prefab/subtree
335
+ * instantiation passes stricter options.
336
+ */
337
+ type HydrateOptions = {
338
+ /**
339
+ * When false, no camera in the snapshot is promoted to the world camera.
340
+ * Defaults to true (full scene loads want their default camera active);
341
+ * prefab spawns pass false so a spawned camera never hijacks the view.
342
+ */
343
+ assignPrimaryCamera?: boolean;
344
+ /**
345
+ * "world" (default) re-applies local transforms for every entity in the
346
+ * world after parent links restore — correct for full scene loads.
347
+ * "created" limits the pass to entities created by THIS hydrate call, so
348
+ * mid-session spawns don't touch unrelated live entities.
349
+ */
350
+ applyTransformsScope?: "world" | "created";
278
351
  };
279
352
  declare const HYDRATABLE_ENTITY_KINDS: Set<EcsEntityKind>;
280
353
 
281
- declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): HydrateWorldFromSnapshotResult;
354
+ declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem, options?: HydrateOptions): HydrateWorldFromSnapshotResult;
282
355
  declare function hydrateWorldFromSnapshot(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): number;
283
356
 
357
+ declare function buildComponentValueMaps(snapshot: EcsWorldStateSnapshotLike): ComponentValueMaps;
358
+
359
+ declare function restoreComponentState(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps): void;
360
+
361
+ declare function restorePostCreateComponents(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps, idMap: Map<number, number>): void;
362
+
284
363
  /**
285
364
  * Override where the DRACO decoder files (draco_wasm_wrapper.js,
286
365
  * draco_decoder.wasm, draco_decoder.js) are fetched from. Embedding apps
@@ -311,4 +390,133 @@ declare function loadSharedGltf(url: string, load: () => Promise<GLTF>): Promise
311
390
  */
312
391
  declare function clearModelCache(url?: string): void;
313
392
 
314
- export { Behaviour, Component, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, HYDRATABLE_ENTITY_KINDS, type HydrateWorldFromSnapshotResult, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, World, WorldEntityView, clearModelCache, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, loadSharedGltf, resolveDracoDecoderPath, setDracoDecoderPath };
393
+ /**
394
+ * Collect the given roots plus every descendant, BFS parent-first, using the
395
+ * `ParentId` component edges. Parent-first ordering matters: serialization
396
+ * renumbers ids in this order and instantiation creates entities in file
397
+ * order, so parents always exist before their children are linked.
398
+ */
399
+ declare function collectEntitySubtree(world: World, rootIds: EntityId[]): EntityId[];
400
+
401
+ type InstantiateSubtreeResult = {
402
+ /** Live entity id of the subtree root, or null when nothing hydrated. */
403
+ rootId: EntityId | null;
404
+ /** Snapshot entity id → live entity id. */
405
+ idMap: Map<number, number>;
406
+ };
407
+ /**
408
+ * Hydrate a self-contained subtree snapshot (a prefab file's `snapshot`)
409
+ * into a LIVE world: fresh entity ids, internal references remapped, no
410
+ * camera promotion, transform pass scoped to the created entities.
411
+ */
412
+ declare function instantiateSubtree(world: World, objectManagementSystem: ObjectManagementSystem, snapshot: SubtreeSnapshot): InstantiateSubtreeResult;
413
+
414
+ /**
415
+ * Per-property prefab override model — pure JSON-space functions shared by
416
+ * the editor (diff/merge at apply time) and future `.scene` tooling.
417
+ *
418
+ * The core problem: an instance's entity ids differ from the prefab file's
419
+ * ids by construction, so raw values can't be compared. Both sides are first
420
+ * CANONICALIZED into nodeId-space: every entity-id-bearing field (kept in
421
+ * sync with `snapshotIdUtils.ts`) becomes `{ $node: "<nodeId>" }` when the id
422
+ * maps to a node inside the same document, or stays a raw id when external.
423
+ * Two canonical values are equal iff they describe the same state relative
424
+ * to their own subtree.
425
+ *
426
+ * Override encoding (stored in `PrefabInstance.overrides`):
427
+ * "<nodeId>|<ComponentName>|<slash/separated/path>"
428
+ * "<nodeId>|<ComponentName>|" // empty path = whole component overridden
429
+ */
430
+
431
+ /** Components that never participate in override diffing/merging. */
432
+ declare const OVERRIDE_DIFF_EXCLUDED_COMPONENTS: Set<string>;
433
+ /**
434
+ * Components excluded ONLY on the instance ROOT node — these are per-instance
435
+ * by definition (where the instance sits in the scene and what it's called).
436
+ */
437
+ declare const OVERRIDE_ROOT_EXCLUDED_COMPONENTS: Set<string>;
438
+ type NodeMaps = {
439
+ idToNode: Map<number, string>;
440
+ nodeToId: Map<string, number>;
441
+ /** nodeId of the subtree root (entity whose ParentId is null/absent). */
442
+ rootNodeId: string | null;
443
+ };
444
+ /** Entity ids of entities whose ParentId is null or absent. */
445
+ declare function findSnapshotRootEntityIds(snapshot: SubtreeSnapshot): number[];
446
+ declare function buildNodeMapsFromSnapshot(snapshot: SubtreeSnapshot): NodeMaps;
447
+ /** Invert the columnar snapshot into entityId → (componentName → value). */
448
+ declare function indexSnapshotByEntity(snapshot: SubtreeSnapshot): Map<number, Map<string, unknown>>;
449
+ /**
450
+ * Canonicalize a serialized component value into nodeId-space:
451
+ * - entity-id fields → `{$node}` (internal) or raw id (external)
452
+ * - ScriptComponent entries keep only `{className, scriptUrl, enabled, data}`
453
+ * (entityId/runtimeState/runtimeMessage are per-instance transients)
454
+ * - Object3DRef keeps only `{visibility}` (the rest is a live object ref)
455
+ *
456
+ * Keep the id-bearing field list in sync with `snapshotIdUtils.ts`.
457
+ */
458
+ declare function canonicalizeComponentValue(componentName: string, value: unknown, idToNode: Map<number, string>): unknown;
459
+ /**
460
+ * Replace every `{$node}` marker (at any depth) with the mapped entity id
461
+ * from `nodeToId`, or null when the node no longer exists. Exact inverse of
462
+ * canonicalization for the id-bearing positions.
463
+ */
464
+ declare function decanonicalizeComponentValue(value: unknown, nodeToId: Map<string, number>): unknown;
465
+ declare const encodeOverride: (nodeId: string, componentName: string, path: string) => string;
466
+ declare function parseOverride(encoded: string): {
467
+ nodeId: string;
468
+ componentName: string;
469
+ path: string;
470
+ } | null;
471
+ /** nodeId → componentName → set of overridden paths. */
472
+ declare function groupOverridePaths(overrides: string[]): Map<string, Map<string, Set<string>>>;
473
+ /**
474
+ * Collect leaf paths where two canonical values differ. Semantics:
475
+ * - `{$node}` refs compare atomically by nodeId
476
+ * - arrays of differing length are ONE atomic override (the array path);
477
+ * equal lengths recurse per index
478
+ * - object key present on one side only marks that key's path
479
+ * - type mismatches mark the current path
480
+ * An empty-string path means the values differ at the top level.
481
+ */
482
+ declare function collectDiffPaths(base: unknown, current: unknown, prefix?: string, out?: string[]): string[];
483
+ /**
484
+ * Diff a live instance subtree against its prefab base (both as serialized
485
+ * subtree snapshots carrying PrefabNode identity) and return the encoded
486
+ * override list: every path where the instance deviates from the base.
487
+ *
488
+ * v1 policies: components missing on the instance produce no override
489
+ * (apply re-adds them); components/nodes only on the instance are local
490
+ * additions and produce no override (apply never touches them).
491
+ */
492
+ declare function computeInstanceOverrides(baseSnapshot: SubtreeSnapshot, instanceSnapshot: SubtreeSnapshot): string[];
493
+ /**
494
+ * Merge a component's NEW canonical file value with an instance's canonical
495
+ * value, preserving the instance side at every overridden path. An empty
496
+ * path ("") means the whole component is overridden → instance wins.
497
+ */
498
+ declare function mergeComponentValue(newFileCanonical: unknown, instanceCanonical: unknown, overridePaths: Set<string> | undefined): unknown;
499
+
500
+ type SerializeEntitySubtreeResult = {
501
+ snapshot: SubtreeSnapshot;
502
+ /**
503
+ * References that pointed OUTSIDE the subtree and were nulled out
504
+ * (ids are LIVE world ids so callers can name the offending entities).
505
+ * The root's own external parent link is nulled silently — it is expected.
506
+ */
507
+ warnings: ExternalRefWarning[];
508
+ /** Component types stripped because they are scene singletons. */
509
+ strippedComponents: string[];
510
+ };
511
+ /**
512
+ * Serialize `rootId` + all descendants into a self-contained snapshot:
513
+ * entity ids renumbered 1..N in BFS parent-first order, all internal id
514
+ * references remapped, external references nulled + reported, root ParentId
515
+ * forced to null. The result is directly consumable by
516
+ * `hydrateWorldFromSnapshotDetailed` / `instantiateSubtree`.
517
+ */
518
+ declare function serializeEntitySubtree(world: World, rootId: EntityId, options?: {
519
+ maxDepth?: number;
520
+ }): SerializeEntitySubtreeResult;
521
+
522
+ export { Behaviour, Component, type ComponentValueMaps, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, EntityId, ExternalRefWarning, HYDRATABLE_ENTITY_KINDS, type HydrateOptions, type HydrateWorldFromSnapshotResult, type InstantiateSubtreeResult, type NodeMaps, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, type SerializeEntitySubtreeResult, SpawnPrefabOptions, SpawnPrefabSource, SubtreeSnapshot, World, WorldEntityView, buildComponentValueMaps, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearModelCache, collectDiffPaths, collectEntitySubtree, computeInstanceOverrides, decanonicalizeComponentValue, encodeOverride, findSnapshotRootEntityIds, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadSharedGltf, mergeComponentValue, parseOverride, resolveDracoDecoderPath, restoreComponentState, restorePostCreateComponents, serializeEntitySubtree, setDracoDecoderPath };