@zylem/game-lib 0.7.0 → 0.8.0

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 (95) hide show
  1. package/README.md +15 -1
  2. package/dist/actions.d.ts +71 -8
  3. package/dist/actions.js +1 -1
  4. package/dist/api/game-lib.api.json +54074 -0
  5. package/dist/api/game-lib.api.md +4544 -0
  6. package/dist/api/game-lib.d.ts +8258 -0
  7. package/dist/api/game-lib.typedoc.json +345421 -0
  8. package/dist/audio.js +1 -1
  9. package/dist/{base-node-life-cycle-CnJ-7zX-.d.ts → base-node-life-cycle-D2NuN1VB.d.ts} +12 -4
  10. package/dist/behavior.d.ts +2 -3
  11. package/dist/behavior.js +1 -1
  12. package/dist/blueprints-TbGY-h53.d.ts +162 -0
  13. package/dist/chunk-7FR5JSQ2.js +1 -0
  14. package/dist/chunk-7GYFZKK7.js +1 -0
  15. package/dist/chunk-7WRQ2UAN.js +1 -0
  16. package/dist/chunk-BH53MBAZ.js +1 -0
  17. package/dist/chunk-BIGH6D34.js +0 -0
  18. package/dist/chunk-CM5YRNBJ.js +19 -0
  19. package/dist/chunk-COM6HJ2L.js +1 -0
  20. package/dist/chunk-D2PATZCC.js +1 -0
  21. package/dist/chunk-DFLI7ICU.js +0 -0
  22. package/dist/chunk-E3UBSUPX.js +1 -0
  23. package/dist/chunk-FKIKN7RP.js +24 -0
  24. package/dist/chunk-G4HONLWC.js +1 -0
  25. package/dist/chunk-IKWE2W6L.js +1 -0
  26. package/dist/chunk-IPWUDOV5.js +1 -0
  27. package/dist/chunk-JEHFHUH4.js +0 -0
  28. package/dist/chunk-JNKPTL77.js +1 -0
  29. package/dist/chunk-JQKS42G4.js +1 -0
  30. package/dist/chunk-M3XNO56P.js +1 -0
  31. package/dist/chunk-ORIDWL3T.js +0 -0
  32. package/dist/chunk-QB3NL7VQ.js +1 -0
  33. package/dist/chunk-TAUWDQZF.js +9 -0
  34. package/dist/chunk-VS2D4B3W.js +1 -0
  35. package/dist/chunk-WQ3WMMZD.js +1 -0
  36. package/dist/chunk-XK63E4SX.js +1 -0
  37. package/dist/chunk-XNDS4YFR.js +1 -0
  38. package/dist/chunk-XNHVRFAK.js +1 -0
  39. package/dist/chunk-ZRT3ZQVH.js +1 -0
  40. package/dist/collision-builder-jF-toPIl.d.ts +38 -0
  41. package/dist/core.d.ts +45 -30
  42. package/dist/core.js +1 -24
  43. package/dist/debug-state-BPT6jEog.d.ts +17 -0
  44. package/dist/debug.d.ts +71 -19
  45. package/dist/debug.js +1 -1
  46. package/dist/{default-controls-BGc61yYl.d.ts → default-controls-0-vCnli7.d.ts} +3 -3
  47. package/dist/{entity-DNkYKfdp.d.ts → entity-BdSI8CL3.d.ts} +63 -444
  48. package/dist/entity-DZbFQ1Wg.d.ts +28 -0
  49. package/dist/{entity-type-map-C94h2TDW.d.ts → entity-type-map-Bd69SpAS.d.ts} +153 -6
  50. package/dist/entity.d.ts +11 -8
  51. package/dist/entity.js +1 -1
  52. package/dist/events.d.ts +10 -1
  53. package/dist/events.js +1 -1
  54. package/dist/{game-Cuj5gy7U.d.ts → game-C1FHVqXl.d.ts} +429 -133
  55. package/dist/game-default-QHROHW2O.js +1 -0
  56. package/dist/{game-interfaces-tfpM5NBk.d.ts → game-interfaces-mchNYSZE.d.ts} +2 -2
  57. package/dist/globals.d.ts +12 -1
  58. package/dist/globals.js +1 -1
  59. package/dist/graphics.d.ts +16 -46
  60. package/dist/graphics.js +1 -1
  61. package/dist/input-ui.d.ts +5 -4
  62. package/dist/input-ui.js +1 -1
  63. package/dist/input.d.ts +4 -3
  64. package/dist/input.js +1 -1
  65. package/dist/{material-Wz83vTTp.d.ts → material-9vJ6SZaI.d.ts} +25 -50
  66. package/dist/public.d.ts +38 -0
  67. package/dist/public.js +1 -0
  68. package/dist/runtime.d.ts +7 -381
  69. package/dist/runtime.js +1 -1
  70. package/dist/schema/entity.schema.json +244 -0
  71. package/dist/schema/game-config.schema.json +625 -0
  72. package/dist/schema/input-config.schema.json +499 -0
  73. package/dist/schema/stage-config.schema.json +93 -0
  74. package/dist/schema/stage.schema.json +271 -0
  75. package/dist/schema.d.ts +538 -0
  76. package/dist/schema.js +1 -0
  77. package/dist/stage-transition-CmGpV4tc.d.ts +46 -0
  78. package/dist/vector-CiSHbivc.d.ts +133 -0
  79. package/dist/web-components.d.ts +15 -12
  80. package/dist/web-components.js +1 -9
  81. package/dist/{zylem-stage-runtime-Cs-UDEVU.d.ts → zylem-camera-C3bn6BTI.d.ts} +62 -264
  82. package/package.json +28 -20
  83. package/dist/chunk-73VZQZUL.js +0 -1
  84. package/dist/chunk-A34ZG3L4.js +0 -1
  85. package/dist/chunk-CDPY4VOQ.js +0 -1
  86. package/dist/chunk-DR6XXZE7.js +0 -19
  87. package/dist/chunk-FM5TBEPO.js +0 -1
  88. package/dist/chunk-G2IIMSUH.js +0 -1
  89. package/dist/chunk-NIH5CONO.js +0 -1
  90. package/dist/chunk-ONWXGBWB.js +0 -1
  91. package/dist/chunk-QEDQDR27.js +0 -1
  92. package/dist/chunk-WKHW2QO2.js +0 -1
  93. package/dist/chunk-YHKXQ2ZN.js +0 -1
  94. package/dist/game-default-PZLLHYL7.js +0 -1
  95. package/dist/world-C9zdyl5d.d.ts +0 -103
@@ -1,9 +1,98 @@
1
- import { Sprite, Color, Object3D, ColorRepresentation, Light, Fog, FogExp2, Scene } from 'three';
2
- import { G as GameEntity, I as GameEntityOptions, M as BaseNode } from './entity-DNkYKfdp.js';
3
- import { a as Vec3Input, b as Vec2Input, T as TexturePath, M as MaterialOptions } from './material-Wz83vTTp.js';
4
- import { S as SetupContext, f as UpdateContext, D as DestroyContext, C as CleanupContext } from './base-node-life-cycle-CnJ-7zX-.js';
5
- import { C as CollisionHandlerDelegate } from './world-C9zdyl5d.js';
1
+ import { Vector3, Sprite, Color, Object3D, ColorRepresentation, Light, Fog, FogExp2, Scene, Raycaster } from 'three';
2
+ import { G as GameEntity, a as GameEntityOptions, B as BaseNode } from './entity-BdSI8CL3.js';
3
+ import { d as Vec3Components, e as Vec3Input, b as Vec2Input } from './vector-CiSHbivc.js';
4
+ import { U as UpdateContext, a as SetupContext, D as DestroyContext, l as CleanupContext } from './base-node-life-cycle-D2NuN1VB.js';
5
+ import { T as TexturePath, e as MaterialOptions } from './material-9vJ6SZaI.js';
6
+ import { Simulation } from '@zylem/behaviors/core';
7
+ import { E as Entity } from './entity-DZbFQ1Wg.js';
6
8
  import { ParticleEmitterBehaviorOptions, ParticleEffectDefinition, ParticleEmitterHandle } from '@zylem/behaviors/particle-emitter';
