@expofp/renderer 1.4.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +112 -32
  2. package/dist/index.js +1578 -1202
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -2,6 +2,9 @@ import { default as default_2 } from 'stats-gl';
2
2
  import { Vector2 } from 'three';
3
3
  import { Vector2Like } from 'three';
4
4
  import { Vector2Tuple } from 'three';
5
+ import { Vector3 } from 'three';
6
+ import { Vector3Like } from 'three';
7
+ import { Vector3Tuple } from 'three';
5
8
  import { WebGLRenderer } from 'three';
6
9
 
7
10
  /** Camera state returned by {@link ControlsAPI.getCameraState}. */
@@ -45,7 +48,7 @@ export declare interface ControlsAPI {
45
48
  * @param immediate If true, applies the change immediately without animation
46
49
  * @returns Promise that resolves when the zoom animation completes
47
50
  */
48
- zoomBy(zoom: number, immediate?: boolean): Promise<void>;
51
+ zoomBy: (zoom: number, immediate?: boolean) => Promise<void>;
49
52
  /**
50
53
  * Zooms the camera to fit the given rectangle.
51
54
  * @param rect Rectangle to zoom to in SVG coordinates
@@ -53,7 +56,7 @@ export declare interface ControlsAPI {
53
56
  * @param immediate If true, applies the change immediately without animation
54
57
  * @returns Promise that resolves when the zoom animation completes
55
58
  */
56
- zoomTo(rect: Rect, options?: Partial<ZoomToOptions>, immediate?: boolean): Promise<void>;
59
+ zoomTo: (rect: Rect, options?: Partial<ZoomToOptions>, immediate?: boolean) => Promise<void>;
57
60
  /**
58
61
  * Pans the camera by the given offset in SVG space.
59
62
  * @param x X offset in SVG space
@@ -61,7 +64,7 @@ export declare interface ControlsAPI {
61
64
  * @param immediate If true, applies the change immediately without animation
62
65
  * @returns Promise that resolves when the pan animation completes
63
66
  */
64
- panBy(x: number, y: number, immediate?: boolean): Promise<void>;
67
+ panBy: (x: number, y: number, immediate?: boolean) => Promise<void>;
65
68
  /**
66
69
  * Pans the camera to the given coordinates in SVG space.
67
70
  * @param x X coordinate in SVG space
@@ -69,7 +72,7 @@ export declare interface ControlsAPI {
69
72
  * @param immediate If true, applies the change immediately without animation
70
73
  * @returns Promise that resolves when the pan animation completes
71
74
  */
72
- panTo(x: number, y: number, immediate?: boolean): Promise<void>;
75
+ panTo: (x: number, y: number, immediate?: boolean) => Promise<void>;
73
76
  /**
74
77
  * Rolls the camera by the given angle in degrees.
75
78
  * Note: This method won't work if {@link ControlsAPI.handlers | handlers.roll} is disabled.
@@ -77,7 +80,7 @@ export declare interface ControlsAPI {
77
80
  * @param immediate If true, applies the change immediately without animation
78
81
  * @returns Promise that resolves when the roll animation completes
79
82
  */
80
- rollBy(angle: number, immediate?: boolean): Promise<void>;
83
+ rollBy: (angle: number, immediate?: boolean) => Promise<void>;
81
84
  /**
82
85
  * Rolls the camera to the given angle in degrees.
83
86
  * Note: This method won't work if {@link ControlsAPI.handlers | handlers.roll} is disabled.
@@ -85,7 +88,7 @@ export declare interface ControlsAPI {
85
88
  * @param immediate If true, applies the change immediately without animation
86
89
  * @returns Promise that resolves when the roll animation completes
87
90
  */
88
- rollTo(angle: number, immediate?: boolean): Promise<void>;
91
+ rollTo: (angle: number, immediate?: boolean) => Promise<void>;
89
92
  /**
90
93
  * Pitches the camera by the given angle in degrees.
91
94
  * Positive angles increase pitch, negative angles decrease pitch.
@@ -94,7 +97,7 @@ export declare interface ControlsAPI {
94
97
  * @param immediate If true, applies the change immediately without animation
95
98
  * @returns Promise that resolves when the pitch animation completes
96
99
  */
97
- pitchBy(angle: number, immediate?: boolean): Promise<void>;
100
+ pitchBy: (angle: number, immediate?: boolean) => Promise<void>;
98
101
  /**
99
102
  * Pitches the camera to the given angle in degrees.
100
103
  * The angle is clamped to the 0-90 degree range.
@@ -103,30 +106,30 @@ export declare interface ControlsAPI {
103
106
  * @param immediate If true, applies the change immediately without animation
104
107
  * @returns Promise that resolves when the pitch animation completes
105
108
  */
106
- pitchTo(angle: number, immediate?: boolean): Promise<void>;
109
+ pitchTo: (angle: number, immediate?: boolean) => Promise<void>;
107
110
  /**
108
111
  * Resets the camera to the starting state.
109
112
  * @param options Configuration for which handlers to reset
110
113
  * @param immediate If true, applies the change immediately without animation
111
114
  * @returns Promise that resolves when all reset animations complete
112
115
  */
113
- resetCamera(options?: Partial<ResetCameraOptions>, immediate?: boolean): Promise<void>;
116
+ resetCamera: (options?: Partial<ResetCameraOptions>, immediate?: boolean) => Promise<void>;
114
117
  /**
115
118
  * Configures smooth time values for camera operations.
116
119
  * @param options Partial configuration object with time values in seconds
117
120
  */
118
- configure(options: Partial<ConfigureOptions>): void;
121
+ configure: (options: Partial<ConfigureOptions>) => void;
119
122
  /**
120
123
  * Sets the camera bounds to restrict camera movement.
121
124
  * Note: This method must be called after the viewport is initialized by `renderer.start()`.
122
125
  * @param rect Rectangle in SVG coordinates defining the camera boundary or `undefined` to remove the boundary
123
126
  */
124
- setCameraBounds(rect?: Rect): void;
127
+ setCameraBounds: (rect?: Rect) => void;
125
128
  /**
126
129
  * Gets the current camera state.
127
130
  * @returns Camera state object with center, zoom, roll, pitch, and ptScale
128
131
  */
129
- getCameraState(): CameraState;
132
+ getCameraState: () => CameraState;
130
133
  }
