@spiffcommerce/preview 3.6.0 → 3.6.2-rc.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.
@@ -1,24 +1,25 @@
1
- import { Color4 } from "@babylonjs/core/Maths/math.color";
2
- import { Mesh } from "@babylonjs/core/Meshes/mesh";
3
- import { Scene } from "@babylonjs/core/scene";
4
- import { AutoRotationBehavior } from "@babylonjs/core/Behaviors/Cameras/autoRotationBehavior";
5
- import { FramingBehavior } from "@babylonjs/core/Behaviors/Cameras/framingBehavior";
6
- import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
7
- import { Vector3 } from "@babylonjs/core/Maths/math.vector";
8
- import { Engine } from "@babylonjs/core/Engines/engine";
9
- import { ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader";
1
+ import { Engine } from '@babylonjs/core/Engines/engine';
2
+ import { ISceneLoaderProgressEvent } from '@babylonjs/core/Loading/sceneLoader';
3
+ import { Scene } from '@babylonjs/core/scene';
4
+ import { Mesh } from '@babylonjs/core/Meshes/mesh';
5
+ import { AutoRotationBehavior } from '@babylonjs/core/Behaviors/Cameras/autoRotationBehavior';
6
+ import { FramingBehavior } from '@babylonjs/core/Behaviors/Cameras/framingBehavior';
7
+ import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
8
+ import { Vector3 } from '@babylonjs/core/Maths/math.vector';
9
+ import { Color4 } from '@babylonjs/core/Maths/math.color';
10
+
10
11
  /**
11
12
  * Defines the different behaviors supported by the camera system
12
13
  * for control when viewing a product.
13
14
  */
14
- export enum ProductCameraRig {
15
+ declare enum ProductCameraRig {
15
16
  Orbit = 0,
16
17
  Pan = 1
17
18
  }
18
19
  /**
19
20
  * Details relating to a model for use in the preview.
20
21
  */
21
- export type ModelDetails = {
22
+ type ModelDetails = {
22
23
  /**
23
24
  * The source of the model to load.
24
25
  */
@@ -32,7 +33,7 @@ export type ModelDetails = {
32
33
  * Identical to CameraAnimation typing, however the
33
34
  * target is always available and hence is not optional.
34
35
  */
35
- export type CameraPose = {
36
+ type CameraPose = {
36
37
  readonly lonDeg: number;
37
38
  readonly radius: number;
38
39
  readonly latDeg: number;
@@ -42,7 +43,7 @@ export type CameraPose = {
42
43
  readonly z: number;
43
44
  };
44
45
  };
45
- export type ThreeDPreviewService = {
46
+ type ThreeDPreviewService = {
46
47
  /**
47
48
  * Allows listeners to be aware of the camera losing focus of the
48
49
  * main product.
@@ -218,7 +219,7 @@ export type ThreeDPreviewService = {
218
219
  * Represents a service capable of managing and returning contexts that
219
220
  * can be used for rendering to textures in the 3D preview.
220
221
  */
221
- export type RenderableContextService = {
222
+ type RenderableContextService = {
222
223
  /**
223
224
  * Returns all managed renderable contexts.
224
225
  */
@@ -229,7 +230,7 @@ export type RenderableContextService = {
229
230
  * with an external canvas. This context allows external clients to render to a texture
230
231
  * in the 3D preview with a simple interface.
231
232
  */
232
- export type RenderableContext = {
233
+ type RenderableContext = {
233
234
  /**
234
235
  * A unique identifier for this renderable context.
235
236
  */
@@ -261,7 +262,7 @@ export type RenderableContext = {
261
262
  */
262
263
  getLastCompletedStaticRender(): number | undefined;
263
264
  };
264
- export type ModelLoadEventData = {
265
+ type ModelLoadEventData = {
265
266
  /**
266
267
  * The type of event that has occurred.
267
268
  */
@@ -271,7 +272,7 @@ export type ModelLoadEventData = {
271
272
  */
272
273
  readonly modelContainer: ModelContainer;
273
274
  };
274
- export type LoadProgressEventData = {
275
+ type LoadProgressEventData = {
275
276
  /**
276
277
  * The total load value of the scene, this is an average of all
277
278
  * 'in progress' loading events. when all events are fully loaded this value will be 100.
@@ -285,7 +286,7 @@ export type LoadProgressEventData = {
285
286
  /**
286
287
  * Used to specify the behavior of a material effect such as clearcoat, sheen and translucency.
287
288
  */
288
- export enum MaterialEffectMode {
289
+ declare enum MaterialEffectMode {
289
290
  /**
290
291
  * When a material variant effect specifies 'None' the effect doesn't change in any way. This is the default behavior.
291
292
  */
@@ -299,14 +300,14 @@ export enum MaterialEffectMode {
299
300
  */
300
301
  ApplyWhenSelected = "ApplyWhenSelected"
301
302
  }
302
- export interface Asset {
303
+ interface Asset {
303
304
  fileLink?: string;
304
305
  }
305
306
  /**
306
307
  * Represents a material resource that can be additively applied to
307
308
  * a material targeted in the scene.
308
309
  */
309
- export type MaterialResource = {
310
+ type MaterialResource = {
310
311
  /**
311
312
  * A unique identified for this material.
312
313
  */
@@ -372,7 +373,7 @@ export type MaterialResource = {
372
373
  * Represents a handle to a material in the 3D scene. The underlying complexity of materials is abstracted
373
374
  * away so the client doesn't need to know anything more than the ID they're given and the name.
374
375
  */
375
- export type MaterialHandle = {
376
+ type MaterialHandle = {
376
377
  /**
377
378
  * The identifier for the material.
378
379
  */
@@ -385,7 +386,7 @@ export type MaterialHandle = {
385
386
  /**
386
387
  * Settings related to the 3D preview.
387
388
  */
388
- export type PreviewOptions = {
389
+ type PreviewOptions = {
389
390
  /**
390
391
  * The color expected to be seen in the background of the product. Expects a hexadecimal value.
391
392
  */
@@ -484,11 +485,16 @@ export type PreviewOptions = {
484
485
  * Configuration for post-processing effects.
485
486
  */
486
487
  readonly renderingPipelineConfiguration?: RenderingPipelineConfiguration;
488
+ /**
489
+ * Function that returns a canvas to be used for rendering. Useful when using the preview in a headless environment.
490
+ * @returns A canvas to be used for rendering.
491
+ */
492
+ readonly createCanvas?: () => HTMLCanvasElement;
487
493
  };
488
494
  /**
489
495
  * Defines an animation to be played on a product.
490
496
  */
491
- export type ModelAnimation = {
497
+ type ModelAnimation = {
492
498
  /**
493
499
  * A value it seconds along the animation timeline to begin at.
494
500
  */
@@ -511,7 +517,7 @@ export type ModelAnimation = {
511
517
  * A CameraAnimation specifies a discrete state that the camera should
512
518
  * animate to. This state represents the final position of the camera after animations have run.
513
519
  */
514
- export type CameraAnimation = {
520
+ type CameraAnimation = {
515
521
  /**
516
522
  * The longitude in degrees the camera should animate to.
517
523
  */
@@ -536,7 +542,7 @@ export type CameraAnimation = {
536
542
  /**
537
543
  * Configuration for various post processing effects.
538
544
  */
539
- export interface RenderingPipelineConfiguration {
545
+ interface RenderingPipelineConfiguration {
540
546
  antiAliasing?: AntiAliasingPipelineConfiguration;
541
547
  bloom?: BloomPipelineConfiguration;
542
548
  chromaticAberration?: ChromaticAberrationPipelineConfiguration;
@@ -550,7 +556,7 @@ export interface RenderingPipelineConfiguration {
550
556
  /**
551
557
  * Anti-aliasing is a technique used to smooth out jagged edges on objects.
552
558
  */
553
- export interface AntiAliasingPipelineConfiguration {
559
+ interface AntiAliasingPipelineConfiguration {
554
560
  /**
555
561
  * The number of samples to use for MSAA. 1, 2, 3, or 4.
556
562
  */
@@ -563,7 +569,7 @@ export interface AntiAliasingPipelineConfiguration {
563
569
  /**
564
570
  * Bloom is a post processing effect that adds a glow to bright areas of the scene.
565
571
  */
566
- export interface BloomPipelineConfiguration {
572
+ interface BloomPipelineConfiguration {
567
573
  enabled?: boolean;
568
574
  /**
569
575
  * The size of the bloom blur kernel.
@@ -585,7 +591,7 @@ export interface BloomPipelineConfiguration {
585
591
  /**
586
592
  * Chromatic Aberration is a post processing effect that separates the RGB channels.
587
593
  */
588
- export interface ChromaticAberrationPipelineConfiguration {
594
+ interface ChromaticAberrationPipelineConfiguration {
589
595
  enabled?: boolean;
590
596
  /**
591
597
  * The amount of separation between the rgb channels.
@@ -606,7 +612,7 @@ export interface ChromaticAberrationPipelineConfiguration {
606
612
  /**
607
613
  * Color Curves is a post processing effect that allows for color correction.
608
614
  */
609
- export interface ColorCurvesConfiguration {
615
+ interface ColorCurvesConfiguration {
610
616
  enabled?: boolean;
611
617
  globalDensity?: number;
612
618
  globalExposure?: number;
@@ -628,7 +634,7 @@ export interface ColorCurvesConfiguration {
628
634
  /**
629
635
  * Depth of Field is a post processing effect that blurs the scene based on distance from the camera.
630
636
  */
631
- export interface DepthOfFieldPipelineConfiguration {
637
+ interface DepthOfFieldPipelineConfiguration {
632
638
  enabled?: boolean;
633
639
  /**
634
640
  * The quality of the blur. Higher values will provide better quality but will be slower.
@@ -654,7 +660,7 @@ export interface DepthOfFieldPipelineConfiguration {
654
660
  /**
655
661
  * Grain is a post processing effect that adds noise to the scene.
656
662
  */
657
- export interface GrainPipelineConfiguration {
663
+ interface GrainPipelineConfiguration {
658
664
  enabled?: boolean;
659
665
  /**
660
666
  * Set this to true to randomize the noise pattern each frame.
@@ -668,7 +674,7 @@ export interface GrainPipelineConfiguration {
668
674
  /**
669
675
  * Miscellaneous post processing effects.
670
676
  */
671
- export interface MiscPipelineConfiguration {
677
+ interface MiscPipelineConfiguration {
672
678
  /**
673
679
  * The amount of contrast to apply to the scene.
674
680
  */
@@ -690,7 +696,7 @@ export interface MiscPipelineConfiguration {
690
696
  /**
691
697
  * Sharpening is a post processing effect that increases the contrast between pixels.
692
698
  */
693
- export interface SharpenPipelineConfiguration {
699
+ interface SharpenPipelineConfiguration {
694
700
  enabled?: boolean;
695
701
  /**
696
702
  * How much of the original color to apply. 0.0 - 1.0.
@@ -701,7 +707,7 @@ export interface SharpenPipelineConfiguration {
701
707
  */
702
708
  edgeAmount?: number;
703
709
  }
704
- export interface VignettePipelineConfiguration {
710
+ interface VignettePipelineConfiguration {
705
711
  enabled?: boolean;
706
712
  /**
707
713
  * "Multiply" or "Opaque". "Multiply" will mix the vignette color with the scene color. "Opaque" will replace the scene color with the vignette color.
@@ -735,13 +741,13 @@ export interface VignettePipelineConfiguration {
735
741
  */
736
742
  weight?: number;
737
743
  }
738
- export interface Color4Configuration {
744
+ interface Color4Configuration {
739
745
  r: number;
740
746
  g: number;
741
747
  b: number;
742
748
  a: number;
743
749
  }
744
- export interface Vector {
750
+ interface Vector {
745
751
  x: number;
746
752
  y: number;
747
753
  z: number;
@@ -749,7 +755,7 @@ export interface Vector {
749
755
  /**
750
756
  * Wraps functionality for interacting with models in the scene.
751
757
  */
752
- export type ModelContainer = {
758
+ type ModelContainer = {
753
759
  /**
754
760
  * Applies a given material modifier to a target material in the scene.
755
761
  * @param targetMaterial The material to target.
@@ -839,7 +845,7 @@ export type ModelContainer = {
839
845
  * Provides references to 3D preview engine objects.
840
846
  * The types of these objects are dependent on the engine being used.
841
847
  */
842
- export type EngineContext = {
848
+ type EngineContext = {
843
849
  /**
844
850
  * The camera being used by the ThreeDPreviewService.
845
851
  */
@@ -856,7 +862,7 @@ export type EngineContext = {
856
862
  /**
857
863
  * A plugin that provides additional functionality to the preview service.
858
864
  */
859
- export type PreviewServicePlugin = {
865
+ type PreviewServicePlugin = {
860
866
  /**
861
867
  * Called when the plugin is first registered with the preview service.
862
868
  * @param previewService A reference to the preview service.
@@ -871,6 +877,20 @@ export type PreviewServicePlugin = {
871
877
  */
872
878
  dispose(isServiceShutdown: boolean): void;
873
879
  };
880
+
881
+ /**
882
+ * Automatically manages construction and destruction of the glow layer.
883
+ */
884
+ declare class GlowLayerManager {
885
+ private readonly scene;
886
+ private readonly intensity;
887
+ private glowLayer?;
888
+ private meshCount;
889
+ constructor(scene: Scene, intensity: number);
890
+ includeMeshes(meshes: readonly Mesh[]): void;
891
+ removeMeshes(meshes: readonly Mesh[]): void;
892
+ }
893
+
874
894
  /**
875
895
  * Configuration for the preview. Optionally, you can provide a custom configuration. (from a workflow for example) Sensible
876
896
  * defaults will be specified for all properties otherwise.
@@ -878,6 +898,7 @@ export type PreviewServicePlugin = {
878
898
  declare class Configuration {
879
899
  readonly customOptions?: PreviewOptions;
880
900
  constructor(options?: PreviewOptions);
901
+ createCanvas(): HTMLCanvasElement;
881
902
  get options(): PreviewOptions;
882
903
  /**
883
904
  * Configuration related to the scene
@@ -922,46 +943,15 @@ declare class Configuration {
922
943
  contrast: number;
923
944
  };
924
945
  get emissiveGlowIntensity(): number;
925
- }
926
- /**
927
- * Represents the dimensions of a texture, enforcing power of two numbers.
928
- */
929
- type RenderDimensions = {
930
- readonly width: PowerOfTwoNumber;
931
- readonly height: PowerOfTwoNumber;
932
- };
933
- /**
934
- * A class containing largely static configuration information.
935
- */
936
- export class RenderingConfiguration {
937
- /**
938
- * Returns the resolution expected for generated textures.
939
- */
940
- static getDynamicTextureResolution(): RenderDimensions;
941
946
  /**
942
- * Returns true when textures should generate mip maps
947
+ * Will return clear color based on custom configuration or a sensible default.
948
+ * @returns A Color4 object for use as a clear color.
943
949
  */
944
- static shouldMipMap(): boolean;
945
- /**
946
- * Returns true when multithreaded rendering is supported.
947
- */
948
- static offscreenRenderingSupported(): boolean;
949
- /**
950
- * Returns the resolution expected for mirror textures.
951
- */
952
- static getMirrorTextureResolution(): PowerOfTwoNumber;
953
- }
954
- export const REFLECTION_PROBE_RESOLUTION = 128;
955
- export type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
956
- export const renderingPipelineDefaults: RenderingPipelineConfiguration;
957
- /**
958
- * Automatically manages construction and destruction of the glow layer.
959
- */
960
- declare class GlowLayerManager {
961
- constructor(scene: Scene, intensity: number);
962
- includeMeshes(meshes: readonly Mesh[]): void;
963
- removeMeshes(meshes: readonly Mesh[]): void;
950
+ private getSceneClearColor;
951
+ private highlightColorFromConfig;
952
+ private hexToColor4;
964
953
  }
954
+
965
955
  /**
966
956
  * A slightly extended version of the ArcRotateCamera.
967
957
  * Configures the camera in a way that best suites product visualization.
@@ -974,6 +964,7 @@ declare class ProductCamera extends ArcRotateCamera {
974
964
  * via panning we can notify ui about the fact to help users reset the camera.
975
965
  */
976
966
  readonly lastFocus: Vector3;
967
+ private panDenominator;
977
968
  /**
978
969
  * Returns the framing behavior of this camera.
979
970
  */
@@ -1014,12 +1005,60 @@ declare class ProductCamera extends ArcRotateCamera {
1014
1005
  */
1015
1006
  static create(scene: Scene, configuration: Configuration, assignActive?: boolean): ProductCamera;
1016
1007
  }
1008
+
1017
1009
  /**
1018
1010
  * An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews
1019
1011
  * is designed to be optional, anyone can come along and implement their own 3D preview service or
1020
1012
  * they can use this one to get things running more quickly.
1021
1013
  */
1022
- export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
1014
+ declare class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
1015
+ private readonly camera;
1016
+ private readonly configuration;
1017
+ private readonly engine;
1018
+ private readonly scene;
1019
+ /**
1020
+ * The current progress of loading the scene. A value between 0-100.
1021
+ */
1022
+ private loadProgress;
1023
+ /**
1024
+ * The last camera animation requested if the scene wasn't ready.
1025
+ */
1026
+ private queuedCameraAnimation?;
1027
+ /**
1028
+ * When listeners have been notified of a change in camera target position
1029
+ * this field will be set to true.
1030
+ */
1031
+ private focusLostNotified;
1032
+ /**
1033
+ * A list of listener who want to know about the progress of scene loading.
1034
+ */
1035
+ private loadObservable;
1036
+ /**
1037
+ * An observable handling loss of target focus by the camera.
1038
+ */
1039
+ private focusLostObservable;
1040
+ /**
1041
+ * An observable handling the initialization of the preview service.
1042
+ */
1043
+ private initializedCallbacks;
1044
+ /**
1045
+ * Whether or not the preview service has been initialized.
1046
+ */
1047
+ private isInitialized;
1048
+ /**
1049
+ * A collection of callbacks to be invoked when a model is loaded or unloaded.
1050
+ */
1051
+ private modelLoadEventCallbacks;
1052
+ private glowLayerManager;
1053
+ /**
1054
+ * When instantiated, contains a list of meshes that contribute to highlighting
1055
+ * in the scene.
1056
+ */
1057
+ private highlightLayer?;
1058
+ private renderingPipeline;
1059
+ private modelContainers;
1060
+ private plugins;
1061
+ private screenshotPrepareResolve;
1023
1062
  constructor(options?: PreviewOptions);
1024
1063
  getEngineContext(): {
1025
1064
  engine: Engine;
@@ -1060,6 +1099,57 @@ export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
1060
1099
  unregisterPlugin(plugin: PreviewServicePlugin): void;
1061
1100
  getGlowLayerManager(): GlowLayerManager;
1062
1101
  modelUnloaded(modelContainer: ModelContainer): void;
1102
+ private triggerModelLoadEvent;
1103
+ private handleMaterialProgressCallback;
1104
+ private handleModelProgressCallback;
1105
+ /**
1106
+ * Given a valid canvas element, will remove any existing input controls
1107
+ * and re-attach them to the given canvas. The pan mouse button can be set
1108
+ * to either 0 (left mouse) or 2 (right mouse).
1109
+ */
1110
+ private reattachControls;
1111
+ /**
1112
+ * Computes a load listener event based on current state of scene.
1113
+ */
1114
+ private getLoadListenerEvent;
1115
+ /**
1116
+ * Computes the average loading time across all loading events and notifies
1117
+ * listeners of the current load progress.
1118
+ */
1119
+ private notifyLoadHandlers;
1120
+ }
1121
+
1122
+ /**
1123
+ * Represents the dimensions of a texture, enforcing power of two numbers.
1124
+ */
1125
+ type RenderDimensions = {
1126
+ readonly width: PowerOfTwoNumber;
1127
+ readonly height: PowerOfTwoNumber;
1128
+ };
1129
+ /**
1130
+ * A class containing largely static configuration information.
1131
+ */
1132
+ declare class RenderingConfiguration {
1133
+ /**
1134
+ * Returns the resolution expected for generated textures.
1135
+ */
1136
+ static getDynamicTextureResolution(): RenderDimensions;
1137
+ /**
1138
+ * Returns true when textures should generate mip maps
1139
+ */
1140
+ static shouldMipMap(): boolean;
1141
+ /**
1142
+ * Returns true when multithreaded rendering is supported.
1143
+ */
1144
+ static offscreenRenderingSupported(): boolean;
1145
+ /**
1146
+ * Returns the resolution expected for mirror textures.
1147
+ */
1148
+ static getMirrorTextureResolution(): PowerOfTwoNumber;
1149
+ private static getIsMobile;
1063
1150
  }
1151
+ declare const REFLECTION_PROBE_RESOLUTION = 128;
1152
+ type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
1153
+ declare const renderingPipelineDefaults: RenderingPipelineConfiguration;
1064
1154
 
1065
- //# sourceMappingURL=types.d.ts.map
1155
+ export { AntiAliasingPipelineConfiguration, Asset, BloomPipelineConfiguration, CameraAnimation, CameraPose, ChromaticAberrationPipelineConfiguration, Color4Configuration, ColorCurvesConfiguration, DepthOfFieldPipelineConfiguration, EngineContext, GrainPipelineConfiguration, LoadProgressEventData, MaterialEffectMode, MaterialHandle, MaterialResource, MiscPipelineConfiguration, ModelAnimation, ModelContainer, ModelDetails, ModelLoadEventData, PowerOfTwoNumber, PreviewOptions, PreviewServicePlugin, ProductCameraRig, REFLECTION_PROBE_RESOLUTION, RenderableContext, RenderableContextService, RenderingConfiguration, RenderingPipelineConfiguration, SharpenPipelineConfiguration, SpiffCommerce3DPreviewService, ThreeDPreviewService, Vector, VignettePipelineConfiguration, renderingPipelineDefaults };