9
+ import { Line2 } from 'three/addons/lines/webgpu/Line2.js';
10
+
11
+ /**
12
+ * Interface for entities that handle collision events.
13
+ */
14
+ interface CollisionHandlerDelegate {
15
+ handlePostCollision(params: any): boolean;
16
+ handleIntersectionEvent(params: any): void;
17
+ }
18
+ /**
19
+ * Physics world wrapper.
20
+ *
21
+ * Owns a `@zylem/behaviors` {@link Simulation} (wasm ECS + physics) and
22
+ * translates its handle-based API into game-lib's uuid/entity world model:
23
+ * spawning entities from their body/collider definitions, tracking live
24
+ * collision pairs from simulation events, and dispatching game collision
25
+ * callbacks each frame.
26
+ */
27
+ declare class ZylemWorld implements Entity<ZylemWorld> {
28
+ type: string;
29
+ readonly simulation: Simulation;
30
+ collisionMap: Map<string, GameEntity<any>>;
31
+ collisionBehaviorMap: Map<string, GameEntity<any>>;
32
+ _removalMap: Map<string, GameEntity<any>>;
33
+ private activeCollisionPairs;
34
+ private livePairs;
35
+ private handleIdToUuid;
36
+ private currentCollisionTimeMs;
37
+ private readonly zeroGravity;
38
+ /** Fixed timestep in seconds used for each physics step. */
39
+ readonly fixedTimestep: number;
40
+ /**
41
+ * Interpolation alpha (0..1) representing the fraction of an unprocessed
42
+ * timestep remaining after the last physics step. Used to interpolate
43
+ * rendering transforms between the previous and current physics state.
44
+ */
45
+ interpolationAlpha: number;
46
+ /** Shared step counter handed to every {@link SimulationBody}. */
47
+ private readonly stepClock;
48
+ /**
49
+ * Create the wasm-backed physics world for a stage.
50
+ * @param gravity World gravity.
51
+ * @param physicsRate Physics update rate in Hz (default 60).
52
+ */
53
+ static create(gravity: Vector3 | Vec3Components, physicsRate?: number): Promise<ZylemWorld>;
54
+ constructor(simulation: Simulation, physicsRate?: number, zeroGravity?: boolean);
55
+ addEntity(entity: any): void;
56
+ setForRemoval(entity: any): void;
57
+ destroyEntity(entity: GameEntity<any>): void;
58
+ setup(): void;
59
+ /**
60
+ * Advance the physics simulation. The fixed-timestep accumulator lives
61
+ * inside the Simulation; this method translates its events into game
62
+ * collision dispatch.
63
+ */
64
+ update(params: UpdateContext<any>): void;
65
+ private hasCollisionPhaseListeners;
66
+ private applyCollisionEvents;
67
+ private snapshotLivePairs;
68
+ updatePostCollisionBehaviors(delta: number): void;
69
+ private processPendingRemovals;
70
+ private removeEntityFromTracking;
71
+ private pruneActiveCollisionPairs;
72
+ private entityHasCollisionPhaseListener;
73
+ private processCollisionPairs;
74
+ private dispatchCollisionPhase;
75
+ private dispatchIntersectionDelegates;
76
+ /**
77
+ * Physics raycast resolved to game entities. Used by debug tooling
78
+ * (hover/select/delete picking).
79
+ */
80
+ raycast(origin: {
81
+ x: number;
82
+ y: number;
83
+ z: number;
84
+ }, direction: {
85
+ x: number;
86
+ y: number;
87
+ z: number;
88
+ }, maxDistance: number): {
89
+ uuid: string | null;
90
+ distance: number;
91
+ normal: [number, number, number];
92
+ } | null;
93
+ destroy(): void;
94
+ private clearEntityPhysicsState;
95
+ }
7
96
 