131
134
 
132
135
  /**
@@ -136,6 +139,13 @@ export declare interface ControlsAPI {
136
139
  */
137
140
  export declare function createVector2(vector2: IVector2): Vector2;
138
141
 
142
+ /**
143
+ * Converts multiple vector3 representations to a {@link Vector3} instance.
144
+ * @param vector3 Vector3 representation as a tuple/POJO
145
+ * @returns Vector3 instance
146
+ */
147
+ export declare function createVector3(vector3: IVector3 | IVector2): Vector3;
148
+
139
149
  /**
140
150
  * Mapping of engine-wide events to their payloads
141
151
  */
@@ -160,9 +170,27 @@ export declare type EventHandler<Payload> = (payload: Payload) => void;
160
170
  * Public API for interacting with the event system
161
171
  */
162
172
  export declare interface EventsAPI {
173
+ /**
174
+ * Add an event listener for a specific event
175
+ * @param event - The event to listen for
176
+ * @param handler - The handler to call when the event is emitted
177
+ */
163
178
  addEventListener<E extends keyof EngineEvents>(event: E, handler: EventHandler<EngineEvents[E]>): void;
179
+ /**
180
+ * Remove an event listener for a specific event
181
+ * @param event - The event to remove the listener for
182
+ * @param handler - The handler to remove
183
+ */
164
184
  removeEventListener<E extends keyof EngineEvents>(event: E, handler: EventHandler<EngineEvents[E]>): void;
185
+ /**
186
+ * Check if there are any listeners for a specific event
187
+ * @param event - The event to check
188
+ * @returns true if there are listeners, false otherwise
189
+ */
165
190
  hasListeners<E extends keyof EngineEvents>(event: E): boolean;
191
+ /**
192
+ * Clear all event listeners
193
+ */
166
194
  clear(): void;
167
195
  }
