@spiffcommerce/preview 2.0.2 → 2.1.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/dist/types.d.ts CHANGED
@@ -1,522 +1,522 @@
1
- import { ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader";
2
- import { Scene } from "@babylonjs/core/scene";
3
- /**
4
- * Defines the different behaviors supported by the camera system
5
- * for control when viewing a product.
6
- */
7
- export enum ProductCameraRig {
8
- Orbit = 0,
9
- Pan = 1
10
- }
11
- /**
12
- * Details relating to a model for use in the preview.
13
- */
14
- export type ModelDetails = {
15
- readonly model?: string;
16
- readonly contextService: RenderableContextService;
17
- };
18
- /**
19
- * Identical to CameraAnimation typing, however the
20
- * target is always available and hence is not optional.
21
- */
22
- export type CameraPose = {
23
- readonly lonDeg: number;
24
- readonly radius: number;
25
- readonly latDeg: number;
26
- readonly target: {
27
- readonly x: number;
28
- readonly y: number;
29
- readonly z: number;
30
- };
31
- };
32
- export type ThreeDPreviewService = {
33
- /**
34
- * Allows listeners to be aware of the camera losing focus of the
35
- * main product.
36
- * @param listener A function to be called when focus is lost.
37
- */
38
- registerFocusLostListener(listener: () => void): void;
39
- /**
40
- * Removes a listener from the focusLost observers. The listener will
41
- * no longer be notified
42
- * @param listener The listener to remove.
43
- */
44
- unregisterFocusLostListener(listener: () => void): void;
45
- /**
46
- * Providers listeners with information about load progress when
47
- * the preview is loading scenes.
48
- * @param listener A function to get load progress updates
49
- */
50
- registerLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
51
- /**
52
- * Allows you to pass any function that originally called registerLoadProgressListener()
53
- * to have it excluded from load progress updates.
54
- * If the function was never registered this call has no effect.
55
- * @param listener The listener to exclude from load progress.
56
- */
57
- unregisterLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
58
- /**
59
- * Request that the scene renders to a given canvas
60
- * @param canvas The canvas we should render to.
61
- */
62
- registerView(canvas: HTMLCanvasElement): void;
63
- /**
64
- * Returns the number of active viewers of the scene. Useful for
65
- * avoiding unnecessary rendering when there are no active viewers.
66
- */
67
- getNumViewports(): number;
68
- /**
69
- * Tells babylon that we no longer want the given canvas to be rendered to.
70
- * @param canvas The canvas to be excluded from rendering.
71
- */
72
- unregisterView(canvas: HTMLCanvasElement): void;
73
- /**
74
- * Shutdown the preview engine. Noop if the engine is not initialized.
75
- */
76
- shutdown(): void;
77
- /**
78
- * Initialize the scene. Also initialize the engine, if it hasn't been done already.
79
- */
80
- initialize(src: string, contextService?: RenderableContextService): Promise<void>;
81
- /**
82
- * Executes an animation in the currently loaded scene.
83
- * @param animation The current animation track to run.
84
- */
85
- executeModelAnimation(animation: ModelAnimation): void;
86
- /**
87
- * Executes an animation of the camera.
88
- * @param animation The animation to execute.
89
- */
90
- executeCameraAnimation(animation: CameraAnimation): void;
91
- /**
92
- * Returns the values of the Arc Rotate Camera
93
- */
94
- getCameraPose(): CameraPose | undefined;
95
- /**
96
- * Sets the values of the Arc Rotate Camera
97
- */
98
- setCameraPose(cameraPose: CameraPose): void;
99
- /**
100
- * Applies a given material modifier to a target material in the scene.
101
- * @param targetMaterial The material to target.
102
- * @param key A unique key used to identify this action.
103
- * @param material The material modifier to apply.
104
- */
105
- applyMaterialVariant(targetMaterial: string, key: string, material: MaterialResource, removeWhenUndefined?: boolean): Promise<void>;
106
- /**
107
- * Applies a given model variant to the scene.
108
- * @param key A unique key used to identify this action.
109
- * @param model modelDetails -> An asset containing a model file to be loaded into the scene.
110
- * @param layouts modelDetails -> The layouts of the workflow, used for applying dynamic textures.
111
- */
112
- applyModelVariant(key: string, modelDetails: ModelDetails, replaceProductModel: boolean): Promise<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
- * Get current load progress for the scene.
132
- */
133
- getSceneInitializationProgress(): number;
134
- /**
135
- * Returns the current configuration object applied to the scene.
136
- */
137
- getCurrentConfiguration(): PreviewOptions | undefined;
138
- /**
139
- * Takes a screenshot of the scene using a given
140
- * camera animation otherwise using the existing orientation
141
- * of the camera in the scene. A resolution must be provided
142
- * to render the scene at.
143
- */
144
- renderSceneScreenshot(resolution: number, cameraAnimation: CameraAnimation): Promise<string>;
145
- /**
146
- * Returns true when the current configuration allows the user
147
- * to rotate around the product.
148
- */
149
- orbitEnabled(): boolean;
150
- /**
151
- * When called will trigger the internal engine to match the current
152
- * canvas size. This ensures the image renders correctly in the view and
153
- * also prevents performance problems.
154
- */
155
- fireResizeEvent(): void;
156
- /**
157
- * A callback when the user clicks in the scene and a material is hit.
158
- */
159
- onMaterialSelected(cb: (material: MaterialHandle) => void): void;
160
- /**
161
- * Designed for use when utilizing the 3D preview in an editor format.
162
- * List named materials that are available in the scene.
163
- */
164
- listMaterials(): readonly MaterialHandle[];
165
- /**
166
- * Designed for use when utilizing the 3D preview in an editor format.
167
- * Given a list of material names, highlights the associated meshes in the scene.
168
- */
169
- setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
170
- };
171
- /**
172
- * Represents a service capable of managing and returning contexts that
173
- * can be used for rendering to textures in the 3D preview.
174
- */
175
- export type RenderableContextService = {
176
- /**
177
- * Returns all managed renderable contexts.
178
- */
179
- getAll(): ReadonlyMap<string, RenderableContext>;
180
- };
181
- /**
182
- * A renderable context represents the relationship of a texture in the 3D preview
183
- * with an external canvas. This context allows external clients to render to a texture
184
- * in the 3D preview with a simple interface.
185
- */
186
- export type RenderableContext = {
187
- /**
188
- * A unique identifier for this renderable context.
189
- */
190
- getID(): string;
191
- /**
192
- * A name for this renderable.
193
- */
194
- getName(): string;
195
- /**
196
- * Sets the render context associated to this renderable.
197
- * @param ctx The context to use for rendering.
198
- */
199
- setStaticContext(ctx: CanvasRenderingContext2D): void;
200
- /**
201
- * Get the render context associated to this renderable.
202
- */
203
- getStaticContext(): CanvasRenderingContext2D | undefined;
204
- /**
205
- * Sets whether or not this renderable is dirty and will need re-rendering.
206
- * @param value The new value
207
- */
208
- setStaticContextDirty(value: boolean): void;
209
- /**
210
- * When this context has been set as dirty, returns true.
211
- */
212
- getStaticContextDirty(): boolean;
213
- /**
214
- * A timestamp for the last successful render of the context.
215
- */
216
- getLastCompletedStaticRender(): number | undefined;
217
- };
218
- export type LoadProgressEventData = {
219
- /**
220
- * The total load value of the scene, this is an average of all
221
- * 'in progress' loading events. when all events are fully loaded this value will be 100.
222
- */
223
- readonly loadValue: number;
224
- /**
225
- * This value is true when the base model and scene have been initialized.
226
- */
227
- readonly sceneInitialized: boolean;
228
- };
229
- /**
230
- * Used to specify the behavior of a material effect such as clearcoat, sheen and translucency.
231
- */
232
- export enum MaterialEffectMode {
233
- /**
234
- * When a material variant effect specifies 'None' the effect doesn't change in any way. This is the default behavior.
235
- */
236
- None = "None",
237
- /**
238
- * When a material variant effect specifies 'RemoveWhenSelected' the effect is removed.
239
- */
240
- RemoveWhenSelected = "RemoveWhenSelected",
241
- /**
242
- * When a material variant effect specifies 'ApplyWhenSelected' the effect is enabled.
243
- */
244
- ApplyWhenSelected = "ApplyWhenSelected"
245
- }
246
- /**
247
- * Represents a material resource that can be additively applied to
248
- * a material targeted in the scene.
249
- */
250
- export type MaterialResource = {
251
- /**
252
- * A unique identified for this material.
253
- */
254
- id: string;
255
- /**
256
- * The name of this material
257
- */
258
- name: string;
259
- /**
260
- * Defines the base color of a surface before any other calculations are made.
261
- */
262
- albedoMapKey?: string;
263
- albedoKey?: string;
264
- /**
265
- * Defines the transparency of a surface.
266
- */
267
- alphaMapKey?: string;
268
- alphaKey?: string;
269
- /**
270
- * Defines shadowing on a surface.
271
- */
272
- ambientMapKey?: string;
273
- ambientKey?: string;
274
- /**
275
- * Defines the amount of light being emitted from a surface.
276
- */
277
- emissionMapKey?: string;
278
- emissionKey?: string;
279
- /**
280
- * Identical to roughness.
281
- */
282
- metallicMapKey?: string;
283
- metallicKey?: string;
284
- /**
285
- * Defines the direction light will bounce in when it hits a point on a surface.
286
- */
287
- normalMapKey?: string;
288
- normalKey?: string;
289
- /**
290
- * Used to define how smooth a surface is.
291
- */
292
- roughnessMapKey?: string;
293
- roughnessKey?: string;
294
- /**
295
- * Used to define refreaction of light on a surface.
296
- */
297
- refractionMapKey?: string;
298
- refractionKey?: string;
299
- /**
300
- * The intensity of refraction, when refraction is enabled via a texture.
301
- */
302
- refractionIntensity?: number;
303
- /**
304
- * When enabled the material will be displayed with a clearcoat affect for simulating coated plastic surfaces.
305
- */
306
- clearCoat: MaterialEffectMode;
307
- /**
308
- * Index of refraction when clear coat is enabled.
309
- */
310
- clearCoatIOR?: number;
311
- /**
312
- * The date that this material resource was created
313
- */
314
- createdAt: string;
315
- /**
316
- * The date that this material resource was last updated.
317
- */
318
- updatedAt: string;
319
- };
320
- /**
321
- * Represents a handle to a material in the 3D scene. The underlying complexity of materials is abstracted
322
- * away so the client doesn't need to know anything more than the ID they're given and the name.
323
- */
324
- export type MaterialHandle = {
325
- /**
326
- * The identifier for the material.
327
- */
328
- readonly id: string;
329
- /**
330
- * The human readable name for the material.
331
- */
332
- readonly name: string;
333
- };
334
- /**
335
- * Settings related to the 3D preview.
336
- */
337
- export type PreviewOptions = {
338
- /**
339
- * The color expected to be seen in the background of the product. Expects a hexadecimal value.
340
- */
341
- readonly backgroundColor?: string;
342
- /**
343
- * Image to be used as a background when running withh transparency, the image
344
- * will be scaled and centered to fill the preview based on aspect ratio.
345
- */
346
- readonly backgroundImage?: string;
347
- /**
348
- * The closest zoom the camera can achieve to the product.
349
- */
350
- readonly maxZoomOverride?: number;
351
- /**
352
- * The furthest zoom the camera can achieve to the product.
353
- */
354
- readonly minZoomOverride?: number;
355
- /**
356
- * The environment file used to calculate product lighting.
357
- */
358
- readonly environmentFile?: string;
359
- /**
360
- * The lowest point, vertically, that the camera can rotate to.
361
- * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
362
- */
363
- readonly lowerBetaLimitDeg?: number;
364
- /**
365
- * The highest point, vertically, that the camera can rotate to.
366
- * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
367
- */
368
- readonly upperBetaLimitDeg?: number;
369
- /**
370
- * The leftmost point, horizontally, that the camera can rotate to.
371
- * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
372
- */
373
- readonly lowerAlphaLimitDeg?: number;
374
- /**
375
- * The rightmost point, horizontally, that the camera can rotate to.
376
- * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
377
- */
378
- readonly upperAlphaLimitDeg?: number;
379
- /**
380
- * When set the product while rotate slowly
381
- */
382
- readonly autoRotation?: boolean;
383
- /**
384
- * Time in milliseconds before the product starts rotating after a user input has taken control.
385
- */
386
- readonly idleTimeBeforeRotation?: number;
387
- /**
388
- * When set the 3D preview won't attempt to orient the product automatically to its front view at load.
389
- */
390
- readonly disableAutomaticOrientation?: boolean;
391
- /**
392
- * When true the action bar won't be displayed to the user.
393
- */
394
- readonly disableActionBar?: boolean;
395
- /**
396
- * When set, mousing over the model in this preview will highlight the associated mesh/material.
397
- * When layout contexts are provided, only the materials with matching names will highlight.
398
- */
399
- readonly highlightOnMaterialHover?: boolean;
400
- /**
401
- * Sets the color of highlights when enabled. Expects hexadecimal value.
402
- */
403
- readonly highlightColor?: string;
404
- };
405
- /**
406
- * Defines an animation to be play on a product.
407
- */
408
- export type ModelAnimation = {
409
- /**
410
- * A value it seconds along the animation timeline to begin at.
411
- */
412
- readonly from: number;
413
- /**
414
- * A value in seconds along the animation timeline to end at.
415
- */
416
- readonly to?: number;
417
- /**
418
- * When true the animation will loop. The only behavior currently is to reset
419
- * back to from but we could have it bounce back and forth and/or follow a curve.
420
- */
421
- readonly loop: boolean;
422
- };
423
- /**
424
- * A CameraAnimation specifies a discrete state that the camera should
425
- * animate to. This state represents the final position of the camera after animations have run.
426
- */
427
- export type CameraAnimation = {
428
- /**
429
- * The longitude in degrees the camera should animate to.
430
- */
431
- readonly lonDeg: number;
432
- /**
433
- * The latitude in degrees the camera should animate to.
434
- */
435
- readonly latDeg: number;
436
- /**
437
- * An optional target for the camera to focus on in the scene.
438
- */
439
- readonly target?: {
440
- readonly x: number;
441
- readonly y: number;
442
- readonly z: number;
443
- };
444
- /**
445
- * A value in scene units specifying camera distance from the target.
446
- */
447
- readonly radius?: number;
448
- };
449
- /**
450
- * Represents the dimensions of a texture, enforcing power of two numbers.
451
- */
452
- type RenderDimensions = {
453
- readonly width: PowerOfTwoNumber;
454
- readonly height: PowerOfTwoNumber;
455
- };
456
- /**
457
- * A class containing largely static configuration information.
458
- */
459
- export class RenderingConfiguration {
460
- /**
461
- * Returns the resolution expected for generated textures.
462
- */
463
- static getDynamicTextureResolution(): RenderDimensions;
464
- /**
465
- * Returns true when textures should generate mip maps
466
- */
467
- static shouldMipMap(): boolean;
468
- /**
469
- * Returns true when multithreaded rendering is supported.
470
- */
471
- static offscreenRenderingSupported(): boolean;
472
- /**
473
- * Returns the resolution expected for mirror textures.
474
- */
475
- static getMirrorTextureResolution(): PowerOfTwoNumber;
476
- }
477
- export const REFLECTION_PROBE_RESOLUTION = 128;
478
- export type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
479
- /**
480
- * An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews
481
- * is designed to be optional, anyone can come along and implement their own 3D preview service or
482
- * they can use this one to get things running more quickly.
483
- */
484
- export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
485
- constructor(canvas?: HTMLCanvasElement, options?: PreviewOptions);
486
- registerFocusLostListener(listener: () => void): void;
487
- unregisterFocusLostListener(listener: () => void): void;
488
- registerLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
489
- unregisterLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
490
- registerView(canvas: HTMLCanvasElement): void;
491
- getNumViewports(): number;
492
- unregisterView(canvas: HTMLCanvasElement): void;
493
- shutdown(): void;
494
- getSceneInitializationProgress(): number;
495
- initialize(src?: string, contextService?: RenderableContextService): Promise<void>;
496
- executeModelAnimation(animation: ModelAnimation): void;
497
- executeCameraAnimation(animation: CameraAnimation): void;
498
- getCameraPose(): CameraPose | undefined;
499
- setCameraPose(cameraPose: CameraPose): void;
500
- applyMaterialVariant(targetMaterial: string, key: string, material: MaterialResource, removeWhenUndefined?: boolean): Promise<void>;
501
- applyModelVariant(key: string, modelDetails: ModelDetails, replaceProductModel: boolean): Promise<void>;
502
- setCameraState(rigType: ProductCameraRig): void;
503
- animateToLastCameraFocus(): Promise<void>;
504
- setAutoRotation(shouldAutoRotate: boolean): void;
505
- getCurrentConfiguration(): PreviewOptions | undefined;
506
- renderSceneScreenshot(resolution: number, camAnim: CameraAnimation): Promise<string>;
507
- orbitEnabled(): boolean;
508
- fireResizeEvent(): void;
509
- onMaterialSelected(cb: (material: MaterialHandle) => void): void;
510
- listMaterials(): readonly MaterialHandle[];
511
- setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
512
- initXRExperience(buttonEl: HTMLElement): void;
513
- }
514
- /**
515
- * Adds a tags a base mesh to the scene.
516
- * TODO: Move this to another file with other creation/initialization functionality?
517
- * @param src A url to a valid glb scene
518
- * @param progressHandler A handler for load progress events.
519
- */
520
- export function createBaseModel(src: string, scene: Scene, progressHandler?: (event: ISceneLoaderProgressEvent) => void): Promise<void>;
1
+ import { ISceneLoaderProgressEvent } from "@babylonjs/core/Loading/sceneLoader";
2
+ import { Scene } from "@babylonjs/core/scene";
3
+ /**
4
+ * Defines the different behaviors supported by the camera system
5
+ * for control when viewing a product.
6
+ */
7
+ export enum ProductCameraRig {
8
+ Orbit = 0,
9
+ Pan = 1
10
+ }
11
+ /**
12
+ * Details relating to a model for use in the preview.
13
+ */
14
+ export type ModelDetails = {
15
+ readonly model?: string;
16
+ readonly contextService: RenderableContextService;
17
+ };
18
+ /**
19
+ * Identical to CameraAnimation typing, however the
20
+ * target is always available and hence is not optional.
21
+ */
22
+ export type CameraPose = {
23
+ readonly lonDeg: number;
24
+ readonly radius: number;
25
+ readonly latDeg: number;
26
+ readonly target: {
27
+ readonly x: number;
28
+ readonly y: number;
29
+ readonly z: number;
30
+ };
31
+ };
32
+ export type ThreeDPreviewService = {
33
+ /**
34
+ * Allows listeners to be aware of the camera losing focus of the
35
+ * main product.
36
+ * @param listener A function to be called when focus is lost.
37
+ */
38
+ registerFocusLostListener(listener: () => void): void;
39
+ /**
40
+ * Removes a listener from the focusLost observers. The listener will
41
+ * no longer be notified
42
+ * @param listener The listener to remove.
43
+ */
44
+ unregisterFocusLostListener(listener: () => void): void;
45
+ /**
46
+ * Providers listeners with information about load progress when
47
+ * the preview is loading scenes.
48
+ * @param listener A function to get load progress updates
49
+ */
50
+ registerLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
51
+ /**
52
+ * Allows you to pass any function that originally called registerLoadProgressListener()
53
+ * to have it excluded from load progress updates.
54
+ * If the function was never registered this call has no effect.
55
+ * @param listener The listener to exclude from load progress.
56
+ */
57
+ unregisterLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
58
+ /**
59
+ * Request that the scene renders to a given canvas
60
+ * @param canvas The canvas we should render to.
61
+ */
62
+ registerView(canvas: HTMLCanvasElement): void;
63
+ /**
64
+ * Returns the number of active viewers of the scene. Useful for
65
+ * avoiding unnecessary rendering when there are no active viewers.
66
+ */
67
+ getNumViewports(): number;
68
+ /**
69
+ * Tells babylon that we no longer want the given canvas to be rendered to.
70
+ * @param canvas The canvas to be excluded from rendering.
71
+ */
72
+ unregisterView(canvas: HTMLCanvasElement): void;
73
+ /**
74
+ * Shutdown the preview engine. Noop if the engine is not initialized.
75
+ */
76
+ shutdown(): void;
77
+ /**
78
+ * Initialize the scene. Also initialize the engine, if it hasn't been done already.
79
+ */
80
+ initialize(src: string, contextService?: RenderableContextService): Promise<void>;
81
+ /**
82
+ * Executes an animation in the currently loaded scene.
83
+ * @param animation The current animation track to run.
84
+ */
85
+ executeModelAnimation(animation: ModelAnimation): void;
86
+ /**
87
+ * Executes an animation of the camera.
88
+ * @param animation The animation to execute.
89
+ */
90
+ executeCameraAnimation(animation: CameraAnimation): void;
91
+ /**
92
+ * Returns the values of the Arc Rotate Camera
93
+ */
94
+ getCameraPose(): CameraPose | undefined;
95
+ /**
96
+ * Sets the values of the Arc Rotate Camera
97
+ */
98
+ setCameraPose(cameraPose: CameraPose): void;
99
+ /**
100
+ * Applies a given material modifier to a target material in the scene.
101
+ * @param targetMaterial The material to target.
102
+ * @param key A unique key used to identify this action.
103
+ * @param material The material modifier to apply.
104
+ */
105
+ applyMaterialVariant(targetMaterial: string, key: string, material: MaterialResource, removeWhenUndefined?: boolean): Promise<void>;
106
+ /**
107
+ * Applies a given model variant to the scene.
108
+ * @param key A unique key used to identify this action.
109
+ * @param model modelDetails -> An asset containing a model file to be loaded into the scene.
110
+ * @param layouts modelDetails -> The layouts of the workflow, used for applying dynamic textures.
111
+ */
112
+ applyModelVariant(key: string, modelDetails: ModelDetails, replaceProductModel: boolean): Promise<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
+ * Get current load progress for the scene.
132
+ */
133
+ getSceneInitializationProgress(): number;
134
+ /**
135
+ * Returns the current configuration object applied to the scene.
136
+ */
137
+ getCurrentConfiguration(): PreviewOptions | undefined;
138
+ /**
139
+ * Takes a screenshot of the scene using a given
140
+ * camera animation otherwise using the existing orientation
141
+ * of the camera in the scene. A resolution must be provided
142
+ * to render the scene at.
143
+ */
144
+ renderSceneScreenshot(resolution: number, cameraAnimation: CameraAnimation): Promise<string>;
145
+ /**
146
+ * Returns true when the current configuration allows the user
147
+ * to rotate around the product.
148
+ */
149
+ orbitEnabled(): boolean;
150
+ /**
151
+ * When called will trigger the internal engine to match the current
152
+ * canvas size. This ensures the image renders correctly in the view and
153
+ * also prevents performance problems.
154
+ */
155
+ fireResizeEvent(): void;
156
+ /**
157
+ * A callback when the user clicks in the scene and a material is hit.
158
+ */
159
+ onMaterialSelected(cb: (material: MaterialHandle) => void): void;
160
+ /**
161
+ * Designed for use when utilizing the 3D preview in an editor format.
162
+ * List named materials that are available in the scene.
163
+ */
164
+ listMaterials(): readonly MaterialHandle[];
165
+ /**
166
+ * Designed for use when utilizing the 3D preview in an editor format.
167
+ * Given a list of material names, highlights the associated meshes in the scene.
168
+ */
169
+ setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
170
+ };
171
+ /**
172
+ * Represents a service capable of managing and returning contexts that
173
+ * can be used for rendering to textures in the 3D preview.
174
+ */
175
+ export type RenderableContextService = {
176
+ /**
177
+ * Returns all managed renderable contexts.
178
+ */
179
+ getAll(): ReadonlyMap<string, RenderableContext>;
180
+ };
181
+ /**
182
+ * A renderable context represents the relationship of a texture in the 3D preview
183
+ * with an external canvas. This context allows external clients to render to a texture
184
+ * in the 3D preview with a simple interface.
185
+ */
186
+ export type RenderableContext = {
187
+ /**
188
+ * A unique identifier for this renderable context.
189
+ */
190
+ getID(): string;
191
+ /**
192
+ * A name for this renderable.
193
+ */
194
+ getName(): string;
195
+ /**
196
+ * Sets the render context associated to this renderable.
197
+ * @param ctx The context to use for rendering.
198
+ */
199
+ setStaticContext(ctx: CanvasRenderingContext2D): void;
200
+ /**
201
+ * Get the render context associated to this renderable.
202
+ */
203
+ getStaticContext(): CanvasRenderingContext2D | undefined;
204
+ /**
205
+ * Sets whether or not this renderable is dirty and will need re-rendering.
206
+ * @param value The new value
207
+ */
208
+ setStaticContextDirty(value: boolean): void;
209
+ /**
210
+ * When this context has been set as dirty, returns true.
211
+ */
212
+ getStaticContextDirty(): boolean;
213
+ /**
214
+ * A timestamp for the last successful render of the context.
215
+ */
216
+ getLastCompletedStaticRender(): number | undefined;
217
+ };
218
+ export type LoadProgressEventData = {
219
+ /**
220
+ * The total load value of the scene, this is an average of all
221
+ * 'in progress' loading events. when all events are fully loaded this value will be 100.
222
+ */
223
+ readonly loadValue: number;
224
+ /**
225
+ * This value is true when the base model and scene have been initialized.
226
+ */
227
+ readonly sceneInitialized: boolean;
228
+ };
229
+ /**
230
+ * Used to specify the behavior of a material effect such as clearcoat, sheen and translucency.
231
+ */
232
+ export enum MaterialEffectMode {
233
+ /**
234
+ * When a material variant effect specifies 'None' the effect doesn't change in any way. This is the default behavior.
235
+ */
236
+ None = "None",
237
+ /**
238
+ * When a material variant effect specifies 'RemoveWhenSelected' the effect is removed.
239
+ */
240
+ RemoveWhenSelected = "RemoveWhenSelected",
241
+ /**
242
+ * When a material variant effect specifies 'ApplyWhenSelected' the effect is enabled.
243
+ */
244
+ ApplyWhenSelected = "ApplyWhenSelected"
245
+ }
246
+ /**
247
+ * Represents a material resource that can be additively applied to
248
+ * a material targeted in the scene.
249
+ */
250
+ export type MaterialResource = {
251
+ /**
252
+ * A unique identified for this material.
253
+ */
254
+ id: string;
255
+ /**
256
+ * The name of this material
257
+ */
258
+ name: string;
259
+ /**
260
+ * Defines the base color of a surface before any other calculations are made.
261
+ */
262
+ albedoMapKey?: string;
263
+ albedoKey?: string;
264
+ /**
265
+ * Defines the transparency of a surface.
266
+ */
267
+ alphaMapKey?: string;
268
+ alphaKey?: string;
269
+ /**
270
+ * Defines shadowing on a surface.
271
+ */
272
+ ambientMapKey?: string;
273
+ ambientKey?: string;
274
+ /**
275
+ * Defines the amount of light being emitted from a surface.
276
+ */
277
+ emissionMapKey?: string;
278
+ emissionKey?: string;
279
+ /**
280
+ * Identical to roughness.
281
+ */
282
+ metallicMapKey?: string;
283
+ metallicKey?: string;
284
+ /**
285
+ * Defines the direction light will bounce in when it hits a point on a surface.
286
+ */
287
+ normalMapKey?: string;
288
+ normalKey?: string;
289
+ /**
290
+ * Used to define how smooth a surface is.
291
+ */
292
+ roughnessMapKey?: string;
293
+ roughnessKey?: string;
294
+ /**
295
+ * Used to define refreaction of light on a surface.
296
+ */
297
+ refractionMapKey?: string;
298
+ refractionKey?: string;
299
+ /**
300
+ * The intensity of refraction, when refraction is enabled via a texture.
301
+ */
302
+ refractionIntensity?: number;
303
+ /**
304
+ * When enabled the material will be displayed with a clearcoat affect for simulating coated plastic surfaces.
305
+ */
306
+ clearCoat: MaterialEffectMode;
307
+ /**
308
+ * Index of refraction when clear coat is enabled.
309
+ */
310
+ clearCoatIOR?: number;
311
+ /**
312
+ * The date that this material resource was created
313
+ */
314
+ createdAt: string;
315
+ /**
316
+ * The date that this material resource was last updated.
317
+ */
318
+ updatedAt: string;
319
+ };
320
+ /**
321
+ * Represents a handle to a material in the 3D scene. The underlying complexity of materials is abstracted
322
+ * away so the client doesn't need to know anything more than the ID they're given and the name.
323
+ */
324
+ export type MaterialHandle = {
325
+ /**
326
+ * The identifier for the material.
327
+ */
328
+ readonly id: string;
329
+ /**
330
+ * The human readable name for the material.
331
+ */
332
+ readonly name: string;
333
+ };
334
+ /**
335
+ * Settings related to the 3D preview.
336
+ */
337
+ export type PreviewOptions = {
338
+ /**
339
+ * The color expected to be seen in the background of the product. Expects a hexadecimal value.
340
+ */
341
+ readonly backgroundColor?: string;
342
+ /**
343
+ * Image to be used as a background when running withh transparency, the image
344
+ * will be scaled and centered to fill the preview based on aspect ratio.
345
+ */
346
+ readonly backgroundImage?: string;
347
+ /**
348
+ * The closest zoom the camera can achieve to the product.
349
+ */
350
+ readonly maxZoomOverride?: number;
351
+ /**
352
+ * The furthest zoom the camera can achieve to the product.
353
+ */
354
+ readonly minZoomOverride?: number;
355
+ /**
356
+ * The environment file used to calculate product lighting.
357
+ */
358
+ readonly environmentFile?: string;
359
+ /**
360
+ * The lowest point, vertically, that the camera can rotate to.
361
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
362
+ */
363
+ readonly lowerBetaLimitDeg?: number;
364
+ /**
365
+ * The highest point, vertically, that the camera can rotate to.
366
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
367
+ */
368
+ readonly upperBetaLimitDeg?: number;
369
+ /**
370
+ * The leftmost point, horizontally, that the camera can rotate to.
371
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
372
+ */
373
+ readonly lowerAlphaLimitDeg?: number;
374
+ /**
375
+ * The rightmost point, horizontally, that the camera can rotate to.
376
+ * https://doc.babylonjs.com/divingDeeper/cameras/camera_introduction
377
+ */
378
+ readonly upperAlphaLimitDeg?: number;
379
+ /**
380
+ * When set the product while rotate slowly
381
+ */
382
+ readonly autoRotation?: boolean;
383
+ /**
384
+ * Time in milliseconds before the product starts rotating after a user input has taken control.
385
+ */
386
+ readonly idleTimeBeforeRotation?: number;
387
+ /**
388
+ * When set the 3D preview won't attempt to orient the product automatically to its front view at load.
389
+ */
390
+ readonly disableAutomaticOrientation?: boolean;
391
+ /**
392
+ * When true the action bar won't be displayed to the user.
393
+ */
394
+ readonly disableActionBar?: boolean;
395
+ /**
396
+ * When set, mousing over the model in this preview will highlight the associated mesh/material.
397
+ * When layout contexts are provided, only the materials with matching names will highlight.
398
+ */
399
+ readonly highlightOnMaterialHover?: boolean;
400
+ /**
401
+ * Sets the color of highlights when enabled. Expects hexadecimal value.
402
+ */
403
+ readonly highlightColor?: string;
404
+ };
405
+ /**
406
+ * Defines an animation to be play on a product.
407
+ */
408
+ export type ModelAnimation = {
409
+ /**
410
+ * A value it seconds along the animation timeline to begin at.
411
+ */
412
+ readonly from: number;
413
+ /**
414
+ * A value in seconds along the animation timeline to end at.
415
+ */
416
+ readonly to?: number;
417
+ /**
418
+ * When true the animation will loop. The only behavior currently is to reset
419
+ * back to from but we could have it bounce back and forth and/or follow a curve.
420
+ */
421
+ readonly loop: boolean;
422
+ };
423
+ /**
424
+ * A CameraAnimation specifies a discrete state that the camera should
425
+ * animate to. This state represents the final position of the camera after animations have run.
426
+ */
427
+ export type CameraAnimation = {
428
+ /**
429
+ * The longitude in degrees the camera should animate to.
430
+ */
431
+ readonly lonDeg: number;
432
+ /**
433
+ * The latitude in degrees the camera should animate to.
434
+ */
435
+ readonly latDeg: number;
436
+ /**
437
+ * An optional target for the camera to focus on in the scene.
438
+ */
439
+ readonly target?: {
440
+ readonly x: number;
441
+ readonly y: number;
442
+ readonly z: number;
443
+ };
444
+ /**
445
+ * A value in scene units specifying camera distance from the target.
446
+ */
447
+ readonly radius?: number;
448
+ };
449
+ /**
450
+ * Represents the dimensions of a texture, enforcing power of two numbers.
451
+ */
452
+ type RenderDimensions = {
453
+ readonly width: PowerOfTwoNumber;
454
+ readonly height: PowerOfTwoNumber;
455
+ };
456
+ /**
457
+ * A class containing largely static configuration information.
458
+ */
459
+ export class RenderingConfiguration {
460
+ /**
461
+ * Returns the resolution expected for generated textures.
462
+ */
463
+ static getDynamicTextureResolution(): RenderDimensions;
464
+ /**
465
+ * Returns true when textures should generate mip maps
466
+ */
467
+ static shouldMipMap(): boolean;
468
+ /**
469
+ * Returns true when multithreaded rendering is supported.
470
+ */
471
+ static offscreenRenderingSupported(): boolean;
472
+ /**
473
+ * Returns the resolution expected for mirror textures.
474
+ */
475
+ static getMirrorTextureResolution(): PowerOfTwoNumber;
476
+ }
477
+ export const REFLECTION_PROBE_RESOLUTION = 128;
478
+ export type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
479
+ /**
480
+ * An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews
481
+ * is designed to be optional, anyone can come along and implement their own 3D preview service or
482
+ * they can use this one to get things running more quickly.
483
+ */
484
+ export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
485
+ constructor(canvas?: HTMLCanvasElement, options?: PreviewOptions);
486
+ registerFocusLostListener(listener: () => void): void;
487
+ unregisterFocusLostListener(listener: () => void): void;
488
+ registerLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
489
+ unregisterLoadProgressListener(listener: (e: LoadProgressEventData) => void): void;
490
+ registerView(canvas: HTMLCanvasElement): void;
491
+ getNumViewports(): number;
492
+ unregisterView(canvas: HTMLCanvasElement): void;
493
+ shutdown(): void;
494
+ getSceneInitializationProgress(): number;
495
+ initialize(src?: string, contextService?: RenderableContextService): Promise<void>;
496
+ executeModelAnimation(animation: ModelAnimation): void;
497
+ executeCameraAnimation(animation: CameraAnimation): void;
498
+ getCameraPose(): CameraPose | undefined;
499
+ setCameraPose(cameraPose: CameraPose): void;
500
+ applyMaterialVariant(targetMaterial: string, key: string, material: MaterialResource, removeWhenUndefined?: boolean): Promise<void>;
501
+ applyModelVariant(key: string, modelDetails: ModelDetails, replaceProductModel: boolean): Promise<void>;
502
+ setCameraState(rigType: ProductCameraRig): void;
503
+ animateToLastCameraFocus(): Promise<void>;
504
+ setAutoRotation(shouldAutoRotate: boolean): void;
505
+ getCurrentConfiguration(): PreviewOptions | undefined;
506
+ renderSceneScreenshot(resolution: number, camAnim: CameraAnimation): Promise<string>;
507
+ orbitEnabled(): boolean;
508
+ fireResizeEvent(): void;
509
+ onMaterialSelected(cb: (material: MaterialHandle) => void): void;
510
+ listMaterials(): readonly MaterialHandle[];
511
+ setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
512
+ initXRExperience(buttonEl: HTMLElement): void;
513
+ }
514
+ /**
515
+ * Adds a tags a base mesh to the scene.
516
+ * TODO: Move this to another file with other creation/initialization functionality?
517
+ * @param src A url to a valid glb scene
518
+ * @param progressHandler A handler for load progress events.
519
+ */
520
+ export function createBaseModel(src: string, scene: Scene, progressHandler?: (event: ISceneLoaderProgressEvent) => void): Promise<void>;
521
521
 
522
522
  //# sourceMappingURL=types.d.ts.map