illutions 0.23.1 → 0.24.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.1
4
+
5
+ ### Added
6
+
7
+ - Added the `PROGRESSBAR_HIDDEN` event.
8
+
9
+ ### Changed
10
+
11
+ - Renamed the `aaCfg` interface to `AaCfg`.
12
+
13
+ ### Fixed
14
+
15
+ - Fixed an incorrect `objTarget.position` when enabling orbit or FPV controls after setting it in `Cam3D.onReady()`.
16
+
17
+ ## 0.24.0
18
+
19
+ ### Added
20
+
21
+ - Added animation modes `BlendMode`, `FinishMode`, `LoopMode`, `StopMode`
22
+ - Added `fadeDuration` to `playClip()` and `playClipCam()`.
23
+ - Added `Audio.load()` to load audio without starting playback.
24
+ - Added the `AudioLoadedEvent` (`AUDIO_LOADED`) event for handling completed audio loading.
25
+
26
+ ### Changed
27
+
28
+ - Replaced `pauseActions` with `stopMode` and `infinite` with `loop` in animation clip playback.
29
+ - Renamed `Raycast.trackSelectable()` to `Raycast.trackSelectables()`.
30
+ - Changed the `LightCfg` shadow defaults to match the corresponding Three.js defaults, while keeping `castShadow` enabled by default.
31
+
32
+ ### Fixed
33
+
34
+ - Fixed visual stuttering when transitioning from orbit rotation to panning with damping enabled by keeping `OrbitCtrls` in `lookMode = 'target'` for all OrbitControls interactions.
35
+
3
36
  ## 0.23.1
4
37
 
5
38
  ### FIXED
package/dist/main.d.ts CHANGED
@@ -35,7 +35,7 @@ import { TierResult } from 'detect-gpu';
35
35
  * Defines the shared anti-aliasing settings.
36
36
  * @category Cfg
37
37
  */
