@spiffcommerce/preview 5.5.8-alpha.4 → 5.6.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.
@@ -0,0 +1,1170 @@
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
+
11
+ /**
12
+ * Defines the different behaviors supported by the camera system
13
+ * for control when viewing a product.
14
+ */
15
+ declare enum ProductCameraRig {
16
+ Orbit = 0,
17
+ Pan = 1
18
+ }
19
+ /**
20
+ * Details relating to a model for use in the preview.
21
+ */
22
+ type ModelDetails = {
23
+ /**
24
+ * The source of the model to load.
25
+ */
26
+ readonly model?: string;
27
+ /**
28
+ * A reference to the renderable context service to use.
29
+ */
30
+ readonly contextService?: RenderableContextService;
31
+ };
32
+ /**
33
+ * Identical to CameraAnimation typing, however the
34
+ * target is always available and hence is not optional.
35
+ */
36
+ type CameraPose = {
37
+ readonly lonDeg: number;
38
+ readonly radius: number;
39
+ readonly latDeg: number;
40
+ readonly target: {
41
+ readonly x: number;
42
+ readonly y: number;
43
+ readonly z: number;
44
+ };
45
+ };
46
+ type ThreeDPreviewService = {
47
+ /**
48
+ * Returns a promise which resolves when the scene has been initialized.
49
+ */
50
+ getInitializationPromise(): Promise<void>;
51
+ /**
52
+ * True when the scene has been initialized. This is when the initializationPromise resolves. Remember you may need
53
+ * to await a model's initialization promise as well if you want to hide the scene until the model is loaded.
54
+ */
55
+ getInitializationComplete(): boolean;
56
+ /**
57
+ * Allows listeners to be aware of the camera losing focus of the
58
+ * main product.
59
+ * @param listener A function to be called when focus is lost.
60
+ */
61
+ registerFocusLostListener(listener: () => void): void;
62
+ /**
63
+ * Removes a listener from the focusLost observers. The listener will
64
+ * no longer be notified
65
+ * @param listener The listener to remove.
66
+ */
67
+ unregisterFocusLostListener(listener: () => void): void;
68
+ /**
69
+ * Provides listeners with information about model load events.
70
+ * @param listener A function to get load events. The eventType will be 'load' or 'unload',
71
+ * and the modelContainer will be the model that was loaded or unloaded.
72
+ */
73
+ registerModelLoadEventListener(listener: (e: ModelLoadEventData) => void): void;
74
+ /**
75
+ * Allows you to pass any function that originally called registerModelLoadEventListener()
76
+ * to have it excluded from load events.
77
+ * If the function was never registered this call has no effect.
78
+ * @param listener The listener to exclude from load events.
79
+ */
80
+ unregisterModelLoadEventListener(listener: (e: ModelLoadEventData) => void): void;
81
+ /**
82
+ * Request that the scene renders to a given canvas
83
+ * @param canvas The canvas we should render to.
84
+ */
85
+ registerView(canvas: HTMLCanvasElement): void;
86
+ /**
87
+ * Returns the number of active viewers of the scene. Useful for
88
+ * avoiding unnecessary rendering when there are no active viewers.
89
+ */
90
+ getNumViewports(): number;
91
+ /**
92
+ * Tells babylon that we no longer want the given canvas to be rendered to.
93
+ * @param canvas The canvas to be excluded from rendering.
94
+ */
95
+ unregisterView(canvas: HTMLCanvasElement): void;
96
+ /**
97
+ * Shutdown the preview engine and all registered plugins. Noop if the engine is not initialized.
98
+ */
99
+ shutdown(): void;
100
+ /**
101
+ * Executes an animation of the camera.
102
+ * @param animation The animation to execute.
103
+ */
104
+ executeCameraAnimation(animation: CameraAnimation): Promise<void>;
105
+ /**
106
+ * Returns the values of the Arc Rotate Camera
107
+ */
108
+ getCameraPose(): CameraPose | undefined;
109
+ /**
110
+ * Sets the values of the Arc Rotate Camera
111
+ */
112
+ setCameraPose(cameraPose: CameraPose): void;
113
+ /**
114
+ * Controls the current control state of the camera.
115
+ * @param rigType The control type to use.
116
+ */
117
+ setCameraState(rigType: ProductCameraRig): void;
118
+ /**
119
+ * Restores the product camera to it's last set focus point. If the user has
120
+ * been panning this will animate the camera to the original focus point. If the camera is still
121
+ * focused on it's origin point this function is a noop.
122
+ */
123
+ animateToLastCameraFocus(): Promise<void>;
124
+ /**
125
+ * When configuration has allowed for auto rotation we
126
+ * can pause the rotation via this function.
127
+ * @param shouldAutoRotate When true rotation is running, paused otherwise.
128
+ */
129
+ setAutoRotation(shouldAutoRotate: boolean): void;
130
+ /**
131
+ * Returns the current configuration object applied to the scene.
132
+ */
133
+ getCurrentConfiguration(): PreviewOptions | undefined;
134
+ /**
135
+ * Takes a screenshot of the scene using a given
136
+ * camera animation otherwise using the existing orientation
137
+ * of the camera in the scene. A resolution must be provided
138
+ * to render the scene at.
139
+ */
140
+ renderSceneScreenshot(resolution: number, cameraAnimation: CameraAnimation): Promise<string>;
141
+ /**
142
+ * Returns true when the current configuration allows the user
143
+ * to rotate around the product.
144
+ */
145
+ orbitEnabled(): boolean;
146
+ /**
147
+ * Flips a given transform from one handedness to another.
148
+ * NOTE: Will provide sensible defaults if only some values are provided.
149
+ * @param position The position vector for the transform
150
+ * @param rotation The rotation vector for the transform. NOTE: Should be expressed in radians.
151
+ * @param scale The scale vector for the transform
152
+ */
153
+ flipTransform(position?: Vector, rotation?: Vector, scale?: Vector): {
154
+ position: Vector;
155
+ rotation: Vector;
156
+ scale: Vector;
157
+ };
158
+ /**
159
+ * When called will trigger the internal engine to match the current
160
+ * canvas size. This ensures the image renders correctly in the view and
161
+ * also prevents performance problems.
162
+ */
163
+ fireResizeEvent(): void;
164
+ /**
165
+ * Designed for use when utilizing the 3D preview in an editor format.
166
+ * Given a list of material names, highlights the associated meshes in the scene.
167
+ */
168
+ setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
169
+ /**
170
+ * Sets the rendering pipeline configuration for the scene. Overwrites any existing configuration.
171
+ * @param renderingPipelineConfiguration The configuration to apply. Empty values will be set to default.
172
+ */
173
+ setRenderingPipelineConfiguration(renderingPipelineConfiguration: RenderingPipelineConfiguration): void;
174
+ /**
175
+ * Loads a model into the scene.
176
+ * @param modelDetails The details of the model to load.
177
+ * @returns A reference to the model container. Call `getInitializationPromise()` to wait for the model to be loaded.
178
+ */
179
+ loadModel(modelDetails: ModelDetails): ModelContainer;
180
+ /**
181
+ * Preloads a model into the scene. This will load the model into memory, but it will not be visible in the scene.
182
+ * @param url The url of the model to preload.
183
+ */
184
+ preloadModel(url: string): Promise<void>;
185
+ /**
186
+ * Returns all loaded models.
187
+ * @returns A map of id to model container.
188
+ */
189
+ getAllModels(): ReadonlyArray<ModelContainer>;
190
+ /**
191
+ * Retrieves a loaded model by it's id.
192
+ * @param id The id of the model to retrieve.
193
+ * @returns The model container if it exists, undefined otherwise.
194
+ */
195
+ getModelById(id: string): ModelContainer | undefined;
196
+ /**
197
+ * Registers a plugin with the preview service.
198
+ * @param plugin The plugin to register.
199
+ */
200
+ registerPlugin(plugin: PreviewServicePlugin): void;
201
+ /**
202
+ * Removes a plugin from the preview service.
203
+ * @param plugin The plugin to remove.
204
+ */
205
+ unregisterPlugin(plugin: PreviewServicePlugin): void;
206
+ /**
207
+ * Sets the preview options for the scene. Certain options may not be applied, as they are only applicable upon initialization.
208
+ * @param options The options to apply.
209
+ */
210
+ updatePreviewOptions(options: PreviewOptions): void;
211
+ };
212
+ /**
213
+ * Represents a service capable of managing and returning contexts that
214
+ * can be used for rendering to textures in the 3D preview.
215
+ */
216
+ type RenderableContextService = {
217
+ /**
218
+ * Returns all managed renderable contexts.
219
+ */
220
+ getAll(): ReadonlyMap<string, RenderableContext>;
221
+ };
222
+ /**
223
+ * A renderable context represents the relationship of a texture in the 3D preview
224
+ * with an external canvas. This context allows external clients to render to a texture
225
+ * in the 3D preview with a simple interface.
226
+ */
227
+ type RenderableContext = {
228
+ /**
229
+ * A unique identifier for this renderable context.
230
+ */
231
+ getID(): string;
232
+ /**
233
+ * A name for this renderable.
234
+ */
235
+ getName(): string;
236
+ /**
237
+ * Sets the render context associated to this renderable.
238
+ * @param ctx The context to use for rendering.
239
+ */
240
+ setStaticContext(ctx: CanvasRenderingContext2D): void;
241
+ /**
242
+ * Get the render context associated to this renderable.
243
+ */
244
+ getStaticContext(): CanvasRenderingContext2D | undefined;
245
+ /**
246
+ * Sets whether or not this renderable is dirty and will need re-rendering.
247
+ * @param value The new value
248
+ */
249
+ setStaticContextDirty(value: boolean): void;
250
+ /**
251
+ * When this context has been set as dirty, returns true.
252
+ */
253
+ getStaticContextDirty(): boolean;
254
+ /**
255
+ * A timestamp for the last successful render of the context.
256
+ */
257
+ getLastCompletedStaticRender(): number | undefined;
258
+ };
259
+ type ModelLoadEventData = {
260
+ /**
261
+ * The type of event that has occurred.
262
+ */
263
+ readonly eventType: "load" | "unload";
264
+ /**
265
+ * The model that has been loaded or unloaded.
266
+ */
267
+ readonly modelContainer: ModelContainer;
268
+ };
269
+ type LoadProgressEventData = {
270
+ /**
271
+ * The total load value of the scene, this is an average of all
272
+ * 'in progress' loading events. when all events are fully loaded this value will be 100.
273
+ */
274
+ readonly loadValue: number;
275
+ /**
276
+ * This value is true when the base model and scene have been initialized.
277
+ */
278
+ readonly sceneInitialized: boolean;
279
+ };
280
+ /**
281
+ * Used to specify the behavior of a material effect such as clearcoat, sheen and translucency.
282
+ */
283
+ declare enum MaterialEffectMode {
284
+ /**
285
+ * When a material variant effect specifies 'None' the effect doesn't change in any way. This is the default behavior.
286
+ */
287
+ None = "None",
288
+ /**
289
+ * When a material variant effect specifies 'RemoveWhenSelected' the effect is removed.
290
+ */
291
+ RemoveWhenSelected = "RemoveWhenSelected",
292
+ /**
293
+ * When a material variant effect specifies 'ApplyWhenSelected' the effect is enabled.
294
+ */
295
+ ApplyWhenSelected = "ApplyWhenSelected"
296
+ }
297
+ interface Asset {
298
+ fileLink?: string;
299
+ }
300
+ /**
301
+ * Represents a material resource that can be additively applied to
302
+ * a material targeted in the scene.
303
+ */
304
+ type MaterialResource = {
305
+ /**
306
+ * A unique identified for this material.
307
+ */
308
+ id: string;
309
+ /**
310
+ * The name of this material
311
+ */
312
+ name: string;
313
+ /**
314
+ * Defines the base color of a surface before any other calculations are made.
315
+ */
316
+ albedoMap?: Asset;
317
+ /**
318
+ * Defines the transparency of a surface.
319
+ */
320
+ alphaMap?: Asset;
321
+ /**
322
+ * Defines shadowing on a surface.
323
+ */
324
+ ambientMap?: Asset;
325
+ /**
326
+ * Defines the amount of light being emitted from a surface.
327
+ */
328
+ emissionMap?: Asset;
329
+ /**
330
+ * Identical to roughness.
331
+ */
332
+ metallicMap?: Asset;
333
+ /**
334
+ * Defines the direction light will bounce in when it hits a point on a surface.
335
+ */
336
+ normalMap?: Asset;
337
+ /**
338
+ * Used to define how smooth a surface is.
339
+ */
340
+ roughnessMap?: Asset;
341
+ /**
342
+ * Used to define refraction of light on a surface.
343
+ */
344
+ refractionMap?: Asset;
345
+ /**
346
+ * The intensity of refraction, when refraction is enabled via a texture.
347
+ */
348
+ refractionIntensity?: number;
349
+ /**
350
+ * Used to define reflection of light on a surface.
351
+ */
352
+ reflectionMap?: Asset;
353
+ /**
354
+ * The intensity of reflection, when reflection is enabled via a texture.
355
+ */
356
+ reflectionIntensity?: number;
357
+ /**
358
+ * The rotation of the reflection texture (along the up axis), in degrees.
359
+ */
360
+ reflectionRotation?: number;
361
+ /**
362
+ * When enabled the material will be displayed with a clearcoat affect for simulating coated plastic surfaces.
363
+ */
364
+ clearCoat: MaterialEffectMode;
365
+ /**
366
+ * Index of refraction when clear coat is enabled.
367
+ */
368
+ clearCoatIOR?: number;
369
+ /**
370
+ * The date that this material resource was created
371
+ */
372
+ createdAt: string;
373
+ /**
374
+ * The date that this material resource was last updated.
375
+ */
376
+ updatedAt: string;
377
+ };
378
+ /**
379
+ * Represents a handle to a material in the 3D scene. The underlying complexity of materials is abstracted
380
+ * away so the client doesn't need to know anything more than the ID they're given and the name.
381
+ */
382
+ type MaterialHandle = {
383
+ /**
384
+ * The identifier for the material.
385
+ */
386
+ readonly id: string;
387
+ /**
388
+ * The human readable name for the material.
389
+ */
390
+ readonly name: string;
391
+ };
392
+ /**
393
+ * Settings related to the 3D preview.
394
+ */
395
+ type PreviewOptions = {
396
+ /**
397
+ * The color expected to be seen in the background of the product. Expects a hexadecimal value.
398
+ */
399
+ readonly backgroundColor?: string;
400
+ /**
401
+ * Image to be used as a background when running withh transparency, the image
402
+ * will be scaled and centered to fill the preview based on aspect ratio.
403
+ * Will implicitly set transparency to true.
404
+ */
405
+ readonly backgroundImage?: string;
406
+ /**
407
+ * When true, the canvas background will be transparent.
408
+ */
409
+ readonly transparentBackground?: boolean;
410
+ /**
411
+ * The closest zoom the camera can achieve to the product.
412
+ */
413
+ readonly maxZoomOverride?: number;
414
+ /**
415
+ * The furthest zoom the camera can achieve to the product.
416
+ */
417
+ readonly minZoomOverride?: number;
418
+ /**
419
+ * The environment file used to calculate product lighting.
420
+ */
421
+ readonly environmentFile?: string;
422
+ /**
423
+ * The intensity of the environment lighting.
424
+ */
425
+ readonly environmentIntensity?: number;
426
+ /**
427
+ * The rotation (around the y axis) of the environment lighting, in degrees.
428
+ */
429
+ readonly environmentRotationY?: number;
430
+ /**
431
+ * The lowest point, vertically, that the camera can rotate to.
432
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
433
+ */
434
+ readonly lowerBetaLimitDeg?: number;
435
+ /**
436
+ * The highest point, vertically, that the camera can rotate to.
437
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
438
+ */
439
+ readonly upperBetaLimitDeg?: number;
440
+ /**
441
+ * The leftmost point, horizontally, that the camera can rotate to.
442
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
443
+ */
444
+ readonly lowerAlphaLimitDeg?: number;
445
+ /**
446
+ * The rightmost point, horizontally, that the camera can rotate to.
447
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
448
+ */
449
+ readonly upperAlphaLimitDeg?: number;
450
+ /**
451
+ * When set the product while rotate slowly
452
+ */
453
+ readonly autoRotation?: boolean;
454
+ /**
455
+ * Time in milliseconds before the product starts rotating after a user input has taken control.
456
+ */
457
+ readonly idleTimeBeforeRotation?: number;
458
+ /**
459
+ * When set the 3D preview won't attempt to orient the product automatically to its front view at load.
460
+ */
461
+ readonly disableAutomaticOrientation?: boolean;
462
+ /**
463
+ * When true the action bar won't be displayed to the user.
464
+ */
465
+ readonly disableActionBar?: boolean;
466
+ /**
467
+ * When set, mousing over the model in this preview will highlight the associated mesh/material.
468
+ * When layout contexts are provided, only the materials with matching names will highlight.
469
+ */
470
+ readonly highlightOnMaterialHover?: boolean;
471
+ /**
472
+ * Sets the color of highlights when enabled. Expects hexadecimal value.
473
+ */
474
+ readonly highlightColor?: string;
475
+ /**
476
+ * Configuration rleated to lighting of the scene.
477
+ */
478
+ readonly lighting?: {
479
+ /**
480
+ * Sets camera exposure. Higher values will make the scene brighter.
481
+ */
482
+ exposure?: number;
483
+ /**
484
+ * Sets camera contrast. Higher values will increase the contrast of the scene.
485
+ */
486
+ contrast?: number;
487
+ };
488
+ /**
489
+ * The intensity of the glow effect that is present when a material has an emissive texture.
490
+ */
491
+ readonly emissiveGlowIntensity?: number;
492
+ /**
493
+ * When true the preview system operates in a noRender mode. It silently accepts all requests and modifies internal state
494
+ * based on those requests. However no rendering will actually be occuring. Can be useful in situations where testing requires
495
+ * a 3D preview but the actual rendering is not important.
496
+ */
497
+ readonly noRender?: boolean;
498
+ /**
499
+ * When true the preview system will not allow the user to pan the camera.
500
+ */
501
+ readonly noPan?: boolean;
502
+ /**
503
+ * Configuration for post-processing effects.
504
+ */
505
+ readonly renderingPipelineConfiguration?: RenderingPipelineConfiguration;
506
+ /**
507
+ * Function that returns a canvas to be used for rendering. Useful when using the preview in a headless environment.
508
+ * @returns A canvas to be used for rendering.
509
+ */
510
+ readonly createCanvas?: () => HTMLCanvasElement;
511
+ };
512
+ /**
513
+ * Defines an animation to be played on a product.
514
+ */
515
+ type ModelAnimation = {
516
+ /**
517
+ * A value it seconds along the animation timeline to begin at.
518
+ */
519
+ readonly from?: number;
520
+ /**
521
+ * A value in seconds along the animation timeline to end at.
522
+ */
523
+ readonly to?: number;
524
+ /**
525
+ * When true the animation will loop. The only behavior currently is to reset
526
+ * back to from but we could have it bounce back and forth and/or follow a curve.
527
+ */
528
+ readonly loop?: boolean;
529
+ /**
530
+ * The name of the animation to play.
531
+ */
532
+ readonly name?: string;
533
+ };
534
+ /**
535
+ * A CameraAnimation specifies a discrete state that the camera should
536
+ * animate to. This state represents the final position of the camera after animations have run.
537
+ */
538
+ type CameraAnimation = {
539
+ /**
540
+ * The longitude in degrees the camera should animate to.
541
+ */
542
+ readonly lonDeg: number;
543
+ /**
544
+ * The latitude in degrees the camera should animate to.
545
+ */
546
+ readonly latDeg: number;
547
+ /**
548
+ * An optional target for the camera to focus on in the scene.
549
+ */
550
+ readonly target?: {
551
+ readonly x: number;
552
+ readonly y: number;
553
+ readonly z: number;
554
+ };
555
+ /**
556
+ * A value in scene units specifying camera distance from the target.
557
+ */
558
+ readonly radius?: number;
559
+ };
560
+ /**
561
+ * Configuration for various post processing effects.
562
+ */
563
+ interface RenderingPipelineConfiguration {
564
+ antiAliasing?: AntiAliasingPipelineConfiguration;
565
+ bloom?: BloomPipelineConfiguration;
566
+ chromaticAberration?: ChromaticAberrationPipelineConfiguration;
567
+ colorCurves?: ColorCurvesConfiguration;
568
+ depthOfField?: DepthOfFieldPipelineConfiguration;
569
+ grain?: GrainPipelineConfiguration;
570
+ misc?: MiscPipelineConfiguration;
571
+ sharpen?: SharpenPipelineConfiguration;
572
+ vignette?: VignettePipelineConfiguration;
573
+ }
574
+ /**
575
+ * Anti-aliasing is a technique used to smooth out jagged edges on objects.
576
+ */
577
+ interface AntiAliasingPipelineConfiguration {
578
+ /**
579
+ * The number of samples to use for MSAA. 1, 2, 3, or 4.
580
+ */
581
+ samples?: number;
582
+ /**
583
+ * When true FXAA will be used instead of MSAA.
584
+ */
585
+ fxaaEnabled?: boolean;
586
+ }
587
+ /**
588
+ * Bloom is a post processing effect that adds a glow to bright areas of the scene.
589
+ */
590
+ interface BloomPipelineConfiguration {
591
+ enabled?: boolean;
592
+ /**
593
+ * The size of the bloom blur kernel.
594
+ */
595
+ kernel?: number;
596
+ /**
597
+ * The scale of the bloom effect. Lower values will provide better performance.
598
+ */
599
+ scale?: number;
600
+ /**
601
+ * The threshold at which the bloom effect will be applied.
602
+ */
603
+ threshold?: number;
604
+ /**
605
+ * The strength of the bloom effect.
606
+ */
607
+ weight?: number;
608
+ }
609
+ /**
610
+ * Chromatic Aberration is a post processing effect that separates the RGB channels.
611
+ */
612
+ interface ChromaticAberrationPipelineConfiguration {
613
+ enabled?: boolean;
614
+ /**
615
+ * The amount of separation between the rgb channels.
616
+ */
617
+ aberrationAmount?: number;
618
+ /**
619
+ * The direction of the separation, in screen space.
620
+ */
621
+ direction?: {
622
+ x: number;
623
+ y: number;
624
+ };
625
+ /**
626
+ * How much the effect will increase towards the edges of the screen.
627
+ */
628
+ radialIntensity?: number;
629
+ }
630
+ /**
631
+ * Color Curves is a post processing effect that allows for color correction.
632
+ */
633
+ interface ColorCurvesConfiguration {
634
+ enabled?: boolean;
635
+ globalDensity?: number;
636
+ globalExposure?: number;
637
+ globalHue?: number;
638
+ globalSaturation?: number;
639
+ highlightsDensity?: number;
640
+ highlightsExposure?: number;
641
+ highlightsHue?: number;
642
+ highlightsSaturation?: number;
643
+ midtonesDensity?: number;
644
+ midtonesExposure?: number;
645
+ midtonesHue?: number;
646
+ midtonesSaturation?: number;
647
+ shadowsDensity?: number;
648
+ shadowsExposure?: number;
649
+ shadowsHue?: number;
650
+ shadowsSaturation?: number;
651
+ }
652
+ /**
653
+ * Depth of Field is a post processing effect that blurs the scene based on distance from the camera.
654
+ */
655
+ interface DepthOfFieldPipelineConfiguration {
656
+ enabled?: boolean;
657
+ /**
658
+ * The quality of the blur. Higher values will provide better quality but will be slower.
659
+ */
660
+ blurLevel?: "Low" | "Medium" | "High";
661
+ /**
662
+ * The distance from the camera to the focus point.
663
+ */
664
+ focusDistance?: number;
665
+ /**
666
+ * The focal length of the camera, in millimeters.
667
+ */
668
+ focalLength?: number;
669
+ /**
670
+ * The f-stop of the camera. The diameter of the lens aperture will be calculated by lensSize / fStop.
671
+ */
672
+ fStop?: number;
673
+ /**
674
+ * The size of the lens, in millimeters. The diameter of the lens aperture will be calculated by lensSize / fStop.
675
+ */
676
+ lensSize?: number;
677
+ }
678
+ /**
679
+ * Grain is a post processing effect that adds noise to the scene.
680
+ */
681
+ interface GrainPipelineConfiguration {
682
+ enabled?: boolean;
683
+ /**
684
+ * Set this to true to randomize the noise pattern each frame.
685
+ */
686
+ animated?: boolean;
687
+ /**
688
+ * The intensity of the noise.
689
+ */
690
+ intensity?: number;
691
+ }
692
+ /**
693
+ * Miscellaneous post processing effects.
694
+ */
695
+ interface MiscPipelineConfiguration {
696
+ /**
697
+ * The amount of contrast to apply to the scene.
698
+ */
699
+ contrast?: number;
700
+ /**
701
+ * The amount of exposure to apply to the scene.
702
+ */
703
+ exposure?: number;
704
+ /**
705
+ * Applies a pre-defined color grading LUT to the scene.
706
+ */
707
+ toneMappingEnabled?: boolean;
708
+ /**
709
+ * The type of tone mapping to use. "Standard" or "ACES". "ACES" applies a tone that is similar to Unity and Unreal.
710
+ * @default "standard"
711
+ */
712
+ toneMappingType?: "Standard" | "ACES";
713
+ }
714
+ /**
715
+ * Sharpening is a post processing effect that increases the contrast between pixels.
716
+ */
717
+ interface SharpenPipelineConfiguration {
718
+ enabled?: boolean;
719
+ /**
720
+ * How much of the original color to apply. 0.0 - 1.0.
721
+ */
722
+ colorAmount?: number;
723
+ /**
724
+ * The intensity of the sharpening effect.
725
+ */
726
+ edgeAmount?: number;
727
+ }
728
+ interface VignettePipelineConfiguration {
729
+ enabled?: boolean;
730
+ /**
731
+ * "Multiply" or "Opaque". "Multiply" will mix the vignette color with the scene color. "Opaque" will replace the scene color with the vignette color.
732
+ */
733
+ blendMode?: "Multiply" | "Opaque";
734
+ /**
735
+ * The FOV of the camera. This is used to calculate the vignette size.
736
+ */
737
+ cameraFov?: number;
738
+ /**
739
+ * The offset of the vignette center, in screen space.
740
+ */
741
+ center?: {
742
+ x: number;
743
+ y: number;
744
+ };
745
+ /**
746
+ * The color of the vignette, provided as an RGBA value.
747
+ */
748
+ colorRgba?: Color4Configuration;
749
+ /**
750
+ * The color of the vignette, provided as a hex string.
751
+ */
752
+ colorHex?: string;
753
+ /**
754
+ * Horizontal stretch of the vignette. Higher values will cause the vignette to be appear more like bars on the top and bottom of the screen.
755
+ */
756
+ stretch?: number;
757
+ /**
758
+ * The strength/size of the vignette effect.
759
+ */
760
+ weight?: number;
761
+ }
762
+ interface Color4Configuration {
763
+ r: number;
764
+ g: number;
765
+ b: number;
766
+ a: number;
767
+ }
768
+ interface Vector {
769
+ x: number;
770
+ y: number;
771
+ z: number;
772
+ }
773
+ /**
774
+ * Wraps functionality for interacting with models in the scene.
775
+ */
776
+ type ModelContainer = {
777
+ /**
778
+ * Applies a given material modifier to a target material in the scene.
779
+ * @param targetMaterial The material to target.
780
+ * @param key A unique key used to identify this action.
781
+ * @param material The material modifier to apply.
782
+ * @param removeWhenUndefined Whether or not to remove the material modifier when the material is undefined.
783
+ */
784
+ applyMaterialVariant(targetMaterial: string, key: string, material: Partial<MaterialResource>, removeWhenUndefined?: boolean): Promise<void>;
785
+ /**
786
+ * Applies a given model variant to the scene.
787
+ * @param key A unique key used to identify this action.
788
+ * @param model modelDetails -> An asset containing a model file to be loaded into the scene.
789
+ * If undefined, the model will be removed from the scene.
790
+ * @param replaceProductModel Whether or not to replace the product model with the new model.
791
+ */
792
+ applyModelVariant(key: string, modelDetails: ModelDetails | undefined, replaceProductModel: boolean): Promise<void>;
793
+ /**
794
+ * Executes an animation on the model.
795
+ * @param animation The animation track to run.
796
+ * @returns A promise which resolves when the animation has completed. If the animation is looping, the promise will resolve after the first loop.
797
+ */
798
+ executeAnimation(animation: ModelAnimation): Promise<void>;
799
+ /**
800
+ * Disposes all resources associated with the model container.
801
+ * Note: This will also remove the container from the preview service.
802
+ */
803
+ dispose(): void;
804
+ /**
805
+ * Returns the animations available on the model.
806
+ * @param includeVariants When true, animations on model variants will be included. Defaults to false.
807
+ */
808
+ getAnimations(includeVariants?: boolean): readonly ModelAnimation[];
809
+ /**
810
+ * Returns the unique ID of the model container.
811
+ */
812
+ getId(): string;
813
+ /**
814
+ * Returns a promise which resolves when the model has been initialized.
815
+ */
816
+ getInitializationPromise(): Promise<ModelContainer>;
817
+ /**
818
+ * Returns true if the model has been initialized.
819
+ */
820
+ getIsInitialized(): boolean;
821
+ /**
822
+ * List named materials that are available on the model.
823
+ * Designed for use when utilizing the 3D preview in an editor format.
824
+ */
825
+ listMaterials(): readonly MaterialHandle[];
826
+ /**
827
+ * Registers a callback that will be invoked when a material is under the cursor.
828
+ * @param callback The callback to register.
829
+ */
830
+ registerMaterialSelectedCallback(callback: (material: MaterialHandle) => void): void;
831
+ /**
832
+ * Removes a callback that was previously registered to be invoked when a material is under the cursor.
833
+ * @param callback The callback to unregister.
834
+ */
835
+ unregisterMaterialSelectedCallback(callback: (material: MaterialHandle) => void): void;
836
+ /**
837
+ * Registers a callback that will be invoked when a material is no longer under the cursor.
838
+ * @param callback The callback to register.
839
+ */
840
+ registerMaterialDeselectedCallback(callback: (material: MaterialHandle) => void): void;
841
+ /**
842
+ * Removes a callback that was previously registered to be invoked when a material is no longer under the cursor.
843
+ * @param callback The callback to unregister.
844
+ */
845
+ unregisterMaterialDeselectedCallback(callback: (material: MaterialHandle) => void): void;
846
+ /**
847
+ * The position of the model, in scene space.
848
+ */
849
+ position: Vector;
850
+ /**
851
+ * The rotation of the model, in scene space.
852
+ */
853
+ rotation: Vector;
854
+ /**
855
+ * The scale of the model, in scene space.
856
+ */
857
+ scale: Vector;
858
+ /**
859
+ * Custom metadata associated with the model.
860
+ */
861
+ metadata: Map<string, any>;
862
+ };
863
+ /**
864
+ * Provides references to 3D preview engine objects.
865
+ * The types of these objects are dependent on the engine being used.
866
+ */
867
+ type EngineContext = {
868
+ /**
869
+ * The camera being used by the ThreeDPreviewService.
870
+ */
871
+ camera: any;
872
+ /**
873
+ * The 3D engine.
874
+ */
875
+ engine: any;
876
+ /**
877
+ * The active scene.
878
+ */
879
+ scene: any;
880
+ };
881
+ /**
882
+ * A plugin that provides additional functionality to the preview service.
883
+ */
884
+ type PreviewServicePlugin = {
885
+ /**
886
+ * Called when the plugin is first registered with the preview service.
887
+ * @param previewService A reference to the preview service.
888
+ * @param context A reference to the engine context.
889
+ */
890
+ initialize(previewService: ThreeDPreviewService, context: EngineContext): void;
891
+ /**
892
+ * Called when the plugin is unregistered from the preview service.
893
+ * Use this to cleanup any resources that have been allocated.
894
+ * This will be called automatically when the preview service is shutdown, or when the plugin is unregistered.
895
+ * @param isServiceShutdown True if the service is being shutdown, false if the plugin is being unregistered.
896
+ */
897
+ dispose(isServiceShutdown: boolean): void;
898
+ };
899
+
900
+ /**
901
+ * Automatically manages construction and destruction of the glow layer.
902
+ */
903
+ declare class GlowLayerManager {
904
+ private readonly scene;
905
+ private intensity;
906
+ private glowLayer?;
907
+ private meshCount;
908
+ constructor(scene: Scene, intensity: number);
909
+ setIntensity(intensity: number): void;
910
+ includeMeshes(meshes: readonly Mesh[]): void;
911
+ removeMeshes(meshes: readonly Mesh[]): void;
912
+ }
913
+
914
+ /**
915
+ * Configuration for the preview. Optionally, you can provide a custom configuration. (from a workflow for example) Sensible
916
+ * defaults will be specified for all properties otherwise.
917
+ */
918
+ declare class Configuration {
919
+ readonly customOptions?: PreviewOptions;
920
+ constructor(options?: PreviewOptions);
921
+ createCanvas(): HTMLCanvasElement;
922
+ get options(): PreviewOptions | undefined;
923
+ /**
924
+ * Configuration related to the scene
925
+ */
926
+ get scene(): {
927
+ clearColor: Color4;
928
+ transparentBackground: string | true | undefined;
929
+ environment: {
930
+ file: string;
931
+ intensity: number;
932
+ rotationY: number;
933
+ };
934
+ };
935
+ /**
936
+ * Configuration related to the camera used to view and interact with the scene.
937
+ */
938
+ get camera(): {
939
+ autoOrientation: boolean;
940
+ autoRotation: {
941
+ enabled: boolean;
942
+ idleTimeMs: number;
943
+ };
944
+ limits: {
945
+ min: {
946
+ alpha: number | undefined;
947
+ beta: number | undefined;
948
+ radius: number | undefined;
949
+ };
950
+ max: {
951
+ alpha: number | undefined;
952
+ beta: number | undefined;
953
+ radius: number | undefined;
954
+ };
955
+ };
956
+ };
957
+ /**
958
+ * Configuration related to the highlighting system. Highlights are used to add
959
+ * a visual cue to the user that something is moused over in the preview.
960
+ */
961
+ get highlights(): {
962
+ enabled: boolean;
963
+ color: Color4;
964
+ };
965
+ get lighting(): {
966
+ exposure: number;
967
+ contrast: number;
968
+ };
969
+ get emissiveGlowIntensity(): number;
970
+ /**
971
+ * Will return clear color based on custom configuration or a sensible default.
972
+ * @returns A Color4 object for use as a clear color.
973
+ */
974
+ private getSceneClearColor;
975
+ private highlightColorFromConfig;
976
+ private hexToColor4;
977
+ }
978
+
979
+ /**
980
+ * A slightly extended version of the ArcRotateCamera.
981
+ * Configures the camera in a way that best suites product visualization.
982
+ * Also provides some convenience functions for interacting with the camera at runtime.
983
+ */
984
+ declare class ProductCamera extends ArcRotateCamera {
985
+ constructor(name: string, alpha: number, beta: number, radius: number, target: Vector3, scene: Scene, configuration: Configuration, setActiveOnSceneIfNoneActive?: boolean);
986
+ updateConfiguration(configuration: Configuration): void;
987
+ /**
988
+ * Stores the current executed target point of the camera. If the camera target changes
989
+ * via panning we can notify ui about the fact to help users reset the camera.
990
+ */
991
+ readonly lastFocus: Vector3;
992
+ get isRunningFramingBehavior(): boolean;
993
+ set isRunningFramingBehavior(value: boolean);
994
+ private _isRunningFramingBehavior;
995
+ private framingBehaviourCallback?;
996
+ private panDenominator;
997
+ private panEnabled;
998
+ setPanEnabled(enabled: boolean): void;
999
+ /**
1000
+ * Returns the framing behavior of this camera.
1001
+ */
1002
+ getFramingBehavior(): FramingBehavior;
1003
+ /**
1004
+ * Returns the auto rotation behavior of this camera, this may
1005
+ * not always be available.
1006
+ */
1007
+ getAutoRotationBehavior(): AutoRotationBehavior | undefined;
1008
+ /**
1009
+ * Activates framing on this camera causing the camera to focus on
1010
+ * the scene and bound itself in a sensible fashion to the scene content.
1011
+ */
1012
+ enableFramingBehavior(): FramingBehavior;
1013
+ /**
1014
+ * Animates the camera back to the initial target when it has drifted to another position.
1015
+ * @param onAnimationComplete A callback when the camera has finished animating.
1016
+ * @param time The time in milliseconds the animation should take.
1017
+ */
1018
+ rerunFramingBehavior(onAnimationComplete?: () => void, time?: number): void;
1019
+ /**
1020
+ * Activates the auto rotation behavior causing the camera to rotate slowly around
1021
+ * it's target.
1022
+ * @param idleTime The number of milliseconds before the camera starts rotating after the user last interacted.
1023
+ */
1024
+ enableAutoRotationBehavior(idleTime?: number): void;
1025
+ /**
1026
+ * Stops the auto rotation functionality immediately.
1027
+ */
1028
+ disableAutoRotationBehavior(): void;
1029
+ updateRadiusBounds(radius: number): void;
1030
+ /**
1031
+ * A static function used to instantiate a single product camera instance on a scene. This camera will assume
1032
+ * the active camera role on the scene and any existing active camera will be disposed.
1033
+ * @param scene The scene to attach the camera to.
1034
+ * @param configuration A configuration object to define the cameras limitations.
1035
+ * @param assignActive If true the camera will be assigned as the active camera on the scene.
1036
+ * @param disablePan If true the camera will not allow panning.
1037
+ */
1038
+ static create(scene: Scene, configuration: Configuration, assignActive?: boolean): ProductCamera;
1039
+ }
1040
+
1041
+ /**
1042
+ * An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews
1043
+ * is designed to be optional, anyone can come along and implement their own 3D preview service or
1044
+ * they can use this one to get things running more quickly.
1045
+ */
1046
+ declare class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
1047
+ private readonly camera;
1048
+ private readonly engine;
1049
+ private readonly scene;
1050
+ private configuration;
1051
+ /**
1052
+ * The last camera animation requested if the scene wasn't ready.
1053
+ */
1054
+ private queuedCameraAnimation?;
1055
+ /**
1056
+ * When listeners have been notified of a change in camera target position
1057
+ * this field will be set to true.
1058
+ */
1059
+ private focusLostNotified;
1060
+ /**
1061
+ * An observable handling loss of target focus by the camera.
1062
+ */
1063
+ private focusLostObservable;
1064
+ /**
1065
+ * A collection of callbacks to be invoked when a model is loaded or unloaded.
1066
+ */
1067
+ private modelLoadEventCallbacks;
1068
+ private glowLayerManager;
1069
+ /**
1070
+ * When instantiated, contains a list of meshes that contribute to highlighting
1071
+ * in the scene.
1072
+ */
1073
+ private highlightLayer?;
1074
+ private renderingPipeline;
1075
+ private modelContainers;
1076
+ private plugins;
1077
+ private screenshotPrepareResolve;
1078
+ private readonly initPromise;
1079
+ private initComplete;
1080
+ private isAnimatingCamera;
1081
+ private queuedAnimationFunction?;
1082
+ constructor(options?: PreviewOptions);
1083
+ getInitializationPromise(): Promise<void>;
1084
+ getInitializationComplete(): boolean;
1085
+ getEngineContext(): {
1086
+ engine: Engine;
1087
+ scene: Scene;
1088
+ camera: ProductCamera;
1089
+ };
1090
+ registerFocusLostListener(listener: () => void): void;
1091
+ unregisterFocusLostListener(listener: () => void): void;
1092
+ registerModelLoadEventListener(listener: (e: ModelLoadEventData) => void): void;
1093
+ unregisterModelLoadEventListener(listener: (e: ModelLoadEventData) => void): void;
1094
+ registerView(canvas: HTMLCanvasElement): void;
1095
+ getNumViewports(): number;
1096
+ unregisterView(canvas: HTMLCanvasElement): void;
1097
+ shutdown(): void;
1098
+ private renderLoop;
1099
+ executeCameraAnimation(animation: CameraAnimation): Promise<void>;
1100
+ getCameraPose(): CameraPose | undefined;
1101
+ setCameraPose(cameraPose: CameraPose): void;
1102
+ setCameraState(rigType: ProductCameraRig): void;
1103
+ animateToLastCameraFocus(): Promise<void>;
1104
+ setAutoRotation(shouldAutoRotate: boolean): void;
1105
+ getCurrentConfiguration(): PreviewOptions | undefined;
1106
+ renderSceneScreenshot(resolution: number, camAnim: CameraAnimation): Promise<string>;
1107
+ orbitEnabled(): boolean;
1108
+ fireResizeEvent(): void;
1109
+ setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
1110
+ setRenderingPipelineConfiguration(renderingPipelineConfiguration: RenderingPipelineConfiguration): void;
1111
+ loadModel(modelDetails: ModelDetails, progressHandler?: (event: ISceneLoaderProgressEvent) => void): ModelContainer;
1112
+ preloadModel(url: string): Promise<void>;
1113
+ getAllModels(): ReadonlyArray<ModelContainer>;
1114
+ getModelById(id: string): ModelContainer | undefined;
1115
+ registerPlugin(plugin: PreviewServicePlugin): void;
1116
+ unregisterPlugin(plugin: PreviewServicePlugin): void;
1117
+ getGlowLayerManager(): GlowLayerManager;
1118
+ modelUnloaded(modelContainer: ModelContainer): void;
1119
+ private triggerModelLoadEvent;
1120
+ /**
1121
+ * Flips a transform around the origin.
1122
+ */
1123
+ flipTransform(position?: Vector, rotation?: Vector, scale?: Vector): {
1124
+ position: Vector;
1125
+ rotation: Vector;
1126
+ scale: Vector;
1127
+ };
1128
+ updatePreviewOptions(options: PreviewOptions): void;
1129
+ /**
1130
+ * Given a valid canvas element, will remove any existing input controls
1131
+ * and re-attach them to the given canvas. The pan mouse button can be set
1132
+ * to either 0 (left mouse) or 2 (right mouse).
1133
+ */
1134
+ private reattachControls;
1135
+ }
1136
+
1137
+ /**
1138
+ * Represents the dimensions of a texture, enforcing power of two numbers.
1139
+ */
1140
+ type RenderDimensions = {
1141
+ readonly width: PowerOfTwoNumber;
1142
+ readonly height: PowerOfTwoNumber;
1143
+ };
1144
+ /**
1145
+ * A class containing largely static configuration information.
1146
+ */
1147
+ declare class RenderingConfiguration {
1148
+ /**
1149
+ * Returns the resolution expected for generated textures.
1150
+ */
1151
+ static getDynamicTextureResolution(): RenderDimensions;
1152
+ /**
1153
+ * Returns true when textures should generate mip maps
1154
+ */
1155
+ static shouldMipMap(): boolean;
1156
+ /**
1157
+ * Returns true when multithreaded rendering is supported.
1158
+ */
1159
+ static offscreenRenderingSupported(): boolean;
1160
+ /**
1161
+ * Returns the resolution expected for mirror textures.
1162
+ */
1163
+ static getMirrorTextureResolution(): PowerOfTwoNumber;
1164
+ private static getIsMobile;
1165
+ }
1166
+ declare const REFLECTION_PROBE_RESOLUTION = 128;
1167
+ type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
1168
+ declare const renderingPipelineDefaults: RenderingPipelineConfiguration;
1169
+
1170
+ 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 };