168
196
 
@@ -252,6 +280,8 @@ export declare function isTextLayer(layer: LayerDef): layer is TypedLayerDef<Tex
252
280
 
253
281
  export declare type IVector2 = Vector2 | Vector2Like | Vector2Tuple;
254
282
 
283
+ export declare type IVector3 = Vector3 | Vector3Like | Vector3Tuple;
284
+
255
285
  /** Layer definition */
256
286
  export declare interface LayerDef extends SharedDef {
257
287
  /** Layer's name */
@@ -260,6 +290,8 @@ export declare interface LayerDef extends SharedDef {
260
290
  interactive?: boolean;
261
291
  /** Collection of layer's children. Mixing different types of children is not supported. */
262
292
  children: RenderableDefCollection;
293
+ /** Layer's rendering mode, 2d or 3d. Optional, 2d by default. */
294
+ mode?: "2d" | "3d";
263
295
  }
264
296
 
265
297
  /** Line definition */
@@ -303,14 +335,14 @@ export declare interface PitchHandlerOptions {
303
335
  /** Polygon shape instance. */
304
336
  export declare class Polygon {
305
337
  /** Array of polygon vertices. */
306
- readonly vertices: Vector2[];
338
+ readonly vertices: Vector3[];
307
339
  /** Array of polygon indices. Each index is a triplet of vertex indices forming a triangle. */
308
340
  readonly indices: Index[];
309
341
  /**
310
342
  * @param vertices Array of polygon vertices.
311
343
  * @param indices Array of polygon indices. Each index is a triplet of vertex indices forming a triangle.
312
344
  */
313
- constructor(vertices: IVector2[], indices: Index[]);
345
+ constructor(vertices: (IVector3 | IVector2)[], indices: Index[]);
314
346
  /**
315
347
  * Converts a {@link Rect} to a {@link Polygon}.
316
348
  * @param rect {@link Rect} instance
@@ -387,12 +419,17 @@ export declare class Renderer {
387
419
  private viewportSystem;
388
420
  private interactionsSystem;
389
421
  private controlsSystem;
422
+ private controlsAPI?;
423
+ private eventsAPI?;
424
+ private viewportAPI?;
390
425
  private clock;
391
426
  private renderer;
392
- private viewport?;
393
- private needsRedraw;
427
+ private visibleRectValue?;
394
428
  private memoryInfoExtension;
395
- private memoryInfo;
429
+ private memoryInfo?;
430
+ private initialized;
431
+ private disposed;
432
+ private needsRedraw;
396
433
  /**
397
434
  * @param opts {@link RendererOptions}
398
435
  */
@@ -405,6 +442,10 @@ export declare class Renderer {
405
442
  * {@link EventsAPI} instance for subscribing to internal events
406
443
  */
407
444
  get events(): EventsAPI;
445
+ /**
446
+ * {@link ViewportAPI} instance for view transforms and external transforms.
447
+ */
448
+ get viewport(): ViewportAPI;
408
449
  /**
409
450
  * Optional sub-rectangle of the viewport that is used for positioning scene's viewbox
410
451
  */
@@ -419,40 +460,59 @@ export declare class Renderer {
419
460
  get context(): WebGLRenderer;
420
461
  /* Excluded from this release type: size */
421
462
  /**
422
- * Sets the renderer to external mode, where parts of rendering process are not managed by the renderer (e.g. Mapbox GL JS).
423
- * @param staticTransformMatrix static transform matrix to apply to the scene
463
+ * Returns true if the renderer is in external mode, meaning that webgl context is managed outside of the renderer
464
+ * (for example, when using Mapbox GL JS as a host context). In this mode renderer will not clear the canvas before
465
+ * rendering, and will not automatically compute scene and camera transformations. Clients are responsible for setting
466
+ * the matrices manually by using {@link Renderer.viewport} methods.
424
467
  */
425
- setExternalTransform(staticTransformMatrix: number[]): void;
468
+ get isExternalMode(): boolean;
426
469
  /**
427
- * Update scene matrix from dynamic transform matrix.
428
- * @param dynamicTransformMatrix dynamic transform matrix (changes every frame)
470
+ * Returns true if the renderer is initialized, meaning that the viewport and scene have been set up.
429
471
  */
430
- updateExternalCamera(dynamicTransformMatrix: number[]): void;
472
+ get isInitialized(): boolean;
431
473
  /**
432
- * Initialize the scene and start the rendering loop
474
+ * Returns true if the renderer is disposed, meaning that all WebGL resources have been released.
475
+ */
476
+ get isDisposed(): boolean;
477
+ /**
478
+ * Initializes viewport and scene with the given scene definition.
479
+ * Should be called once on startup. Repeated calls will produce console warnings.
433
480
  * @param sceneDef {@link SceneDef} to render
434
- * @param startLoop whether to start the rendering loop
435
481
  */
436
- start(sceneDef: SceneDef, startLoop?: boolean): void;
482
+ init(sceneDef: SceneDef): void;
483
+ /**
484
+ * Start the rendering loop
485
+ */
486
+ start(): void;
437
487
  /**
438
488
  * Update the given defs to make them reflect the current state
439
489
  * @param defs {@link RenderableDef} array to update
440
490
  */
441
491
  update(...defs: RenderableDef[]): void;
442
492
  /**
443
- * Converts coordinates from canvas space to SVG space.
444
- * @param point point in canvas space (relative to the canvas's top left corner), in css pixels
445
- * @returns point in SVG space
493
+ * Render a single frame
446
494
  */
447
- screenToSvg(point: Vector2Like): Vector2Like;
495
+ render(): void;
448
496
  /**
449
- * Main rendering loop
497
+ * Stop the rendering loop
450
498
  */
451
- render(): void;
499
+ stop(): void;
500
+ /**
501
+ * Dispose all WebGL resources. This calls {@link Renderer.stop} internally.
502
+ * WARNING: This method is final and cannot be undone. Attempting to use the renderer after calling this method
503
+ * will result in a console warning and no-op methods. If you need to re-initialize the renderer, create a new instance.
504
+ */
505
+ dispose(): void;
452
506
  private resizeCanvasToDisplaySize;
453
507
  private updateMemoryInfo;
454
508
  private onContextLost;
455
509
  private onContextRestored;
510
+ private initContext;
511
+ private assertNotDisposed;
512
+ private assertInitialized;
513
+ private assertNotInitialized;
514
+ private assertNotExternalMode;
515
+ private assertExternalMode;
456
516
  }
457
517
 
458
518
  /**
@@ -573,6 +633,26 @@ export declare interface UI {
573
633
  memoryInfoPanel: HTMLDivElement;
574
634
  }
575
635
 
636
+ /** Viewport system public API. */
637
+ export declare interface ViewportAPI {
638
+ /**
639
+ * Convert canvas coordinates (CSS pixels, relative to canvas top-left) to SVG coordinates.
640
+ * @param point point in canvas space (CSS pixels)
641
+ * @returns point in SVG coordinates or undefined if point is outside the SVG plane
642
+ */
643
+ canvasToSvg: (point: Vector2Like) => Vector2Like | undefined;
644
+ /**
645
+ * Set static part of an svg -> px transform matrix
646
+ * @param staticTransformMatrix static transform matrix to apply to the scene
647
+ */
648
+ setStaticTransform: (staticTransformMatrix: number[]) => void;
649
+ /**
650
+ * Set dynamic part of an svg -> px transform matrix. Should be called every frame.
651
+ * @param dynamicTransformMatrix dynamic transform matrix (changes every frame)
652
+ */
653
+ setDynamicTransform: (dynamicTransformMatrix: number[]) => void;
654
+ }
655
+
576
656
  /** Options for the {@link ControlsAPI.zoomTo} method. */
577
657
  export declare interface ZoomToOptions {
578
658
  /** Maximum zoom factor. */