illutions 0.23.1 → 0.24.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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### Added
6
+
7
+ - Added animation modes `BlendMode`, `FinishMode`, `LoopMode`, `StopMode`
8
+ - Added `fadeDuration` to `playClip()` and `playClipCam()`.
9
+ - Added `Audio.load()` to load audio without starting playback.
10
+ - Added the `AudioLoadedEvent` (`AUDIO_LOADED`) event for handling completed audio loading.
11
+
12
+ ### Changed
13
+
14
+ - Replaced `pauseActions` with `stopMode` and `infinite` with `loop` in animation clip playback.
15
+ - Renamed `Raycast.trackSelectable()` to `Raycast.trackSelectables()`.
16
+ - Changed the `LightCfg` shadow defaults to match the corresponding Three.js defaults, while keeping `castShadow` enabled by default.
17
+
18
+ ### Fixed
19
+
20
+ - Fixed visual stuttering when transitioning from orbit rotation to panning with damping enabled by keeping `OrbitCtrls` in `lookMode = 'target'` for all OrbitControls interactions.
21
+
3
22
  ## 0.23.1
4
23
 
5
24
  ### FIXED
package/dist/main.d.ts CHANGED
@@ -137,7 +137,8 @@ declare class Audio_2 {
137
137
  private readonly ctx;
138
138
  private readonly loader;
139
139
  private readonly engine;
140
- private readonly sounds;
140
+ private readonly events;
141
+ private readonly loadedSounds;
141
142
  private readonly params;
142
143
  private listener;
143
144
  /* Excluded from this release type: __constructor */
@@ -165,32 +166,32 @@ declare class Audio_2 {
165
166
  isPlaying({ name }: {
166
167
  name: string;
167
168
  }): boolean;
169
+ private loadSound;
168
170
  /**
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**
171
+ * Loads an audio file without playing it and sends an `AUDIO_LOADED` event when the sound is ready.
172
+ * @param params - The sound options.
177
173
  */
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;
174
+ load({ name, url, object, volume, fade, loop }: SoundParams): void;
186
175
  /**
187
- * Plays an already loaded audio with a smooth fade-in.
176
+ * Loads an audio file and plays it automatically when loading is complete.
177
+ * Use this method when no separate `AUDIO_LOADED` handling is required.
178
+ * @param params - The sound options.
179
+ */
180
+ loadAndPlay({ name, url, object, volume, fade, loop }: SoundParams): void;
181
+ /**
182
+ * Plays an audio that has finished loading, with a smooth fade-in.
183
+ * When using {@link load}, call this method after receiving the matching `AUDIO_LOADED` event.
184
+ * This method does not wait for an audio file that is still loading.
188
185
  * @param params - Parameter object.
189
- * @param params.name - The name of the audio to play.
186
+ * @param params.name - The name of the loaded audio to play.
190
187
  */
191
188
  play({ name }: {
192
189
  name: string;
193
190
  }): void;
191
+ /**
192
+ * Resumes the Web Audio context after a user gesture.
193
+ */
194
+ resume(): void;
194
195
  private setAttribute;
195
196
  private setAudioContext;
196
197
  /**
@@ -283,6 +284,21 @@ export declare interface AudioCfg {
283
284
  coneOuterGain: number;
284
285
  }
285
286
 
287
+ /** @event Fired when an audio file has finished loading and is ready for playback. */
288
+ export declare interface AudioLoadedEvent {
289
+ /** Identifies this event type. */
290
+ type: 'AUDIO_LOADED';
291
+ /** The unique name assigned to the loaded sound. */
292
+ soundName: string;
293
+ }
294
+
295
+ /**
296
+ * Defines how an animation action is blended with other active actions.
297
+ * - `'normal'`: Blends the action's values with other normal actions according to their weights.
298
+ * - `'additive'`: Adds the action's values to the current animation result according to its weight.
299
+ */
300
+ export declare type BlendMode = 'normal' | 'additive';
301
+
286
302
  /**
287
303
  * Wraps a `THREE.Camera` and provides a structured interface for configuring and controlling camera settings.
288
304
  * @category 3D Objects
@@ -597,15 +613,16 @@ export declare class Engine {
597
613
  private readonly cfg;
598
614
  private readonly infoBox;
599
615
  private actionObserver;
616
+ private readonly objActions;
600
617
  private gltf;
601
618
  private mixer;
619
+ private callbacks;
620
+ private canvas;
602
621
  private composer;
603
622
  /* Excluded from this release type: renderer */
604
623
  private renderPipeline;
605
624
  /* Excluded from this release type: sceneReady */
606
625
  /* Excluded from this release type: rendererReady */
607
- private callbacks;
608
- private canvas;
609
626
  private fxaaPass;
610
627
  private outputPass;
611
628
  private renderPass;
@@ -633,6 +650,7 @@ export declare class Engine {
633
650
  /* Excluded from this release type: __constructor */
634
651
  /* Excluded from this release type: init */
635
652
  private initWebGpuRenderer;
653
+ private addActionToObj;
636
654
  /**
637
655
  * Registers a callback that is executed on every requestAnimationFrame update.
638
656
  * @param {(deltaTime: number) => void} cb - Callback executed once per frame with `deltaTime`.
@@ -736,6 +754,8 @@ export declare class Engine {
736
754
  [key: string]: any;
737
755
  }): void;
738
756
  private calcEaseArea;
757
+ private stopObjActions;
758
+ private finishAction;
739
759
  /**
740
760
  * Selects the active anti-aliasing mode. The modes `'fxaa'` and `'smaa'` lazy-load their required modules.
741
761
  * @param aaMode - The anti-aliasing mode to use.
@@ -755,37 +775,43 @@ export declare class Engine {
755
775
  /* Excluded from this release type: isPostEnabled */
756
776
  private isPostGpu;
757
777
  private loadScene;
758
- private pauseObjActions;
759
778
  /**
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.
779
+ * Finds a Three.js animation clip by name and plays it through the `THREE.AnimationMixer`.
762
780
  *
763
- * @param params - Parameter object for controlling the animation playback.
781
+ * @param params - Parameters for controlling the animation playback.
764
782
  * @param params.obj - The name of the object whose animation clip should be played.
765
783
  * @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'**
784
+ * @param params.blendMode - How the action is blended with other active actions. Default: **'normal'**
785
+ * @param params.finishMode - Whether the final pose is held or faded out after the final loop. Default: **'hold'**
786
+ * @param params.loop - Number of plays or `'infinite'` for endless looping. Default: **1**
787
+ * @param params.stopMode - Which previous actions of the same object are stopped before playback. Default: **'all'**
788
+ * @param params.fadeDuration - Duration in seconds for fading affected previous actions out and the new action in. Default: **0**
789
+ * @param params.fadeDurationFinish - Duration in seconds for `finishMode: 'fadeOut'`. Default: **0**
767
790
  * @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
-
791
+ * @param params.reset - If `true`, resets the clip before playback. Default: **false**
792
+ * @param params.startSpeed - Initial playback speed for speed interpolation. Default: **0**
793
+ * @param params.endSpeed - Target playback speed. Default: **1**
794
+ * @param params.duration - Duration in seconds for speed interpolation. Default: **0**
795
+ * @param params.ease - GSAP easing function name. Default: **'power1.inOut'**
796
+ *
775
797
  * @remarks
776
- * The method interpolates `timeScale` of the `THREE.AnimationAction`, allowing smooth acceleration or deceleration of animation playback.
798
+ * `finishMode` and `fadeDurationFinish` have no effect when `loop` is `'infinite'`.
777
799
  *
778
800
  * **Events**
779
801
  *
780
802
  * {@link ClipEvent}
781
803
  */
782
- playClip({ obj, clip: clipName, pauseActions, reverse, infinite, reset, startSpeed, endSpeed, duration, ease }: {
804
+ playClip({ obj, clip: clipName, blendMode, finishMode, loop, stopMode, fadeDuration, fadeDurationFinish, reverse, reset, startSpeed, endSpeed, duration, ease }: {
783
805
  obj: string;
784
806
  clip: string;
785
807
  singleAction?: boolean;
786
- pauseActions?: PauseObjectActions;
808
+ blendMode?: BlendMode;
809
+ finishMode?: FinishMode;
810
+ loop?: LoopMode;
811
+ stopMode?: StopMode;
812
+ fadeDuration?: number;
813
+ fadeDurationFinish?: number;
787
814
  reverse?: boolean;
788
- infinite?: boolean;
789
815
  reset?: boolean;
790
816
  startSpeed?: number;
791
817
  endSpeed?: number;
@@ -793,34 +819,36 @@ export declare class Engine {
793
819
  ease?: string;
794
820
  }): void;
795
821
  /**
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.
822
+ * Finds a camera animation clip by name and plays it through the `THREE.AnimationMixer`.
798
823
  *
799
- * @param params - Parameter object for controlling the animation playback.
824
+ * @param params - Parameters for controlling the camera animation playback.
800
825
  * @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'**
826
+ * @param params.clip - The name of the camera animation clip to play.
827
+ * @param params.blendMode - How the action is blended with other active actions. Default: **'normal'**
828
+ * @param params.loop - Number of plays or `'infinite'` for endless looping. Default: **1**
829
+ * @param params.stopMode - Which previous actions of the same object are stopped before playback. Default: **'all'**
830
+ * @param params.fadeDuration - Duration in seconds for fading affected previous actions out and the new action in. Default: **0**
831
+
803
832
  * @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.
833
+ * @param params.reset - If `true`, resets the clip before playback. Default: **false**
834
+ * @param params.startSpeed - Initial playback speed for speed interpolation. Default: **0**
835
+ * @param params.endSpeed - Target playback speed. Default: **1**
836
+ * @param params.duration - Duration in seconds for speed interpolation. Default: **0**
837
+ * @param params.ease - GSAP easing function name. Default: **'power1.inOut'**
813
838
  *
839
+
814
840
  * **Events**
815
841
  *
816
842
  * {@link ClipEvent}
817
843
  */
818
- playClipCam({ obj, clip: clipName, pauseActions, reverse, infinite, reset, startSpeed, endSpeed, duration, ease }: {
844
+ playClipCam({ obj, clip: clipName, blendMode, loop, stopMode, fadeDuration, reverse, reset, startSpeed, endSpeed, duration, ease }: {
819
845
  obj: string;
820
846
  clip: string;
821
- pauseActions?: PauseObjectActions;
847
+ blendMode?: BlendMode;
848
+ loop?: LoopMode;
849
+ stopMode?: StopMode;
850
+ fadeDuration?: number;
822
851
  reverse?: boolean;
823
- infinite?: boolean;
824
852
  reset?: boolean;
825
853
  startSpeed?: number;
826
854
  endSpeed?: number;
@@ -1090,6 +1118,7 @@ export declare class Events {
1090
1118
  private enqueue;
1091
1119
  /* Excluded from this release type: anim */
1092
1120
  /* Excluded from this release type: animFade */
1121
+ /* Excluded from this release type: audioLoaded */
1093
1122
  /* Excluded from this release type: clip */
1094
1123
  /* Excluded from this release type: clipFade */
1095
1124
  /* Excluded from this release type: modelError */
@@ -1103,6 +1132,13 @@ export declare class Events {
1103
1132
  /* Excluded from this release type: windowResize */
1104
1133
  }
1105
1134
 
1135
+ /**
1136
+ * Defines how an animation action behaves after its final loop.
1137
+ * - `'hold'`: Keeps the action enabled and holds its final pose.
1138
+ * - `'fadeOut'`: Fades the action out using `fadeDurationFinish`, or disables it immediately when the duration is `0`.
1139
+ */
1140
+ export declare type FinishMode = 'hold' | 'fadeOut';
1141
+
1106
1142
  /**
1107
1143
  * Defines the fog settings controlling scene depth-based color attenuation.
1108
1144
  * @category Cfg
@@ -1430,38 +1466,50 @@ export declare class Light3D extends Obj3D {
1430
1466
  * @category Cfg
1431
1467
  */
1432
1468
  export declare interface LightCfg {
1469
+ /**
1470
+ * If true, the light casts shadows.
1471
+ * @default true
1472
+ */
1473
+ castShadow: boolean;
1433
1474
  /**
1434
1475
  * Shadow map resolution along the horizontal axis.
1435
- * @default 2048
1476
+ * @default 512
1436
1477
  */
1437
1478
  mapWidth: number;
1438
1479
  /**
1439
1480
  * Shadow map resolution along the vertical axis.
1440
- * @default 2048
1481
+ * @default 512
1441
1482
  */
1442
1483
  mapHeight: number;
1443
1484
  /**
1444
1485
  * Constant shadow bias applied to reduce shadow acne.
1445
- * @default -0.00002
1486
+ * @default 0
1446
1487
  */
1447
1488
  bias: number;
1448
1489
  /**
1449
1490
  * Normal-based shadow bias to further reduce shadow artifacts.
1450
- * @default 0.005
1491
+ * @default 0
1451
1492
  */
1452
1493
  normalBias: number;
1453
1494
  /**
1454
1495
  * Near clipping plane of the light's shadow camera.
1455
- * @default 0.1
1496
+ * @default 0.5
1456
1497
  */
1457
1498
  near: number;
1458
1499
  /**
1459
1500
  * Far clipping plane of the light's shadow camera.
1460
- * @default 5
1501
+ * @default 500
1461
1502
  */
1462
1503
  far: number;
1463
1504
  }
1464
1505
 
1506
+ /**
1507
+ * Defines how often an animation action is played.
1508
+ * - `number`: Plays the action the specified positive number of times.
1509
+ * - `'infinite'`: Repeats the action indefinitely.
1510
+ */
1511
+ export declare type LoopMode = number | 'infinite';
1512
+
1465
1513
  /**
1466
1514
  * Defines the menu bar settings used to display licensed UI controls and branding.
1467
1515
  * @category Cfg
@@ -1822,8 +1870,6 @@ export declare class OrbitCtrls {
1822
1870
  private readonly params;
1823
1871
  private orbitCtrlsFirstChange;
1824
1872
  private callback;
1825
- private listenerPointersStart;
1826
- private listenerPointersEnd;
1827
1873
  private readonly touchPointerIds;
1828
1874
  /* Excluded from this release type: __constructor */
1829
1875
  /** Creates three.js `OrbitControls`. */
@@ -1859,8 +1905,6 @@ export declare class OrbitCtrls {
1859
1905
  * The extension is executed once immediately when `use()` is called.
1860
1906
  */
1861
1907
  use(extension: (orbitCtrls: OrbitCtrls) => void): void;
1862
- private updatePointersEnd;
1863
- private updatePointersStart;
1864
1908
  }
1865
1909
 
1866
1910
  /**
@@ -1956,15 +2000,6 @@ export declare interface OrbitCtrlsEvent {
1956
2000
  type: 'ORBITCTRLS_CHANGED' | 'ORBITCTRLS_DISABLED' | 'ORBITCTRLS_ENABLED' | 'ORBITCTRLS_END' | 'ORBITCTRLS_START' | 'ORBITCTRLS_DISPOSED';
1957
2001
  }
1958
2002
 
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
2003
  /**
1969
2004
  * Defines the post-processing settings used by the rendering pipeline.
1970
2005
  * @category Cfg
@@ -2058,7 +2093,7 @@ export declare class Raycast {
2058
2093
  * @param params - Parameter object.
2059
2094
  * @param params.objs3D - The `Obj3D` instances to track.
2060
2095
  */
2061
- trackSelectable({ objs3D }: {
2096
+ trackSelectables({ objs3D }: {
2062
2097
  objs3D: Obj3D[];
2063
2098
  }): void;
2064
2099
  /**
@@ -2203,7 +2238,7 @@ export declare interface RenderCfg {
2203
2238
  /**
2204
2239
  * Parameters passed to `THREE.WebGPURenderer`.
2205
2240
  */
2206
- params: WebGpuRendererParameters;
2241
+ params: WebGpuRendererParams;
2207
2242
  };
2208
2243
  }
2209
2244
 
@@ -2262,6 +2297,22 @@ export declare interface SmaaCfg {
2262
2297
  guiOpened: boolean;
2263
2298
  }
2264
2299
 
2300
+ /** Parameters used to load a global or positional audio source. */
2301
+ export declare type SoundParams = {
2302
+ /** Unique name used to identify the audio source. */
2303
+ name: string;
2304
+ /** Path or URL to the audio file. */
2305
+ url: string;
2306
+ /** Name of the scene object for positional audio. Use an empty string for global audio. */
2307
+ object: string;
2308
+ /** Target playback volume. Default: `0`. */
2309
+ volume?: number;
2310
+ /** Fade-in duration in seconds. Default: `2`. */
2311
+ fade?: number;
2312
+ /** Whether playback should loop. Default: `true`. */
2313
+ loop?: boolean;
2314
+ };
2315
+
2265
2316
  /**
2266
2317
  * Defines the screen-space ambient occlusion settings used to enhance depth and shading.
2267
2318
  * @category Cfg
@@ -2516,10 +2567,18 @@ export declare interface StateMachineCfg {
2516
2567
  inspector: boolean;
2517
2568
  }
2518
2569
 
2570
+ /**
2571
+ * Defines which previous active animation actions of the same object are stopped before a new action is played.
2572
+ * - `'all'`: Stops all previous active actions.
2573
+ * - `'last'`: Stops only the most recently played previous active action.
2574
+ * - `'none'`: Keeps all previous active actions running.
2575
+ */
2576
+ export declare type StopMode = 'all' | 'last' | 'none';
2577
+
2519
2578
  /** Function returned by an event subscription. Calling it removes the associated listener. */
2520
2579
  export declare type Unsubscribe = () => void;
2521
2580
 
2522
- export declare type WebGpuRendererParameters = NonNullable<ConstructorParameters<typeof THREE_WEBGPU_TYPE.WebGPURenderer>[0]>;
2581
+ export declare type WebGpuRendererParams = NonNullable<ConstructorParameters<typeof THREE_WEBGPU_TYPE.WebGPURenderer>[0]>;
2523
2582
 
2524
2583
  /** @event Fired when the window size changes and triggers the corresponding XState event. */
2525
2584
  export declare interface WindowResizeEvent {