@zylem/game-lib 0.6.3 → 0.7.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.
- package/README.md +3 -1
- package/dist/actions.d.ts +255 -8
- package/dist/actions.js +1 -772
- package/dist/audio.d.ts +13 -0
- package/dist/audio.js +1 -0
- package/dist/base-node-life-cycle-CnJ-7zX-.d.ts +143 -0
- package/dist/behavior.d.ts +3 -0
- package/dist/behavior.js +1 -0
- package/dist/chunk-4QLJUQSJ.js +1 -0
- package/dist/chunk-73VZQZUL.js +1 -0
- package/dist/chunk-A34ZG3L4.js +1 -0
- package/dist/chunk-CDPY4VOQ.js +1 -0
- package/dist/chunk-DR6XXZE7.js +19 -0
- package/dist/chunk-FM5TBEPO.js +1 -0
- package/dist/chunk-G2IIMSUH.js +1 -0
- package/dist/chunk-MSC2BEO5.js +1 -0
- package/dist/chunk-NIH5CONO.js +1 -0
- package/dist/chunk-ONWXGBWB.js +1 -0
- package/dist/chunk-QEDQDR27.js +1 -0
- package/dist/chunk-QXVH6POE.js +1 -0
- package/dist/chunk-RXDTAWI2.js +29 -0
- package/dist/chunk-WKHW2QO2.js +1 -0
- package/dist/chunk-XRP4JJXL.js +1 -0
- package/dist/chunk-YHEWKN7N.js +1 -0
- package/dist/chunk-YHKXQ2ZN.js +1 -0
- package/dist/core.d.ts +206 -13
- package/dist/core.js +24 -9160
- package/dist/debug.d.ts +24 -0
- package/dist/debug.js +1 -0
- package/dist/default-controls-BGc61yYl.d.ts +111 -0
- package/dist/entity-DNkYKfdp.d.ts +1043 -0
- package/dist/entity-type-map-C94h2TDW.d.ts +781 -0
- package/dist/entity.d.ts +265 -0
- package/dist/entity.js +1 -0
- package/dist/events.d.ts +172 -0
- package/dist/events.js +1 -0
- package/dist/game-Cuj5gy7U.d.ts +1590 -0
- package/dist/game-default-PZLLHYL7.js +1 -0
- package/dist/game-interfaces-tfpM5NBk.d.ts +90 -0
- package/dist/globals.d.ts +104 -0
- package/dist/globals.js +1 -0
- package/dist/graphics.d.ts +83 -0
- package/dist/graphics.js +1 -0
- package/dist/input-ui.d.ts +34 -0
- package/dist/input-ui.js +1 -0
- package/dist/input.d.ts +72 -0
- package/dist/input.js +1 -0
- package/dist/material-Wz83vTTp.d.ts +151 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1 -0
- package/dist/web-components.d.ts +67 -0
- package/dist/web-components.js +9 -0
- package/dist/world-C9zdyl5d.d.ts +103 -0
- package/dist/zylem-stage-runtime-Cs-UDEVU.d.ts +777 -0
- package/package.json +54 -41
- package/dist/actions.js.map +0 -1
- package/dist/behavior/platformer-3d.d.ts +0 -296
- package/dist/behavior/platformer-3d.js +0 -518
- package/dist/behavior/platformer-3d.js.map +0 -1
- package/dist/behavior/ricochet-2d.d.ts +0 -274
- package/dist/behavior/ricochet-2d.js +0 -394
- package/dist/behavior/ricochet-2d.js.map +0 -1
- package/dist/behavior/screen-wrap.d.ts +0 -86
- package/dist/behavior/screen-wrap.js +0 -195
- package/dist/behavior/screen-wrap.js.map +0 -1
- package/dist/behavior/thruster.d.ts +0 -10
- package/dist/behavior/thruster.js +0 -234
- package/dist/behavior/thruster.js.map +0 -1
- package/dist/behavior/world-boundary-2d.d.ts +0 -141
- package/dist/behavior/world-boundary-2d.js +0 -181
- package/dist/behavior/world-boundary-2d.js.map +0 -1
- package/dist/behavior-descriptor-BWNWmIjv.d.ts +0 -142
- package/dist/blueprints-BWGz8fII.d.ts +0 -26
- package/dist/camera-B5e4c78l.d.ts +0 -468
- package/dist/camera.d.ts +0 -6
- package/dist/camera.js +0 -1406
- package/dist/camera.js.map +0 -1
- package/dist/composition-DrzFrbqI.d.ts +0 -218
- package/dist/core-DAkskq6Y.d.ts +0 -498
- package/dist/core.js.map +0 -1
- package/dist/entities-DC9ce_vx.d.ts +0 -416
- package/dist/entities.d.ts +0 -9
- package/dist/entities.js +0 -4069
- package/dist/entities.js.map +0 -1
- package/dist/entity-BpbZqg19.d.ts +0 -1100
- package/dist/entity-Bq_eNEDI.d.ts +0 -28
- package/dist/entity-types-DAu8sGJH.d.ts +0 -26
- package/dist/global-change-Dc8uCKi2.d.ts +0 -25
- package/dist/main.d.ts +0 -654
- package/dist/main.js +0 -13355
- package/dist/main.js.map +0 -1
- package/dist/stage-types-BFsm3qsZ.d.ts +0 -567
- package/dist/stage.d.ts +0 -51
- package/dist/stage.js +0 -5738
- package/dist/stage.js.map +0 -1
- package/dist/thruster-DhRaJnoL.d.ts +0 -172
- package/dist/world-Be5m1XC1.d.ts +0 -31
package/dist/audio.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Howl } from 'howler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plays a ricochet sound effect when boundary collision occurs
|
|
5
|
+
*/
|
|
6
|
+
declare function ricochetSound(frequency?: number, duration?: number): void;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Plays a ping-pong beep sound effect.
|
|
10
|
+
*/
|
|
11
|
+
declare function pingPongBeep(frequency?: number, duration?: number): void;
|
|
12
|
+
|
|
13
|
+
export { pingPongBeep, ricochetSound };
|
package/dist/audio.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(i=800,t=.05){c(i,t)}function c(i,t){let e=new(window.AudioContext||window.webkitAudioContext),n=e.createOscillator(),o=e.createGain();n.type="sawtooth",n.frequency.value=i,o.gain.setValueAtTime(.05,e.currentTime),o.gain.exponentialRampToValueAtTime(.001,e.currentTime+t),n.connect(o),o.connect(e.destination),n.start(),n.stop(e.currentTime+t)}function a(i=440,t=.1){u(i,t)}function u(i,t){let e=new(window.AudioContext||window.webkitAudioContext),n=e.createOscillator(),o=e.createGain();n.type="square",n.frequency.value=i,o.gain.setValueAtTime(.05,e.currentTime),o.gain.exponentialRampToValueAtTime(.001,e.currentTime+t),n.connect(o),o.connect(e.destination),n.start(),n.stop(e.currentTime+t)}import{Howl as x}from"howler";export{x as Howl,a as pingPongBeep,r as ricochetSound};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
|
|
3
|
+
/** Input
|
|
4
|
+
*
|
|
5
|
+
* Maximum number of local players is 8.
|
|
6
|
+
* All input can be mapped to a gamepad or keyboard but shares the common
|
|
7
|
+
* interface represented as a gamepad.
|
|
8
|
+
*/
|
|
9
|
+
type InputPlayerNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
10
|
+
type InputPlayer = `p${InputPlayerNumber}`;
|
|
11
|
+
interface ButtonState {
|
|
12
|
+
pressed: boolean;
|
|
13
|
+
released: boolean;
|
|
14
|
+
held: number;
|
|
15
|
+
}
|
|
16
|
+
interface AnalogState {
|
|
17
|
+
value: number;
|
|
18
|
+
held: number;
|
|
19
|
+
}
|
|
20
|
+
interface InputGamepad {
|
|
21
|
+
playerNumber: InputPlayerNumber;
|
|
22
|
+
buttons: {
|
|
23
|
+
A: ButtonState;
|
|
24
|
+
B: ButtonState;
|
|
25
|
+
X: ButtonState;
|
|
26
|
+
Y: ButtonState;
|
|
27
|
+
Start: ButtonState;
|
|
28
|
+
Select: ButtonState;
|
|
29
|
+
L: ButtonState;
|
|
30
|
+
R: ButtonState;
|
|
31
|
+
};
|
|
32
|
+
directions: {
|
|
33
|
+
Up: ButtonState;
|
|
34
|
+
Down: ButtonState;
|
|
35
|
+
Left: ButtonState;
|
|
36
|
+
Right: ButtonState;
|
|
37
|
+
};
|
|
38
|
+
shoulders: {
|
|
39
|
+
LTrigger: ButtonState;
|
|
40
|
+
RTrigger: ButtonState;
|
|
41
|
+
};
|
|
42
|
+
axes: {
|
|
43
|
+
Horizontal: AnalogState;
|
|
44
|
+
Vertical: AnalogState;
|
|
45
|
+
SecondaryHorizontal: AnalogState;
|
|
46
|
+
SecondaryVertical: AnalogState;
|
|
47
|
+
};
|
|
48
|
+
/** Screen-space cursor position (normalized 0..1). Only populated by MouseProvider. */
|
|
49
|
+
pointer?: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
type Inputs = Record<InputPlayer, InputGamepad>;
|
|
55
|
+
type ButtonName = keyof InputGamepad['buttons'];
|
|
56
|
+
interface InputProvider {
|
|
57
|
+
getInput(delta: number): Partial<InputGamepad>;
|
|
58
|
+
isConnected(): boolean;
|
|
59
|
+
getName(): string;
|
|
60
|
+
dispose?(): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type LoadingEvent = {
|
|
64
|
+
type: 'start' | 'progress' | 'complete';
|
|
65
|
+
message?: string;
|
|
66
|
+
progress?: number;
|
|
67
|
+
total?: number;
|
|
68
|
+
current?: number;
|
|
69
|
+
};
|
|
70
|
+
interface IGame<TGlobals extends Record<string, unknown> = any> {
|
|
71
|
+
start: () => Promise<this>;
|
|
72
|
+
nextStage: () => void;
|
|
73
|
+
previousStage: () => void;
|
|
74
|
+
reset: () => Promise<void>;
|
|
75
|
+
pause: () => Promise<void>;
|
|
76
|
+
resume: () => Promise<void>;
|
|
77
|
+
onLoading: (callback: (event: LoadingEvent) => void) => void;
|
|
78
|
+
loadStageFromId: (stageId: string) => Promise<void>;
|
|
79
|
+
end: () => Promise<void>;
|
|
80
|
+
goToStage: () => void;
|
|
81
|
+
}
|
|
82
|
+
interface IStage {
|
|
83
|
+
onUpdate: (callback: UpdateFunction<IStage>) => void;
|
|
84
|
+
onSetup: (callback: SetupFunction<IStage>) => void;
|
|
85
|
+
onDestroy: (callback: DestroyFunction<IStage>) => void;
|
|
86
|
+
}
|
|
87
|
+
interface ICamera {
|
|
88
|
+
move: (position: Vector3) => void;
|
|
89
|
+
rotate: (pitch: number, yaw: number, roll: number) => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type GlobalRecord = Record<string, unknown>;
|
|
93
|
+
/** Setup */
|
|
94
|
+
interface SetupContext<T, TGlobals extends GlobalRecord = any> {
|
|
95
|
+
me: T;
|
|
96
|
+
globals: TGlobals;
|
|
97
|
+
inputs?: Inputs;
|
|
98
|
+
camera?: ICamera;
|
|
99
|
+
stage?: IStage;
|
|
100
|
+
game?: IGame<TGlobals>;
|
|
101
|
+
}
|
|
102
|
+
interface SetupFunction<T, TGlobals extends GlobalRecord = any> {
|
|
103
|
+
(context: SetupContext<T, TGlobals>): void;
|
|
104
|
+
}
|
|
105
|
+
/** Loaded */
|
|
106
|
+
interface LoadedContext<T, TGlobals extends GlobalRecord = any> {
|
|
107
|
+
me: T;
|
|
108
|
+
globals: TGlobals;
|
|
109
|
+
}
|
|
110
|
+
interface LoadedFunction<T, TGlobals extends GlobalRecord = any> {
|
|
111
|
+
(context: LoadedContext<T, TGlobals>): void;
|
|
112
|
+
}
|
|
113
|
+
/** Update */
|
|
114
|
+
type UpdateContext<T, TGlobals extends GlobalRecord = any> = {
|
|
115
|
+
me: T;
|
|
116
|
+
delta: number;
|
|
117
|
+
inputs: Inputs;
|
|
118
|
+
globals: TGlobals;
|
|
119
|
+
camera: ICamera;
|
|
120
|
+
stage?: IStage;
|
|
121
|
+
game?: IGame<TGlobals>;
|
|
122
|
+
};
|
|
123
|
+
interface UpdateFunction<T, TGlobals extends GlobalRecord = any> {
|
|
124
|
+
(context: UpdateContext<T, TGlobals>): void;
|
|
125
|
+
}
|
|
126
|
+
/** Destroy */
|
|
127
|
+
interface DestroyContext<T, TGlobals extends GlobalRecord = any> {
|
|
128
|
+
me: T;
|
|
129
|
+
globals: TGlobals;
|
|
130
|
+
}
|
|
131
|
+
interface DestroyFunction<T, TGlobals extends GlobalRecord = any> {
|
|
132
|
+
(context: DestroyContext<T, TGlobals>): void;
|
|
133
|
+
}
|
|
134
|
+
/** Cleanup */
|
|
135
|
+
interface CleanupContext<T, TGlobals extends GlobalRecord = any> {
|
|
136
|
+
me: T;
|
|
137
|
+
globals: TGlobals;
|
|
138
|
+
}
|
|
139
|
+
interface CleanupFunction<T, TGlobals extends GlobalRecord = any> {
|
|
140
|
+
(context: CleanupContext<T, TGlobals>): void;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type { AnalogState as A, ButtonState as B, CleanupContext as C, DestroyContext as D, InputPlayer as I, LoadedContext as L, SetupContext as S, UpdateFunction as U, Inputs as a, InputGamepad as b, ButtonName as c, InputPlayerNumber as d, InputProvider as e, UpdateContext as f, LoadingEvent as g, SetupFunction as h, LoadedFunction as i, DestroyFunction as j, CleanupFunction as k, IGame as l };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { Behavior, BehaviorDescriptor, BehaviorHandle, BehaviorRef, BehaviorSystem, BehaviorSystemFactory, BoundaryRicochet3DCoordinator, BoundaryRicochetCoordinator, BurstParticlePresetOptions, CooldownBehavior, CooldownConfig, CooldownEntry, CooldownHandle, CooldownOptions, DefineBehaviorConfig, Destructible3DBehavior, Destructible3DBehaviorOptions, Destructible3DColliderOptions, Destructible3DFragmentColliderShape, Destructible3DFragmentPhysicsOptions, Destructible3DHandle, DestructibleMesh, DestructiblePrebakeWorkerAPI, FirstPersonContext, FirstPersonController, FirstPersonControllerBehavior, FirstPersonControllerOptions, FirstPersonEntity, FirstPersonEvent, FirstPersonFSM, FirstPersonInputComponent, FirstPersonMovementComponent, FirstPersonShooterCoordinator, FirstPersonShooterInput, FirstPersonState, FirstPersonStateComponent, FractureOptions, FractureOptionsInput, JumpConfig2D, JumpConfig3D, JumpContext2D, JumpContext3D, JumpInput2D, JumpInput3D, JumpState2D, JumpState3D, Jumper2D, Jumper2DBehavior, Jumper2DBehaviorOptions, Jumper2DEntity, Jumper2DEvent, Jumper2DFSM, Jumper2DState, Jumper2DTickEvent, Jumper2DTickResult, Jumper3D, Jumper3DBehavior, Jumper3DBehaviorOptions, Jumper3DEntity, Jumper3DEvent, Jumper3DFSM, Jumper3DState, JumperTickEvent, JumperTickResult, MultidirectionalSpaceShooterCoordinator, MultidirectionalSpaceShooterInput, ParticleEffectDefinition, ParticleEmitterBehavior, ParticleEmitterBehaviorOptions, ParticleEmitterHandle, ParticleMagicAgency, ParticleMagicAlignment, ParticleMagicModifierInput, ParticleMagicModifierOptions, ParticleMagicOrder, ParticleMagicRealityEffect, ParticleMagicTemperament, ParticlePresetMaterialOptions, PhysicsBodyComponent, PlainBufferGeometryPayload, PlainFractureOptions, Platformer3DBehavior, Platformer3DBehaviorOptions, Platformer3DContext, Platformer3DEntity, Platformer3DEvent, Platformer3DFSM, Platformer3DInputComponent, Platformer3DMovementBehavior, Platformer3DMovementComponent, Platformer3DState, Platformer3DStateComponent, PlatformerCollisionContext, PlayerInput, PrebakeWorkerRequest, PrebakeWorkerResponse, Ricochet2DBehavior, Ricochet2DCollisionContext, Ricochet2DEvent, Ricochet2DFSM, Ricochet2DHandle, Ricochet2DOptions, Ricochet2DResult, Ricochet2DState, Ricochet3DBehavior, Ricochet3DCallback, Ricochet3DCollisionContext, Ricochet3DEvent, Ricochet3DFSM, Ricochet3DHandle, Ricochet3DOptions, Ricochet3DResult, Ricochet3DState, RicochetCallback, ScreenVisibilityBehavior, ScreenVisibilityChangeContext, ScreenVisibilityFSM, ScreenVisibilityHandle, ScreenVisibilityOptions, ScreenVisibilitySize, ScreenVisibilitySnapshot, ScreenWrapBehavior, ScreenWrapEvent, ScreenWrapFSM, ScreenWrapOptions, ScreenWrapState, SemanticParticlePresetOptions, Shooter2DBehavior, Shooter2DBehaviorOptions, Shooter2DFireArgs, Shooter2DHandle, Shooter2DProjectileFactory, Shooter2DSourceEntity, Shooter2DStageLike, Shooter2DStateComponent, Shooter2DTarget, ThrusterBehavior, ThrusterBehaviorOptions, ThrusterEntity, ThrusterEvent, ThrusterFSM, ThrusterFSMContext, ThrusterInputComponent, ThrusterMovementBehavior, ThrusterMovementComponent, ThrusterState, ThrusterStateComponent, TopDownMovementBehavior, TopDownMovementBehaviorOptions, TopDownMovementComponent, TopDownMovementEntity, TopDownMovementHandle, TopDownMovementInputComponent, TopDownMovementRuntimeBehavior, TopDownMovementStateComponent, TopDownShooterCoordinator, TopDownShooterInput, TransformComponent, Vec3Like, ViewmodelConfig, VoronoiOptions, WorldBoundary2DBehavior, WorldBoundary2DBounds, WorldBoundary2DEvent, WorldBoundary2DFSM, WorldBoundary2DHandle, WorldBoundary2DHit, WorldBoundary2DHits, WorldBoundary2DOptions, WorldBoundary2DPosition, WorldBoundary2DState, WorldBoundary3DBehavior, WorldBoundary3DBounds, WorldBoundary3DEvent, WorldBoundary3DFSM, WorldBoundary3DHandle, WorldBoundary3DHit, WorldBoundary3DHits, WorldBoundary3DOptions, WorldBoundary3DPosition, WorldBoundary3DState, computeWorldBoundary2DHits, computeWorldBoundary3DHits, createFirstPersonInputComponent, createFirstPersonMovementComponent, createFirstPersonStateComponent, createJumpConfig2D, createJumpConfig3D, createJumpInput2D, createJumpInput3D, createJumpState2D, createJumpState3D, createPhysicsBodyComponent, createPlatformer3DInputComponent, createPlatformer3DMovementComponent, createPlatformer3DStateComponent, createShooter2DStateComponent, createThrusterInputComponent, createThrusterMovementComponent, createThrusterStateComponent, createTopDownMovementComponent, createTopDownMovementInputComponent, createTopDownMovementStateComponent, createTransformComponent, defineBehavior, fireCooldown, getCooldown, getCooldownStore, hasAnyWorldBoundary2DHit, hasAnyWorldBoundary3DHit, particleEffect, particlePresets, registerCooldown, resetCooldown, tickCooldowns, useBehavior } from '@zylem/behaviors';
|
|
2
|
+
export { RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY, RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY, RUNTIME_PONG_BALL_BEHAVIOR_KEY, RUNTIME_RICOCHET_2D_BEHAVIOR_KEY, RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY, RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY, RuntimeGoalZone2DBehavior, RuntimeGoalZone2DEvent, RuntimeGoalZone2DHandle, RuntimeGoalZone2DOptions, RuntimePaddleInput2DBehavior, RuntimePaddleInput2DOptions, RuntimePongBallBehavior, RuntimePongBallHandle, RuntimePongBallOptions, RuntimeRicochet2DBehavior, RuntimeRicochet2DEvent, RuntimeRicochet2DHandle, RuntimeRicochet2DOptions, RuntimeTriggerRegion2DBehavior, RuntimeTriggerRegion2DEvent, RuntimeTriggerRegion2DHandle, RuntimeTriggerRegion2DOptions, RuntimeWorldBoundary2DBehavior, RuntimeWorldBoundary2DOptions, bindRuntimePongBallHandle, emitRuntimeGoal, emitRuntimeRicochet, emitRuntimeTriggerRegionEnter } from '@zylem/behaviors/runtime-pong';
|
|
3
|
+
export { RUNTIME_BOUNDARY_2D_BEHAVIOR_KEY, RUNTIME_DYNAMIC_CIRCLE_BODY_2D_BEHAVIOR_KEY, RUNTIME_PLAYER_INPUT_2D_BEHAVIOR_KEY, RuntimeBoundary2DBehavior, RuntimeBoundary2DOptions, RuntimeDynamicCircleBody2DBehavior, RuntimeDynamicCircleBody2DHandle, RuntimeDynamicCircleBody2DOptions, RuntimePlayerInput2DBehavior, RuntimePlayerInput2DOptions, RuntimeRicochet2DBehavior as RuntimeRicochet2DDescriptor, RuntimeTriggerRegion2DBehavior as RuntimeTriggerRegion2DDescriptor, bindRuntimeDynamicCircleBody2DHandle } from '@zylem/behaviors/runtime-2d';
|
package/dist/behavior.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BoundaryRicochet3DCoordinator as t,BoundaryRicochetCoordinator as r,CooldownBehavior as n,Destructible3DBehavior as i,DestructibleMesh as a,FirstPersonController as D,FirstPersonControllerBehavior as m,FirstPersonEvent as l,FirstPersonFSM as u,FirstPersonShooterCoordinator as p,FirstPersonState as c,FractureOptions as s,Jumper2D as h,Jumper2DBehavior as d,Jumper2DEvent as R,Jumper2DFSM as B,Jumper2DState as v,Jumper2DTickEvent as C,Jumper3D as y,Jumper3DBehavior as P,Jumper3DEvent as S,Jumper3DFSM as E,Jumper3DState as T,JumperTickEvent as M,MultidirectionalSpaceShooterCoordinator as O,ParticleEmitterBehavior as g,Platformer3DBehavior as I,Platformer3DEvent as f,Platformer3DFSM as _,Platformer3DMovementBehavior as F,Platformer3DState as H,Ricochet2DBehavior as W,Ricochet2DEvent as J,Ricochet2DFSM as b,Ricochet2DState as w,Ricochet3DBehavior as A,Ricochet3DEvent as V,Ricochet3DFSM as N,Ricochet3DState as x,ScreenVisibilityBehavior as k,ScreenVisibilityFSM as Y,ScreenWrapBehavior as U,ScreenWrapEvent as G,ScreenWrapFSM as K,ScreenWrapState as L,Shooter2DBehavior as Z,ThrusterBehavior as z,ThrusterEvent as j,ThrusterFSM as q,ThrusterMovementBehavior as Q,ThrusterState as X,TopDownMovementBehavior as $,TopDownMovementRuntimeBehavior as ee,TopDownShooterCoordinator as oe,WorldBoundary2DBehavior as te,WorldBoundary2DEvent as re,WorldBoundary2DFSM as ne,WorldBoundary2DState as ie,WorldBoundary3DBehavior as ae,WorldBoundary3DEvent as De,WorldBoundary3DFSM as me,WorldBoundary3DState as le,computeWorldBoundary2DHits as ue,computeWorldBoundary3DHits as pe,createFirstPersonInputComponent as ce,createFirstPersonMovementComponent as se,createFirstPersonStateComponent as he,createJumpConfig2D as de,createJumpConfig3D as Re,createJumpInput2D as Be,createJumpInput3D as ve,createJumpState2D as Ce,createJumpState3D as ye,createPhysicsBodyComponent as Pe,createPlatformer3DInputComponent as Se,createPlatformer3DMovementComponent as Ee,createPlatformer3DStateComponent as Te,createShooter2DStateComponent as Me,createThrusterInputComponent as Oe,createThrusterMovementComponent as ge,createThrusterStateComponent as Ie,createTopDownMovementComponent as fe,createTopDownMovementInputComponent as _e,createTopDownMovementStateComponent as Fe,createTransformComponent as He,defineBehavior as We,fireCooldown as Je,getCooldown as be,getCooldownStore as we,hasAnyWorldBoundary2DHit as Ae,hasAnyWorldBoundary3DHit as Ve,particleEffect as Ne,particlePresets as xe,registerCooldown as ke,resetCooldown as Ye,tickCooldowns as Ue,useBehavior as Ge}from"@zylem/behaviors";import{RuntimeGoalZone2DBehavior as ze,RuntimePaddleInput2DBehavior as je,RuntimePongBallBehavior as qe,RuntimeRicochet2DBehavior as Qe,RuntimeTriggerRegion2DBehavior as Xe,RuntimeWorldBoundary2DBehavior as $e,RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY as eo,RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY as oo,RUNTIME_PONG_BALL_BEHAVIOR_KEY as to,RUNTIME_RICOCHET_2D_BEHAVIOR_KEY as ro,RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY as no,RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY as io,bindRuntimePongBallHandle as ao,emitRuntimeGoal as Do,emitRuntimeRicochet as mo,emitRuntimeTriggerRegionEnter as lo}from"@zylem/behaviors/runtime-pong";import{RuntimeBoundary2DBehavior as po,RuntimeDynamicCircleBody2DBehavior as co,RuntimePlayerInput2DBehavior as so,RuntimeRicochet2DBehavior as ho,RuntimeTriggerRegion2DBehavior as Ro,RUNTIME_BOUNDARY_2D_BEHAVIOR_KEY as Bo,RUNTIME_DYNAMIC_CIRCLE_BODY_2D_BEHAVIOR_KEY as vo,RUNTIME_PLAYER_INPUT_2D_BEHAVIOR_KEY as Co,bindRuntimeDynamicCircleBody2DHandle as yo}from"@zylem/behaviors/runtime-2d";export{t as BoundaryRicochet3DCoordinator,r as BoundaryRicochetCoordinator,n as CooldownBehavior,i as Destructible3DBehavior,a as DestructibleMesh,D as FirstPersonController,m as FirstPersonControllerBehavior,l as FirstPersonEvent,u as FirstPersonFSM,p as FirstPersonShooterCoordinator,c as FirstPersonState,s as FractureOptions,h as Jumper2D,d as Jumper2DBehavior,R as Jumper2DEvent,B as Jumper2DFSM,v as Jumper2DState,C as Jumper2DTickEvent,y as Jumper3D,P as Jumper3DBehavior,S as Jumper3DEvent,E as Jumper3DFSM,T as Jumper3DState,M as JumperTickEvent,O as MultidirectionalSpaceShooterCoordinator,g as ParticleEmitterBehavior,I as Platformer3DBehavior,f as Platformer3DEvent,_ as Platformer3DFSM,F as Platformer3DMovementBehavior,H as Platformer3DState,Bo as RUNTIME_BOUNDARY_2D_BEHAVIOR_KEY,vo as RUNTIME_DYNAMIC_CIRCLE_BODY_2D_BEHAVIOR_KEY,eo as RUNTIME_GOAL_ZONE_2D_BEHAVIOR_KEY,oo as RUNTIME_PADDLE_INPUT_2D_BEHAVIOR_KEY,Co as RUNTIME_PLAYER_INPUT_2D_BEHAVIOR_KEY,to as RUNTIME_PONG_BALL_BEHAVIOR_KEY,ro as RUNTIME_RICOCHET_2D_BEHAVIOR_KEY,no as RUNTIME_TRIGGER_REGION_2D_BEHAVIOR_KEY,io as RUNTIME_WORLD_BOUNDARY_2D_BEHAVIOR_KEY,W as Ricochet2DBehavior,J as Ricochet2DEvent,b as Ricochet2DFSM,w as Ricochet2DState,A as Ricochet3DBehavior,V as Ricochet3DEvent,N as Ricochet3DFSM,x as Ricochet3DState,po as RuntimeBoundary2DBehavior,co as RuntimeDynamicCircleBody2DBehavior,ze as RuntimeGoalZone2DBehavior,je as RuntimePaddleInput2DBehavior,so as RuntimePlayerInput2DBehavior,qe as RuntimePongBallBehavior,Qe as RuntimeRicochet2DBehavior,ho as RuntimeRicochet2DDescriptor,Xe as RuntimeTriggerRegion2DBehavior,Ro as RuntimeTriggerRegion2DDescriptor,$e as RuntimeWorldBoundary2DBehavior,k as ScreenVisibilityBehavior,Y as ScreenVisibilityFSM,U as ScreenWrapBehavior,G as ScreenWrapEvent,K as ScreenWrapFSM,L as ScreenWrapState,Z as Shooter2DBehavior,z as ThrusterBehavior,j as ThrusterEvent,q as ThrusterFSM,Q as ThrusterMovementBehavior,X as ThrusterState,$ as TopDownMovementBehavior,ee as TopDownMovementRuntimeBehavior,oe as TopDownShooterCoordinator,te as WorldBoundary2DBehavior,re as WorldBoundary2DEvent,ne as WorldBoundary2DFSM,ie as WorldBoundary2DState,ae as WorldBoundary3DBehavior,De as WorldBoundary3DEvent,me as WorldBoundary3DFSM,le as WorldBoundary3DState,yo as bindRuntimeDynamicCircleBody2DHandle,ao as bindRuntimePongBallHandle,ue as computeWorldBoundary2DHits,pe as computeWorldBoundary3DHits,ce as createFirstPersonInputComponent,se as createFirstPersonMovementComponent,he as createFirstPersonStateComponent,de as createJumpConfig2D,Re as createJumpConfig3D,Be as createJumpInput2D,ve as createJumpInput3D,Ce as createJumpState2D,ye as createJumpState3D,Pe as createPhysicsBodyComponent,Se as createPlatformer3DInputComponent,Ee as createPlatformer3DMovementComponent,Te as createPlatformer3DStateComponent,Me as createShooter2DStateComponent,Oe as createThrusterInputComponent,ge as createThrusterMovementComponent,Ie as createThrusterStateComponent,fe as createTopDownMovementComponent,_e as createTopDownMovementInputComponent,Fe as createTopDownMovementStateComponent,He as createTransformComponent,We as defineBehavior,Do as emitRuntimeGoal,mo as emitRuntimeRicochet,lo as emitRuntimeTriggerRegionEnter,Je as fireCooldown,be as getCooldown,we as getCooldownStore,Ae as hasAnyWorldBoundary2DHit,Ve as hasAnyWorldBoundary3DHit,Ne as particleEffect,xe as particlePresets,ke as registerCooldown,Ye as resetCooldown,Ue as tickCooldowns,Ge as useBehavior};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{proxy as b,subscribe as p}from"valtio/vanilla";function i(t,e){if(!e)return;let n=e.split("."),o=t;for(let a of n){if(o==null||typeof o!="object")return;o=o[a]}return o}function d(t,e,n){if(!e)return;let o=e.split("."),a=t;for(let l=0;l<o.length-1;l++){let r=o[l];(a[r]==null||typeof a[r]!="object")&&(a[r]={}),a=a[r]}a[o[o.length-1]]=n}var g=class{listeners=new Map;on(e,n){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(n),()=>this.off(e,n)}off(e,n){this.listeners.get(e)?.delete(n)}emit(e,n){let o=this.listeners.get(e);if(o)for(let a of o)try{a(n)}catch(l){console.error(`Error in event handler for ${e}`,l)}}dispose(){this.listeners.clear()}},c=new g;var s=b({id:"",globals:{},time:0}),u=new Set;function k(t,e){let n=i(s.globals,t);d(s.globals,t,e),c.emit("game:state:updated",{path:t,value:e,previousValue:n})}function G(t,e){let n=i(s.globals,t);return n===void 0?(d(s.globals,t,e),e):n}function h(t){return i(s.globals,t)}function E(t,e){let n=i(s.globals,t),o=p(s.globals,()=>{let a=i(s.globals,t);a!==n&&(n=a,e(a))});return u.add(o),()=>{o(),u.delete(o)}}function w(t,e){let n=t.map(a=>i(s.globals,a)),o=p(s.globals,()=>{let a=t.map(r=>i(s.globals,r));a.some((r,f)=>r!==n[f])&&(n=a,e(a))});return u.add(o),()=>{o(),u.delete(o)}}function S(){return s.globals}function P(t){for(let[e,n]of Object.entries(t))d(s.globals,e,n)}function K(){s.globals={}}function C(){for(let t of u)t();u.clear()}export{i as a,d as b,c,s as d,k as e,G as f,h as g,E as h,w as i,S as j,P as k,K as l,C as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as l,d as c,h as a,k as d}from"./chunk-G2IIMSUH.js";import{ActiveCollisionTypes as D,ColliderDesc as g,RigidBodyDesc as h,RigidBodyType as p,Vector3 as I}from"@dimforge/rapier3d-compat";var u=new Map,m=0;function C(o){let e=u.get(o);return e===void 0&&(e=m++%16,u.set(o,e)),e}function x(o){let e=0;return o.forEach(t=>{let i=C(t);e|=1<<i}),e}var y=class{static=!1;sensor=!1;gravity=new I(0,0,0);build(e){let t=this.bodyDesc({isDynamicBody:!this.static}),i=this.collider(e),s=e.collisionType;if(s){let f=C(s),r=65535;e.collisionFilter&&(r=x(e.collisionFilter)),i.setCollisionGroups(f<<16|r)}let{KINEMATIC_FIXED:n,DEFAULT:b}=D;return i.activeCollisionTypes=this.sensor?n:b,[t,i]}withCollision(e){return this.sensor=e?.sensor??this.sensor,this.static=e?.static??this.static,this}collider(e){let t=d(e.size,c),i={x:t.x/2,y:t.y/2,z:t.z/2},s=g.cuboid(i.x,i.y,i.z),n=a(e.position,l);return s.setTranslation(n.x,n.y,n.z),s}bodyDesc({isDynamicBody:e=!0}){let t=e?p.Dynamic:p.Fixed;return new h(t).setTranslation(0,0,0).setGravityScale(1).setCanSleep(!1).setCcdEnabled(!0)}};export{C as a,x as b,y as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as p}from"./chunk-CDPY4VOQ.js";import{a as _,b as h}from"./chunk-YHKXQ2ZN.js";var I=4294967295,F=12,q=6,C=7,z=(n=>(n[n.Dynamic=0]="Dynamic",n[n.Static=1]="Static",n[n.KinematicPosition=2]="KinematicPosition",n[n.KinematicVelocity=3]="KinematicVelocity",n))(z||{}),v=(e=>(e[e.Two=2]="Two",e[e.Three=3]="Three",e))(v||{}),w=(e=>(e[e.Two=2]="Two",e[e.Three=3]="Three",e))(w||{}),A=(e=>(e[e.Mirror=0]="Mirror",e[e.Angled=1]="Angled",e))(A||{}),S=(e=>(e[e.Xy=0]="Xy",e[e.Xz=1]="Xz",e))(S||{}),M=(a=>(a[a.CollisionStarted=1]="CollisionStarted",a[a.CollisionStopped=2]="CollisionStopped",a[a.BoundaryHit=3]="BoundaryHit",a[a.Ricochet=4]="Ricochet",a[a.RegionEntered=5]="RegionEntered",a[a.JumpStarted=6]="JumpStarted",a[a.Landed=7]="Landed",a[a.Wrapped=8]="Wrapped",a[a.CooldownFired=9]="CooldownFired",a))(M||{}),d=class{exports;memory;renderView=new Float32Array(0);eventView=new Float32Array(0);poseView=new Float32Array(0);vec3View=new Float32Array(0);queryView=new Float32Array(0);scratchView=new Float32Array(0);constructor(t,e={}){this.exports=t,this.memory=t.memory;let r=Math.max(e.initialCapacity??64,8);t.zylem_stage_create(r),e.gravity&&t.zylem_stage_set_gravity(e.gravity[0],e.gravity[1],e.gravity[2]),this.refreshViews()}refreshViews(){let t=this.memory.buffer,e=this.exports.zylem_stage_render_ptr(),r=this.exports.zylem_stage_render_len(),n=this.exports.zylem_stage_event_ptr(),s=this.exports.zylem_stage_event_len(),u=this.exports.zylem_stage_pose_ptr(),o=this.exports.zylem_stage_pose_len(),m=this.exports.zylem_stage_vec3_ptr(),a=this.exports.zylem_stage_query_ptr(),l=this.exports.zylem_stage_query_len(),c=this.exports.zylem_stage_scratch_ptr(),y=this.exports.zylem_stage_scratch_capacity();this.renderView=r>0?new Float32Array(t,e,r):new Float32Array(0),this.eventView=s>0?new Float32Array(t,n,s):new Float32Array(0),this.poseView=o>0?new Float32Array(t,u,o):new Float32Array(0),this.vec3View=m!==0?new Float32Array(t,m,3):new Float32Array(0),this.queryView=l>0?new Float32Array(t,a,l):new Float32Array(0),this.scratchView=y>0?new Float32Array(t,c,y):new Float32Array(0)}step(t){let e=this.exports.zylem_stage_step(t);return this.refreshViews(),e}dispose(){this.exports.zylem_stage_destroy()}get tickCount(){return this.exports.zylem_stage_tick_count()>>>0}get activeCount(){return this.exports.zylem_stage_active_count()>>>0}setGravity(t,e,r){this.exports.zylem_stage_set_gravity(t,e,r)}createEntity(){let t=this.exports.zylem_stage_create_entity()>>>0;return this.refreshViews(),t}destroyEntity(t){return this.exports.zylem_stage_destroy_entity(t)!==0}attachBody(t,e){return this.exports.zylem_stage_attach_body(t,e.kind,e.position[0],e.position[1],e.position[2],e.rotation[0],e.rotation[1],e.rotation[2],e.rotation[3],e.linearDamping,e.angularDamping,e.gravityScale,e.canSleep?1:0,e.ccdEnabled?1:0,e.lockRotation[0]?1:0,e.lockRotation[1]?1:0,e.lockRotation[2]?1:0,e.lockTranslation[0]?1:0,e.lockTranslation[1]?1:0,e.lockTranslation[2]?1:0)!==0}addCollider(t,e){let r=e.offset,n=e.sensor?1:0,s=e.collisionGroups>>>0,u=e.friction,o=e.restitution;switch(e.shape.type){case"box":{let[m,a,l]=e.shape.halfExtents;return this.exports.zylem_stage_add_collider_box(t,m,a,l,r[0],r[1],r[2],u,o,n,s)!==0}case"sphere":return this.exports.zylem_stage_add_collider_sphere(t,e.shape.radius,r[0],r[1],r[2],u,o,n,s)!==0;case"capsule":return this.exports.zylem_stage_add_collider_capsule(t,e.shape.halfHeight,e.shape.radius,r[0],r[1],r[2],u,o,n,s)!==0;case"cylinder":return this.exports.zylem_stage_add_collider_cylinder(t,e.shape.halfHeight,e.shape.radius,r[0],r[1],r[2],u,o,n,s)!==0;case"convexHull":{let m=e.shape.vertices;if(m.length%3!==0)return!1;let a=this.stageScratch(m);return this.exports.zylem_stage_add_collider_convex_hull(t,a,m.length/3,r[0],r[1],r[2],u,o,n,s)!==0}case"trimesh":{let m=e.shape.vertices,a=e.shape.indices;if(m.length%3!==0||a.length%3!==0)return!1;let l=this.stageScratch(m),c=this.stageScratchIndices(a,l+m.length);return this.exports.zylem_stage_add_collider_trimesh(t,l,m.length/3,c,a.length,r[0],r[1],r[2],u,o,n,s)!==0}case"heightfield":{let m=e.shape.heights,a=this.stageScratch(m);return this.exports.zylem_stage_add_collider_heightfield(t,e.shape.rows,e.shape.cols,e.shape.scale[0],e.shape.scale[1],e.shape.scale[2],a,r[0],r[1],r[2],u,o,s)!==0}default:{let m=e.shape;return!1}}}stageScratch(t,e=0){return this.scratchView.set(t,e),e}stageScratchIndices(t,e){for(let r=0;r<t.length;r++)this.scratchView[e+r]=t[r];return e}getPose(t,e){if(!(this.exports.zylem_stage_get_pose(t)!==0))return null;let n=this.poseView,s=e??{position:[0,0,0],rotation:[0,0,0,1]};return s.position[0]=n[0],s.position[1]=n[1],s.position[2]=n[2],s.rotation[0]=n[3],s.rotation[1]=n[4],s.rotation[2]=n[5],s.rotation[3]=n[6],s}setPosition(t,e,r,n){return this.exports.zylem_stage_set_position(t,e,r,n)!==0}setRotation(t,e,r,n,s){return this.exports.zylem_stage_set_rotation(t,e,r,n,s)!==0}setLinearVelocity(t,e,r,n){return this.exports.zylem_stage_set_linvel(t,e,r,n)!==0}getLinearVelocity(t,e){if(this.exports.zylem_stage_get_linvel(t)===0)return null;let r=this.vec3View,n=e??[0,0,0];return n[0]=r[0],n[1]=r[1],n[2]=r[2],n}setAngularVelocity(t,e,r,n){return this.exports.zylem_stage_set_angvel(t,e,r,n)!==0}applyImpulse(t,e,r,n){return this.exports.zylem_stage_apply_impulse(t,e,r,n)!==0}get render(){return this.renderView}get renderStride(){return 12}drainEvents(){let t=this.exports.zylem_stage_event_count()>>>0;if(t===0)return[];let e=this.eventView,r=new Array(t);for(let n=0;n<t;n++){let s=n*6,u=e[s+1],o=e[s+2];r[n]={type:e[s]|0,primarySlot:Number.isNaN(u)?null:u>>>0,secondarySlot:Number.isNaN(o)?null:o>>>0,payload:[e[s+3],e[s+4],e[s+5]]}}return r}get queryScratch(){return this.queryView}attachCooldown(t){return this.exports.zylem_stage_attach_cooldown(t)!==0}registerCooldown(t,e,r,n=!1){return this.exports.zylem_stage_cooldown_register(t,e>>>0,r,n?1:0)!==0}fireCooldown(t,e){return this.exports.zylem_stage_cooldown_fire(t,e>>>0)!==0}resetCooldown(t,e){return this.exports.zylem_stage_cooldown_reset(t,e>>>0)!==0}cooldownRemaining(t,e){return this.exports.zylem_stage_cooldown_remaining(t,e>>>0)}attachWorldBoundary(t,e,r){return this.exports.zylem_stage_attach_world_boundary(t,e,r.top,r.bottom,r.left,r.right,r.front,r.back,r.padding??0)!==0}queryWorldBoundary(t){if(this.exports.zylem_stage_query_world_boundary(t)===0)return null;let e=this.queryView;return{hits:e[0]|0,clamped:[e[1],e[2],e[3]]}}attachScreenWrap(t,e){return this.exports.zylem_stage_attach_screen_wrap(t,e.width,e.height,e.centerX??0,e.centerY??0,e.edgeThreshold??0)!==0}queryScreenWrap(t){if(this.exports.zylem_stage_query_screen_wrap(t)===0)return null;let e=this.queryView;return{fsm:e[0]|0,lastWrappedAxes:e[1]|0}}attachRicochet(t,e,r){return this.exports.zylem_stage_attach_ricochet(t,e,r.minSpeed,r.maxSpeed,r.speedMultiplier,r.maxAngleDeg,r.reflectionMode)!==0}queryRicochet(t){if(this.exports.zylem_stage_query_ricochet(t)===0)return null;let e=this.queryView;return{bounces:e[0]|0,lastKind:e[1]|0}}attachThruster(t,e){return this.exports.zylem_stage_attach_thruster(t,e.maxSpeed,e.acceleration,e.turnRateRadPerSec,e.linearDamping)!==0}setThrusterInput(t,e,r){this.exports.zylem_stage_set_thruster_input(t,e,r)}queryThruster(t){if(this.exports.zylem_stage_query_thruster(t)===0)return null;let e=this.queryView;return{headingRad:e[0],speed:e[1]}}attachTopDown(t,e){return this.exports.zylem_stage_attach_top_down(t,e.plane,e.speed,e.faceMovement?1:0)!==0}setTopDownInput(t,e,r){this.exports.zylem_stage_set_top_down_input(t,e,r)}attachJumper2D(t,e){return this.exports.zylem_stage_attach_jumper_2d(t,e.jumpForce,e.maxJumps>>>0,e.jumpBufferTime,e.coyoteTime,e.gravity)!==0}setJumper2DInput(t,e){this.exports.zylem_stage_set_jumper_2d_input(t,e?1:0)}queryJumper2D(t){if(this.exports.zylem_stage_query_jumper_2d(t)===0)return null;let e=this.queryView;return{grounded:e[0]>.5,jumpCount:e[1]|0,coyote:e[2],jumpBuffer:e[3]}}attachJumper3D(t,e){return this.exports.zylem_stage_attach_jumper_3d(t,e.jumpForce,e.maxJumps>>>0,e.gravity)!==0}setJumper3DInput(t,e){this.exports.zylem_stage_set_jumper_3d_input(t,e?1:0)}queryJumper3D(t){if(this.exports.zylem_stage_query_jumper_3d(t)===0)return null;let e=this.queryView;return{grounded:e[0]>.5,jumpCount:e[1]|0,verticalVelocity:e[2]}}attachShooter2D(t,e){return this.exports.zylem_stage_attach_shooter_2d(t,e.fireRateHz,e.muzzleOffsetX,e.muzzleOffsetY,e.muzzleSpeed)!==0}fireShooter2D(t,e,r,n,s){return this.exports.zylem_stage_shooter_2d_fire(t,e,r,n,s)!==0}queryShooter2D(t){if(this.exports.zylem_stage_query_shooter_2d(t)===0)return null;let e=this.queryView;return{cooldown:e[0],firedCount:e[1]|0}}attachPlatformer3D(t,e){return this.exports.zylem_stage_attach_platformer_3d(t,e.halfHeight,e.radius,e.walkSpeed,e.runSpeed,e.jumpForce,e.maxJumps>>>0,e.gravity)!==0}setPlatformer3DInputAxes(t,e,r){this.exports.zylem_stage_set_platformer_3d_input_axes(t,e,r)}setPlatformer3DInputButtons(t,e,r){this.exports.zylem_stage_set_platformer_3d_input_buttons(t,e?1:0,r?1:0)}queryPlatformer3D(t){if(this.exports.zylem_stage_query_platformer_3d(t)===0)return null;let e=this.queryView;return{grounded:e[0]>.5,jumpCount:e[1]|0,fsmState:e[2]|0,speed:e[3]}}attachFirstPerson(t,e){return this.exports.zylem_stage_attach_first_person(t,e.walkSpeed,e.runSpeed,e.eyeHeight,e.lookSensitivity)!==0}setFirstPersonInput(t,e){this.exports.zylem_stage_set_first_person_input(t,e.moveX,e.moveZ,e.lookYawDelta,e.lookPitchDelta,e.run?1:0)}queryFirstPerson(t){if(this.exports.zylem_stage_query_first_person(t)===0)return null;let e=this.queryView;return{yaw:e[0],pitch:e[1],speed:e[2],eyeHeight:e[3]}}};async function V(i,t={}){let e;i instanceof ArrayBuffer?e=i:e=await(await fetch(i)).arrayBuffer();let{instance:r}=await WebAssembly.instantiate(e,t.imports??{}),n=r.exports;return new d(n,t)}function R(){return{runtimeDiagnostics(){return p.enabled}}}import{InstancedMesh as g,Matrix4 as b,Vector3 as f,Quaternion as k}from"three";var x=class i{batches=new Map;entityToBatch=new Map;scene=null;static DEFAULT_CAPACITY=128;static GROWTH_FACTOR=2;setScene(t){this.scene=t}static generateBatchKey(t){let e={geo:`${t.geometryType}:${_(t.dimensions)}`,mat:t.materialPath||"none",shader:t.shaderType||"standard",color:t.colorHex??16777215};return h(_(e))}static generateEntityBatchKey(t){let e=t.options;if(e.runtime?.batchKeyOverride)return e.runtime.batchKeyOverride;let r=t.constructor?.type?.description||"unknown",n=e.size||{x:1,y:1,z:1},s=e.material||{};return i.generateBatchKey({geometryType:r,dimensions:{x:n.x,y:n.y,z:n.z},materialPath:s.path||null,shaderType:s.shader?"custom":"standard",colorHex:s.color?.getHex?.()||e.color?.getHex?.()||16777215})}register(t,e,r,n){let s=this.batches.get(n);s||(s=this.createBatch(n,e,r));let u;return s.freeIndices.length>0?u=s.freeIndices.pop():(u=s.entities.length,u>=s.capacity&&this.growBatch(s),s.entities.push(null)),s.entities[u]=t,s.entityMap.set(t.uuid,u),this.entityToBatch.set(t.uuid,n),s.instancedMesh.count=Math.max(s.instancedMesh.count,u+1),s.activeIndices.push(u),s.dirtyIndices.add(u),u}unregister(t){let e=this.entityToBatch.get(t.uuid);if(!e)return;let r=this.batches.get(e);if(!r)return;let n=r.entityMap.get(t.uuid);if(n===void 0)return;r.entities[n]=null,r.entityMap.delete(t.uuid),this.entityToBatch.delete(t.uuid),r.freeIndices.push(n);let s=r.activeIndices.indexOf(n);if(s!==-1){let o=r.activeIndices.pop();s<r.activeIndices.length&&(r.activeIndices[s]=o)}r.dirtyIndices.delete(n);let u=new b;u.makeScale(0,0,0),r.instancedMesh.setMatrixAt(n,u),r.instancedMesh.instanceMatrix.needsUpdate=!0}markDirty(t){let e=this.entityToBatch.get(t.uuid);if(!e)return;let r=this.batches.get(e);if(!r)return;let n=r.entityMap.get(t.uuid);n!==void 0&&r.dirtyIndices.add(n)}update(){let t=new b,e=new f,r=new k,n=new f(1,1,1);for(let s of this.batches.values()){if(s.activeIndices.length===0)continue;let u=!1;if(s.dirtyIndices.size>0){for(let o of s.dirtyIndices)this.updateInstanceMatrix(s,o,t,e,r,n);s.dirtyIndices.clear(),u=!0}for(let o of s.activeIndices){let m=s.entities[o];m&&m.body&&(this.updateInstanceMatrix(s,o,t,e,r,n),u=!0)}u&&(s.instancedMesh.instanceMatrix.needsUpdate=!0)}}updateInstanceMatrix(t,e,r,n,s,u){let o=t.entities[e];if(o){if(o.body){let m=o.body.translation(),a=o.body.rotation();n.set(m.x,m.y,m.z),s.set(a.x,a.y,a.z,a.w),r.compose(n,s,u)}else o.mesh?(o.mesh.updateMatrix(),r.copy(o.mesh.matrix)):o.group&&(o.group.updateMatrix(),r.copy(o.group.matrix));t.instancedMesh.setMatrixAt(e,r)}}getBatchInfo(t){let e=this.entityToBatch.get(t.uuid);if(!e)return null;let r=this.batches.get(e);if(!r)return null;let n=r.entityMap.get(t.uuid);return n===void 0?null:{batchKey:e,instanceId:n}}getStats(){let t=0,e=[];for(let[r,n]of this.batches){let s=n.entityMap.size;t+=s,e.push({key:r,count:s,capacity:n.capacity})}return{batchCount:this.batches.size,totalInstances:t,batches:e}}dispose(){for(let t of this.batches.values())this.scene&&this.scene.remove(t.instancedMesh),t.instancedMesh.dispose(),t.geometry.dispose();this.batches.clear(),this.entityToBatch.clear()}createBatch(t,e,r){let n=i.DEFAULT_CAPACITY,s=new g(e,r,n);s.count=0,s.frustumCulled=!1;let u=new b().makeScale(0,0,0);for(let m=0;m<n;m++)s.setMatrixAt(m,u);s.instanceMatrix.needsUpdate=!0;let o={key:t,instancedMesh:s,geometry:e,material:r,entityMap:new Map,entities:[],freeIndices:[],activeIndices:[],dirtyIndices:new Set,capacity:n};return this.batches.set(t,o),this.scene&&this.scene.add(s),o}growBatch(t){let e=t.capacity*i.GROWTH_FACTOR,r=new g(t.geometry,t.material,e);r.count=t.instancedMesh.count,r.frustumCulled=!1;let n=new b;for(let u=0;u<t.capacity;u++)t.instancedMesh.getMatrixAt(u,n),r.setMatrixAt(u,n);let s=new b().makeScale(0,0,0);for(let u=t.capacity;u<e;u++)r.setMatrixAt(u,s);r.instanceMatrix.needsUpdate=!0,this.scene&&(this.scene.remove(t.instancedMesh),this.scene.add(r)),t.instancedMesh.dispose(),t.instancedMesh=r,t.capacity=e}};export{x as a,I as b,F as c,q as d,C as e,z as f,v as g,w as h,A as i,S as j,M as k,d as l,V as m,R as n};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{proxy as n}from"valtio";var e=n({enabled:!1,paused:!1,tool:"none",selectedEntity:null,hoveredEntity:null,flags:new Set});function l(){return e.paused}function i(t){e.paused=t}function a(){return e.tool}function r(t){e.tool=t}function u(t){e.selectedEntity=t}function s(){return e.hoveredEntity}function d(t){e.hoveredEntity=t}function y(){e.hoveredEntity=null}export{e as a,l as b,i as c,a as d,r as e,u as f,s as g,d as h,y as i};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{a as R}from"./chunk-QXVH6POE.js";import{a as C,b as G}from"./chunk-YHKXQ2ZN.js";import{b as p,i as h}from"./chunk-G2IIMSUH.js";var B=`
|
|
2
|
+
uniform vec2 uvScale;
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
|
|
5
|
+
void main() {
|
|
6
|
+
vUv = uv;
|
|
7
|
+
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
8
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
9
|
+
}
|
|
10
|
+
`;var X=`
|
|
11
|
+
uniform sampler2D tDiffuse;
|
|
12
|
+
varying vec2 vUv;
|
|
13
|
+
|
|
14
|
+
void main() {
|
|
15
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
16
|
+
|
|
17
|
+
gl_FragColor = texel;
|
|
18
|
+
}
|
|
19
|
+
`,O={vertex:B,fragment:X};import{Color as A,RepeatWrapping as v,SRGBColorSpace as te}from"three";import{MeshBasicNodeMaterial as ae,MeshStandardNodeMaterial as P}from"three/webgpu";import{LoadingManager as ee,Cache as k}from"three";import{TextureLoader as W,RepeatWrapping as E}from"three";var M=16,L=class{loader;constructor(){this.loader=new W}isSupported(e){let t=e.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","webp","bmp","tga"].includes(t||"")}async load(e,t){let a=await this.loader.loadAsync(e,r=>{t?.onProgress&&r.lengthComputable&&t.onProgress(r.loaded/r.total)});return t?.repeat&&a.repeat.copy(h(t.repeat,p)),a.wrapS=t?.wrapS??E,a.wrapT=t?.wrapT??E,t?.colorSpace!==void 0&&(a.colorSpace=t.colorSpace),a.anisotropy=t?.anisotropy??M,a}clone(e){let t=e.clone();return t.anisotropy=e.anisotropy||M,t.needsUpdate=!0,t}};import{GLTFLoader as J}from"three/addons/loaders/GLTFLoader.js";import{DRACOLoader as K}from"three/addons/loaders/DRACOLoader.js";import{KTX2Loader as Z}from"three/addons/loaders/KTX2Loader.js";import{MeshoptDecoder as $}from"three/addons/libs/meshopt_decoder.module.js";import{Mesh as j}from"three";import{clone as I}from"three/addons/utils/SkeletonUtils.js";function u(s){let e=I(s),t=[],a=[];s.traverse(r=>t.push(r)),e.traverse(r=>a.push(r));for(let r=0;r<t.length;r++){let o=t[r],i=a[r];!(o instanceof j)||!(i instanceof j)||(o.geometry?.clone&&(i.geometry=o.geometry.clone()),o.material&&(i.material=Array.isArray(o.material)?o.material.map(n=>n.clone()):o.material.clone()))}return e}function N(s){let e=s.indexOf("?"),t=s.indexOf("#"),a=[e,t].filter(r=>r>=0).reduce((r,o)=>Math.min(r,o),s.length);return s.slice(0,a)}function c(s){let e=N(s),t=e.lastIndexOf("/"),a=t>=0?e.slice(t+1):e,r=a.lastIndexOf(".");return r<0||r===a.length-1?null:a.slice(r+1).toLowerCase()}var V=["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"],_="https://www.gstatic.com/draco/v1/decoders/",g=class{loader;dracoLoader;ktx2Loader=null;meshoptEnabled=!1;configuredRenderer=null;ktx2TranscoderPath=null;constructor(){this.dracoLoader=new K,this.dracoLoader.setDecoderPath(_),this.loader=new J,this.loader.setDRACOLoader(this.dracoLoader),this.setMeshoptEnabled(!0)}isSupported(e){let t=c(e);return["gltf","glb"].includes(t||"")}async configureRuntime({meshopt:e=!0,ktx2TranscoderPath:t,renderer:a=null}={}){this.setMeshoptEnabled(e!==!1);let r=this.normalizeTranscoderPath(t);if(!r){this.clearKTX2Loader();return}if(!a)throw new Error("GLTFLoaderAdapter.configureRuntime requires a renderer when ktx2TranscoderPath is provided.");(!this.ktx2Loader||this.ktx2TranscoderPath!==r)&&(this.clearKTX2Loader(),this.ktx2Loader=new Z,this.ktx2Loader.setTranscoderPath(r),this.loader.setKTX2Loader(this.ktx2Loader),this.ktx2TranscoderPath=r,this.configuredRenderer=null),!(!this.ktx2Loader||this.configuredRenderer===a)&&(this.ktx2Loader.detectSupport(a),this.configuredRenderer=a)}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let a=await fetch(e);if(!a.ok)throw new Error(`Failed to fetch ${e}: ${a.status} ${a.statusText}`);let r=await a.arrayBuffer(),o=await this.loader.parseAsync(r,e);return this.applyTextureAnisotropy(o.scene),{object:o.scene,animations:o.animations,gltf:o}}catch(a){return console.error(`Async fetch GLTF load failed for ${e}, falling back to loader.load():`,a),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((a,r)=>{this.loader.load(e,o=>{this.applyTextureAnisotropy(o.scene),a({object:o.scene,animations:o.animations,gltf:o})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>r(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone()),gltf:e.gltf}}applyTextureAnisotropy(e){e.traverse(t=>{let a=t.material;if(!a)return;let r=Array.isArray(a)?a:[a];for(let o of r)for(let i of V){let n=o[i];if(n&&n.isTexture){let d=n;d.anisotropy=M,d.needsUpdate=!0}}})}setMeshoptEnabled(e){if(e){if(this.meshoptEnabled)return;this.loader.setMeshoptDecoder($),this.meshoptEnabled=!0;return}this.meshoptEnabled&&(this.loader.setMeshoptDecoder(void 0),this.meshoptEnabled=!1)}clearKTX2Loader(){this.ktx2Loader&&(this.ktx2Loader.dispose(),this.ktx2Loader=null),this.loader.setKTX2Loader(void 0),this.configuredRenderer=null,this.ktx2TranscoderPath=null}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}};import{FBXLoader as z}from"three/addons/loaders/FBXLoader.js";var T=class{loader;constructor(){this.loader=new z}isSupported(e){return c(e)==="fbx"}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let a=await fetch(e);if(!a.ok)throw new Error(`Failed to fetch ${e}: ${a.status} ${a.statusText}`);let r=await a.arrayBuffer(),o=this.loader.parse(r,e);return{object:o,animations:o.animations||[]}}catch(a){return console.error(`Async fetch FBX load failed for ${e}, falling back to loader.load():`,a),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((a,r)=>{this.loader.load(e,o=>{a({object:o,animations:o.animations||[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>r(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone())}}};import{OBJLoader as H}from"three/addons/loaders/OBJLoader.js";import{MTLLoader as Y}from"three/addons/loaders/MTLLoader.js";var y=class{loader;mtlLoader;constructor(){this.loader=new H,this.mtlLoader=new Y}isSupported(e){return c(e)==="obj"}async load(e,t){return t?.mtlPath&&await this.loadMTL(t.mtlPath),new Promise((a,r)=>{this.loader.load(e,o=>{a({object:o,animations:[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>r(o))})}async loadMTL(e){return new Promise((t,a)=>{this.mtlLoader.load(e,r=>{r.preload(),this.loader.setMaterials(r),t()},void 0,r=>a(r))})}clone(e){return{object:u(e.object),animations:[]}}};import{AudioLoader as q}from"three";var x=class{loader;constructor(){this.loader=new q}isSupported(e){let t=c(e);return["mp3","ogg","wav","flac","aac","m4a"].includes(t||"")}async load(e,t){return new Promise((a,r)=>{this.loader.load(e,o=>a(o),o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>r(o))})}};import{FileLoader as Q}from"three";var m=class{loader;constructor(){this.loader=new Q}isSupported(e){return!0}async load(e,t){let a=t?.responseType??"text";return this.loader.setResponseType(a),new Promise((r,o)=>{this.loader.load(e,i=>r(i),i=>{t?.onProgress&&i.lengthComputable&&t.onProgress(i.loaded/i.total)},i=>o(i))})}},b=class{fileLoader;constructor(){this.fileLoader=new m}isSupported(e){return c(e)==="json"}async load(e,t){return await this.fileLoader.load(e,{...t,responseType:"json"})}};var w=class s{static instance=null;textureCache=new Map;modelCache=new Map;audioCache=new Map;fileCache=new Map;jsonCache=new Map;pendingGLTFRuntimePath=null;pendingGLTFRuntimePromise=null;pendingGLTFRuntimeResolve=null;textureLoader;gltfLoader;fbxLoader;objLoader;audioLoader;fileLoader;jsonLoader;loadingManager;events;stats={texturesLoaded:0,modelsLoaded:0,audioLoaded:0,filesLoaded:0,cacheHits:0,cacheMisses:0};constructor(){this.textureLoader=new L,this.gltfLoader=new g,this.fbxLoader=new T,this.objLoader=new y,this.audioLoader=new x,this.fileLoader=new m,this.jsonLoader=new b,this.loadingManager=new ee,this.loadingManager.onProgress=(e,t,a)=>{this.events.emit("batch:progress",{loaded:t,total:a})},this.events=R(),k.enabled=!0}static getInstance(){return s.instance||(s.instance=new s),s.instance}static resetInstance(){s.instance&&(s.instance.clearCache(),s.instance=null)}async loadTexture(e,t){return this.loadWithCache(e,"texture",this.textureCache,()=>this.textureLoader.load(e,t),t,a=>{if(!t?.clone)return a;let r=this.textureLoader.clone(a);return t.repeat&&r.repeat.copy(h(t.repeat,p)),t.wrapS!==void 0&&(r.wrapS=t.wrapS),t.wrapT!==void 0&&(r.wrapT=t.wrapT),r})}async loadGLTF(e,t){return await this.waitForPreparedGLTFRuntime(),this.loadWithCache(e,"gltf",this.modelCache,()=>this.gltfLoader.load(e,t),t,a=>t?.clone?this.gltfLoader.clone(a):a)}prepareGLTFRuntime(e){let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&(this.pendingGLTFRuntimePath===t&&this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePath=t,this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePromise=new Promise(a=>{this.pendingGLTFRuntimeResolve=a}))))}async configureGLTFRuntime(e){await this.gltfLoader.configureRuntime(e);let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&e?.renderer&&this.resolvePreparedGLTFRuntime(t)}async loadFBX(e,t){return this.loadWithCache(e,"fbx",this.modelCache,()=>this.fbxLoader.load(e,t),t,a=>t?.clone?this.fbxLoader.clone(a):a)}async loadOBJ(e,t){let a=t?.mtlPath?`${e}:${t.mtlPath}`:e;return this.loadWithCache(a,"obj",this.modelCache,()=>this.objLoader.load(e,t),t,r=>t?.clone?this.objLoader.clone(r):r)}async loadModel(e,t){let a=c(e);switch(a){case"gltf":case"glb":return this.loadGLTF(e,t);case"fbx":return this.loadFBX(e,t);case"obj":return this.loadOBJ(e,t);default:throw new Error(`Unsupported model format: ${a}`)}}async loadAudio(e,t){return this.loadWithCache(e,"audio",this.audioCache,()=>this.audioLoader.load(e,t),t)}async loadFile(e,t){let a=t?.responseType?`${e}:${t.responseType}`:e;return this.loadWithCache(a,"file",this.fileCache,()=>this.fileLoader.load(e,t),t)}async loadJSON(e,t){return this.loadWithCache(e,"json",this.jsonCache,()=>this.jsonLoader.load(e,t),t)}async loadBatch(e){let t=new Map,a=e.map(async r=>{try{let o;switch(r.type){case"texture":o=await this.loadTexture(r.url,r.options);break;case"gltf":o=await this.loadGLTF(r.url,r.options);break;case"fbx":o=await this.loadFBX(r.url,r.options);break;case"obj":o=await this.loadOBJ(r.url,r.options);break;case"audio":o=await this.loadAudio(r.url,r.options);break;case"file":o=await this.loadFile(r.url,r.options);break;case"json":o=await this.loadJSON(r.url,r.options);break;default:throw new Error(`Unknown asset type: ${r.type}`)}t.set(r.url,o)}catch(o){throw this.events.emit("asset:error",{url:r.url,type:r.type,error:o}),o}});return await Promise.all(a),this.events.emit("batch:complete",{urls:e.map(r=>r.url)}),t}async preload(e){await this.loadBatch(e)}isCached(e){return this.textureCache.has(e)||this.modelCache.has(e)||this.audioCache.has(e)||this.fileCache.has(e)||this.jsonCache.has(e)}clearCache(e){e?(this.textureCache.delete(e),this.modelCache.delete(e),this.audioCache.delete(e),this.fileCache.delete(e),this.jsonCache.delete(e)):(this.textureCache.clear(),this.modelCache.clear(),this.audioCache.clear(),this.fileCache.clear(),this.jsonCache.clear(),k.clear(),this.pendingGLTFRuntimePath=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimeResolve=null)}getStats(){return{...this.stats}}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}async loadWithCache(e,t,a,r,o,i){o?.forceReload&&a.delete(e);let n=a.get(e);if(n){this.stats.cacheHits++,this.events.emit("asset:loaded",{url:e,type:t,fromCache:!0});let l=await n.promise;return i?i(l):l}this.stats.cacheMisses++,this.events.emit("asset:loading",{url:e,type:t});let d=r(),f={promise:d,loadedAt:Date.now()};a.set(e,f);try{let l=await d;return f.result=l,this.updateStats(t),this.events.emit("asset:loaded",{url:e,type:t,fromCache:!1}),i?i(l):l}catch(l){throw a.delete(e),this.events.emit("asset:error",{url:e,type:t,error:l}),l}}updateStats(e){switch(e){case"texture":this.stats.texturesLoaded++;break;case"gltf":case"fbx":case"obj":this.stats.modelsLoaded++;break;case"audio":this.stats.audioLoaded++;break;case"file":case"json":this.stats.filesLoaded++;break}}async waitForPreparedGLTFRuntime(){this.pendingGLTFRuntimePromise&&await this.pendingGLTFRuntimePromise}resolvePreparedGLTFRuntime(e){this.pendingGLTFRuntimePath&&this.pendingGLTFRuntimePath!==e||(this.pendingGLTFRuntimeResolve?.(),this.pendingGLTFRuntimeResolve=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimePath=null)}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}},F=w.getInstance();import{uniform as Mt,uv as vt,time as Ot,vec3 as wt,vec4 as Ft,float as At,Fn as Pt}from"three/tsl";function re(s){return"colorNode"in s}function D(s){return"fragment"in s&&"vertex"in s}function oe(s){return!!s&&D(s)&&s.vertex===O.vertex&&s.fragment===O.fragment}var U=class s{static batchMaterialMap=new Map;static clearBatchCache(){s.batchMaterialMap.clear()}materials=[];useTSL;constructor(e=!0){this.useTSL=e}batchMaterial(e,t){let a=G(C(e)),r=s.batchMaterialMap.get(a);if(r){let o=r.geometryMap.get(t);o?r.geometryMap.set(t,o+1):r.geometryMap.set(t,1)}else s.batchMaterialMap.set(a,{geometryMap:new Map([[t,1]]),material:this.materials[0]})}build(e,t){let{path:a,normalMap:r,repeat:o,color:i,shader:n,opacity:d}=e,f=oe(n),l=!!n&&!f,S=!!a&&(!n||f);S?this.setTexture(a??null,o,!0,d,i):l&&n?re(n)?this.setTSLShader(n,d):D(n)&&(console.warn("MaterialBuilder: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(i??new A("#ffffff"),!0,d)):a&&this.setTexture(a,o,!0,d,i),i&&!S&&!l&&this.withColor(i,!0,d),this.materials.length===0&&this.setColor(new A("#ffffff"),!0,d),r&&this.materials.length>0&&this.setNormalMap(r,o),this.batchMaterial(e,t)}withColor(e,t=!1,a){return this.setColor(e,t,a),this}withShader(e,t){return this.setShader(e,t),this}withTSLShader(e,t){return this.setTSLShader(e,t),this}applyOpacity(e,t,a=!1){t!==void 0&&(e.opacity=t),e.transparent=a||t!==void 0&&t<1,e.needsUpdate=!0}setTexture(e=null,t=p,a=!0,r,o){if(!e)return;let i=new P;o&&(i.color=o),this.applyOpacity(i,r),this.materials.push(i),F.loadTexture(e,{clone:!0,repeat:h(t,p),colorSpace:te}).then(n=>{n.wrapS=v,n.wrapT=v,i.map=n,i.needsUpdate=!0})}setNormalMap(e,t=p){let a=this.materials[this.materials.length-1];a&&F.loadTexture(e,{clone:!0,repeat:h(t,p)}).then(r=>{r.wrapS=v,r.wrapT=v,a instanceof P&&(a.normalMap=r,a.needsUpdate=!0)})}setColor(e,t=!0,a){let r=new P;r.color=e,this.applyOpacity(r,a),this.materials.push(r)}setShader(e,t){console.warn("MaterialBuilder.setShader: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(new A("#ffffff"),!0,t)}setTSLShader(e,t){this.materials.push(se(e,t))}};function se(s,e){let t=new ae;return t.colorNode=s.colorNode,e!==void 0&&(t.opacity=e),t.transparent=!!s.transparent||e!==void 0&&e<1,t.needsUpdate=!0,t}export{B as a,O as b,M as c,c as d,F as e,re as f,D as g,U as h,se as i,Mt as j,vt as k,Ot as l,wt as m,Ft as n,At as o,Pt as p};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function u(i,e){return i.priority!==e.priority?i.priority-e.priority:i.sourceId.localeCompare(e.sourceId)}function s(i,e,d){let r=!1,y=0,l=!1,c=i,a=Number.NEGATIVE_INFINITY;for(let t of e){let o=t[d];if(o!=null){if(r=!0,t.mode==="add"){y+=o;continue}(!l||t.priority>=a)&&(l=!0,a=t.priority,c=o)}}return{touched:r,value:(l?c:0)+y}}function f(i,e){return{x:s(i.x,e,"x"),y:s(i.y,e,"y"),z:s(i.z,e,"z")}}function p(i){for(let e in i.velocityChannels)delete i.velocityChannels[e];i.dirty.velocityChannels=!1}function m(i,e){if(!i.body)return;let d=e.dirty.position,r=e.dirty.rotation,y=e.dirty.angularVelocity,l=e.dirty.velocityX||e.dirty.velocityY||e.dirty.velocityZ,c=e.dirty.velocity,a=e.dirty.velocityChannels;if(!d&&!r&&!y&&!l&&!c&&!a)return;let t=[];if(a)for(let o in e.velocityChannels){let n=e.velocityChannels[o];t.push({sourceId:o,mode:n.mode??"replace",priority:n.priority??0,x:n.x,y:n.y,z:n.z})}if(c?t.push({sourceId:"__legacy_velocity__",mode:"replace",priority:-100,x:e.velocity.x,y:e.velocity.y,z:e.velocity.z}):l&&t.push({sourceId:"__legacy_per_axis__",mode:"replace",priority:-100,x:e.dirty.velocityX?e.velocity.x:void 0,y:e.dirty.velocityY?e.velocity.y:void 0,z:e.dirty.velocityZ?e.velocity.z:void 0}),t.length>0){let o=i.body.linvel();t.length>1&&t.sort(u);let n=f(o,t);i.body.setLinvel({x:n.x.touched?n.x.value:o.x,y:n.y.touched?n.y.value:o.y,z:n.z.touched?n.z.value:o.z},!0)}if(r&&i.body.setRotation(e.rotation,!0),y&&i.body.setAngvel(e.angularVelocity,!0),d){let o=i.body.translation();i.body.setTranslation({x:o.x+e.position.x,y:o.y+e.position.y,z:o.z+e.position.z},!0)}e.dirty.position=!1,e.dirty.rotation=!1,e.dirty.velocity=!1,e.dirty.velocityX=!1,e.dirty.velocityY=!1,e.dirty.velocityZ=!1,p(e),e.dirty.angularVelocity=!1}export{m as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Vector2 as x,Vector3 as b}from"three";import{Vector3 as f}from"@dimforge/rapier3d-compat";var i=Object.freeze({x:0,y:0}),k=Object.freeze({x:1,y:1}),p=Object.freeze({x:0,y:0,z:0}),A=Object.freeze({x:1,y:1,z:1});function V(n){return typeof n=="number"&&Number.isFinite(n)}function a(n){return n!=null&&typeof n=="object"&&("x"in n||"y"in n)}function l(n){return n!=null&&typeof n=="object"&&("x"in n||"y"in n||"z"in n)}function m(n,t,e){if(!n)return e;let r=n[t];return V(r)?r:e}function y(n,t,e){if(!n)return e;let r=n[t];return V(r)?r:e}function u(n,t,e,r){return n?Array.isArray(n)?m(n,e,r):y(n,t,r):r}function o(n,t,e,r){return n?Array.isArray(n)?m(n,e,r):y(n,t,r):r}function z(n){return{x:u(n,"x",0,0),y:u(n,"y",1,0)}}function C(n){return{x:o(n,"x",0,0),y:o(n,"y",1,0),z:o(n,"z",2,0)}}function h(n){return Array.isArray(n)||a(n)}function T(n){return Array.isArray(n)||l(n)}function I(n,t=i){let e=z(t);return{x:u(n,"x",0,e.x),y:u(n,"y",1,e.y)}}function s(n,t=p){let e=C(t);return{x:o(n,"x",0,e.x),y:o(n,"y",1,e.y),z:o(n,"z",2,e.z)}}function R(n,t=i){let{x:e,y:r}=I(n,t);return new x(e,r)}function O(n,t=p){let{x:e,y:r,z:c}=s(n,t);return new b(e,r,c)}function P(n,t=p){let{x:e,y:r,z:c}=s(n,t);return new f(e,r,c)}export{i as a,k as b,p as c,A as d,h as e,T as f,I as g,s as h,R as i,O as j,P as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(n,e){return{[n]:{key:e}}}function k(n){return r(n,{ArrowLeft:["axes.Left"],ArrowRight:["axes.Right"],ArrowUp:["axes.Up"],ArrowDown:["axes.Down"]})}function x(n){return r(n,{ArrowLeft:["axes.SecondaryLeft"],ArrowRight:["axes.SecondaryRight"],ArrowUp:["axes.SecondaryUp"],ArrowDown:["axes.SecondaryDown"]})}function w(n){return r(n,{ArrowLeft:["directions.Left"],ArrowRight:["directions.Right"],ArrowUp:["directions.Up"],ArrowDown:["directions.Down"]})}function A(n){return r(n,{w:["directions.Up"],s:["directions.Down"],a:["directions.Left"],d:["directions.Right"]})}function G(n){return r(n,{a:["axes.Left"],d:["axes.Right"],w:["axes.Up"],s:["axes.Down"]})}function J(n){return r(n,{j:["axes.Left"],l:["axes.Right"],i:["axes.Up"],k:["axes.Down"]})}function B(n){return r(n,{j:["directions.Left"],l:["directions.Right"],i:["directions.Up"],k:["directions.Down"]})}function D(n,e){return{[n]:{mouse:{pointerLock:!0,sensitivity:e?.sensitivity}}}}function P(n,e){return{[n]:{mouse:{pointerLock:!1,sensitivity:e?.sensitivity}}}}function b(n,e){return{[n]:{touch:{enabled:e?.enabled??"auto",...e}}}}var h=["p1","p2","p3","p4","p5","p6","p7","p8"];function L(...n){let e={};for(let u of n)for(let t of h){let s=u[t];if(!s)continue;let o=e[t]??{},f=o.mouse||s.mouse?{...o.mouse,...s.mouse,mapping:{...o.mouse?.mapping,...s.mouse?.mapping}}:void 0,a=T(o.touch,s.touch);e[t]={key:{...o.key,...s.key},mouse:f,touch:a,includeDefaults:s.includeDefaults??o.includeDefaults}}return e}function T(n,e){if(!(!n&&!e))return n?e?{...n,...e,style:i(n.style,e.style),joysticks:m(n.joysticks,e.joysticks),buttons:I(n.buttons,e.buttons)}:d(n):d(e)}function m(n,e){if(e===void 0)return p(n);if(e===!1)return!1;let u=n||void 0;return{left:c(u?.left,e.left),right:c(u?.right,e.right)}}function c(n,e){return e===void 0?l(n):e===!1?!1:n?{...n,...e,style:i(n.style,e.style),position:i(n.position,e.position),svg:i(n.svg,e.svg)}:l(e)}function I(n,e){if(e===void 0)return y(n);if(e===!1)return!1;let u=n||void 0,t=u?C(u):{};for(let[s,o]of Object.entries(e)){let f=s,a=t[f];if(o===!1){t[f]=!1;continue}if(!a){t[f]=g(o);continue}t[f]={...a,...o,style:i(a.style,o.style),position:i(a.position,o.position)}}return t}function d(n){if(n)return{...n,style:i(void 0,n.style),joysticks:p(n.joysticks),buttons:y(n.buttons)}}function p(n){if(n!==void 0)return n===!1?!1:V(n)}function l(n){if(n!==void 0)return n===!1?!1:{...n,style:i(void 0,n.style),position:i(void 0,n.position),svg:i(void 0,n.svg)}}function y(n){if(n!==void 0)return n===!1?!1:C(n)}function g(n){return{...n,style:i(void 0,n.style),position:i(void 0,n.position)}}function V(n){return{left:l(n.left),right:l(n.right)}}function C(n){let e={};for(let[u,t]of Object.entries(n))e[u]=t===!1?!1:g(t);return e}function i(n,e){if(!(!n&&!e))return{...n??{},...e??{}}}export{k as a,x as b,w as c,A as d,G as e,J as f,B as g,D as h,P as i,b as j,L as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as f,k as F,m as x,p as g,q as z,s as _}from"./chunk-ONWXGBWB.js";import{c as I}from"./chunk-DR6XXZE7.js";import{d as y,i as C,j as d}from"./chunk-G2IIMSUH.js";import{Color as M,Group as W,Sprite as U,SpriteMaterial as Y,CanvasTexture as R,LinearFilter as S,Vector2 as X,ClampToEdgeWrapping as P}from"three";import{MeshStandardMaterial as k,MeshBasicMaterial as V,MeshPhongMaterial as H}from"three";function B(r){return r&&typeof r.getDebugInfo=="function"}var m=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:s,y:n,z:o}=this.entity.mesh.position;return`${s.toFixed(2)}, ${n.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:i}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${i.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:n,y:o,z:p}=this.entity.mesh.rotation,a=c=>(c*180/Math.PI).toFixed(1);return`${a(n)}\xB0, ${a(o)}\xB0, ${a(p)}\xB0`}let{x:t,y:e,z:i}=this.entity.options.rotation||{x:0,y:0,z:0},s=n=>(n*180/Math.PI).toFixed(1);return`${s(t)}\xB0, ${s(e)}\xB0, ${s(i)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof k||t instanceof V||t instanceof H)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),B(this.entity)){let i=this.entity.getDebugInfo();return{...t,...i}}return t}};var h={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new X(24,24),zDistance:1},b=class extends _{createEntity(t){return new l(t)}},N=Symbol("Text"),l=class r extends x{static type=N;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=f(h,t),this.options.screenPosition=C(this.options.screenPosition,h.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new W,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new R(this._canvas),this._texture.minFilter=S,this._texture.magFilter=S;let t=new Y({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new U(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,i,s){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${i}`;let n=this._ctx.measureText(t),o=Math.ceil(n.width),p=Math.ceil(e*1.4),a=Math.max(2,o+s*2),c=Math.max(2,p+s*2),v=a!==this._lastCanvasW||c!==this._lastCanvasH;return this._canvas.width=a,this._canvas.height=c,this._lastCanvasW=a,this._lastCanvasH=c,{sizeChanged:v}}drawCenteredText(t,e,i){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${i}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new R(this._canvas),this._texture.minFilter=S,this._texture.magFilter=S,this._texture.wrapS=P,this._texture.wrapT=P),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))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,i=this.options.fontFamily??h.fontFamily,s=this.options.padding??4,{sizeChanged:n}=this.measureAndResizeCanvas(t,e,i,s);this.drawCenteredText(t,e,i),this.updateTexture(!!n),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof M?t:new M(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,i){let s=t.x>=0&&t.x<=1,n=t.y>=0&&t.y<=1;return{px:s?t.x*e:t.x,py:n?t.y*i:t.y}}computeWorldExtents(t,e){let i=1,s=1;if(t.isPerspectiveCamera){let n=t,o=Math.tan(n.fov*Math.PI/180/2)*e;i=o*n.aspect,s=o}else if(t.isOrthographicCamera){let n=t;i=(n.right-n.left)/2,s=(n.top-n.bottom)/2}return{worldHalfW:i,worldHalfH:s}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let s=t*2/e,n=this._canvas.height,o=Math.max(1e-4,n*s),p=this._canvas.width/this._canvas.height,a=o*p;this._sprite.scale.set(a,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),i=Math.max(.25,e/32),s=i*t;this._sprite.scale.set(s,i,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:i}=this.getResolution(),s=C(this.options.screenPosition,h.screenPosition),{px:n,py:o}=this.getScreenPixels(s,e,i),p=Math.max(.001,this.options.zDistance??1),{worldHalfW:a,worldHalfH:c}=this.computeWorldExtents(t,p),v=n/e*2-1,D=1-o/i*2,G=v*a,$=D*c;this.group?.position.set(G,$,-p),this.updateSpriteScale(c,i)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new m(this).buildDebugInfo(),type:String(r.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function E(...r){return g({args:r,defaultConfig:{...h},EntityClass:l,BuilderClass:b,entityType:l.type,cloneFactory:t=>E(t??{})})}import{ColliderDesc as L}from"@dimforge/rapier3d-compat";import{Euler as Q,Group as q,Quaternion as j,Vector3 as J}from"three";import{TextureLoader as K,SpriteMaterial as tt,Sprite as et,SRGBColorSpace as it}from"three";var A={...F,size:new J(1,1,1),images:[],animations:[]},T=class extends z{collider(t){let e=d(t.collisionSize,t.size??y),i={x:e.x/2,y:e.y/2,z:e.z/2};return L.cuboid(i.x,i.y,i.z)}},w=class extends _{createEntity(t){return new u(t)}},nt=Symbol("Sprite"),u=class r extends x{static type=nt;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;constructor(t){super(),this.options=f(A,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.group=void 0,this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new K,i=d(this.options.size,y);t.forEach((s,n)=>{let o=e.load(s.file);o.colorSpace=it,o.anisotropy=I;let p=new tt({map:o,transparent:!0}),a=new et(p);a.position.normalize(),a.scale.set(i.x,i.y,i.z),a.visible=n===0,this.sprites.push(a),this.spriteMap.set(s.name,n)}),this.group=new q,this.group.add(...this.sprites)}createAnimations(t){t.forEach(e=>{let{name:i,frames:s,loop:n=!1,speed:o=1}=e,p={frames:s.map((a,c)=>({key:a,index:c,time:(typeof o=="number"?o:o[c])*(c+1),duration:typeof o=="number"?o:o[c]})),loop:n};this.animations.set(i,p)})}setSprite(t){let i=this.spriteMap.get(t)??0;this.currentSpriteIndex=i,this.sprites.forEach((s,n)=>{s.visible=this.currentSpriteIndex===n})}setAnimation(t,e){let i=this.animations.get(t);if(!i)return;let{loop:s,frames:n}=i,o=n[this.currentAnimationIndex];t===this.currentAnimation?(this.currentAnimationFrame=o.key,this.currentAnimationTime+=e,this.setSprite(this.currentAnimationFrame)):this.currentAnimation=t,this.currentAnimationTime>o.time&&this.currentAnimationIndex++,this.currentAnimationIndex>=n.length&&(s?(this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime=n[this.currentAnimationIndex].time)}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let s=new j(t.x,t.y,t.z,t.w),n=new Q().setFromQuaternion(s,"XYZ");e.material.rotation=n.z}let i=d(this.options.size,y);e.scale.set(i.x,i.y,i.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent()}buildInfo(){return{...new m(this).buildDebugInfo(),type:String(r.type)}}};function O(...r){return g({args:r,defaultConfig:A,EntityClass:u,BuilderClass:w,CollisionBuilderClass:T,entityType:u.type,cloneFactory:t=>O(t??{})})}var Z={registry:new Map,register(r,t){this.registry.set(r,t)},createFromBlueprint(r){let t=this.registry.get(r.type);if(!t)throw new Error(`Unknown entity type: ${r.type}`);let e={...r.data,position:r.position?{x:r.position[0],y:r.position[1],z:0}:void 0,name:r.id};return t(e)}};Z.register("text",r=>E(r));Z.register("sprite",r=>O(r));function Dt(r){return{template:r,generate(t){let e=[];for(let i=0;i<t;i++)e.push(r.clone());return e}}}export{m as a,N as b,l as c,E as d,nt as e,u as f,O as g,Z as h,Dt as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as L,d as be,e as P,h as ge}from"./chunk-DR6XXZE7.js";import{a as ae,b as le}from"./chunk-YHEWKN7N.js";import{a as me,b as fe,c as ye}from"./chunk-73VZQZUL.js";import{c as E,d as T,e as ce,f as $,g as ue,h,i as pe,j as z,k as de}from"./chunk-G2IIMSUH.js";import{p as he}from"./chunk-XRP4JJXL.js";import{ActiveCollisionTypes as Oe,ColliderDesc as A,RigidBodyDesc as Xe,RigidBodyType as xe}from"@dimforge/rapier3d-compat";import{Vector3 as We}from"three";import{Color as Ye,Vector2 as Ce,Vector3 as ve}from"three";import{Vector3 as q}from"@dimforge/rapier3d-compat";function B(o){if(!o||typeof o!="object")return!1;let e=Object.getPrototypeOf(o);return e===Object.prototype||e===null}function u(o){if(o==null||typeof o=="function"||typeof o!="object")return o;if(o instanceof Ye||o instanceof Ce||o instanceof ve)return o.clone();if(o instanceof q)return new q(o.x,o.y,o.z);if(o instanceof Float32Array)return new Float32Array(o);if(Array.isArray(o))return o.map(e=>u(e));if(B(o)){let e={};for(let[t,i]of Object.entries(o))t!=="_builders"&&(e[t]=u(i));return e}return o}function g(o,e){let t=u(o);if(!e)return t;if(!B(t)||!B(e))return u(e);let i=t;for(let[n,s]of Object.entries(e)){if(n==="_builders"||s===void 0)continue;let r=i[n];if(n==="shader"){i[n]=u(s);continue}if(r instanceof Ce&&ce(s)){i[n]=pe(s,r);continue}if(r instanceof ve&&$(s)){i[n]=z(s,r);continue}if(r instanceof q&&$(s)){i[n]=de(s,r);continue}if(B(r)&&B(s)){i[n]=g(r,s);continue}i[n]=u(s)}return i}function Ee(o){return o&&o.__kind==="collision"}function J(o){return o.cloneComponent()}function $e(o){let e=o?xe.Fixed:xe.Dynamic;return new Xe(e).setTranslation(0,0,0).setGravityScale(1).setCanSleep(!1).setCcdEnabled(!0)}function qe(o,e){if(e.offset){let t=h(e.offset,E);o.setTranslation(t.x,t.y,t.z)}if(e.sensor&&(o.setSensor(!0),o.activeCollisionTypes=Oe.KINEMATIC_FIXED),e.collisionType){let t=me(e.collisionType),i=65535;e.collisionFilter&&(i=fe(e.collisionFilter)),o.setCollisionGroups(t<<16|i)}}function S(o,e,t){return qe(o,e),{__kind:"collision",bodyDesc:$e(e.static??!1),colliderDesc:o,cloneComponent:t}}function Je(o={}){let e=h(o.size,T),t=A.cuboid(e.x/2,e.y/2,e.z/2),i=u(o);return S(t,o,()=>Je(i))}function Qe(o={}){let e=A.ball(o.radius??1),t=u(o);return S(e,o,()=>Qe(t))}function et(o={}){let e=o.radius??1,t=o.height??2,i=A.cone(t/2,e),n=u(o);return S(i,o,()=>et(n))}function tt(o={}){let e=o.radius??1,t=o.height??2,i=A.cone(t/2,e),n=u(o);return S(i,o,()=>tt(n))}function it(o={}){let e=Math.max(o.radiusTop??1,o.radiusBottom??1),t=o.height??2,i=A.cylinder(t/2,e),n=u(o);return S(i,o,()=>it(n))}function ot(o={}){let e=o.radius??.5,t=o.length??1,i=A.capsule(t/2,e),n=u(o);return S(i,o,()=>ot(n))}function nt(o={}){let e=ue(o.tile,{x:10,y:10}),t=o.subdivisions??10,i=new We(e.x,1,e.y),n=(t+1)*(t+1),s=o.heightData??new Float32Array(n),r=A.heightfield(t,t,s,i),a={...o,static:o.static??!0},l=u(a);return S(r,a,()=>nt(l))}function st(o={}){let e=h(o.size,T),t=A.cuboid(e.x/2,e.y/2,e.z/2);t.setSensor(!0),t.activeCollisionTypes=Oe.KINEMATIC_FIXED;let i={...o,static:o.static??!0,sensor:!0},n=u(i);return S(t,i,()=>st(n))}import{Mesh as Se,ShaderMaterial as pt,Group as dt}from"three";var _e=import.meta.env.VITE_DEBUG_FLAG==="true";import{nanoid as rt}from"nanoid";var v=class o{parent=null;children=[];options;uuid="";name="";markedForRemoval=!1;lifecycleCallbacks={setup:[],loaded:[],update:[],destroy:[],cleanup:[]};trackLifecycleRegistrations=!1;userLifecycleRegistrations=[];constructor(e=[]){let t=e.filter(i=>!(i instanceof o)).reduce((i,n)=>({...i,...n}),{});this.options=t,this.uuid=rt()}onSetup(...e){return this.lifecycleCallbacks.setup.push(...e),this.recordLifecycleRegistration("onSetup",e),this}onLoaded(...e){return this.lifecycleCallbacks.loaded.push(...e),this.recordLifecycleRegistration("onLoaded",e),this}onUpdate(...e){return this.lifecycleCallbacks.update.push(...e),this.recordLifecycleRegistration("onUpdate",e),this}onDestroy(...e){return this.lifecycleCallbacks.destroy.push(...e),this.recordLifecycleRegistration("onDestroy",e),this}onCleanup(...e){return this.lifecycleCallbacks.cleanup.push(...e),this.recordLifecycleRegistration("onCleanup",e),this}prependSetup(...e){return this.lifecycleCallbacks.setup.unshift(...e),this.recordLifecycleRegistration("prependSetup",e),this}prependUpdate(...e){return this.lifecycleCallbacks.update.unshift(...e),this.recordLifecycleRegistration("prependUpdate",e),this}setParent(e){this.parent=e}getParent(){return this.parent}add(e){this.children.push(e),e.setParent(this)}remove(e){let t=this.children.indexOf(e);t!==-1&&(this.children.splice(t,1),e.setParent(null))}getChildren(){return this.children}isComposite(){return this.children.length>0}enableUserLifecycleTracking(){this.trackLifecycleRegistrations=!0}replayUserLifecycleRegistrationsTo(e,t){for(let i of this.userLifecycleRegistrations){let n=t?i.callbacks.map(s=>t(s)):[...i.callbacks];switch(i.method){case"onSetup":e.onSetup(...n);break;case"onLoaded":e.onLoaded(...n);break;case"onUpdate":e.onUpdate(...n);break;case"onDestroy":e.onDestroy(...n);break;case"onCleanup":e.onCleanup(...n);break;case"prependSetup":e.prependSetup(...n);break;case"prependUpdate":e.prependUpdate(...n);break}}}cloneChildrenInto(e){for(let t of this.children)e.add(at(t))}nodeSetup(e){this.markedForRemoval=!1,typeof this._setup=="function"&&this._setup(e);for(let t of this.lifecycleCallbacks.setup)t(e);this.children.forEach(t=>t.nodeSetup(e))}nodeUpdate(e){if(!this.markedForRemoval){typeof this._update=="function"&&this._update(e),typeof this._tickActions=="function"&&this._tickActions(e.delta);for(let t of this.lifecycleCallbacks.update)t(e);this.children.forEach(t=>t.nodeUpdate(e))}}nodeDestroy(e){if(!this.markedForRemoval){this.children.forEach(t=>t.nodeDestroy(e));for(let t of this.lifecycleCallbacks.destroy)t(e);typeof this._destroy=="function"&&this._destroy(e),this.markedForRemoval=!0;for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}}async nodeLoaded(e){typeof this._loaded=="function"&&await this._loaded(e);for(let t of this.lifecycleCallbacks.loaded)t(e)}nodeCleanup(e){this.children.forEach(t=>t.nodeCleanup?.(e));for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}getOptions(){return this.options}setOptions(e){this.options={...this.options,...e}}recordLifecycleRegistration(e,t){!this.trackLifecycleRegistrations||t.length===0||this.userLifecycleRegistrations.push({method:e,callbacks:[...t]})}};function at(o){let e=o?.clone;if(typeof e!="function")throw new Error(`Cannot clone child node "${o.name||o.uuid||"unknown"}": missing clone() support.`);return e.call(o)}import{createTransformStore as ht}from"@zylem/behaviors/core";import{makeMoveable as lt}from"@zylem/behaviors/core";function Ae(o){let e=lt(o);return he(e)}import{clearVelocityIntent as De}from"@zylem/behaviors/core";import{Color as ct,Vector3 as ut}from"three";var V={position:new ut(0,0,0),material:{color:new ct("#ffffff"),shader:L},collision:{static:!1}};function ki(o,e){let t=o.filter(n=>!(n instanceof v)),i=g(e);for(let n of t)i=g(i,n);return i}function mt(o){return o!=null&&typeof o=="object"}function Me(o){return{phase:o?.phase??"stay",cooldownMs:o?.cooldownMs}}function ft(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var M=class extends v{group;mesh;materials;bodyDesc=null;body=null;physicsAttached=!1;colliderDesc;collider;custom={};colliderDescs=[];colliders=[];compoundMeshes=[];debugInfo={};debugMaterial;collisionDelegate={collision:[],cooldowns:new Map,nextId:0};collisionType;batchKey=null;instanceId=-1;isInstanced=!1;runtimeSlot=-1;runtimeHandle=-1;runtimeAttached=!1;wasmStageRef=null;eventDelegate=new ae;behaviorRefs=[];cloneFactory=null;trackAddedComponents=!1;trackedComponents=[];transformStore;moveX;moveY;moveZ;moveXY;moveXZ;move;resetVelocity;moveForwardXY;getPosition;getVelocity;setPosition;setPositionX;setPositionY;setPositionZ;wrapAroundXY;wrapAround3D;rotateInDirection;rotateYEuler;rotateEuler;rotateX;rotateY;rotateZ;setRotationY;setRotationX;setRotationZ;setRotationDegrees;setRotationDegreesY;setRotationDegreesX;setRotationDegreesZ;setRotation;getRotation;constructor(){super(),this.transformStore=ht(),Ae(this)}getPose(){if(this.wasmStageRef&&this.runtimeHandle>=0){let n=this.wasmStageRef.getPose(this.runtimeHandle);if(n)return{position:{x:n.position[0],y:n.position[1],z:n.position[2]},rotation:{x:n.rotation[0],y:n.rotation[1],z:n.rotation[2],w:n.rotation[3]}}}let e=this.body;if(!e)return null;let t=e.translation(),i=e.rotation();return{position:{x:t.x,y:t.y,z:t.z},rotation:{x:i.x,y:i.y,z:i.z,w:i.w}}}setPose(e){if(this.wasmStageRef&&this.runtimeHandle>=0){let i=!0;if(e.position){let n=h(e.position);i=this.wasmStageRef.setPosition(this.runtimeHandle,n.x,n.y,n.z)&&i}if(e.rotation){let{x:n,y:s,z:r,w:a}=e.rotation;i=this.wasmStageRef.setRotation(this.runtimeHandle,n,s,r,a)&&i}return i}let t=this.body;if(!t)return!1;if(e.position){let i=h(e.position);t.setTranslation({x:i.x,y:i.y,z:i.z},!0)}return e.rotation&&t.setRotation(e.rotation,!0),!0}add(...e){for(let t of e)t instanceof Se?(this.addMeshComponent(t),this.trackComponent(t)):Ee(t)?(this.addCollisionComponent(t),this.trackComponent(t)):super.add(t);return this}addMeshComponent(e){if(this.mesh)this.compoundMeshes.push(e),this.group||(this.group=new dt,this.group.add(this.mesh)),this.group.add(e);else if(this.mesh=e,this.materials||(this.materials=[]),e.material){let t=e.material;Array.isArray(t)?this.materials.push(...t):this.materials.push(t)}}addCollisionComponent(e){if(this.bodyDesc)this.colliderDescs.push(e.colliderDesc);else{this.bodyDesc=e.bodyDesc,this.colliderDesc=e.colliderDesc,this.colliderDescs.push(e.colliderDesc);let t=h(this.options?.position,E);this.bodyDesc.setTranslation(t.x,t.y,t.z)}}trackComponent(e){if(this.trackAddedComponents){if(e instanceof Se){this.trackedComponents.push({kind:"mesh",component:Fe(e)});return}this.trackedComponents.push({kind:"collision",component:J(e)})}}_actions=[];runAction(e){return this._actions.push(e),e}action(e){return e.persistent=!0,this._actions.push(e),e}clearActions(){this._actions.length=0}_tickActions(e){if(this._actions.length===0)return;let t=this.transformStore;t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,De(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1;for(let i=this._actions.length-1;i>=0;i--){let n=this._actions[i];n.tick(this,e),n.done&&!n.persistent&&this._actions.splice(i,1)}this._actions.length===0&&(t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,De(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1)}create(){return this.name=this.options.name||"",this}clone(e){if(!this.cloneFactory)throw new Error(`Cannot clone ${this.constructor.name}: clone() is only supported for entities created by official factory helpers.`);let t=this.cloneFactory(g(this.options,e)),i=this.copyBehaviorRefsTo(t),n=r=>bt(r,i);this.replayUserLifecycleRegistrationsTo(t,n);let s=this.getCollisionRegistrations();if(s.length>0)for(let r of s)t.onCollision(n(r.callback),r.options);for(let r of this.trackedComponents){if(r.kind==="mesh"){t.add(Fe(r.component));continue}t.add(J(r.component))}return this.cloneChildrenInto(t),t}finalizeCloneSupport(e){return this.cloneFactory=e,this.enableUserLifecycleTracking(),this.trackAddedComponents=!0,this}onCollision(...e){let t=[...this.collisionDelegate.collision??[]],i=this.collisionDelegate.nextId??0;if(e.length===1||e.length===2&&(e[1]==null||mt(e[1]))){let n=e[0];if(!n)return this;let s=e[1];return t.push({id:i,callback:n,options:Me(s)}),i+=1,this.collisionDelegate.collision=t,this.collisionDelegate.nextId=i,this}for(let n of e)t.push({id:i,callback:n,options:Me()}),i+=1;return this.collisionDelegate.collision=t,this.collisionDelegate.nextId=i,this}use(e,t){let i={descriptor:e,options:{...e.defaultOptions,...t}};this.behaviorRefs.push(i);let n={getFSM:()=>i.fsm??null,getOptions:()=>i.options,ref:i},s=e.createHandle?.(i)??{};return{...n,...s}}getBehaviorRefs(){return this.behaviorRefs}getCollisionCallbacks(){return this.getCollisionRegistrations().map(e=>e.callback)}getCollisionRegistrations(){return(this.collisionDelegate.collision??[]).map(e=>({id:e.id,callback:e.callback,options:{...e.options}}))}copyBehaviorRefsTo(e){let t=new Map;for(let i of this.behaviorRefs){e.use(i.descriptor,u(i.options));let n=e.getBehaviorRefs().at(-1);n&&t.set(i,n)}return t}_setup(e){for(let t=this._actions.length-1;t>=0;t--){let i=this._actions[t];i.done&&!i.persistent?this._actions.splice(t,1):i.reset()}}async _loaded(e){}_update(e){this.updateMaterials(e)}_destroy(e){}_cleanup(e){this.disposeEvents();for(let t of this.compoundMeshes)t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(i=>i.dispose()):t.material?.dispose();this.compoundMeshes.length=0,this.debugMaterial?.dispose(),this.debugMaterial=void 0,this.group?.removeFromParent()}_collision(e,t,i={phase:"stay",nowMs:ft()}){if(!this.collisionDelegate.collision?.length)return;let n=this.collisionDelegate.cooldowns??new Map;this.collisionDelegate.cooldowns=n;for(let s of this.collisionDelegate.collision){if(s.options.phase!==i.phase)continue;let r=s.options.cooldownMs;if(r!=null){let a=`${s.id}:${e.uuid}`,l=n.get(a);if(l!=null&&i.nowMs-l<r)continue;n.set(a,i.nowMs)}s.callback({entity:this,other:e,globals:t})}}updateMaterials(e){if(this.materials?.length)for(let t of this.materials)t instanceof pt&&t.uniforms&&t.uniforms.iTime&&(t.uniforms.iTime.value+=e.delta)}buildInfo(){let e={};return e.name=this.name,e.uuid=this.uuid,e}dispatch(e,t){this.eventDelegate.dispatch(e,t),le.emit(e,t)}listen(e,t){return this.eventDelegate.listen(e,t)}disposeEvents(){this.eventDelegate.dispose()}};function yt(o){let e=new M;return e.options={...V,...o},Q(e,t=>yt(t??{}))}function Fe(o){let e=o.clone(!0),t=[],i=[];o.traverse(n=>t.push(n)),e.traverse(n=>i.push(n));for(let n=0;n<t.length;n++){let s=t[n],r=i[n];s?.geometry?.clone&&(r.geometry=s.geometry.clone()),s?.material&&(r.material=Array.isArray(s.material)?s.material.map(a=>a.clone()):s.material.clone())}return e}function bt(o,e){return e.size===0?o:((...t)=>{let i=Array.from(e.entries()).map(([n,s])=>({sourceRef:n,options:n.options,fsm:n.fsm,hasFSM:Object.prototype.hasOwnProperty.call(n,"fsm"),targetRef:s}));for(let n of i)n.sourceRef.options=n.targetRef.options,n.targetRef.fsm===void 0?delete n.sourceRef.fsm:n.sourceRef.fsm=n.targetRef.fsm;try{return o(...t)}finally{for(let n=i.length-1;n>=0;n--){let s=i[n];s.sourceRef.options=s.options,s.hasFSM?s.sourceRef.fsm=s.fsm:delete s.sourceRef.fsm}}})}function Q(o,e){return o.finalizeCloneSupport(e),o}function Te(o){return typeof o?.load=="function"&&typeof o?.data=="function"}var G=class{entityReference;constructor(e){this.entityReference=e}load(){this.entityReference.load&&this.entityReference.load()}data(){return this.entityReference.data?this.entityReference.data():null}};function Re(o){let{args:e,defaultConfig:t,EntityClass:i,BuilderClass:n,entityType:s,MeshBuilderClass:r,CollisionBuilderClass:a,cloneFactory:l}=o,d=null,m,f=e.findIndex(p=>!(p instanceof v));f!==-1&&(m=e.splice(f,1).find(C=>!(C instanceof v)));let y=m?g(t,m):g(t);e.push(y);for(let p of e){if(p instanceof v)continue;let C=null,O=new i(p);try{if(Te(O)){let c=new G(O);c.load(),C=c.data()}}catch(c){console.error("Error creating entity with loader:",c)}d=new n(p,O,r?new r(C):null,a?new a(C):null),p.material&&d.withMaterial(p.material,s)}if(!d)throw new Error(`missing options for ${String(s)}, builder is not initialized.`);return Q(d.build(),p=>l(p))}import{ActiveCollisionTypes as Y,ColliderDesc as X}from"@dimforge/rapier3d-compat";import{Box3 as je,BufferAttribute as Dt,SkinnedMesh as Mt,MeshStandardMaterial as Ft,Group as Tt,Vector3 as K,Matrix4 as Rt}from"three";var R=class{async loadFile(e,t){switch(be(e)){case"fbx":{let n=await P.loadFBX(e,t);return{object:n.object,animation:n.animations?.[0]}}case"gltf":case"glb":{let n=await P.loadGLTF(e,t);return{object:n.object,gltf:n.gltf}}case"obj":return{object:(await P.loadOBJ(e,t)).object};default:throw new Error(`Unsupported file type: ${e}`)}}};import{AnimationMixer as gt,Bone as Be,LoopOnce as Ct,LoopRepeat as vt}from"three";function xt(o){let e=o.lastIndexOf(".");return e>=0?o.slice(0,e):o}function Ot(o,e){if(!o?.name?.endsWith(".position"))return!1;let t=xt(o.name),i=e.get(t);return i instanceof Be?!(i.parent instanceof Be):/hips\.position$/i.test(o.name)||/root\.position$/i.test(o.name)}function Et(o,e,t){for(let i of o.tracks){if(!Ot(i,e)||!i.values||i.values.length<3)continue;let n=i.values[0],s=i.values[1],r=i.values[2];for(let a=0;a<i.values.length;a+=3)i.values[a]=n,t&&(i.values[a+1]=s),i.values[a+2]=r}return o}var I=class{constructor(e){this.target=e}_mixer=null;_actions={};_animations=[];_currentAction=null;_pauseAtPercentage=0;_isPaused=!1;_queuedKey=null;_fadeDuration=.5;_currentKey="";_assetLoader=new R;async loadAnimations(e,t={}){if(!e.length)return;let i=t.stripRootMotionY??!1,n=await Promise.all(e.map(a=>this._assetLoader.loadFile(a.path))),s=new Map;this.target.traverse(a=>{a.name&&s.set(a.name,a)});let r=[];n.forEach((a,l)=>{a.animation&&r.push({key:e[l].key||l.toString(),clip:Et(a.animation,s,i)})}),r.length&&(this._animations=r.map(a=>a.clip),this._mixer=new gt(this.target),r.forEach(({key:a,clip:l})=>{this._actions[a]=this._mixer.clipAction(l)}),this.playAnimation({key:r[0].key}))}update(e){if(!this._mixer||!this._currentAction)return;this._mixer.update(e);let t=this._currentAction.getClip().duration*(this._pauseAtPercentage/100);if(!this._isPaused&&this._pauseAtPercentage>0&&this._currentAction.time>=t&&(this._currentAction.time=t,this._currentAction.paused=!0,this._isPaused=!0,this._queuedKey!==null)){let i=this._actions[this._queuedKey];i.reset().play(),this._currentAction.crossFadeTo(i,this._fadeDuration,!1),this._currentAction=i,this._currentKey=this._queuedKey,this._queuedKey=null}}playAnimation(e){if(!this._mixer)return;let{key:t,pauseAtPercentage:i=0,pauseAtEnd:n=!1,fadeToKey:s,fadeDuration:r=.5}=e;if(t===this._currentKey)return;let a=this._actions[t];if(!a)return;if(a===this._currentAction){this._currentKey=t;return}this._queuedKey=s||null,this._fadeDuration=r,this._pauseAtPercentage=n?100:i,this._isPaused=!1;let l=this._currentAction;this._pauseAtPercentage>0?(a.setLoop(Ct,1/0),a.clampWhenFinished=!0):(a.setLoop(vt,1/0),a.clampWhenFinished=!1),a.reset().play(),l&&l.crossFadeTo(a,r,!1),this._currentAction=a,this._currentKey=t}dispose(){Object.values(this._actions).forEach(e=>{e.stop()}),this._mixer&&(this._mixer.stopAllAction(),this._mixer.uncacheRoot(this.target),this._mixer=null),this._actions={},this._animations=[],this._currentAction=null,this._currentKey=""}get currentAnimationKey(){return this._currentKey}get animations(){return this._animations}};import{BufferGeometry as At,Mesh as we,Color as St}from"three";import{Mesh as _t}from"three";var U=class{_build(e,t,i){let{batched:n,material:s}=e;n&&console.warn("warning: mesh batching is not implemented");let r=new _t(t,i.at(-1));return r.position.set(0,0,0),r.castShadow=!0,r.receiveShadow=!0,r}_postBuild(){}};var N=class extends ye{},ke=class extends U{build(e){return new At}postBuild(){}},Z=class{meshBuilder;collisionBuilder;materialBuilder;options;entity;constructor(e,t,i,n){this.options=e,this.entity=t,this.meshBuilder=i,this.collisionBuilder=n,this.materialBuilder=new ge;let s={meshBuilder:this.meshBuilder,collisionBuilder:this.collisionBuilder,materialBuilder:this.materialBuilder};this.options._builders=s,t&&t.options&&(t.options._builders=s)}withPosition(e){return this.options.position=e,this}withMaterial(e,t){return this.materialBuilder&&this.materialBuilder.build(e,t),this}applyMaterialToGroup(e,t){e.traverse(i=>{i instanceof we&&i.type==="SkinnedMesh"&&t[0]&&!i.material.map&&(i.material=t[0]),i.castShadow=!0,i.receiveShadow=!0})}build(){let e=this.entity;if(this.materialBuilder&&(e.materials=this.materialBuilder.materials),this.meshBuilder&&e.materials){let t=this.meshBuilder.build(this.options);e.mesh=this.meshBuilder._build(this.options,t,e.materials),this.meshBuilder.postBuild()}if(e.group&&e.materials&&this.applyMaterialToGroup(e.group,e.materials),this.collisionBuilder){this.collisionBuilder.withCollision(this.options?.collision||{});let[t,i]=this.collisionBuilder.build(this.options);e.bodyDesc=t,e.colliderDesc=i,e.colliderDescs.push(i);let{x:n,y:s,z:r}=h(this.options.position,E);e.bodyDesc.setTranslation(n,s,r)}if(this.options.collisionType&&(e.collisionType=this.options.collisionType),this.options.color instanceof St){let t=i=>{let n=i;n&&n.color&&n.color.set&&n.color.set(this.options.color)};if(e.materials?.length)for(let i of e.materials)t(i);if(e.mesh&&e.mesh.material){let i=e.mesh.material;Array.isArray(i)?i.forEach(t):t(i)}e.group&&e.group.traverse(i=>{if(i instanceof we&&i.material){let n=i.material;Array.isArray(n)?n.forEach(t):t(n)}})}return e}};var ze={...V,material:{shader:L},animations:[],models:[],collisionShape:"capsule"};function w(o){return z(o.scale,T)}function j(o){let e=o.collision?.position;return e?h(e,E):null}function ee(o){return!!o.collision?.size}function Bt(o){o.hasWarnedDynamicTrimesh||(o.hasWarnedDynamicTrimesh=!0,console.warn(`Actor "${o.name||o.uuid}" requested collisionShape="trimesh" on a dynamic body; falling back to bounds.`))}function Le(o,e,t){let i=o==="model"?"bounds":o??"capsule";return i==="trimesh"&&!e?(t?.(),"bounds"):i}function wt(o,e,t){return o.__zylemShapeData={shape:"trimesh",vertices:Array.from(e),indices:Array.from(t)},o}function Pe(o,e){let t=o.x||.5,i=o.y||1,n=o.z||.5,s=Math.max(t,n)/2,r=i/2,a=Math.max(0,r-s),l=X.capsule(a,s);return l.setSensor(!1),l.setTranslation(e.x,e.y,e.z),l.activeCollisionTypes=Y.DEFAULT,l}function F(o){let e=h(o.collision?.size??o.size,{x:.5,y:1,z:.5}),t=e.y||1,i=j(o);return Pe({x:e.x||.5,y:t,z:e.z||.5},i??{x:0,y:t/2,z:0})}function Ve(o){let e=o.collision?.size;if(!e)return null;let t=h(e,E),i=t.x/2,n=t.y/2,s=t.z/2,r=X.cuboid(i,n,s),a=j(o);return r.setSensor(!1),r.setTranslation(a?.x??0,a?.y??n,a?.z??0),r.activeCollisionTypes=Y.DEFAULT,r}function Ge(o,e,t){let n=e.matrixWorld.clone().invert().multiply(o.matrixWorld);return new Rt().makeScale(t.x,t.y,t.z).multiply(n)}function te(o,e,t){o.updateMatrixWorld(!0);let i=!1,n=new je;if(o.traverse(a=>{if(!a.isMesh)return;let l=a,d=l.geometry;if(!d)return;let m=null;if(l instanceof Mt?(l.computeBoundingBox(),m=l.boundingBox?.clone()??null):(d.computeBoundingBox(),m=d.boundingBox?.clone()??null),!m)return;let f=m.applyMatrix4(Ge(l,e,t));if(!i){n.copy(f),i=!0;return}n.union(f)}),!i||n.isEmpty())return null;let s=new K,r=new K;return n.getSize(s),n.getCenter(r),{size:s,center:r}}function kt(o,e,t){o.updateMatrixWorld(!0);let i=[],n=[],s=new je,r=new K,a=!1;if(o.traverse(d=>{if(!d.isMesh)return;let m=d,f=m.geometry;if(!f)return;let y=f.getAttribute("position");if(!(y instanceof Dt))return;let p=Ge(m,e,t),C=i.length/3;for(let c=0;c<y.count;c++)r.set(y.getX(c),y.getY(c),y.getZ(c)),r.applyMatrix4(p),i.push(r.x,r.y,r.z),s.expandByPoint(r);let O=f.getIndex();if(O)for(let c=0;c<O.count;c++)n.push(C+O.getX(c));else for(let c=0;c<y.count;c++)n.push(C+c);a=!0}),!a||i.length===0||n.length===0)return null;let l=new K;return s.getCenter(l),{vertices:new Float32Array(i),indices:new Uint32Array(n),center:l}}function Ie(o,e,t){let i=Ve(t);if(i)return i;if(!o||!e)return F(t);let n=te(o,e,w(t));if(!n)return F(t);let s=X.cuboid(n.size.x/2,n.size.y/2,n.size.z/2),r=j(t);return s.setSensor(!1),s.setTranslation(r?.x??n.center.x,r?.y??n.center.y,r?.z??n.center.z),s.activeCollisionTypes=Y.DEFAULT,s}function Ue(o,e,t,i,n){if(ee(n)||!o||!e)return F(n);let s=te(o,e,w(n));if(!s)return F(n);let a=j(n);if(!a){let l=t&&i?te(t,i,w(n)):null;a=l?{x:l.center.x,y:l.center.y,z:l.center.z}:{x:s.center.x,y:s.center.y,z:s.center.z}}return Pe({x:s.size.x,y:s.size.y,z:s.size.z},a)}function Ne(o,e,t){let i=Ve(t);if(i)return i;if(!o||!e)return F(t);let n=kt(o,e,w(t));if(!n)return F(t);let s=wt(X.trimesh(n.vertices,n.indices),n.vertices,n.indices),r=j(t);return r&&s.setTranslation(r.x-n.center.x,r.y-n.center.y,r.z-n.center.z),s.setSensor(!1),s.activeCollisionTypes=Y.DEFAULT,s}function H(o){o&&o.traverse(e=>{if(!e.isMesh)return;let t=e;t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(i=>i.dispose()):t.material?.dispose()})}var ie=class extends N{objectModel=null;collisionSource=null;collisionShape="capsule";constructor(e){super(),this.objectModel=e.objectModel,this.collisionSource=e.collisionSource??e.objectModel??null,this.collisionShape=e.collisionShape??"capsule"}collider(e){let t=Le(this.collisionShape,!!e.collision?.static);return t==="bounds"?Ie(this.objectModel,this.objectModel,e):t==="trimesh"?Ne(this.objectModel,this.objectModel,e):Ue(this.collisionSource,this.collisionSource,this.objectModel,this.objectModel,e)}},oe=class extends Z{createEntity(e){return new k(e)}},jt=Symbol("Actor"),k=class extends M{static type=jt;_object=null;_collisionSource=null;_animationDelegate=null;_modelFileNames=[];_assetLoader=new R;_loadGeneration=0;_loadStatus="idle";controlledRotation=!1;hasWarnedDynamicTrimesh=!1;constructor(e){super(),this.options=g(ze,e),this.prependUpdate(this.actorUpdate.bind(this)),this.controlledRotation=!0}create(){return this._loadStatus==="idle"&&(this.options.models?.length??0)>0&&this.load(),super.create()}load(){this._loadStatus==="loading"||this._loadStatus==="loaded"||(this._modelFileNames=[...this.options.models||[]],this._modelFileNames.length!==0&&(this.disposeRuntimeState(!0),this._loadStatus="loading",this.loadModelsDeferred(++this._loadGeneration)))}data(){return{animations:this._animationDelegate?.animations,objectModel:this._object,collisionSource:this._collisionSource??this._object,collisionShape:this.options.collisionShape}}needsDeferredModelCollision(){return this.requiresLoadedCollisionSource()?!this.getRuntimeCollisionSource():!1}synchronizeRuntimeCollider(){let e=this.getResolvedCollisionShape(),t;if(e==="bounds")t=Ie(this._object,this.group??this._object,this.options);else if(e==="trimesh")t=Ne(this._object,this.group??this._object,this.options);else{let i=this.getRuntimeCollisionSource();t=Ue(i,i,this._object,this._object,this.options)}this.colliderDesc=t,this.colliderDescs.length>0?this.colliderDescs[0]=t:this.colliderDescs.push(t)}actorUpdate(e){this._animationDelegate?.update(e.delta)}actorDestroy(){this._loadGeneration+=1,this._loadStatus="idle",this.disposeRuntimeState(!0),this._modelFileNames=[]}_cleanup(e){super._cleanup(e),this.actorDestroy()}playAnimation(e){this._animationDelegate?.playAnimation(e)}get object(){return this._object}get collisionSource(){return this._collisionSource??this._object}getDebugInfo(){let e={type:"Actor",models:this._modelFileNames.length>0?this._modelFileNames:"none",modelLoaded:!!this._object,scale:(()=>{let t=h(this.options.scale,T);return`${t.x}, ${t.y}, ${t.z}`})(),collisionShape:this.getResolvedCollisionShape()};if(this._animationDelegate&&(e.currentAnimation=this._animationDelegate.currentAnimationKey||"none",e.animationsCount=this.options.animations?.length||0),this._object){let t=0,i=0;this._object.traverse(n=>{if(!n.isMesh)return;t++;let s=n.geometry;s?.attributes.position&&(i+=s.attributes.position.count)}),e.meshCount=t,e.vertexCount=i}return e}getResolvedCollisionShape(){return Le(this.options.collisionShape,!!this.options.collision?.static,()=>Bt(this))}requiresLoadedCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?!ee(this.options):e==="capsule"?!ee(this.options)&&this.getCollisionSourceSelection().file!==null:!1}getRuntimeCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?this._object:this._collisionSource??this._object}getCollisionSourceSelection(){let e=this.options.models?.[0]??null,t=this.options.animations?.[0]?.path??null;return t?{file:t,reuseVisibleModel:t===e}:{file:e,reuseVisibleModel:!0}}disposeRuntimeState(e){this._animationDelegate&&(this._animationDelegate.dispose(),this._animationDelegate=null);let t=this._collisionSource;H(this._object),t&&t!==this._object&&H(t),this._object=null,this._collisionSource=null,e&&this.group&&(this.group.clear(),this.group=void 0)}loadModelsDeferred(e){this.dispatch("entity:model:loading",{entityId:this.uuid,files:this._modelFileNames});let t=this.getCollisionSourceSelection(),i=this._modelFileNames.map(s=>this._assetLoader.loadFile(s,{clone:!0})),n=t.file&&!t.reuseVisibleModel?this._assetLoader.loadFile(t.file,{clone:!0}):Promise.resolve(null);Promise.all([Promise.all(i),n]).then(([s,r])=>{if(e!==this._loadGeneration){s.forEach(l=>H(l.object??null)),r?.object&&H(r.object);return}this._object=s[0]?.object??null,this._collisionSource=t.reuseVisibleModel?this._object:r?.object??this._object,this._loadStatus=this._object?"loaded":"idle";let a=0;this._object&&(this._object.traverse(l=>{l.isMesh&&a++}),this.group=new Tt,this.group.add(this._object),this.group.scale.copy(w(this.options)),this.applyMaterialOverrides(),this._animationDelegate=new I(this._object),this._animationDelegate.loadAnimations(this.options.animations||[],{stripRootMotionY:this.options.stripRootMotionY??!1}).then(()=>{e===this._loadGeneration&&this.dispatch("entity:animation:loaded",{entityId:this.uuid,animationCount:this.options.animations?.length||0})})),this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!!this._object,meshCount:a})}).catch(s=>{e===this._loadGeneration&&(this._loadStatus="idle",console.error("Failed to load actor model",s),this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!1,meshCount:0,errorMessage:s instanceof Error?s.message:String(s)}))})}applyMaterialOverrides(){let e=this.options.material;!e||!e.color&&!e.path&&e.opacity===void 0||this._object&&this._object.traverse(t=>{if(!t.isMesh)return;let i=t;i.material=Array.isArray(i.material)?i.material.map(n=>this.tintMaterial(n,e)):this.tintMaterial(i.material,e),e.color&&(i.castShadow=!0,i.receiveShadow=!0)})}tintMaterial(e,t){let i="color"in e,n=!!t.color,s=t.opacity!==void 0;if(!n&&!s)return e;if(n&&!i)return new Ft({color:t.color,emissiveIntensity:.5,lightMapIntensity:.5,fog:!0,opacity:t.opacity??1,transparent:s&&t.opacity<1});let r=e.clone();if(n&&"color"in r&&r.color.copy(t.color),s&&"opacity"in r&&"transparent"in r){let a=r;a.opacity=t.opacity,a.transparent=t.opacity<1}return r.needsUpdate=!0,r}};function zt(...o){return Re({args:o,defaultConfig:ze,EntityClass:k,BuilderClass:oe,CollisionBuilderClass:ie,entityType:k.type,cloneFactory:e=>zt(e??{})})}import{Color as Kt,Fog as Yt,FogExp2 as Xt,Group as Wt}from"three";import{Color as Lt}from"three";import{Fn as He,fog as Pt,positionWorld as Ze,positionView as Vt,uniform as b,float as Gt,vec3 as x,clamp as ne,mix as _,max as It,smoothstep as Ut,floor as Nt,fract as se,dot as Zt}from"three/tsl";var W=class{values;u={time:b(0),heightEnabled:b(0),heightLevel:b(0),heightFalloff:b(0),noiseEnabled:b(0),noiseScale:b(0),noiseStrength:b(0),noiseSpeed:b(0)};attachedScene=null;constructor(e){this.values={...e},this.syncUniforms()}setValues(e){Object.assign(this.values,e),this.syncUniforms()}tick(e){this.values.time+=e,this.u.time.value=this.values.time}scan(e){if(this.attachedScene===e)return;let t=e.fog;t&&(e.fogNode=this.buildFogNode(t),this.attachedScene=e)}unpatchAll(){this.attachedScene&&(this.attachedScene.fogNode=null,this.attachedScene=null)}syncUniforms(){this.u.time.value=this.values.time,this.u.heightEnabled.value=this.values.heightEnabled,this.u.heightLevel.value=this.values.heightLevel,this.u.heightFalloff.value=this.values.heightFalloff,this.u.noiseEnabled.value=this.values.noiseEnabled,this.u.noiseScale.value=this.values.noiseScale,this.u.noiseStrength.value=this.values.noiseStrength,this.u.noiseSpeed.value=this.values.noiseSpeed}buildFogNode(e){let t=e.isFogExp2===!0,i=b(new Lt(e.color)),n=Vt.z.negate(),s=t?this.exp2Factor(b(e.density),n):Ut(b(e.near),b(e.far),n),r=this.u.heightLevel.sub(Ze.y),a=ne(r.mul(It(this.u.heightFalloff,0)),0,1),l=_(s,s.mul(a),this.u.heightEnabled),d=Ze.mul(this.u.noiseScale).add(x(this.u.time.mul(this.u.noiseSpeed),0,this.u.time.mul(this.u.noiseSpeed).mul(.5))),f=Ht(d).sub(.5).mul(2).mul(ne(this.u.noiseStrength,0,1)),y=ne(l.add(l.mul(f)),0,1),p=_(l,y,this.u.noiseEnabled);return Pt(i,p)}exp2Factor(e,t){return e.mul(e).mul(t).mul(t).negate().exp().oneMinus()}},D=He(([o])=>{let e=se(o.mul(x(443.8975,397.2973,491.1871))),t=e.add(Zt(e,e.yzx.add(19.27)));return se(t.x.add(t.y).mul(t.z))}),Ht=He(([o])=>{let e=Nt(o),t=se(o),i=t.mul(t).mul(Gt(3).sub(t.mul(2))),n=D(e.add(x(0,0,0))),s=D(e.add(x(1,0,0))),r=D(e.add(x(0,1,0))),a=D(e.add(x(1,1,0))),l=D(e.add(x(0,0,1))),d=D(e.add(x(1,0,1))),m=D(e.add(x(0,1,1))),f=D(e.add(x(1,1,1))),y=_(n,s,i.x),p=_(r,a,i.x),C=_(l,d,i.x),O=_(m,f,i.x),c=_(y,p,i.y),Ke=_(C,O,i.y);return _(c,Ke,i.z)});var $t=Symbol("Fog"),qt="#9aa3ad",Jt=.015,Qt=10,ei=250,ti=5,ii=.2,oi=.05,ni=.15,si=.1,re=class extends M{static type=$t;threeFog=null;attachedScene=null;patcher;patcherEnabled;constructor(e={}){super(),this.options={...e};let t=this.resolveUniformValues(this.options);this.patcher=new W(t),this.patcherEnabled=ai(this.options)}create(){return super.create(),this.threeFog=ri(this.options),this.group=new Wt,this.group.name=this.name?`Fog:${this.name}`:"Fog",this}attachToScene(e){this.threeFog&&(this.attachedScene=e,e.fog=this.threeFog,this.patcherEnabled&&this.patcher.scan(e))}_update(e){super._update(e),!(!this.attachedScene||!this.patcherEnabled)&&(this.patcher.tick(e.delta),this.patcher.scan(this.attachedScene))}_cleanup(e){this.patcher.unpatchAll(),this.attachedScene&&this.attachedScene.fog===this.threeFog&&(this.attachedScene.fog=null),this.attachedScene=null,this.threeFog=null,super._cleanup(e)}resolveUniformValues(e){let t=e.height,i=e.noise;return{time:0,heightEnabled:t?.enabled?1:0,heightLevel:t?.level??ti,heightFalloff:t?.falloff??ii,noiseEnabled:i?1:0,noiseScale:i?.scale??oi,noiseStrength:i?.strength??ni,noiseSpeed:i?.speed??si}}};function ri(o){let e=new Kt(o.color??qt);return(o.type??"linear")==="exp2"?new Xt(e,o.density??Jt):new Yt(e,o.start??Qt,o.end??ei)}function ai(o){let e=!!o.height?.enabled,t=!!o.noise;return e||t}function on(o={}){return new re(o)}export{v as a,g as b,Je as c,Qe as d,et as e,tt as f,it as g,ot as h,nt as i,st as j,V as k,ki as l,M as m,yt as n,Q as o,Re as p,N as q,ke as r,Z as s,jt as t,k as u,zt as v,$t as w,re as x,on as y};
|