@zylem/game-lib 0.6.2 → 0.6.4
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/LICENSE +21 -0
- package/README.md +9 -16
- package/dist/actions.d.ts +30 -21
- package/dist/actions.js +793 -146
- package/dist/actions.js.map +1 -1
- package/dist/behavior/jumper-2d.d.ts +114 -0
- package/dist/behavior/jumper-2d.js +711 -0
- package/dist/behavior/jumper-2d.js.map +1 -0
- package/dist/behavior/platformer-3d.d.ts +296 -0
- package/dist/behavior/platformer-3d.js +761 -0
- package/dist/behavior/platformer-3d.js.map +1 -0
- package/dist/behavior/ricochet-2d.d.ts +275 -0
- package/dist/behavior/ricochet-2d.js +425 -0
- package/dist/behavior/ricochet-2d.js.map +1 -0
- package/dist/behavior/ricochet-3d.d.ts +117 -0
- package/dist/behavior/ricochet-3d.js +443 -0
- package/dist/behavior/ricochet-3d.js.map +1 -0
- package/dist/behavior/screen-visibility.d.ts +79 -0
- package/dist/behavior/screen-visibility.js +358 -0
- package/dist/behavior/screen-visibility.js.map +1 -0
- package/dist/behavior/screen-wrap.d.ts +87 -0
- package/dist/behavior/screen-wrap.js +246 -0
- package/dist/behavior/screen-wrap.js.map +1 -0
- package/dist/behavior/shooter-2d.d.ts +79 -0
- package/dist/behavior/shooter-2d.js +180 -0
- package/dist/behavior/shooter-2d.js.map +1 -0
- package/dist/behavior/thruster.d.ts +11 -0
- package/dist/behavior/thruster.js +292 -0
- package/dist/behavior/thruster.js.map +1 -0
- package/dist/behavior/top-down-movement.d.ts +56 -0
- package/dist/behavior/top-down-movement.js +125 -0
- package/dist/behavior/top-down-movement.js.map +1 -0
- package/dist/behavior/world-boundary-2d.d.ts +142 -0
- package/dist/behavior/world-boundary-2d.js +235 -0
- package/dist/behavior/world-boundary-2d.js.map +1 -0
- package/dist/behavior/world-boundary-3d.d.ts +76 -0
- package/dist/behavior/world-boundary-3d.js +274 -0
- package/dist/behavior/world-boundary-3d.js.map +1 -0
- package/dist/behavior-descriptor-BXnVR8Ki.d.ts +159 -0
- package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-DmbK2dki.d.ts} +2 -2
- package/dist/camera-4XO5gbQH.d.ts +905 -0
- package/dist/camera.d.ts +3 -2
- package/dist/camera.js +1653 -377
- package/dist/camera.js.map +1 -1
- package/dist/composition-BASvMKrW.d.ts +218 -0
- package/dist/{core-bO8TzV7u.d.ts → core-CARRaS55.d.ts} +110 -69
- package/dist/core.d.ts +11 -6
- package/dist/core.js +10766 -5626
- package/dist/core.js.map +1 -1
- package/dist/{entities-DvByhMGU.d.ts → entities-ChFirVL9.d.ts} +133 -29
- package/dist/entities.d.ts +5 -3
- package/dist/entities.js +4679 -3202
- package/dist/entities.js.map +1 -1
- package/dist/entity-vj-HTjzU.d.ts +1169 -0
- package/dist/global-change-2JvMaz44.d.ts +25 -0
- package/dist/main.d.ts +1118 -16
- package/dist/main.js +17538 -8499
- package/dist/main.js.map +1 -1
- package/dist/physics-pose-DCc4oE44.d.ts +25 -0
- package/dist/physics-protocol-BDD3P5W2.d.ts +200 -0
- package/dist/physics-worker.d.ts +21 -0
- package/dist/physics-worker.js +306 -0
- package/dist/physics-worker.js.map +1 -0
- package/dist/physics.d.ts +205 -0
- package/dist/physics.js +577 -0
- package/dist/physics.js.map +1 -0
- package/dist/stage-types-C19IhuzA.d.ts +731 -0
- package/dist/stage.d.ts +11 -7
- package/dist/stage.js +8024 -3852
- package/dist/stage.js.map +1 -1
- package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
- package/dist/thruster-23lzoPZd.d.ts +180 -0
- package/dist/world-DfgxoNMt.d.ts +105 -0
- package/package.json +53 -13
- package/dist/behaviors.d.ts +0 -854
- package/dist/behaviors.js +0 -1209
- package/dist/behaviors.js.map +0 -1
- package/dist/camera-CeJPAgGg.d.ts +0 -116
- package/dist/moveable-B_vyA6cw.d.ts +0 -67
- package/dist/stage-types-Bd-KtcYT.d.ts +0 -375
- package/dist/transformable-CUhvyuYO.d.ts +0 -67
- package/dist/world-C8tQ7Plj.d.ts +0 -774
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
import { Object3D, WebGLRenderer, Vector2, Scene, Camera, Vector3, Quaternion, WebGLRenderTarget, Texture } from 'three';
|
|
2
|
+
import { S as StageEntity } from './entity-Bq_eNEDI.js';
|
|
3
|
+
import { WebGPURenderer } from 'three/webgpu';
|
|
4
|
+
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
5
|
+
|
|
6
|
+
declare const Perspectives: {
|
|
7
|
+
readonly FirstPerson: "first-person";
|
|
8
|
+
readonly ThirdPerson: "third-person";
|
|
9
|
+
readonly Isometric: "isometric";
|
|
10
|
+
readonly Flat2D: "flat-2d";
|
|
11
|
+
readonly Fixed2D: "fixed-2d";
|
|
12
|
+
readonly TopDown: "top-down";
|
|
13
|
+
};
|
|
14
|
+
type PerspectiveType = (typeof Perspectives)[keyof typeof Perspectives];
|
|
15
|
+
|
|
16
|
+
interface CameraDebugState {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
selected: string[];
|
|
19
|
+
}
|
|
20
|
+
interface CameraDebugDelegate {
|
|
21
|
+
subscribe(listener: (state: CameraDebugState) => void): () => void;
|
|
22
|
+
resolveTarget(uuid: string): Object3D | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Renderer type option for choosing rendering backend
|
|
27
|
+
* - 'auto': Try WebGPU first, fall back to WebGL
|
|
28
|
+
* - 'webgpu': Force WebGPU (error if not supported)
|
|
29
|
+
* - 'webgl': Force WebGL
|
|
30
|
+
*/
|
|
31
|
+
type RendererType = 'auto' | 'webgpu' | 'webgl';
|
|
32
|
+
/**
|
|
33
|
+
* Union type for renderer instances
|
|
34
|
+
*/
|
|
35
|
+
type ZylemRenderer = WebGLRenderer | WebGPURenderer;
|
|
36
|
+
/**
|
|
37
|
+
* Viewport definition in normalized coordinates (0-1).
|
|
38
|
+
* Represents a rectangular region of the canvas for camera rendering.
|
|
39
|
+
*/
|
|
40
|
+
interface Viewport {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if WebGPU is supported in the current browser
|
|
48
|
+
*/
|
|
49
|
+
declare function isWebGPUSupported(): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* RendererManager owns the shared WebGL/WebGPU renderer, canvas element,
|
|
52
|
+
* effect composer, and render loop. There is one RendererManager per game.
|
|
53
|
+
*
|
|
54
|
+
* It iterates active cameras and renders each with its configured viewport.
|
|
55
|
+
*/
|
|
56
|
+
declare class RendererManager {
|
|
57
|
+
renderer: ZylemRenderer;
|
|
58
|
+
composer: EffectComposer;
|
|
59
|
+
screenResolution: Vector2;
|
|
60
|
+
rendererType: RendererType;
|
|
61
|
+
private _isWebGPU;
|
|
62
|
+
private _initialized;
|
|
63
|
+
private _sceneRef;
|
|
64
|
+
private _lastAnimationTimestamp;
|
|
65
|
+
constructor(screenResolution?: Vector2, rendererType?: RendererType);
|
|
66
|
+
/**
|
|
67
|
+
* Check if the renderer has been initialized
|
|
68
|
+
*/
|
|
69
|
+
get initialized(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Check if using WebGPU renderer
|
|
72
|
+
*/
|
|
73
|
+
get isWebGPU(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Initialize the renderer (must be called before rendering).
|
|
76
|
+
* Async because WebGPU requires async initialization.
|
|
77
|
+
*/
|
|
78
|
+
initRenderer(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Set the current scene reference for rendering.
|
|
81
|
+
*/
|
|
82
|
+
setScene(scene: Scene): void;
|
|
83
|
+
/**
|
|
84
|
+
* Setup post-processing render pass for a camera (WebGL only).
|
|
85
|
+
*/
|
|
86
|
+
setupRenderPass(scene: Scene, camera: Camera): void;
|
|
87
|
+
/**
|
|
88
|
+
* Start the render loop. Calls the provided callback each frame.
|
|
89
|
+
*/
|
|
90
|
+
startRenderLoop(onFrame: (delta: number) => void): void;
|
|
91
|
+
/**
|
|
92
|
+
* Stop the render loop.
|
|
93
|
+
*/
|
|
94
|
+
stopRenderLoop(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Render a scene from a single camera's perspective.
|
|
97
|
+
* Sets the viewport based on the camera's viewport config.
|
|
98
|
+
*/
|
|
99
|
+
renderCamera(scene: Scene, camera: ZylemCamera): void;
|
|
100
|
+
/**
|
|
101
|
+
* Render a camera to its offscreen render target (WebGL only).
|
|
102
|
+
* Bypasses the EffectComposer since post-processing is not needed
|
|
103
|
+
* for render-to-texture output.
|
|
104
|
+
*
|
|
105
|
+
* The camera must have a non-null renderTarget.
|
|
106
|
+
*/
|
|
107
|
+
renderCameraToTarget(scene: Scene, camera: ZylemCamera): void;
|
|
108
|
+
/**
|
|
109
|
+
* Render a scene from multiple cameras, each with their own viewport.
|
|
110
|
+
* Cameras are rendered in order (first = bottom layer, last = top layer).
|
|
111
|
+
*/
|
|
112
|
+
renderCameras(scene: Scene, cameras: ZylemCamera[]): void;
|
|
113
|
+
/**
|
|
114
|
+
* Simple single-camera render (backwards compatible).
|
|
115
|
+
* Uses the full viewport for a single camera.
|
|
116
|
+
*/
|
|
117
|
+
render(scene: Scene, camera: Camera): void;
|
|
118
|
+
/**
|
|
119
|
+
* Resize the renderer and update resolution.
|
|
120
|
+
*/
|
|
121
|
+
resize(width: number, height: number): void;
|
|
122
|
+
/**
|
|
123
|
+
* Update renderer pixel ratio (DPR).
|
|
124
|
+
*/
|
|
125
|
+
setPixelRatio(dpr: number): void;
|
|
126
|
+
/**
|
|
127
|
+
* Get the DOM element for the renderer.
|
|
128
|
+
*/
|
|
129
|
+
getDomElement(): HTMLCanvasElement;
|
|
130
|
+
/**
|
|
131
|
+
* Dispose renderer, composer, and related resources.
|
|
132
|
+
*/
|
|
133
|
+
dispose(): void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Represents a full camera pose: position, rotation, projection params, and optional lookAt.
|
|
138
|
+
* This is the canonical data structure that flows through the camera pipeline.
|
|
139
|
+
*/
|
|
140
|
+
interface CameraPose {
|
|
141
|
+
position: Vector3;
|
|
142
|
+
rotation: Quaternion;
|
|
143
|
+
fov?: number;
|
|
144
|
+
zoom?: number;
|
|
145
|
+
near?: number;
|
|
146
|
+
far?: number;
|
|
147
|
+
/** When set, the camera orients to look at this point (takes priority over rotation). */
|
|
148
|
+
lookAt?: Vector3;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* An additive delta applied on top of a CameraPose.
|
|
152
|
+
* Used by CameraActions to apply transient offsets (shake, recoil, etc.).
|
|
153
|
+
*/
|
|
154
|
+
interface PoseDelta {
|
|
155
|
+
position?: Vector3;
|
|
156
|
+
rotation?: Quaternion;
|
|
157
|
+
fov?: number;
|
|
158
|
+
zoom?: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Minimal transform representation for pipeline targets.
|
|
162
|
+
*/
|
|
163
|
+
interface TransformLike {
|
|
164
|
+
position: Vector3;
|
|
165
|
+
rotation?: Quaternion;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Per-frame context passed to every pipeline module (perspectives, behaviors, actions).
|
|
169
|
+
*/
|
|
170
|
+
interface CameraContext {
|
|
171
|
+
/** Frame delta time in seconds. */
|
|
172
|
+
dt: number;
|
|
173
|
+
/** Elapsed time in seconds since camera started updating. */
|
|
174
|
+
time: number;
|
|
175
|
+
/** Current viewport dimensions and aspect ratio. */
|
|
176
|
+
viewport: {
|
|
177
|
+
width: number;
|
|
178
|
+
height: number;
|
|
179
|
+
aspect: number;
|
|
180
|
+
};
|
|
181
|
+
/** Named targets the camera can track. 'primary' is targets[0] by convention. */
|
|
182
|
+
targets: Record<string, TransformLike>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A perspective produces the base camera pose each frame.
|
|
186
|
+
* Exactly one perspective is active per camera at a time.
|
|
187
|
+
*/
|
|
188
|
+
interface CameraPerspective {
|
|
189
|
+
id: string;
|
|
190
|
+
/** Compute the raw desired pose for this frame given the current context. */
|
|
191
|
+
getBasePose(ctx: CameraContext): CameraPose;
|
|
192
|
+
/** Optional defaults for smoothing and other pipeline settings. */
|
|
193
|
+
defaults?: {
|
|
194
|
+
damping?: number;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Behaviors modify the desired pose each frame.
|
|
199
|
+
* They are keyed by name (idempotent add) and sorted by priority.
|
|
200
|
+
*/
|
|
201
|
+
interface CameraBehavior {
|
|
202
|
+
/** Receive current context and pose, return a modified pose. */
|
|
203
|
+
update(ctx: CameraContext, pose: CameraPose): CameraPose;
|
|
204
|
+
/** Called when the behavior is attached to the pipeline. */
|
|
205
|
+
onAttach?(ctx: CameraContext): void;
|
|
206
|
+
/** Called when the behavior is removed from the pipeline. */
|
|
207
|
+
onDetach?(ctx: CameraContext): void;
|
|
208
|
+
/** Sort order: lower runs first. Default 0. */
|
|
209
|
+
priority?: number;
|
|
210
|
+
/** When false, the behavior is skipped during the pipeline run. */
|
|
211
|
+
enabled?: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Actions are transient effects that apply additive deltas (screenshake, recoil, etc.).
|
|
215
|
+
* They self-expire when isDone() returns true and are automatically removed.
|
|
216
|
+
*/
|
|
217
|
+
interface CameraAction {
|
|
218
|
+
/** Return the additive delta for this frame. */
|
|
219
|
+
update(ctx: CameraContext): PoseDelta;
|
|
220
|
+
/** Return true when the action has completed and should be removed. */
|
|
221
|
+
isDone(ctx: CameraContext): boolean;
|
|
222
|
+
/** Sort order for action application. Default 0. */
|
|
223
|
+
priority?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Debug snapshot returned by pipeline.getState().
|
|
227
|
+
*/
|
|
228
|
+
interface CameraPipelineState {
|
|
229
|
+
perspectiveId: string | null;
|
|
230
|
+
desiredPose: CameraPose | null;
|
|
231
|
+
finalPose: CameraPose | null;
|
|
232
|
+
activeBehaviors: string[];
|
|
233
|
+
activeActionCount: number;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* CameraPipeline runs a deterministic per-frame update:
|
|
238
|
+
*
|
|
239
|
+
* Perspective -> Behaviors (priority) -> Actions (deltas) -> Smoothing -> finalPose
|
|
240
|
+
*
|
|
241
|
+
* It separates "desired pose" from "final pose". Everything writes to desired;
|
|
242
|
+
* only smoothing converts desired into the final committed pose.
|
|
243
|
+
*/
|
|
244
|
+
declare class CameraPipeline {
|
|
245
|
+
/** Active perspective (exactly one at a time). */
|
|
246
|
+
perspective: CameraPerspective | null;
|
|
247
|
+
/** Keyed behaviors, sorted by priority each frame. */
|
|
248
|
+
private behaviors;
|
|
249
|
+
/** Active transient actions. Expired actions are auto-removed. */
|
|
250
|
+
private actions;
|
|
251
|
+
/** The desired pose after perspective + behaviors + actions. */
|
|
252
|
+
private _desiredPose;
|
|
253
|
+
/** The smoothed final pose committed to the Three.js camera. */
|
|
254
|
+
private _finalPose;
|
|
255
|
+
/** Whether the pipeline has run at least once (prevents lerp from origin on first frame). */
|
|
256
|
+
private _initialized;
|
|
257
|
+
/** Smoothing factor: 0 = no movement, 1 = instant snap. */
|
|
258
|
+
damping: number;
|
|
259
|
+
constructor(perspective?: CameraPerspective);
|
|
260
|
+
/**
|
|
261
|
+
* Run the full pipeline for one frame.
|
|
262
|
+
* Returns the final pose that should be committed to the Three.js camera.
|
|
263
|
+
*/
|
|
264
|
+
run(ctx: CameraContext): CameraPose;
|
|
265
|
+
/**
|
|
266
|
+
* Add or replace a behavior by key (idempotent).
|
|
267
|
+
* Calls onDetach on the old behavior and onAttach on the new one.
|
|
268
|
+
*/
|
|
269
|
+
addBehavior(key: string, behavior: CameraBehavior, ctx?: CameraContext): void;
|
|
270
|
+
/**
|
|
271
|
+
* Remove a behavior by key. Calls onDetach if a context is provided.
|
|
272
|
+
*/
|
|
273
|
+
removeBehavior(key: string, ctx?: CameraContext): boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Check whether a behavior with the given key exists.
|
|
276
|
+
*/
|
|
277
|
+
hasBehavior(key: string): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Add a transient action. Actions self-expire via isDone().
|
|
280
|
+
*/
|
|
281
|
+
addAction(action: CameraAction): void;
|
|
282
|
+
/**
|
|
283
|
+
* Return a debug snapshot of the pipeline state.
|
|
284
|
+
*/
|
|
285
|
+
getState(): CameraPipelineState;
|
|
286
|
+
/**
|
|
287
|
+
* Set a new perspective. Resets the pipeline initialization flag so the
|
|
288
|
+
* first frame with the new perspective snaps instead of lerping from the old pose.
|
|
289
|
+
*/
|
|
290
|
+
setPerspective(perspective: CameraPerspective): void;
|
|
291
|
+
private getSortedBehaviors;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* ZylemCamera is a lightweight camera wrapper that manages the Three.js camera,
|
|
296
|
+
* the camera pose pipeline, and viewport configuration. Rendering is handled
|
|
297
|
+
* by RendererManager.
|
|
298
|
+
*
|
|
299
|
+
* The pipeline runs: Perspective -> Behaviors -> Actions -> Smoothing -> Commit.
|
|
300
|
+
* When orbit/debug controls are active, the pipeline is bypassed.
|
|
301
|
+
*/
|
|
302
|
+
declare class ZylemCamera {
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated No longer used. Kept as null for backward compatibility
|
|
305
|
+
* with code that checks `camera.cameraRig` (e.g. scene graph insertion).
|
|
306
|
+
*/
|
|
307
|
+
cameraRig: Object3D | null;
|
|
308
|
+
camera: Camera;
|
|
309
|
+
screenResolution: Vector2;
|
|
310
|
+
_perspective: PerspectiveType;
|
|
311
|
+
frustumSize: number;
|
|
312
|
+
rendererType: RendererType;
|
|
313
|
+
sceneRef: Scene | null;
|
|
314
|
+
/** Name for camera manager lookup. */
|
|
315
|
+
name: string;
|
|
316
|
+
/**
|
|
317
|
+
* Viewport in normalized coordinates (0-1).
|
|
318
|
+
* Default is fullscreen: { x: 0, y: 0, width: 1, height: 1 }
|
|
319
|
+
*/
|
|
320
|
+
viewport: Viewport;
|
|
321
|
+
/**
|
|
322
|
+
* Multiple targets for the camera to follow/frame.
|
|
323
|
+
*/
|
|
324
|
+
targets: StageEntity[];
|
|
325
|
+
/**
|
|
326
|
+
* The camera pose pipeline.
|
|
327
|
+
* Exposed so CameraWrapper can delegate addBehavior/addAction/getState.
|
|
328
|
+
*/
|
|
329
|
+
pipeline: CameraPipeline;
|
|
330
|
+
/**
|
|
331
|
+
* Offscreen render target for render-to-texture (RTT) cameras.
|
|
332
|
+
* When set, the camera renders to this target instead of the screen viewport.
|
|
333
|
+
* Created via createRenderTarget() or automatically by setCameraFeed().
|
|
334
|
+
*/
|
|
335
|
+
renderTarget: WebGLRenderTarget | null;
|
|
336
|
+
/**
|
|
337
|
+
* @deprecated Use `targets` array instead. Kept for backward compatibility.
|
|
338
|
+
*/
|
|
339
|
+
get target(): StageEntity | null;
|
|
340
|
+
set target(entity: StageEntity | null);
|
|
341
|
+
private orbitController;
|
|
342
|
+
private _useOrbitalControls;
|
|
343
|
+
/** When true, debug-mode orbital controls are not attached to this camera. */
|
|
344
|
+
_skipDebugOrbit: boolean;
|
|
345
|
+
/** Reference to the shared renderer manager (set during setup). */
|
|
346
|
+
private _rendererManager;
|
|
347
|
+
/** Elapsed time tracker for CameraContext. */
|
|
348
|
+
private _elapsedTime;
|
|
349
|
+
constructor(perspective: PerspectiveType, screenResolution: Vector2, frustumSize?: number, rendererType?: RendererType);
|
|
350
|
+
/**
|
|
351
|
+
* Setup the camera with a scene and renderer manager.
|
|
352
|
+
*/
|
|
353
|
+
setup(scene: Scene, rendererManager?: RendererManager): Promise<void>;
|
|
354
|
+
/**
|
|
355
|
+
* Legacy setup method for backward compatibility.
|
|
356
|
+
* Creates a temporary RendererManager internally.
|
|
357
|
+
* @deprecated Use setup(scene, rendererManager) instead.
|
|
358
|
+
*/
|
|
359
|
+
setupLegacy(scene: Scene): Promise<void>;
|
|
360
|
+
/**
|
|
361
|
+
* Update the camera each frame.
|
|
362
|
+
*
|
|
363
|
+
* When orbit/debug controls are active, the pipeline is skipped and
|
|
364
|
+
* orbit controls manage the camera directly. Otherwise, the pipeline
|
|
365
|
+
* runs: Perspective -> Behaviors -> Actions -> Smoothing -> Commit.
|
|
366
|
+
*/
|
|
367
|
+
update(delta: number): void;
|
|
368
|
+
/**
|
|
369
|
+
* Check if debug mode is active (orbit controls taking over camera).
|
|
370
|
+
*/
|
|
371
|
+
isDebugModeActive(): boolean;
|
|
372
|
+
/**
|
|
373
|
+
* Enable user-configured orbital controls (not debug mode).
|
|
374
|
+
*/
|
|
375
|
+
enableOrbitalControls(): void;
|
|
376
|
+
/**
|
|
377
|
+
* Disable user-configured orbital controls.
|
|
378
|
+
*/
|
|
379
|
+
disableOrbitalControls(): void;
|
|
380
|
+
/**
|
|
381
|
+
* Whether user orbital controls are enabled.
|
|
382
|
+
*/
|
|
383
|
+
get useOrbitalControls(): boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Add a target entity for the camera to follow/frame.
|
|
386
|
+
*/
|
|
387
|
+
addTarget(entity: StageEntity): void;
|
|
388
|
+
/**
|
|
389
|
+
* Remove a target entity.
|
|
390
|
+
*/
|
|
391
|
+
removeTarget(entity: StageEntity): void;
|
|
392
|
+
/**
|
|
393
|
+
* Clear all targets.
|
|
394
|
+
*/
|
|
395
|
+
clearTargets(): void;
|
|
396
|
+
/**
|
|
397
|
+
* Set the viewport for this camera (normalized 0-1 coordinates).
|
|
398
|
+
*/
|
|
399
|
+
setViewport(x: number, y: number, width: number, height: number): void;
|
|
400
|
+
/**
|
|
401
|
+
* Resize camera projection.
|
|
402
|
+
*/
|
|
403
|
+
resize(width: number, height: number): void;
|
|
404
|
+
/**
|
|
405
|
+
* Create an offscreen render target for this camera.
|
|
406
|
+
* When a render target is present, CameraManager renders this camera
|
|
407
|
+
* to the target instead of the screen viewport.
|
|
408
|
+
*
|
|
409
|
+
* @param width Texture width in pixels (default 512)
|
|
410
|
+
* @param height Texture height in pixels (default 512)
|
|
411
|
+
*/
|
|
412
|
+
createRenderTarget(width?: number, height?: number): WebGLRenderTarget;
|
|
413
|
+
/**
|
|
414
|
+
* Get the texture from the render target (for applying to a mesh material).
|
|
415
|
+
* Returns null if no render target has been created.
|
|
416
|
+
*/
|
|
417
|
+
getRenderTexture(): Texture | null;
|
|
418
|
+
/**
|
|
419
|
+
* Dispose camera resources.
|
|
420
|
+
*/
|
|
421
|
+
destroy(): void;
|
|
422
|
+
/**
|
|
423
|
+
* Attach a delegate to react to debug state changes.
|
|
424
|
+
* Skipped when _skipDebugOrbit is true so the pipeline always runs.
|
|
425
|
+
*/
|
|
426
|
+
setDebugDelegate(delegate: CameraDebugDelegate | null): void;
|
|
427
|
+
/**
|
|
428
|
+
* Directly set the camera position.
|
|
429
|
+
*/
|
|
430
|
+
move(position: Vector3): void;
|
|
431
|
+
/**
|
|
432
|
+
* Apply incremental rotation to the camera.
|
|
433
|
+
*/
|
|
434
|
+
rotate(pitch: number, yaw: number, roll: number): void;
|
|
435
|
+
/**
|
|
436
|
+
* Get the DOM element for the renderer.
|
|
437
|
+
* @deprecated Access via RendererManager instead.
|
|
438
|
+
*/
|
|
439
|
+
getDomElement(): HTMLCanvasElement;
|
|
440
|
+
/**
|
|
441
|
+
* Get the renderer manager reference.
|
|
442
|
+
*/
|
|
443
|
+
getRendererManager(): RendererManager | null;
|
|
444
|
+
/**
|
|
445
|
+
* Set the renderer manager reference (used by CameraManager during setup).
|
|
446
|
+
*/
|
|
447
|
+
setRendererManager(manager: RendererManager): void;
|
|
448
|
+
/** @deprecated Renderer is now owned by RendererManager */
|
|
449
|
+
get renderer(): any;
|
|
450
|
+
/** @deprecated Composer is now owned by RendererManager */
|
|
451
|
+
get composer(): any;
|
|
452
|
+
/** @deprecated Use RendererManager.setPixelRatio() instead */
|
|
453
|
+
setPixelRatio(dpr: number): void;
|
|
454
|
+
/**
|
|
455
|
+
* Build a CameraContext from current ZylemCamera state.
|
|
456
|
+
* Converts StageEntity[] targets into Record<string, TransformLike>.
|
|
457
|
+
*/
|
|
458
|
+
private buildContext;
|
|
459
|
+
/**
|
|
460
|
+
* Apply the final pipeline pose to the Three.js camera.
|
|
461
|
+
*/
|
|
462
|
+
private commitPose;
|
|
463
|
+
/**
|
|
464
|
+
* Create a Three.js camera based on perspective type.
|
|
465
|
+
*/
|
|
466
|
+
private createCameraForPerspective;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* CameraManager orchestrates multiple cameras per stage.
|
|
471
|
+
*
|
|
472
|
+
* Responsibilities:
|
|
473
|
+
* - Named camera registry (add/remove/get by name or reference)
|
|
474
|
+
* - Active camera list management (determines which cameras render)
|
|
475
|
+
* - Always-available debug camera with orbit controls
|
|
476
|
+
* - Per-frame update of all active cameras' perspective controllers
|
|
477
|
+
* - Coordinating rendering via RendererManager for all active viewports
|
|
478
|
+
*/
|
|
479
|
+
declare class CameraManager {
|
|
480
|
+
/** Named camera registry */
|
|
481
|
+
private cameras;
|
|
482
|
+
/** Currently active cameras, ordered by render layer (first = bottom) */
|
|
483
|
+
private _activeCameras;
|
|
484
|
+
/** Auto-created debug camera with orbit controls */
|
|
485
|
+
private _debugCamera;
|
|
486
|
+
/** Reference to the shared renderer manager */
|
|
487
|
+
private _rendererManager;
|
|
488
|
+
/** Scene reference */
|
|
489
|
+
private _sceneRef;
|
|
490
|
+
/** Counter for auto-generated camera names */
|
|
491
|
+
private _autoNameCounter;
|
|
492
|
+
constructor();
|
|
493
|
+
/**
|
|
494
|
+
* Get the list of currently active cameras.
|
|
495
|
+
*/
|
|
496
|
+
get activeCameras(): ReadonlyArray<ZylemCamera>;
|
|
497
|
+
/**
|
|
498
|
+
* Get the primary active camera (first in the active list).
|
|
499
|
+
*/
|
|
500
|
+
get primaryCamera(): ZylemCamera | null;
|
|
501
|
+
/**
|
|
502
|
+
* Get the debug camera.
|
|
503
|
+
*/
|
|
504
|
+
get debugCamera(): ZylemCamera | null;
|
|
505
|
+
/**
|
|
506
|
+
* Get all registered cameras.
|
|
507
|
+
*/
|
|
508
|
+
get allCameras(): ReadonlyArray<ZylemCamera>;
|
|
509
|
+
/**
|
|
510
|
+
* Add a camera to the manager.
|
|
511
|
+
* If no name is provided, one is auto-generated.
|
|
512
|
+
* The first camera added becomes the active camera.
|
|
513
|
+
*
|
|
514
|
+
* @param camera The ZylemCamera instance to add
|
|
515
|
+
* @param name Optional name for lookup
|
|
516
|
+
* @returns The assigned name
|
|
517
|
+
*/
|
|
518
|
+
addCamera(camera: ZylemCamera, name?: string): string;
|
|
519
|
+
/**
|
|
520
|
+
* Remove a camera by name or reference.
|
|
521
|
+
* Cannot remove the debug camera via this method.
|
|
522
|
+
*/
|
|
523
|
+
removeCamera(nameOrRef: string | ZylemCamera): boolean;
|
|
524
|
+
/**
|
|
525
|
+
* Set a camera as the primary active camera (replaces all active cameras
|
|
526
|
+
* except additional viewport cameras).
|
|
527
|
+
*
|
|
528
|
+
* @param nameOrRef Camera name or reference to activate
|
|
529
|
+
*/
|
|
530
|
+
setActiveCamera(nameOrRef: string | ZylemCamera): boolean;
|
|
531
|
+
/**
|
|
532
|
+
* Add a camera as an additional active camera (for split-screen or PiP).
|
|
533
|
+
*/
|
|
534
|
+
addActiveCamera(nameOrRef: string | ZylemCamera): boolean;
|
|
535
|
+
/**
|
|
536
|
+
* Remove a camera from the active render list (does not remove from registry).
|
|
537
|
+
*/
|
|
538
|
+
deactivateCamera(nameOrRef: string | ZylemCamera): boolean;
|
|
539
|
+
/**
|
|
540
|
+
* Get a camera by name.
|
|
541
|
+
*/
|
|
542
|
+
getCamera(name: string): ZylemCamera | null;
|
|
543
|
+
/**
|
|
544
|
+
* Setup all cameras with the given scene and renderer manager.
|
|
545
|
+
* Also creates the debug camera.
|
|
546
|
+
*/
|
|
547
|
+
setup(scene: Scene, rendererManager: RendererManager): Promise<void>;
|
|
548
|
+
/**
|
|
549
|
+
* Update all active cameras' controllers.
|
|
550
|
+
*/
|
|
551
|
+
update(delta: number): void;
|
|
552
|
+
/**
|
|
553
|
+
* Render all active cameras through the renderer manager.
|
|
554
|
+
* RTT cameras (those with a renderTarget) are rendered first to their
|
|
555
|
+
* offscreen textures, then viewport cameras are rendered to the screen.
|
|
556
|
+
*/
|
|
557
|
+
render(scene: Scene): void;
|
|
558
|
+
/**
|
|
559
|
+
* Create a default third-person camera if no cameras have been added.
|
|
560
|
+
*/
|
|
561
|
+
ensureDefaultCamera(): ZylemCamera;
|
|
562
|
+
/**
|
|
563
|
+
* Dispose all cameras and cleanup.
|
|
564
|
+
*/
|
|
565
|
+
dispose(): void;
|
|
566
|
+
/**
|
|
567
|
+
* Create the always-available debug camera with orbit controls.
|
|
568
|
+
*/
|
|
569
|
+
private createDebugCamera;
|
|
570
|
+
/**
|
|
571
|
+
* Resolve a camera from a name or reference.
|
|
572
|
+
*/
|
|
573
|
+
private resolveCamera;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Configuration for the third-person perspective.
|
|
578
|
+
*/
|
|
579
|
+
interface ThirdPersonOptions {
|
|
580
|
+
/** Distance behind the target. Default 8. */
|
|
581
|
+
distance?: number;
|
|
582
|
+
/** Height above the target. Default 5. */
|
|
583
|
+
height?: number;
|
|
584
|
+
/** Lateral offset from the target (shoulder cam). Default 0. */
|
|
585
|
+
shoulderOffset?: number;
|
|
586
|
+
/** Key in CameraContext.targets to follow. Default 'primary'. */
|
|
587
|
+
targetKey?: string;
|
|
588
|
+
/** Perspective field of view. Default 75. */
|
|
589
|
+
fov?: number;
|
|
590
|
+
/** Padding multiplier when framing multiple targets. Default 1.5. */
|
|
591
|
+
paddingFactor?: number;
|
|
592
|
+
/** Minimum camera distance when multi-framing. Default 5. */
|
|
593
|
+
minDistance?: number;
|
|
594
|
+
/** Fallback camera position when no targets exist (e.g. the user-specified initial position). */
|
|
595
|
+
initialPosition?: Vector3;
|
|
596
|
+
/** Fallback lookAt point when no targets exist. */
|
|
597
|
+
initialLookAt?: Vector3;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Third-person 3D perspective.
|
|
601
|
+
*
|
|
602
|
+
* - 0 targets: returns a static pose behind the origin.
|
|
603
|
+
* - 1 target: camera positioned behind and above the target, looking at it.
|
|
604
|
+
* - 2+ targets: weighted-centroid framing with dynamic distance.
|
|
605
|
+
*/
|
|
606
|
+
declare class ThirdPersonPerspective implements CameraPerspective {
|
|
607
|
+
readonly id = "third-person";
|
|
608
|
+
readonly defaults: {
|
|
609
|
+
damping: number;
|
|
610
|
+
};
|
|
611
|
+
private opts;
|
|
612
|
+
private initialPosition?;
|
|
613
|
+
private initialLookAt?;
|
|
614
|
+
constructor(options?: ThirdPersonOptions);
|
|
615
|
+
getBasePose(ctx: CameraContext): CameraPose;
|
|
616
|
+
/**
|
|
617
|
+
* No targets: use the user-specified initial position if available,
|
|
618
|
+
* otherwise fall back to a default pose behind the origin.
|
|
619
|
+
*/
|
|
620
|
+
private staticPose;
|
|
621
|
+
/**
|
|
622
|
+
* Single target: position = target + offset, lookAt = target.
|
|
623
|
+
*/
|
|
624
|
+
private singleTargetPose;
|
|
625
|
+
/**
|
|
626
|
+
* Multi-target: compute centroid and adjust distance to frame all targets.
|
|
627
|
+
*/
|
|
628
|
+
private multiTargetPose;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Configuration for the fixed 2D perspective.
|
|
633
|
+
*/
|
|
634
|
+
interface Fixed2DOptions {
|
|
635
|
+
/** Fixed camera position. Default (0, 0, 10). */
|
|
636
|
+
position?: {
|
|
637
|
+
x: number;
|
|
638
|
+
y: number;
|
|
639
|
+
z: number;
|
|
640
|
+
};
|
|
641
|
+
/** Orthographic zoom (frustum size). Default 10. */
|
|
642
|
+
zoom?: number;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Fixed 2D perspective.
|
|
646
|
+
*
|
|
647
|
+
* Returns a static orthographic pose looking down the Z-axis.
|
|
648
|
+
* No target following -- the camera stays at the configured position.
|
|
649
|
+
*/
|
|
650
|
+
declare class Fixed2DPerspective implements CameraPerspective {
|
|
651
|
+
readonly id = "fixed-2d";
|
|
652
|
+
readonly defaults: {
|
|
653
|
+
damping: number;
|
|
654
|
+
};
|
|
655
|
+
private opts;
|
|
656
|
+
constructor(options?: Fixed2DOptions);
|
|
657
|
+
getBasePose(_ctx: CameraContext): CameraPose;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Configuration for the first-person perspective.
|
|
662
|
+
*/
|
|
663
|
+
interface FirstPersonOptions {
|
|
664
|
+
/** Vertical offset above the target entity's position (eye height). @default 1.7 */
|
|
665
|
+
eyeHeight?: number;
|
|
666
|
+
/** Default field of view in degrees. @default 75 */
|
|
667
|
+
defaultFov?: number;
|
|
668
|
+
/** Maximum pitch angle in radians. @default Math.PI/2 - 0.01 */
|
|
669
|
+
pitchLimit?: number;
|
|
670
|
+
/** Lerp speed for smooth look-at transitions. @default 5 */
|
|
671
|
+
lookAtLerpSpeed?: number;
|
|
672
|
+
/** Lerp speed for FOV zoom transitions. @default 8 */
|
|
673
|
+
fovLerpSpeed?: number;
|
|
674
|
+
/** Key in CameraContext.targets to follow. @default 'primary' */
|
|
675
|
+
targetKey?: string;
|
|
676
|
+
/** Fallback position when no target entity is attached. */
|
|
677
|
+
initialPosition?: Vector3;
|
|
678
|
+
/** Fallback look-at point used to derive initial yaw/pitch when no target. */
|
|
679
|
+
initialLookAt?: Vector3;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* First-person camera perspective.
|
|
683
|
+
*
|
|
684
|
+
* Position is derived from the attached target entity (+ eye height).
|
|
685
|
+
* Rotation is driven via `look()` / `setLook()` methods called by game code
|
|
686
|
+
* or a future FPS behavior. Supports smooth FOV zoom and lerp'd look-at.
|
|
687
|
+
*/
|
|
688
|
+
declare class FirstPersonPerspective implements CameraPerspective {
|
|
689
|
+
readonly id = "first-person";
|
|
690
|
+
readonly defaults: {
|
|
691
|
+
damping: number;
|
|
692
|
+
};
|
|
693
|
+
private opts;
|
|
694
|
+
/** Fallback position when no target entity is attached. Mutate directly for manual movement. */
|
|
695
|
+
initialPosition?: Vector3;
|
|
696
|
+
private initialLookAt?;
|
|
697
|
+
private _yaw;
|
|
698
|
+
private _pitch;
|
|
699
|
+
private _currentFov;
|
|
700
|
+
private _targetFov;
|
|
701
|
+
private _lookAtTarget;
|
|
702
|
+
private _lookAtLerpSpeed;
|
|
703
|
+
private _currentRotation;
|
|
704
|
+
private _rotationInitialized;
|
|
705
|
+
constructor(options?: FirstPersonOptions);
|
|
706
|
+
/** Accumulate yaw and pitch deltas. Pitch is clamped to the configured limit. */
|
|
707
|
+
look(deltaYaw: number, deltaPitch: number): void;
|
|
708
|
+
/** Set absolute yaw and pitch. Pitch is clamped to the configured limit. */
|
|
709
|
+
setLook(yaw: number, pitch: number): void;
|
|
710
|
+
/** Current yaw in radians. */
|
|
711
|
+
get yaw(): number;
|
|
712
|
+
/** Current pitch in radians. */
|
|
713
|
+
get pitch(): number;
|
|
714
|
+
/** Set the target FOV for a smooth zoom transition (e.g. sniper scope). */
|
|
715
|
+
zoom(fov: number): void;
|
|
716
|
+
/** Return to the default FOV. */
|
|
717
|
+
resetZoom(): void;
|
|
718
|
+
/** Current field of view. */
|
|
719
|
+
get currentFov(): number;
|
|
720
|
+
/**
|
|
721
|
+
* Enable smooth look-at toward a world position.
|
|
722
|
+
* The camera will slerp from the current rotation toward the look-at direction.
|
|
723
|
+
*/
|
|
724
|
+
lookAt(target: Vector3, lerpSpeed?: number): void;
|
|
725
|
+
/** Disable look-at and return to manual yaw/pitch control. */
|
|
726
|
+
clearLookAt(): void;
|
|
727
|
+
getBasePose(ctx: CameraContext): CameraPose;
|
|
728
|
+
private computePosition;
|
|
729
|
+
private computeRotation;
|
|
730
|
+
private lerpFov;
|
|
731
|
+
private deriveYawPitchFromLookAt;
|
|
732
|
+
private deriveYawPitchFromQuaternion;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Perspective-specific options union.
|
|
737
|
+
* Extend as new perspective types are added.
|
|
738
|
+
*/
|
|
739
|
+
type PerspectiveOptions = ThirdPersonOptions | Fixed2DOptions | FirstPersonOptions;
|
|
740
|
+
/**
|
|
741
|
+
* Factory: create a CameraPerspective from a PerspectiveType string.
|
|
742
|
+
* Unrecognized types default to ThirdPersonPerspective.
|
|
743
|
+
*/
|
|
744
|
+
declare function createPerspective(type: PerspectiveType, options?: PerspectiveOptions): CameraPerspective;
|
|
745
|
+
|
|
746
|
+
interface CameraOptions {
|
|
747
|
+
perspective?: PerspectiveType;
|
|
748
|
+
position?: Vector3 | {
|
|
749
|
+
x: number;
|
|
750
|
+
y: number;
|
|
751
|
+
z: number;
|
|
752
|
+
};
|
|
753
|
+
target?: Vector3 | {
|
|
754
|
+
x: number;
|
|
755
|
+
y: number;
|
|
756
|
+
z: number;
|
|
757
|
+
} | any;
|
|
758
|
+
zoom?: number;
|
|
759
|
+
screenResolution?: Vector2;
|
|
760
|
+
/**
|
|
761
|
+
* Renderer type: 'auto' | 'webgpu' | 'webgl'
|
|
762
|
+
* Use 'webgpu' for TSL shaders
|
|
763
|
+
* @default 'webgl'
|
|
764
|
+
*/
|
|
765
|
+
rendererType?: RendererType;
|
|
766
|
+
/**
|
|
767
|
+
* Enable orbital controls for this camera.
|
|
768
|
+
* Can be toggled at runtime via enableOrbitalControls() / disableOrbitalControls().
|
|
769
|
+
* @default false
|
|
770
|
+
*/
|
|
771
|
+
useOrbitalControls?: boolean;
|
|
772
|
+
/**
|
|
773
|
+
* Viewport in normalized coordinates (0-1).
|
|
774
|
+
* Defines where this camera renders on the canvas.
|
|
775
|
+
* @default { x: 0, y: 0, width: 1, height: 1 } (fullscreen)
|
|
776
|
+
*/
|
|
777
|
+
viewport?: Viewport;
|
|
778
|
+
/**
|
|
779
|
+
* Optional name for camera manager lookup.
|
|
780
|
+
*/
|
|
781
|
+
name?: string;
|
|
782
|
+
/**
|
|
783
|
+
* Initial behaviors to attach to the camera pipeline.
|
|
784
|
+
* Keys are used for idempotent add/remove.
|
|
785
|
+
*/
|
|
786
|
+
behaviors?: Record<string, CameraBehavior>;
|
|
787
|
+
/**
|
|
788
|
+
* Pipeline smoothing factor (0-1).
|
|
789
|
+
* 1 = instant snap, 0 = no movement.
|
|
790
|
+
* @default 0.15
|
|
791
|
+
*/
|
|
792
|
+
damping?: number;
|
|
793
|
+
/**
|
|
794
|
+
* When set, the camera renders to an offscreen texture instead of a
|
|
795
|
+
* screen viewport. Use with setCameraFeed() to display the feed on
|
|
796
|
+
* an in-scene mesh (jumbotron, security monitor, portal, etc.).
|
|
797
|
+
*
|
|
798
|
+
* @default undefined (renders to screen)
|
|
799
|
+
*/
|
|
800
|
+
renderToTexture?: {
|
|
801
|
+
/** Texture width in pixels. @default 512 */
|
|
802
|
+
width?: number;
|
|
803
|
+
/** Texture height in pixels. @default 512 */
|
|
804
|
+
height?: number;
|
|
805
|
+
};
|
|
806
|
+
/**
|
|
807
|
+
* When true, this camera will not activate orbital controls in debug mode.
|
|
808
|
+
* The pipeline (and its behaviors) will always run for this camera.
|
|
809
|
+
* Use for cameras with custom behaviors (e.g. FPS mouse-look) that must
|
|
810
|
+
* control the camera through the pipeline rather than debug orbit controls.
|
|
811
|
+
* @default false
|
|
812
|
+
*/
|
|
813
|
+
skipDebugOrbit?: boolean;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* CameraWrapper is the user-facing camera handle returned by createCamera().
|
|
817
|
+
* It provides convenience methods for target management, orbital controls,
|
|
818
|
+
* viewport configuration, and the camera pose pipeline.
|
|
819
|
+
*/
|
|
820
|
+
declare class CameraWrapper {
|
|
821
|
+
cameraRef: ZylemCamera;
|
|
822
|
+
constructor(camera: ZylemCamera);
|
|
823
|
+
/**
|
|
824
|
+
* Add a target entity for the camera to follow/frame.
|
|
825
|
+
* With multiple targets, the camera auto-frames to include all of them.
|
|
826
|
+
*/
|
|
827
|
+
addTarget(entity: StageEntity): void;
|
|
828
|
+
/**
|
|
829
|
+
* Remove a target entity from the camera.
|
|
830
|
+
*/
|
|
831
|
+
removeTarget(entity: StageEntity): void;
|
|
832
|
+
/**
|
|
833
|
+
* Clear all targets. Camera will look at world origin.
|
|
834
|
+
*/
|
|
835
|
+
clearTargets(): void;
|
|
836
|
+
/**
|
|
837
|
+
* Enable orbital controls for this camera.
|
|
838
|
+
* Allows the user to orbit, pan, and zoom the camera.
|
|
839
|
+
*/
|
|
840
|
+
enableOrbitalControls(): void;
|
|
841
|
+
/**
|
|
842
|
+
* Disable orbital controls for this camera.
|
|
843
|
+
*/
|
|
844
|
+
disableOrbitalControls(): void;
|
|
845
|
+
/**
|
|
846
|
+
* Set the viewport for this camera (normalized 0-1 coordinates).
|
|
847
|
+
* @param x Left edge (0 = left of canvas)
|
|
848
|
+
* @param y Bottom edge (0 = bottom of canvas)
|
|
849
|
+
* @param width Width as fraction of canvas
|
|
850
|
+
* @param height Height as fraction of canvas
|
|
851
|
+
*/
|
|
852
|
+
setViewport(x: number, y: number, width: number, height: number): void;
|
|
853
|
+
/**
|
|
854
|
+
* Add or replace a behavior by key (idempotent).
|
|
855
|
+
* Behaviors modify the desired camera pose each frame.
|
|
856
|
+
*
|
|
857
|
+
* @param key Unique key for this behavior (used for replacement/removal).
|
|
858
|
+
* @param behavior The CameraBehavior implementation.
|
|
859
|
+
*/
|
|
860
|
+
addBehavior(key: string, behavior: CameraBehavior): void;
|
|
861
|
+
/**
|
|
862
|
+
* Remove a behavior by key.
|
|
863
|
+
*/
|
|
864
|
+
removeBehavior(key: string): boolean;
|
|
865
|
+
/**
|
|
866
|
+
* Add a transient action (screenshake, recoil, etc.).
|
|
867
|
+
* Actions apply additive deltas and self-expire when isDone() returns true.
|
|
868
|
+
*/
|
|
869
|
+
addAction(action: CameraAction): void;
|
|
870
|
+
/**
|
|
871
|
+
* Switch the camera's active perspective at runtime.
|
|
872
|
+
* The first frame after switching snaps to the new pose (no lerp).
|
|
873
|
+
*
|
|
874
|
+
* @param type Perspective type string (e.g. Perspectives.ThirdPerson).
|
|
875
|
+
* @param options Perspective-specific options (distance, height, zoom, etc.).
|
|
876
|
+
*/
|
|
877
|
+
setPerspective(type: PerspectiveType, options?: PerspectiveOptions): void;
|
|
878
|
+
/**
|
|
879
|
+
* Retrieve the active perspective instance, cast to the desired type.
|
|
880
|
+
* Useful for calling perspective-specific methods (e.g. FirstPersonPerspective.look()).
|
|
881
|
+
*
|
|
882
|
+
* @example
|
|
883
|
+
* const fps = camera.getPerspective<FirstPersonPerspective>();
|
|
884
|
+
* fps.look(dx, dy);
|
|
885
|
+
*/
|
|
886
|
+
getPerspective<T extends CameraPerspective = CameraPerspective>(): T;
|
|
887
|
+
/**
|
|
888
|
+
* Return a debug snapshot of the camera pipeline state.
|
|
889
|
+
* Includes: active perspective, desired/final pose, behavior keys, action count.
|
|
890
|
+
*/
|
|
891
|
+
getState(): CameraPipelineState;
|
|
892
|
+
/**
|
|
893
|
+
* Get the offscreen render texture for this camera.
|
|
894
|
+
* Returns null if the camera was not created with renderToTexture.
|
|
895
|
+
* Use with setCameraFeed() or apply directly to a mesh material.
|
|
896
|
+
*/
|
|
897
|
+
getRenderTexture(): Texture | null;
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Create a camera with the given options.
|
|
901
|
+
* Returns a CameraWrapper for convenient access to camera features.
|
|
902
|
+
*/
|
|
903
|
+
declare function createCamera(options: CameraOptions): CameraWrapper;
|
|
904
|
+
|
|
905
|
+
export { CameraManager as C, FirstPersonPerspective as F, type PerspectiveType as P, RendererManager as R, type TransformLike as T, type Viewport as V, ZylemCamera as Z, CameraWrapper as a, type CameraBehavior as b, createCamera as c, type CameraOptions as d, Perspectives as e, type RendererType as f, type ZylemRenderer as g, type CameraPose as h, isWebGPUSupported as i, type PoseDelta as j, type CameraContext as k, type CameraPerspective as l, type CameraAction as m, type CameraPipelineState as n, CameraPipeline as o, ThirdPersonPerspective as p, Fixed2DPerspective as q, createPerspective as r, type ThirdPersonOptions as s, type Fixed2DOptions as t, type FirstPersonOptions as u, type PerspectiveOptions as v };
|