38
- export declare interface aaCfg {
38
+ export declare interface AaCfg {
39
39
  /**
40
40
  * Whether the GUI anti-aliasing dropdown is open.
41
41
  * @default false
@@ -112,6 +112,8 @@ export declare class App<TClasses extends Classes = {}> {
112
112
  private readonly inspector;
113
113
  readonly comps: CompInsts<NonNullable<TClasses['comps']>>;
114
114
  readonly objs3D: Obj3DInsts<NonNullable<TClasses['objs3D']>>;
115
+ private compsMap;
116
+ private objs3DMap;
115
117
  /* Excluded from this release type: __constructor */
116
118
  init(cfg: Cfg): Promise<void>;
117
119
  /**
@@ -137,7 +139,8 @@ declare class Audio_2 {
137
139
  private readonly ctx;
138
140
  private readonly loader;
139
141
  private readonly engine;
140
- private readonly sounds;
142
+ private readonly events;
143
+ private readonly loadedSounds;
141
144
  private readonly params;
142
145
  private listener;
143
146
  /* Excluded from this release type: __constructor */
@@ -165,32 +168,32 @@ declare class Audio_2 {
165
168
  isPlaying({ name }: {
166
169
  name: string;
167
170
  }): boolean;
171
+ private loadSound;
168
172
  /**
169
- * Loads an audio file and plays it once loaded with a smooth fade-in.
170
- * @param params - The parameters for loading and playing an audio.
171
- * @param params.name - Unique name of the audio.
172
- * @param params.url - Path or URL to the audio file.
173
- * @param params.object - The name of the object to attach the audio to for positional audio. Pass an empty string for global audio.
174
- * @param params.volume - The target playback volume. Default: **0**
175
- * @param params.fade - The fade-in duration of the audio in seconds. Default: **2**
176
- * @param params.loop - Whether the audio should loop. Default: **true**
173
+ * Loads an audio file without playing it and sends an `AUDIO_LOADED` event when the sound is ready.
174
+ * @param params - The sound options.
177
175
  */
178
- loadAndPlay({ name, url, object, volume, fade, loop }: {
179
- name: string;
180
- url: string;
181
- object: string;
182
- volume?: number;
183
- fade?: number;
184
- loop?: boolean;
185
- }): void;
176
+ load({ name, url, object, volume, fade, loop }: SoundParams): void;
186
177
  /**
187
- * Plays an already loaded audio with a smooth fade-in.
178
+ * Loads an audio file and plays it automatically when loading is complete.
179
+ * Use this method when no separate `AUDIO_LOADED` handling is required.
180
+ * @param params - The sound options.
181
+ */
182
+ loadAndPlay({ name, url, object, volume, fade, loop }: SoundParams): void;
183
+ /**
184
+ * Plays an audio that has finished loading, with a smooth fade-in.
185
+ * When using {@link load}, call this method after receiving the matching `AUDIO_LOADED` event.
186
+ * This method does not wait for an audio file that is still loading.
188
187
  * @param params - Parameter object.
189
- * @param params.name - The name of the audio to play.
188
+ * @param params.name - The name of the loaded audio to play.
190
189
  */
191
190
  play({ name }: {
192
191
  name: string;
193
192
  }): void;
193
+ /**
194
+ * Resumes the Web Audio context after a user gesture.
195
+ */
196
+ resume(): void;
194
197
  private setAttribute;
195
198
  private setAudioContext;
196
199
  /**
@@ -283,6 +286,21 @@ export declare interface AudioCfg {
283
286
  coneOuterGain: number;
284
287
  }
285
288
 
289
+ /** @event Fired when an audio file has finished loading and is ready for playback. */
290
+ export declare interface AudioLoadedEvent {
291
+ /** Identifies this event type. */
292
+ type: 'AUDIO_LOADED';
293
+ /** The unique name assigned to the loaded sound. */
294
+ soundName: string;
295
+ }
296
+
297
+ /**
298
+ * Defines how an animation action is blended with other active actions.
299
+ * - `'normal'`: Blends the action's values with other normal actions according to their weights.
300
+ * - `'additive'`: Adds the action's values to the current animation result according to its weight.
301
+ */
302
+ export declare type BlendMode = 'normal' | 'additive';
303
+
286
304
  /**
287
305
  * Wraps a `THREE.Camera` and provides a structured interface for configuring and controlling camera settings.
288
306
  * @category 3D Objects
@@ -597,15 +615,16 @@ export declare class Engine {
597
615
  private readonly cfg;
598
616
  private readonly infoBox;
599
617
  private actionObserver;
618
+ private readonly objActions;
600
619
  private gltf;
601
620
  private mixer;
621
+ private callbacks;
622
+ private canvas;
602
623
  private composer;
603
624
  /* Excluded from this release type: renderer */
604
625
  private renderPipeline;
605
626
  /* Excluded from this release type: sceneReady */
606
627
  /* Excluded from this release type: rendererReady */
607
- private callbacks;
608
- private canvas;
609
628
  private fxaaPass;
610
629
  private outputPass;
611
630
  private renderPass;
@@ -633,6 +652,7 @@ export declare class Engine {
633
652
  /* Excluded from this release type: __constructor */
634
653
  /* Excluded from this release type: init */
635
654
  private initWebGpuRenderer;
655
+ private addActionToObj;
636
656
  /**
637
657
  * Registers a callback that is executed on every requestAnimationFrame update.
638
658
  * @param {(deltaTime: number) => void} cb - Callback executed once per frame with `deltaTime`.
@@ -736,6 +756,8 @@ export declare class Engine {
736
756
  [key: string]: any;
737
757
  }): void;
738
758
  private calcEaseArea;
759
+ private stopObjActions;
760
+ private finishAction;
739
761
  /**
740
762
  * Selects the active anti-aliasing mode. The modes `'fxaa'` and `'smaa'` lazy-load their required modules.
741
763
  * @param aaMode - The anti-aliasing mode to use.
@@ -755,37 +777,43 @@ export declare class Engine {
755
777
  /* Excluded from this release type: isPostEnabled */
756
778
  private isPostGpu;
757
779
  private loadScene;
758
- private pauseObjActions;
759
780
  /**
760
- * The method finds a Three.js animation clip by name, validates that it exists within the loaded GLTF and plays it via the `THREE.AnimationMixer`. It supports fade-in/out speed transitions, reverse playback,
761
- * and infinite looping of the clip.
781
+ * Finds a Three.js animation clip by name and plays it through the `THREE.AnimationMixer`.
762
782
  *
763
- * @param params - Parameter object for controlling the animation playback.
783
+ * @param params - Parameters for controlling the animation playback.
764
784
  * @param params.obj - The name of the object whose animation clip should be played.
765
785
  * @param params.clip - The name of the animation clip to play.
766
- * @param params.pauseActions - Defines which other actions of the same object should be paused before playing this clip. Default: **'all'**
786
+ * @param params.blendMode - How the action is blended with other active actions. Default: **'normal'**
787
+ * @param params.finishMode - Whether the final pose is held or faded out after the final loop. Default: **'hold'**
788
+ * @param params.loop - Number of plays or `'infinite'` for endless looping. Default: **1**
789
+ * @param params.stopMode - Which previous actions of the same object are stopped before playback. Default: **'all'**
790
+ * @param params.fadeDuration - Duration in seconds for fading affected previous actions out and the new action in. Default: **0**
791
+ * @param params.fadeDurationFinish - Duration in seconds for `finishMode: 'fadeOut'`. Default: **0**
767
792
  * @param params.reverse - If `true`, plays the clip in reverse. Default: **false**
768
- * @param params.infinite - If `true`, the animation loops infinitely. Default: **false**
769
- * @param params.reset - If `true`, resets the clip to its start position before playback. In reverse mode, it resets to the clip end. Default: **false**
770
- * @param params.startSpeed - The initial playback speed at the beginning of the fade. Default: **0**
771
- * @param params.endSpeed - The target playback speed at the end of the fade. Default: **1**
772
- * @param params.duration - The duration in seconds for the fade transition between start and end speed. Default: **0**
773
- * @param params.ease - The easing function name for GSAP. Default: **'power1.inOut'**
774
-
793
+ * @param params.reset - If `true`, resets the clip before playback. Default: **false**
794
+ * @param params.startSpeed - Initial playback speed for speed interpolation. Default: **0**
795
+ * @param params.endSpeed - Target playback speed. Default: **1**
796
+ * @param params.duration - Duration in seconds for speed interpolation. Default: **0**
797
+ * @param params.ease - GSAP easing function name. Default: **'power1.inOut'**
798
+ *
775
799
  * @remarks
776
- * The method interpolates `timeScale` of the `THREE.AnimationAction`, allowing smooth acceleration or deceleration of animation playback.
800
+ * `finishMode` and `fadeDurationFinish` have no effect when `loop` is `'infinite'`.
777
801
  *
778
802
  * **Events**
779
803
  *
780
804
  * {@link ClipEvent}
781
805
  */
782
- playClip({ obj, clip: clipName, pauseActions, reverse, infinite, reset, startSpeed, endSpeed, duration, ease }: {
806
+ playClip({ obj, clip: clipName, blendMode, finishMode, loop, stopMode, fadeDuration, fadeDurationFinish, reverse, reset, startSpeed, endSpeed, duration, ease }: {
783
807
  obj: string;
784
808
  clip: string;
785
809
  singleAction?: boolean;
786
- pauseActions?: PauseObjectActions;
810
+ blendMode?: BlendMode;
811
+ finishMode?: FinishMode;
812
+ loop?: LoopMode;
813
+ stopMode?: StopMode;
814
+ fadeDuration?: number;
815
+ fadeDurationFinish?: number;
787
816
  reverse?: boolean;
788
- infinite?: boolean;
789
817
  reset?: boolean;
790
818
  startSpeed?: number;
791
819
  endSpeed?: number;
@@ -793,34 +821,36 @@ export declare class Engine {
793
821
  ease?: string;
794
822
  }): void;
795
823
  /**
796
- * The method finds a camera animation clip by name, validates that it exists within the loaded GLTF and plays it via the `THREE.AnimationMixer`. It supports fade-in/out speed transitions, reverse playback,
797
- * and infinite looping of the clip.
824
+ * Finds a camera animation clip by name and plays it through the `THREE.AnimationMixer`.
798
825
  *
799
- * @param params - Parameter object for controlling the animation playback.
826
+ * @param params - Parameters for controlling the camera animation playback.
800
827
  * @param params.obj - The name of the camera object whose animation clip should be played.
801
- * @param params.clip - The name of the camera object's animation clip to play.
802
- * @param params.pauseActions - Defines which other actions of the same object should be paused before playing this clip. Default: **'all'**
828
+ * @param params.clip - The name of the camera animation clip to play.
829
+ * @param params.blendMode - How the action is blended with other active actions. Default: **'normal'**
830
+ * @param params.loop - Number of plays or `'infinite'` for endless looping. Default: **1**
831
+ * @param params.stopMode - Which previous actions of the same object are stopped before playback. Default: **'all'**
832
+ * @param params.fadeDuration - Duration in seconds for fading affected previous actions out and the new action in. Default: **0**
833
+
803
834
  * @param params.reverse - If `true`, plays the clip in reverse. Default: **false**
804
- * @param params.infinite - If `true`, the animation loops infinitely. Default: **false**
805
- * @param params.reset - If `true`, resets the clip to its start position before playback. In reverse mode, it resets to the clip end. Default: **false**
806
- * @param params.startSpeed - The initial playback speed at the beginning of the fade. Default: **0**
807
- * @param params.endSpeed - The target playback speed at the end of the fade. Default: **1**
808
- * @param params.duration - The duration in seconds for the fade transition between start and end speed. Default: **0**
809
- * @param params.ease - The easing function name for GSAP. Default: **'power1.inOut'**
810
- *
811
- * @remarks
812
- * The method interpolates `timeScale` of the `THREE.AnimationAction`, allowing smooth acceleration or deceleration of camera animation playback.
835
+ * @param params.reset - If `true`, resets the clip before playback. Default: **false**
836
+ * @param params.startSpeed - Initial playback speed for speed interpolation. Default: **0**
837
+ * @param params.endSpeed - Target playback speed. Default: **1**
838
+ * @param params.duration - Duration in seconds for speed interpolation. Default: **0**
839
+ * @param params.ease - GSAP easing function name. Default: **'power1.inOut'**
813
840
  *
841
+
814
842
  * **Events**
815
843
  *
816
844
  * {@link ClipEvent}
817
845
  */
818
- playClipCam({ obj, clip: clipName, pauseActions, reverse, infinite, reset, startSpeed, endSpeed, duration, ease }: {
846
+ playClipCam({ obj, clip: clipName, blendMode, loop, stopMode, fadeDuration, reverse, reset, startSpeed, endSpeed, duration, ease }: {
819
847
  obj: string;
820
848
  clip: string;
821
- pauseActions?: PauseObjectActions;
849
+ blendMode?: BlendMode;
850
+ loop?: LoopMode;
851
+ stopMode?: StopMode;
852
+ fadeDuration?: number;
822
853
  reverse?: boolean;
823
- infinite?: boolean;
824
854
  reset?: boolean;
825
855
  startSpeed?: number;
826
856
  endSpeed?: number;
@@ -1090,6 +1120,7 @@ export declare class Events {
1090
1120
  private enqueue;
1091
1121
  /* Excluded from this release type: anim */
1092
1122
  /* Excluded from this release type: animFade */
1123
+ /* Excluded from this release type: audioLoaded */
1093
1124
  /* Excluded from this release type: clip */
1094
1125
  /* Excluded from this release type: clipFade */
1095
1126
  /* Excluded from this release type: modelError */
@@ -1103,6 +1134,13 @@ export declare class Events {
1103
1134
  /* Excluded from this release type: windowResize */
1104
1135
  }
1105
1136
 
1137
+ /**
1138
+ * Defines how an animation action behaves after its final loop.
1139
+ * - `'hold'`: Keeps the action enabled and holds its final pose.
1140
+ * - `'fadeOut'`: Fades the action out using `fadeDurationFinish`, or disables it immediately when the duration is `0`.
1141
+ */
1142
+ export declare type FinishMode = 'hold' | 'fadeOut';
1143
+
1106
1144
  /**
1107
1145
  * Defines the fog settings controlling scene depth-based color attenuation.
1108
1146
  * @category Cfg
@@ -1430,38 +1468,50 @@ export declare class Light3D extends Obj3D {
1430
1468
  * @category Cfg
1431
1469
  */
1432
1470
  export declare interface LightCfg {
1471
+ /**
1472
+ * If true, the light casts shadows.
1473
+ * @default true
1474
+ */
1475
+ castShadow: boolean;
1433
1476
  /**
1434
1477
  * Shadow map resolution along the horizontal axis.
1435
- * @default 2048
1478
+ * @default 512
1436
1479
  */
1437
1480
  mapWidth: number;
1438
1481
  /**
1439
1482
  * Shadow map resolution along the vertical axis.
1440
- * @default 2048
1483
+ * @default 512
1441
1484
  */
1442
1485
  mapHeight: number;
1443
1486
  /**
1444
1487
  * Constant shadow bias applied to reduce shadow acne.
1445
- * @default -0.00002
1488
+ * @default 0
1446
1489
  */
1447
1490
  bias: number;
1448
1491
  /**
1449
1492
  * Normal-based shadow bias to further reduce shadow artifacts.
1450
- * @default 0.005
1493
+ * @default 0
1451
1494
  */
1452
1495
  normalBias: number;
1453
1496
  /**
1454
1497
  * Near clipping plane of the light's shadow camera.
1455
- * @default 0.1
1498
+ * @default 0.5
1456
1499
  */
1457
1500
  near: number;
1458
1501
  /**
1459
1502
  * Far clipping plane of the light's shadow camera.
1460
- * @default 5
1503
+ * @default 500
1461
1504
  */
1462
1505
  far: number;
1463
1506
  }
1464
1507
 
1508
+ /**
1509
+ * Defines how often an animation action is played.
1510
+ * - `number`: Plays the action the specified positive number of times.
1511
+ * - `'infinite'`: Repeats the action indefinitely.
1512
+ */
1513
+ export declare type LoopMode = number | 'infinite';
1514
+
1465
1515
  /**
1466
1516
  * Defines the menu bar settings used to display licensed UI controls and branding.
1467
1517
  * @category Cfg
@@ -1822,8 +1872,6 @@ export declare class OrbitCtrls {
1822
1872
  private readonly params;
1823
1873
  private orbitCtrlsFirstChange;
1824
1874
  private callback;
1825
- private listenerPointersStart;
1826
- private listenerPointersEnd;
1827
1875
  private readonly touchPointerIds;
1828
1876
  /* Excluded from this release type: __constructor */
1829
1877
  /** Creates three.js `OrbitControls`. */
@@ -1859,8 +1907,6 @@ export declare class OrbitCtrls {
1859
1907
  * The extension is executed once immediately when `use()` is called.
1860
1908
  */
1861
1909
  use(extension: (orbitCtrls: OrbitCtrls) => void): void;
1862
- private updatePointersEnd;
1863
- private updatePointersStart;
1864
1910
  }
1865
1911
 
1866
1912
  /**
@@ -1956,15 +2002,6 @@ export declare interface OrbitCtrlsEvent {
1956
2002
  type: 'ORBITCTRLS_CHANGED' | 'ORBITCTRLS_DISABLED' | 'ORBITCTRLS_ENABLED' | 'ORBITCTRLS_END' | 'ORBITCTRLS_START' | 'ORBITCTRLS_DISPOSED';
1957
2003
  }
1958
2004
 
1959
- /**
1960
- * Defines which existing animation actions of the same object should be paused before a new clip is played.
1961
- * - `'all'`: Pauses all actions of the object.
1962
- * - `'finished'`: Pauses only actions of the object that are no longer active.
1963
- * - `'last'`: Pauses only the last matching action of the object.
1964
- * - `'none'`: Pauses no actions.
1965
- */
1966
- export declare type PauseObjectActions = 'all' | 'finished' | 'last' | 'none';
1967
-
1968
2005
  /**
1969
2006
  * Defines the post-processing settings used by the rendering pipeline.
1970
2007
  * @category Cfg
@@ -1976,7 +2013,7 @@ export declare interface PostCfg {
1976
2013
  */
1977
2014
  guiOpened: boolean;
1978
2015
  /** Anti-aliasing settings. */
1979
- aa: aaCfg;
2016
+ aa: AaCfg;
1980
2017
  /** Shared SSAO settings. */
1981
2018
  ssao: SsaoCfg;
1982
2019
  /** Shared SSR settings. */
@@ -2002,6 +2039,12 @@ export declare interface PostCfg {
2002
2039
  };
2003
2040
  }
2004
2041
 
2042
+ /** @event Fired after the progress bar has finished hiding and triggers the corresponding XState event. */
2043
+ export declare interface ProgressBarHiddenEvent {
2044
+ /** Identifies this event type. */
2045
+ type: 'PROGRESSBAR_HIDDEN';
2046
+ }
2047
+
2005
2048
  /**
2006
2049
  * The Raycast class manages pointer-based raycasting in a `THREE.Scene`. It tracks specified objects, detects cursor intersections with them, and triggers intersection and non-intersection events via
2007
2050
  * the application state. The class dynamically enables or disables pointer listeners depending on the number of tracked objects. It also handles pointer events (click, down, up, move, enter, leave) for the
@@ -2058,7 +2101,7 @@ export declare class Raycast {
2058
2101
  * @param params - Parameter object.
2059
2102
  * @param params.objs3D - The `Obj3D` instances to track.
2060
2103
  */
2061
- trackSelectable({ objs3D }: {
2104
+ trackSelectables({ objs3D }: {
2062
2105
  objs3D: Obj3D[];
2063
2106
  }): void;
2064
2107
  /**
@@ -2203,7 +2246,7 @@ export declare interface RenderCfg {
2203
2246
  /**
2204
2247
  * Parameters passed to `THREE.WebGPURenderer`.
2205
2248
  */
2206
- params: WebGpuRendererParameters;
2249
+ params: WebGpuRendererParams;
2207
2250
  };
2208
2251
  }
2209
2252
 
@@ -2262,6 +2305,22 @@ export declare interface SmaaCfg {
2262
2305
  guiOpened: boolean;
2263
2306
  }
2264
2307
 
2308
+ /** Parameters used to load a global or positional audio source. */
2309
+ export declare type SoundParams = {
2310
+ /** Unique name used to identify the audio source. */
2311
+ name: string;
2312
+ /** Path or URL to the audio file. */
2313
+ url: string;
2314
+ /** Name of the scene object for positional audio. Use an empty string for global audio. */
2315
+ object: string;
2316
+ /** Target playback volume. Default: `0`. */
2317
+ volume?: number;
2318
+ /** Fade-in duration in seconds. Default: `2`. */
2319
+ fade?: number;
2320
+ /** Whether playback should loop. Default: `true`. */
2321
+ loop?: boolean;
2322
+ };
2323
+
2265
2324
  /**
2266
2325
  * Defines the screen-space ambient occlusion settings used to enhance depth and shading.
2267
2326
  * @category Cfg
@@ -2516,10 +2575,18 @@ export declare interface StateMachineCfg {
2516
2575
  inspector: boolean;
2517
2576
  }
2518
2577
 
2578
+ /**
2579
+ * Defines which previous active animation actions of the same object are stopped before a new action is played.
2580
+ * - `'all'`: Stops all previous active actions.
2581
+ * - `'last'`: Stops only the most recently played previous active action.
2582
+ * - `'none'`: Keeps all previous active actions running.
2583
+ */
2584
+ export declare type StopMode = 'all' | 'last' | 'none';
2585
+
2519
2586
  /** Function returned by an event subscription. Calling it removes the associated listener. */
2520
2587
  export declare type Unsubscribe = () => void;
2521
2588
 
2522
- export declare type WebGpuRendererParameters = NonNullable<ConstructorParameters<typeof THREE_WEBGPU_TYPE.WebGPURenderer>[0]>;
2589
+ export declare type WebGpuRendererParams = NonNullable<ConstructorParameters<typeof THREE_WEBGPU_TYPE.WebGPURenderer>[0]>;
2523
2590
 
2524
2591
  /** @event Fired when the window size changes and triggers the corresponding XState event. */
2525
2592
  export declare interface WindowResizeEvent {