8
97
  type SpriteImage = {
9
98
  name: string;
@@ -348,6 +437,12 @@ declare class ZylemActor extends GameEntity<ZylemActorOptions> implements Entity
348
437
  private getCollisionSourceSelection;
349
438
  private disposeRuntimeState;
350
439
  private loadModelsDeferred;
440
+ /**
441
+ * Shift the visible model so its feet sit at the group origin (y = 0).
442
+ * The physics body / render slot stay at the feet anchor; only `_object`
443
+ * is offset so Mixamo-style hip calibration does not float the mesh.
444
+ */
445
+ private alignVisualModelToGround;
351
446
  private applyMaterialOverrides;
352
447
  /**
353
448
  * Produce a cloned material with the requested color/opacity applied.
@@ -750,6 +845,57 @@ declare class ZylemFog extends GameEntity<ZylemFogGameOptions> {
750
845
  */
751
846
  declare function createFog(options?: ZylemFogOptions): ZylemFog;
752
847
 
848
+ interface LinePickResult {
849
+ point: Vector3;
850
+ pointOnLine: Vector3;
851
+ faceIndex: number;
852
+ distance: number;
853
+ }
854
+ type ZylemLineOptions = GameEntityOptions & {
855
+ /** Polyline vertices in world space (minimum 2). */
856
+ points: Vec3Input[];
857
+ /** Optional per-vertex colors (enables `vertexColors` on the material). */
858
+ colors?: ColorRepresentation[];
859
+ linewidth?: number;
860
+ worldUnits?: boolean;
861
+ alphaToCoverage?: boolean;
862
+ opacity?: number;
863
+ transparent?: boolean;
864
+ dashed?: boolean;
865
+ dashSize?: number;
866
+ gapSize?: number;
867
+ /** Default Raycaster threshold for {@link pickFromRaycaster}. */
868
+ pickThreshold?: number;
869
+ };
870
+ declare const LINE_TYPE: unique symbol;
871
+ /**
872
+ * Raycast against a {@link ZylemLine} using Three.js `Line2` picking rules.
873
+ */
874
+ declare function pickZylemLine(raycaster: Raycaster, line: ZylemLine, options?: {
875
+ threshold?: number;
876
+ }): LinePickResult | null;
877
+ declare class ZylemLine extends GameEntity<ZylemLineOptions> {
878
+ static type: symbol;
879
+ private _line;
880
+ private _geometry;
881
+ private _material;
882
+ constructor(options?: Partial<ZylemLineOptions>);
883
+ create(): this;
884
+ /** Replace the polyline vertices at runtime. */
885
+ setPoints(points: Vec3Input[], colors?: ColorRepresentation[]): this;
886
+ getLineObject(): Line2 | null;
887
+ pickFromRaycaster(raycaster: Raycaster, options?: {
888
+ threshold?: number;
889
+ }): LinePickResult | null;
890
+ buildInfo(): Record<string, any>;
891
+ private rebuildLine;
892
+ private applyGroupPosition;
893
+ protected _cleanup(_params: CleanupContext<this>): void;
894
+ private disposeLineResources;
895
+ }
896
+ type LineOptions = BaseNode | Partial<ZylemLineOptions>;
897
+ declare function createLine(...args: Array<LineOptions>): ZylemLine;
898
+
753
899
  /**
754
900
  * Maps entity type symbols to their class types.
755
901
  * Used by getEntityByName to infer return types.
@@ -771,6 +917,7 @@ interface EntityTypeMap {
771
917
  [PARTICLE_SYSTEM_TYPE]: ZylemParticleSystem;
772
918
  [LIGHT_TYPE]: ZylemLight;
773
919
  [FOG_TYPE]: ZylemFog;
920
+ [LINE_TYPE]: ZylemLine;
774
921
  }
775
922
  /**
776
923
  * Type helper: if T is a known type symbol, return the mapped entity type.
@@ -778,4 +925,4 @@ interface EntityTypeMap {
778
925
  */
779
926
  type EntityForType<T> = T extends keyof EntityTypeMap ? EntityTypeMap[T] : BaseNode;
780
927
 
781
- export { type AmbientLightOptions as $, ACTOR_TYPE as A, BOX_TYPE as B, type CollisionShapeType as C, DISK_TYPE as D, createPyramid as E, ZylemPyramid as F, PYRAMID_TYPE as G, createCylinder as H, ZylemCylinder as I, CYLINDER_TYPE as J, createPill as K, ZylemPill as L, PILL_TYPE as M, createParticleSystem as N, type OnHeldParams as O, PLANE_TYPE as P, ZylemParticleSystem as Q, RECT_TYPE as R, SPHERE_TYPE as S, TEXT_TYPE as T, PARTICLE_SYSTEM_TYPE as U, type ZylemParticleSystemOptions as V, createLight as W, ZylemLight as X, LIGHT_TYPE as Y, ZylemBox as Z, type ZylemLightOptions as _, createSphere as a, type HemisphereLightOptions as a0, type DirectionalLightOptions as a1, type PointLightOptions as a2, type SpotLightOptions as a3, type LightShadowOptions as a4, createFog as a5, ZylemFog as a6, FOG_TYPE as a7, type ZylemFogOptions as a8, type ZylemFogType as a9, type ZylemFogHeightOptions as aa, type ZylemFogNoiseOptions as ab, type EntityTypeMap as ac, type EntityForType as ad, ZylemSphere as b, createBox as c, createSprite as d, ZylemSprite as e, SPRITE_TYPE as f, type SpriteImage as g, type SpriteAnimation as h, createPlane as i, ZylemPlane as j, createZone as k, ZylemZone as l, ZONE_TYPE as m, type OnEnterParams as n, type OnExitParams as o, createActor as p, ZylemActor as q, createText as r, ZylemText as s, createRect as t, ZylemRect as u, createDisk as v, ZylemDisk as w, createCone as x, ZylemCone as y, CONE_TYPE as z };
928
+ export { type AmbientLightOptions as $, ACTOR_TYPE as A, BOX_TYPE as B, type CollisionShapeType as C, DISK_TYPE as D, createPyramid as E, ZylemPyramid as F, PYRAMID_TYPE as G, createCylinder as H, ZylemCylinder as I, CYLINDER_TYPE as J, createPill as K, ZylemPill as L, PILL_TYPE as M, createParticleSystem as N, type OnHeldParams as O, PLANE_TYPE as P, ZylemParticleSystem as Q, RECT_TYPE as R, SPHERE_TYPE as S, TEXT_TYPE as T, PARTICLE_SYSTEM_TYPE as U, type ZylemParticleSystemOptions as V, createLight as W, ZylemLight as X, LIGHT_TYPE as Y, ZylemBox as Z, type ZylemLightOptions as _, createSphere as a, type HemisphereLightOptions as a0, type DirectionalLightOptions as a1, type PointLightOptions as a2, type SpotLightOptions as a3, type LightShadowOptions as a4, createFog as a5, ZylemFog as a6, FOG_TYPE as a7, createLine as a8, ZylemLine as a9, LINE_TYPE as aa, pickZylemLine as ab, type ZylemLineOptions as ac, type LinePickResult as ad, type ZylemFogOptions as ae, type ZylemFogType as af, type ZylemFogHeightOptions as ag, type ZylemFogNoiseOptions as ah, type EntityTypeMap as ai, type EntityForType as aj, ZylemWorld as ak, ZylemSphere as b, createBox as c, createSprite as d, ZylemSprite as e, SPRITE_TYPE as f, type SpriteImage as g, type SpriteAnimation as h, createPlane as i, ZylemPlane as j, createZone as k, ZylemZone as l, ZONE_TYPE as m, type OnEnterParams as n, type OnExitParams as o, createActor as p, ZylemActor as q, createText as r, ZylemText as s, createRect as t, ZylemRect as u, createDisk as v, ZylemDisk as w, createCone as x, ZylemCone as y, CONE_TYPE as z };
package/dist/entity.d.ts CHANGED
@@ -1,15 +1,18 @@
1
- export { A as ACTOR_TYPE, $ as AmbientLightOptions, B as BOX_TYPE, z as CONE_TYPE, J as CYLINDER_TYPE, C as CollisionShapeType, D as DISK_TYPE, a1 as DirectionalLightOptions, ad as EntityForType, ac as EntityTypeMap, a7 as FOG_TYPE, a0 as HemisphereLightOptions, Y as LIGHT_TYPE, a4 as LightShadowOptions, n as OnEnterParams, o as OnExitParams, O as OnHeldParams, U as PARTICLE_SYSTEM_TYPE, M as PILL_TYPE, P as PLANE_TYPE, G as PYRAMID_TYPE, a2 as PointLightOptions, R as RECT_TYPE, S as SPHERE_TYPE, f as SPRITE_TYPE, a3 as SpotLightOptions, h as SpriteAnimation, g as SpriteImage, T as TEXT_TYPE, m as ZONE_TYPE, q as ZylemActor, Z as ZylemBox, y as ZylemCone, I as ZylemCylinder, w as ZylemDisk, a6 as ZylemFog, aa as ZylemFogHeightOptions, ab as ZylemFogNoiseOptions, a8 as ZylemFogOptions, a9 as ZylemFogType, X as ZylemLight, _ as ZylemLightOptions, Q as ZylemParticleSystem, V as ZylemParticleSystemOptions, L as ZylemPill, j as ZylemPlane, F as ZylemPyramid, u as ZylemRect, b as ZylemSphere, e as ZylemSprite, s as ZylemText, l as ZylemZone, p as createActor, c as createBox, x as createCone, H as createCylinder, v as createDisk, a5 as createFog, W as createLight, N as createParticleSystem, K as createPill, i as createPlane, E as createPyramid, t as createRect, a as createSphere, d as createSprite, r as createText, k as createZone } from './entity-type-map-C94h2TDW.js';
2
- import { G as GameEntity, I as GameEntityOptions, J as EntityBuilder, K as EntityMeshBuilder, L as EntityCollisionBuilder, M as BaseNode } from './entity-DNkYKfdp.js';
3
- export { Y as CollisionComponent, O as boxCollision, Q as coneCollision, N as create, T as cylinderCollision, U as pillCollision, V as planeCollision, R as pyramidCollision, P as sphereCollision, X as zoneCollision } from './entity-DNkYKfdp.js';
1
+ export { A as ACTOR_TYPE, $ as AmbientLightOptions, B as BOX_TYPE, z as CONE_TYPE, J as CYLINDER_TYPE, C as CollisionShapeType, D as DISK_TYPE, a1 as DirectionalLightOptions, aj as EntityForType, ai as EntityTypeMap, a7 as FOG_TYPE, a0 as HemisphereLightOptions, Y as LIGHT_TYPE, aa as LINE_TYPE, a4 as LightShadowOptions, ad as LinePickResult, n as OnEnterParams, o as OnExitParams, O as OnHeldParams, U as PARTICLE_SYSTEM_TYPE, M as PILL_TYPE, P as PLANE_TYPE, G as PYRAMID_TYPE, a2 as PointLightOptions, R as RECT_TYPE, S as SPHERE_TYPE, f as SPRITE_TYPE, a3 as SpotLightOptions, h as SpriteAnimation, g as SpriteImage, T as TEXT_TYPE, m as ZONE_TYPE, q as ZylemActor, Z as ZylemBox, y as ZylemCone, I as ZylemCylinder, w as ZylemDisk, a6 as ZylemFog, ag as ZylemFogHeightOptions, ah as ZylemFogNoiseOptions, ae as ZylemFogOptions, af as ZylemFogType, X as ZylemLight, _ as ZylemLightOptions, a9 as ZylemLine, ac as ZylemLineOptions, Q as ZylemParticleSystem, V as ZylemParticleSystemOptions, L as ZylemPill, j as ZylemPlane, F as ZylemPyramid, u as ZylemRect, b as ZylemSphere, e as ZylemSprite, s as ZylemText, l as ZylemZone, p as createActor, c as createBox, x as createCone, H as createCylinder, v as createDisk, a5 as createFog, W as createLight, a8 as createLine, N as createParticleSystem, K as createPill, i as createPlane, E as createPyramid, t as createRect, a as createSphere, d as createSprite, r as createText, k as createZone, ab as pickZylemLine } from './entity-type-map-Bd69SpAS.js';
2
+ import { G as GameEntity, a as GameEntityOptions, E as EntityBuilder, D as EntityMeshBuilder, F as EntityCollisionBuilder, B as BaseNode } from './entity-BdSI8CL3.js';
3
+ export { C as CollisionComponent, b as boxCollision, d as coneCollision, c as create, e as cylinderCollision, f as pillCollision, g as planeCollision, p as pyramidCollision, s as sphereCollision, z as zoneCollision } from './entity-BdSI8CL3.js';
4
4
  import { Color, Mesh } from 'three';
5
- import { b as Vec2Input, a as Vec3Input, M as MaterialOptions } from './material-Wz83vTTp.js';
6
- import './base-node-life-cycle-CnJ-7zX-.js';
7
- import './world-C9zdyl5d.js';
8
- import '@dimforge/rapier3d-compat';
5
+ import { b as Vec2Input, e as Vec3Input } from './vector-CiSHbivc.js';
6
+ import { e as MaterialOptions } from './material-9vJ6SZaI.js';
7
+ import './base-node-life-cycle-D2NuN1VB.js';
8
+ import './stage-transition-CmGpV4tc.js';
9
+ import '@zylem/behaviors/core';
10
+ import './entity-DZbFQ1Wg.js';
9
11
  import '@zylem/behaviors/particle-emitter';
12
+ import 'three/addons/lines/webgpu/Line2.js';
13
+ import './collision-builder-jF-toPIl.js';
10
14
  import './events.js';
11
15
  import 'mitt';
12
- import '@zylem/behaviors/core';
13
16
  import 'three/webgpu';
14
17
 
15
18
  interface CreateGameEntityOptions<T extends GameEntity<any>, CreateOptions extends GameEntityOptions> {
package/dist/entity.js CHANGED
@@ -1 +1 @@
1
- import{a as P,b as Ve,c as Ye,d as Ne,e as We,f as Xe,g as Ue,i as je}from"./chunk-NIH5CONO.js";import{a as It,b as Z,c as Y,d as N,e as W,f as X,g as U,h as j,i as Gt,j as q,k as m,l as C,m as p,n as Be,o as x,p as R,q as $,r as K,s as D,t as He,u as Le,v as Fe,w as Ge,x as Ae,y as ke}from"./chunk-ONWXGBWB.js";import{h as At}from"./chunk-DR6XXZE7.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-73VZQZUL.js";import"./chunk-YHKXQ2ZN.js";import{d as V,j as Dt}from"./chunk-4QLJUQSJ.js";import{a as zt,b as gt,c as Bt,d as Ht,g as Lt,h as xt,i as E,j as Ft}from"./chunk-G2IIMSUH.js";import"./chunk-XRP4JJXL.js";import{Vector3 as ti}from"three";import{BoxGeometry as qe,CapsuleGeometry as $e,ConeGeometry as kt,CylinderGeometry as Ke,Mesh as I,MeshStandardMaterial as Qe,SphereGeometry as Je}from"three";function z(i,t=Symbol("mesh")){if(i.material||i.color){let e=new At;if(e.build({...i.material,color:i.color??i.material?.color},t),e.materials.length>0)return e.materials}return[new Qe]}function B(i,t){if(t.position){let e=xt(t.position,Bt);i.position.set(e.x,e.y,e.z)}return i.castShadow=!0,i.receiveShadow=!0,i}function Q(i={}){let t=xt(i.size,Ht),e=new qe(t.x,t.y,t.z),o=z(i);return B(new I(e,o.at(-1)),i)}function J(i={}){let t=new Je(i.radius??1),e=z(i);return B(new I(t,e.at(-1)),i)}function tt(i={}){let t=new kt(i.radius??1,i.height??2,i.radialSegments??32),e=z(i);return B(new I(t,e.at(-1)),i)}function et(i={}){let t=new kt(i.radius??1,i.height??2,4),e=z(i);return B(new I(t,e.at(-1)),i)}function it(i={}){let t=new Ke(i.radiusTop??1,i.radiusBottom??1,i.height??2,i.radialSegments??32),e=z(i);return B(new I(t,e.at(-1)),i)}function ot(i={}){let t=new $e(i.radius??.5,i.length??1,i.capSegments??10,i.radialSegments??20),e=z(i);return B(new I(t,e.at(-1)),i)}var Vt={...m,size:new ti(1,1,1)},Yt=Symbol("Box"),st=class i extends p{static type=Yt;constructor(t){super(),this.options={...Vt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),{x:o,y:s,z:n}=this.options.size??{x:1,y:1,z:1};return{...e,type:String(i.type),size:`${o}, ${s}, ${n}`}}};function Nt(...i){let t=C(i,Vt),e=new st(t);return e.add(Q({size:t.size,material:t.material,color:t.color}),Y({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Nt(o??{}))}var Wt={...m,radius:1},Xt=Symbol("Sphere"),nt=class i extends p{static type=Xt;constructor(t){super(),this.options={...Wt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1;return{...e,type:String(i.type),radius:o.toFixed(2)}}};function Ut(...i){let t=C(i,Wt),e=new nt(t);return e.add(J({radius:t.radius,material:t.material,color:t.color}),N({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Ut(o??{}))}import{ColliderDesc as ii}from"@dimforge/rapier3d-compat";import{PlaneGeometry as oi,Vector2 as jt,Vector3 as Ot}from"three";import{BufferGeometry as ei,Float32BufferAttribute as bt}from"three";var rt=class i extends ei{constructor(t=1,e=1,o=1,s=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:e,widthSegments:o,heightSegments:s};let n=t/2,a=e/2,r=Math.floor(o),l=Math.floor(s),c=r+1,O=l+1,u=t/r,d=e/l,b=[],f=[],y=[],v=[];for(let g=0;g<O;g++){let h=g*d-a;for(let S=0;S<c;S++){let M=S*u-n;f.push(M,0,h),y.push(0,1,0),v.push(S/r),v.push(1-g/l)}}for(let g=0;g<l;g++)for(let h=0;h<r;h++){let S=h+c*g,M=h+c*(g+1),w=h+1+c*(g+1),_=h+1+c*g;b.push(S,M,_),b.push(M,w,_)}this.setIndex(b),this.setAttribute("position",new bt(f,3)),this.setAttribute("normal",new bt(y,3)),this.setAttribute("uv",new bt(v,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new i(t.width,t.height,t.widthSegments,t.heightSegments)}};var at=4,qt={...m,tile:new jt(10,10),repeat:new jt(1,1),collision:{static:!0},subdivisions:at,randomizeHeight:!1,heightScale:1};function $t(i){let t=i.subdivisions??at,e=i.heightMap2D,o=i.heightMap,s=i.subdivisionsX??t,n=i.subdivisionsZ??t;return e&&e.length>0&&e[0]?.length>0?(n=e.length-1,s=e[0].length-1):o&&o.length>0&&(s=o.length-1),{subdivisionsX:s,subdivisionsZ:n}}var Pt=class extends ${collider(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:s}=$t(t),n=new Ot(e.x,1,e.y),a=t._builders?.meshBuilder?.heightData,r=new Ot(n.x,1,n.z);return ii.heightfield(o,s,a,r)}},wt=class extends K{heightData=new Float32Array;columnsRows=new Map;subdivisionsX=at;subdivisionsZ=at;build(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:s}=$t(t);this.subdivisionsX=o,this.subdivisionsZ=s;let n=new Ot(e.x,1,e.y),a=t.heightScale??1,r=new rt(n.x,n.z,o,s),l=new oi(n.x,n.z,o,s),c=o>0?n.x/o:1,O=s>0?n.z/s:1,u=r.attributes.position.array,d=l.attributes.position.array,b=new Map,f=t.heightMap2D,y=t.heightMap,v=t.randomizeHeight??!1,g=(h,S)=>h<0?0:h>S?S:h;for(let h=0;h<d.length;h+=3){let S=d[h],M=d[h+1],w=g(Math.round((S+n.x/2)/c),o),_=g(Math.round((n.z/2-M)/O),s),T=0;if(f){let Rt=f[_];Rt&&(T=Rt[w]??0)}else y&&y.length>0?T=y[w]??0:v&&(T=Math.random()*4);let A=T*a;d[h+2]=A,u[h+1]=A,b.get(_)||b.set(_,new Map),b.get(_).set(w,A)}return this.columnsRows=b,r}postBuild(){let t=[];for(let e=0;e<=this.subdivisionsX;++e)for(let o=0;o<=this.subdivisionsZ;++o){let s=this.columnsRows.get(o);t.push(s?.get(e)??0)}this.heightData=new Float32Array(t)}},Ct=class extends D{createEntity(t){return new H(t)}},Kt=Symbol("Plane"),H=class extends p{static type=Kt;constructor(t){super(),this.options=Z(qt,t)}};function Qt(...i){return R({args:i,defaultConfig:qt,EntityClass:H,BuilderClass:Ct,MeshBuilderClass:wt,CollisionBuilderClass:Pt,entityType:H.type,cloneFactory:t=>Qt(t??{})})}import{Vector3 as si}from"three";var Jt={...m,size:new si(1,1,1),collision:{static:!0}},te=Symbol("Zone"),lt=class extends p{static type=te;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=Z(Jt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((e,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:e}){this._enteredZone.get(t.uuid)?this.held(e,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,e){let o=this._exitedZone.get(e);if(o&&o>1+t){this._exitedZone.delete(e),this._enteredZone.delete(e);let s=this._zoneEntities.get(e);this.options.onExit&&this.options.onExit({self:this,visitor:s,globals:V.globals});return}this._exitedZone.set(e,1+t)}held(t,e){let o=this._enteredZone.get(e.uuid)??0;this._enteredZone.set(e.uuid,o+t),this._exitedZone.set(e.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:e,globals:V.globals,heldTime:o})}};function ee(...i){let t=C(i,Jt),e=new lt(t);return e.add(q({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ee(o??{}))}import{Color as ie,Group as ni,Sprite as ri,SpriteMaterial as ai,CanvasTexture as oe,LinearFilter as pt,Vector2 as ct,ClampToEdgeWrapping as se,ShaderMaterial as ne,Mesh as li,PlaneGeometry as pi,Vector3 as re}from"three";var L={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new ct(24,24),zDistance:1,anchor:new ct(0,0)},St=class extends D{createEntity(t){return new F(t)}},ae=Symbol("Rect"),F=class i extends p{static type=ae;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=Z(L,t),this.options.screenPosition=E(this.options.screenPosition,L.screenPosition),this.options.anchor=E(this.options.anchor,L.anchor),this.group=new ni,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new oe(this._canvas),this._texture.minFilter=pt,this._texture.magFilter=pt;let t=new ai({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new ri(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),e=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,s=this.options.strokeWidth??0,n=t+o*2+s,a=e+o*2+s,r=Math.max(2,n),l=Math.max(2,a),c=r!==this._lastCanvasW||l!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=l,this._lastCanvasW=r,this._lastCanvasH=l,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let O=Math.max(0,this.options.radius??0),u=Math.floor(o+s/2),d=Math.floor(o+s/2),b=Math.floor(t),f=Math.floor(e);if(this._ctx.beginPath(),O>0?this.roundedRectPath(this._ctx,u,d,b,f,O):this._ctx.rect(u,d,b,f),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&s>0&&(this._ctx.lineWidth=s,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(c&&(this._texture.dispose(),this._texture=new oe(this._canvas),this._texture.minFilter=pt,this._texture.magFilter=pt,this._texture.wrapS=se,this._texture.wrapT=se,this._sprite&&this._sprite.material instanceof ne)){let y=this._sprite.material;y.uniforms?.tDiffuse&&(y.uniforms.tDiffuse.value=this._texture),y.uniforms?.iResolution&&y.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,e,o,s,n,a){let r=Math.min(a,Math.floor(Math.min(s,n)/2));t.moveTo(e+r,o),t.lineTo(e+s-r,o),t.quadraticCurveTo(e+s,o,e+s,o+r),t.lineTo(e+s,o+n-r),t.quadraticCurveTo(e+s,o+n,e+s-r,o+n),t.lineTo(e+r,o+n),t.quadraticCurveTo(e,o+n,e,o+n-r),t.lineTo(e,o+r),t.quadraticCurveTo(e,o,e+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof ie?t:new ie(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let e=this.materials[0];e instanceof ne&&(e.transparent=!0,e.depthTest=!1,e.depthWrite=!1,this._texture&&(e.uniforms?.tDiffuse&&(e.uniforms.tDiffuse.value=this._texture),e.uniforms?.iResolution&&this._canvas&&e.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new li(new pi(1,1),e),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let e=this.computeScreenBoundsFromOptions(this.options.bounds);if(e){let{x:o,y:s,width:n,height:a}=e,r=Math.max(2,Math.floor(n)),l=Math.max(2,Math.floor(a)),c=r!==(this.options.width??0)||l!==(this.options.height??0);this.options.screenPosition=new ct(Math.floor(o),Math.floor(s)),this.options.width=r,this.options.height=l,this.options.anchor=new ct(0,0),c&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),s=E(this.options.screenPosition,L.screenPosition),n=s.x,a=s.y,r=Math.max(.001,this.options.zDistance??1),l=1,c=1;if(t.isPerspectiveCamera){let w=t,_=Math.tan(w.fov*Math.PI/180/2)*r;l=_*w.aspect,c=_}else if(t.isOrthographicCamera){let w=t;l=(w.right-w.left)/2,c=(w.top-w.bottom)/2}let O=n/e*2-1,u=1-a/o*2,d=O*l,b=u*c,f=1,y=1;if(this._canvas){let _=c*2/o,T=this._canvas.height;y=Math.max(1e-4,T*_);let A=this._canvas.width/this._canvas.height;f=y*A,this._sprite.scale.set(f,y,1),this._mesh&&this._mesh.scale.set(f,y,1)}let v=E(this.options.anchor,L.anchor),g=Math.min(100,Math.max(0,v.x))/100,h=Math.min(100,Math.max(0,v.y))/100,S=(.5-g)*f,M=(h-.5)*y;this.group?.position.set(d+S,b+M,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let e=this._cameraRef.camera,{width:o,height:s}=this.getResolution(),n=t.clone().project(e),a=(n.x+1)/2*o,r=(1-n.y)/2*s;return{x:a,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:e,right:o,top:s,bottom:n,z:a=0}=t.world,r=this.worldToScreen(new re(e,s,a)),l=this.worldToScreen(new re(o,n,a)),c=Math.min(r.x,l.x),O=Math.min(r.y,l.y),u=Math.abs(l.x-r.x),d=Math.abs(l.y-r.y);return{x:c,y:O,width:u,height:d}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new P(this).buildDebugInfo(),type:String(i.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function le(...i){return R({args:i,defaultConfig:{...L},EntityClass:F,BuilderClass:St,entityType:F.type,cloneFactory:t=>le(t??{})})}import{ColliderDesc as ci}from"@dimforge/rapier3d-compat";import{Group as hi,RingGeometry as mi}from"three";var pe={...m,innerRadius:0,outerRadius:1,thetaSegments:32},_t=class extends ${collider(t){let e=t.outerRadius??1;return ci.cylinder(.1/2,e)}},vt=class extends K{build(t){let e=t.innerRadius??0,o=t.outerRadius??1,s=t.thetaSegments??32,n=new mi(e,o,s);return n.rotateX(-Math.PI/2),n}},Et=class extends D{createEntity(t){return new G(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new hi,t.group.add(t.mesh)),t}},ce=Symbol("Disk"),G=class i extends p{static type=ce;constructor(t){super(),this.options={...pe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.innerRadius??0,s=this.options.outerRadius??1;return{...e,type:String(i.type),innerRadius:o.toFixed(2),outerRadius:s.toFixed(2)}}};function he(...i){return R({args:i,defaultConfig:pe,EntityClass:G,BuilderClass:Et,MeshBuilderClass:vt,CollisionBuilderClass:_t,entityType:G.type,cloneFactory:t=>he(t??{})})}var me={...m,radius:1,height:2,radialSegments:32},ue=Symbol("Cone"),ht=class i extends p{static type=ue;constructor(t){super(),this.options={...me,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,s=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:s.toFixed(2)}}};function de(...i){let t=C(i,me),e=new ht(t);return e.add(tt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),W({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>de(o??{}))}var ye={...m,radius:1,height:2},fe=Symbol("Pyramid"),mt=class i extends p{static type=fe;constructor(t){super(),this.options={...ye,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,s=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:s.toFixed(2)}}};function ge(...i){let t=C(i,ye),e=new mt(t);return e.add(et({radius:t.radius,height:t.height,material:t.material,color:t.color}),X({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ge(o??{}))}var xe={...m,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},be=Symbol("Cylinder"),ut=class i extends p{static type=be;constructor(t){super(),this.options={...xe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radiusTop??1,s=this.options.radiusBottom??1,n=this.options.height??2;return{...e,type:String(i.type),radiusTop:o.toFixed(2),radiusBottom:s.toFixed(2),height:n.toFixed(2)}}};function Oe(...i){let t=C(i,xe),e=new ut(t);return e.add(it({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),U({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Oe(o??{}))}var Pe={...m,radius:.5,length:1,capSegments:10,radialSegments:20},we=Symbol("Pill"),dt=class i extends p{static type=we;constructor(t){super(),this.options={...Pe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??.5,s=this.options.length??1;return{...e,type:String(i.type),radius:o.toFixed(2),length:s.toFixed(2)}}};function Ce(...i){let t=C(i,Pe),e=new dt(t);return e.add(ot({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),j({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Ce(o??{}))}import{Group as ui,Quaternion as di,Vector3 as yi}from"three";import{ParticleEmitterBehavior as Zt}from"@zylem/behaviors/particle-emitter";var fi={...m,effect:{create(){throw new Error("createParticleSystem(...) requires an effect or preset definition.")}},preset:void 0,autoplay:!0,localOffset:void 0,followPosition:!0,followRotation:!0,autoDestroy:!1},Se=Symbol("ParticleSystem");function gi(i){return{effect:i.preset??i.effect,autoplay:i.autoplay,localOffset:i.localOffset,followPosition:i.followPosition,followRotation:i.followRotation,autoDestroy:i.autoDestroy}}var yt=class i extends p{static type=Se;particleHandle=null;constructor(t,e=!0){super(),this.options=Z(fi,t),this.group=new ui;let o=this.options.position;o&&this.group.position.copy(Ft(o)),this.__zylemParticleSystemEntity=!0,this.bindStandaloneTransforms(),e&&(this.particleHandle=this.use(Zt,gi(this.options)))}bindStandaloneTransforms(){let t=()=>{this.options.position=new yi(this.group?.position.x??0,this.group?.position.y??0,this.group?.position.z??0)},e=()=>{this.group&&(this._rotation2DAngle=this.group.rotation.z)};this.setPosition=(o,s,n)=>{this.group?.position.set(o,s,n),t()},this.setPositionX=o=>{this.group&&(this.group.position.x=o,t())},this.setPositionY=o=>{this.group&&(this.group.position.y=o,t())},this.setPositionZ=o=>{this.group&&(this.group.position.z=o,t())},this.getPosition=()=>this.group?{x:this.group.position.x,y:this.group.position.y,z:this.group.position.z}:null,this.setRotation=(o,s,n)=>{this.group?.rotation.set(o,s,n),e()},this.setRotationX=o=>{this.group&&(this.group.rotation.x=o,e())},this.setRotationY=o=>{this.group&&(this.group.rotation.y=o,e())},this.setRotationZ=o=>{this.group&&(this.group.rotation.z=o,e())},this.setRotationDegrees=(o,s,n)=>{this.group?.rotation.set(o*Math.PI/180,s*Math.PI/180,n*Math.PI/180),e()},this.setRotationDegreesX=o=>{this.group&&(this.group.rotation.x=o*Math.PI/180,e())},this.setRotationDegreesY=o=>{this.group&&(this.group.rotation.y=o*Math.PI/180,e())},this.setRotationDegreesZ=o=>{this.group&&(this.group.rotation.z=o*Math.PI/180,e())},this.rotateX=o=>{this.group?.rotateX(o),e()},this.rotateY=o=>{this.group?.rotateY(o),e()},this.rotateZ=o=>{this.group?.rotateZ(o),e()},this.getRotation=()=>{if(!this.group)return null;let o=new di;return this.group.getWorldQuaternion(o),o}}resolveParticleHandle(){if(this.particleHandle)return this.particleHandle;let t=this.getBehaviorRefs().find(s=>s.descriptor.key===Zt.key);if(!t)return null;let e={getFSM:()=>t.fsm??null,getOptions:()=>t.options,ref:t},o=Zt.createHandle?.(t)??{};return this.particleHandle={...e,...o},this.particleHandle}play(){this.resolveParticleHandle()?.play()}stop(){this.resolveParticleHandle()?.stop()}pause(){this.resolveParticleHandle()?.pause()}restart(){this.resolveParticleHandle()?.restart()}burst(){this.resolveParticleHandle()?.burst()}isPlaying(){return this.resolveParticleHandle()?.isPlaying()??!1}getSystem(){return this.resolveParticleHandle()?.getSystem()}buildInfo(){return{...super.buildInfo(),type:String(i.type)}}};function _e(i,t=!0){let e=new yt(i,t);return x(e,o=>_e(o,!1))}function xi(i){return _e(i,!0)}import{AmbientLight as bi,DirectionalLight as Oi,Group as Pi,HemisphereLight as wi,Object3D as Ci,PointLight as Si,SpotLight as _i}from"three";var ve=Symbol("Light"),vi={x:0,y:0,z:0},k=16777215,Ei={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},Zi={mapSize:1024,near:.1,far:500,bias:0,radius:1},ft=class extends p{static type=ve;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new Pi,{light:e,target:o}=Mi(this.options);return t.add(e),o&&t.add(o),this.group=t,this.light=e,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function Mi(i){switch(i.type){case"ambient":return{light:Ti(i),target:null};case"hemisphere":return{light:Ri(i),target:null};case"directional":return Di(i);case"point":return{light:Ii(i),target:null};case"spot":return zi(i)}}function Ti(i){let t=new bi(i.color??k,i.intensity??1);return i.name&&(t.name=i.name),t}function Ri(i){let t=i.skyColor??i.color??k,e=i.groundColor??0,o=new wi(t,e,i.intensity??1);return i.name&&(o.name=i.name),o}function Di(i){let t=new Oi(i.color??k,i.intensity??1);i.name&&(t.name=i.name),Bi(t,i.castShadow??!1,i.shadow);let e=Ee(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function Ii(i){let t=new Si(i.color??k,i.intensity??1,i.distance,i.decay);return i.name&&(t.name=i.name),Ze(t,i.castShadow??!1,i.shadow),t}function zi(i){let t=new _i(i.color??k,i.intensity??1,i.distance,i.angle,i.penumbra,i.decay);i.name&&(t.name=i.name),Ze(t,i.castShadow??!1,i.shadow);let e=Ee(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function Ee(i,t){if(!t)return null;let e=i??vi,o=new Ci;return o.position.set(t.x-e.x,t.y-e.y,t.z-e.z),o}function Bi(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...Ei,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.camera.left=o.left,i.shadow.camera.right=o.right,i.shadow.camera.top=o.top,i.shadow.camera.bottom=o.bottom,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Ze(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...Zi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Hi(i){return new ft(i)}import{Group as Li,Sprite as Fi,SpriteMaterial as Gi,CanvasTexture as Ai,LinearFilter as Me,Color as Te,ClampToEdgeWrapping as Re}from"three";import{getCooldown as De}from"@zylem/behaviors/cooldown";var ki={"top-left":{fx:0,fy:0},"top-center":{fx:.5,fy:0},"top-right":{fx:1,fy:0},"center-left":{fx:0,fy:.5},center:{fx:.5,fy:.5},"center-right":{fx:1,fy:.5},"bottom-left":{fx:0,fy:1},"bottom-center":{fx:.5,fy:1},"bottom-right":{fx:1,fy:1}},Ie=192,Vi={xs:8,sm:16,md:32,lg:48,xl:64},Mt={position:void 0,cooldown:"",iconSize:"md",fillColor:"#333333",showTimer:!0,stickToViewport:!0,screenAnchor:"top-left",screenPosition:{x:0,y:0},zDistance:1,overlayColor:"rgba(0, 0, 0, 0.65)"},Yi=Symbol("CooldownIcon"),Tt=class extends p{static type=Yi;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_iconTexture=null;_iconImage=null;_lastRenderedProgress=-1;constructor(t){super(),this.options=Z(Mt,t),this.options.screenPosition=E(this.options.screenPosition,Mt.screenPosition),this.group=new Li,this.createSprite(),this.prependSetup(this.iconSetup.bind(this)),this.prependUpdate(this.iconUpdate.bind(this)),this.onCleanup(this.iconDestroy.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._canvas.width=256,this._canvas.height=256,this._ctx=this._canvas.getContext("2d"),this._texture=new Ai(this._canvas),this._texture.minFilter=Me,this._texture.magFilter=Me,this._texture.wrapS=Re,this._texture.wrapT=Re;let e=new Gi({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1});if(this._sprite=new Fi(e),this.group?.add(this._sprite),this.options.icon){let o=new Image;o.crossOrigin="anonymous",o.onload=()=>{this._iconImage=o,this.redraw(this._lastRenderedProgress>=0?this._lastRenderedProgress:1)},o.src=this.options.icon}this.redraw(1)}redraw(t){if(!this._canvas||!this._ctx)return;let e=this._ctx,o=this._canvas.width,s=this._canvas.height,n=o/2,a=s/2,r=Math.min(n,a);if(e.clearRect(0,0,o,s),this._iconImage?e.drawImage(this._iconImage,0,0,o,s):(e.fillStyle=this.toCssColor(this.options.fillColor??"#333333"),e.fillRect(0,0,o,s)),t<1){let l=(1-t)*Math.PI*2,c=-Math.PI/2,O=c+l;if(e.save(),e.fillStyle=this.options.overlayColor??"rgba(0, 0, 0, 0.65)",e.beginPath(),e.moveTo(n,a),e.arc(n,a,r+1,c,O,!1),e.closePath(),e.fill(),e.restore(),this.options.showTimer){let u=De(this.options.cooldown);if(u){let d=Math.max(0,u.duration-u.elapsed),b=d>=10?Math.ceil(d).toString():d.toFixed(1),f=Math.floor(o*.3);e.font=`bold ${f}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillStyle="#FFFFFF",e.strokeStyle="#000000",e.lineWidth=2,e.strokeText(b,n,a),e.fillText(b,n,a)}}}this._texture&&(this._texture.needsUpdate=!0),this._lastRenderedProgress=t}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Te?t:new Te(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}iconSetup(t){this._sprite||this.createSprite(),this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}iconUpdate(t){let o=De(this.options.cooldown)?.progress??1;(Math.abs(o-this._lastRenderedProgress)>.02||o===1&&this._lastRenderedProgress!==1)&&this.redraw(o),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}resolveScreenPosition(t,e){let o=this.options.screenAnchor??"top-left",s=Lt(this.options.screenPosition,zt),n=s.x,a=s.y,{fx:r,fy:l}=ki[o],c=r*t,O=l*e,u=e/Ie;return{px:c+n*u,py:O+a*u}}resolveIconSize(t){let e=this.options.iconSize??"md",o,s;typeof e=="string"?o=s=Vi[e]:typeof e=="number"?o=s=e:(o=e.width,s=e.height);let n=t/Ie;return{widthPx:o*n,heightPx:s*n}}computeWorldExtents(t,e){let o=1,s=1;if(t.isPerspectiveCamera){let n=t,a=Math.tan(n.fov*Math.PI/180/2)*e;o=a*n.aspect,s=a}else if(t.isOrthographicCamera){let n=t;o=(n.right-n.left)/2,s=(n.top-n.bottom)/2}return{worldHalfW:o,worldHalfH:s}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),{px:s,py:n}=this.resolveScreenPosition(e,o),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:r,worldHalfH:l}=this.computeWorldExtents(t,a),c=s/e*2-1,O=1-n/o*2,u=c*r,d=O*l;{let f=l*2/o,{widthPx:y,heightPx:v}=this.resolveIconSize(o),g=Math.max(1e-4,y*f),h=Math.max(1e-4,v*f);this._sprite.scale.set(g,h,1)}this.group?.position.set(u,d,-a)}iconDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._iconTexture?.dispose(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null,this._iconTexture=null,this._iconImage=null}};function ze(...i){let t=i.filter(o=>!(o instanceof It)),e={...Mt};for(let o of t)e={...e,...o};return x(new Tt(e),o=>ze(o??{}))}function Ni(i,t,e){e({me:i,globals:t})}function Wi(i,t){let e=t??Dt();Ni(i,e,i.nodeDestroy.bind(i))}export{He as ACTOR_TYPE,Yt as BOX_TYPE,ue as CONE_TYPE,be as CYLINDER_TYPE,ce as DISK_TYPE,Ge as FOG_TYPE,ve as LIGHT_TYPE,Se as PARTICLE_SYSTEM_TYPE,we as PILL_TYPE,Kt as PLANE_TYPE,fe as PYRAMID_TYPE,ae as RECT_TYPE,Xt as SPHERE_TYPE,We as SPRITE_TYPE,Ve as TEXT_TYPE,te as ZONE_TYPE,Le as ZylemActor,st as ZylemBox,ht as ZylemCone,ut as ZylemCylinder,G as ZylemDisk,Ae as ZylemFog,ft as ZylemLight,yt as ZylemParticleSystem,dt as ZylemPill,H as ZylemPlane,mt as ZylemPyramid,F as ZylemRect,nt as ZylemSphere,Xe as ZylemSprite,Ye as ZylemText,lt as ZylemZone,Y as boxCollision,Q as boxMesh,W as coneCollision,tt as coneMesh,Be as create,Fe as createActor,Nt as createBox,de as createCone,ze as createCooldownIcon,Oe as createCylinder,he as createDisk,R as createEntity,je as createEntityFactory,ke as createFog,Hi as createLight,xi as createParticleSystem,Ce as createPill,Qt as createPlane,ge as createPyramid,le as createRect,Ut as createSphere,Ue as createSprite,Ne as createText,ee as createZone,U as cylinderCollision,it as cylinderMesh,Wi as destroy,j as pillCollision,ot as pillMesh,Gt as planeCollision,X as pyramidCollision,et as pyramidMesh,N as sphereCollision,J as sphereMesh,q as zoneCollision};
1
+ import{A as $,B as aa,C as ba,D as ca,E as da,F as ea,G as fa,H as ga,I as ha,J as ia,K as ja,L as ka,M as la,N as ma,O as na,P as oa,Q as pa,R as qa,a as B,b as C,c as D,d as E,e as F,f as G,g as H,h as I,i as J,j as K,k as L,l as M,m as N,n as O,o as P,p as Q,q as R,r as S,s as T,t as U,u as V,v as W,w as X,x as Y,y as Z,z as _}from"./chunk-7FR5JSQ2.js";import{b as q,c as r,d as s,e as t,f as u,g as v,h as w,i as x,j as y,k as z,m as A}from"./chunk-XNDS4YFR.js";import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,n as i,p as j,t as k,u as l,v as m,w as n,x as o,y as p}from"./chunk-XNHVRFAK.js";import"./chunk-CM5YRNBJ.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-E3UBSUPX.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-XRP4JJXL.js";export{k as ACTOR_TYPE,H as BOX_TYPE,Z as CONE_TYPE,da as CYLINDER_TYPE,W as DISK_TYPE,n as FOG_TYPE,ma as LIGHT_TYPE,w as LINE_TYPE,ja as PARTICLE_SYSTEM_TYPE,ga as PILL_TYPE,N as PLANE_TYPE,aa as PYRAMID_TYPE,T as RECT_TYPE,K as SPHERE_TYPE,t as SPRITE_TYPE,q as TEXT_TYPE,Q as ZONE_TYPE,l as ZylemActor,I as ZylemBox,_ as ZylemCone,ea as ZylemCylinder,X as ZylemDisk,o as ZylemFog,na as ZylemLight,y as ZylemLine,ka as ZylemParticleSystem,ha as ZylemPill,O as ZylemPlane,ba as ZylemPyramid,U as ZylemRect,L as ZylemSphere,u as ZylemSprite,r as ZylemText,R as ZylemZone,a as boxCollision,B as boxMesh,c as coneCollision,D as coneMesh,i as create,m as createActor,J as createBox,$ as createCone,pa as createCooldownIcon,fa as createCylinder,Y as createDisk,j as createEntity,A as createEntityFactory,p as createFog,oa as createLight,z as createLine,la as createParticleSystem,ia as createPill,P as createPlane,ca as createPyramid,V as createRect,M as createSphere,v as createSprite,s as createText,S as createZone,e as cylinderCollision,F as cylinderMesh,qa as destroy,x as pickZylemLine,f as pillCollision,G as pillMesh,g as planeCollision,d as pyramidCollision,E as pyramidMesh,b as sphereCollision,C as sphereMesh,h as zoneCollision};
package/dist/events.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as mitt from 'mitt';
2
- import { g as LoadingEvent } from './base-node-life-cycle-CnJ-7zX-.js';
2
+ import { L as LoadingEvent } from './base-node-life-cycle-D2NuN1VB.js';
3
3
  import 'three';
4
+ import './stage-transition-CmGpV4tc.js';
4
5
 
5
6
  /**
6
7
  * Reusable delegate for event emission and subscription.
@@ -77,6 +78,14 @@ interface EntityConfigPayload {
77
78
  y: number;
78
79
  z: number;
79
80
  };
81
+ /** PNG data URL of a framed entity preview, when available. */
82
+ thumbnail?: string | null;
83
+ /** World-space AABB size used for thumbnail rulers. */
84
+ bounds?: {
85
+ width: number;
86
+ height: number;
87
+ depth: number;
88
+ };
80
89
  }
81
90
  /** Payload for state dispatch events from game to editor. */
82
91
  interface StateDispatchPayload {
package/dist/events.js CHANGED
@@ -1 +1 @@
1
- import{a as t,b as e}from"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";export{t as EventEmitterDelegate,e as zylemEventBus};
1
+ import"./chunk-BIGH6D34.js";import{a,b}from"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";export{a as EventEmitterDelegate,b as zylemEventBus};