@spiffcommerce/preview 3.6.2-rc.7 → 3.6.2-rc.9

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.
Files changed (39) hide show
  1. package/dist/index.esm.js +1575 -38
  2. package/dist/index.umd.js +1 -0
  3. package/package.json +4 -6
  4. package/dist/_tslib.esm.js +0 -33
  5. package/dist/animation.esm.js +0 -1364
  6. package/dist/assetCache.esm.js +0 -6
  7. package/dist/blurPostProcess.esm.js +0 -327
  8. package/dist/bumpVertex.esm.js +0 -497
  9. package/dist/compatibilityOptions.esm.js +0 -68
  10. package/dist/configuration.esm.js +0 -121
  11. package/dist/core.esm.js +0 -8135
  12. package/dist/dynamicTexture.esm.js +0 -105
  13. package/dist/easing.esm.js +0 -130
  14. package/dist/effectFallbacks.esm.js +0 -378
  15. package/dist/engine.esm.js +0 -25504
  16. package/dist/glbLoaderExtensions.esm.js +0 -690
  17. package/dist/glowLayer.esm.js +0 -1621
  18. package/dist/glowLayerManager.esm.js +0 -50
  19. package/dist/guid.esm.js +0 -21
  20. package/dist/hdrFilteringFunctions.esm.js +0 -816
  21. package/dist/helperFunctions.esm.js +0 -5145
  22. package/dist/material.esm.js +0 -115
  23. package/dist/math.axis.esm.js +0 -35
  24. package/dist/math.color.esm.js +0 -1661
  25. package/dist/math.path.esm.js +0 -15
  26. package/dist/math.size.esm.js +0 -137
  27. package/dist/mesh.esm.js +0 -11170
  28. package/dist/modelContainer.esm.js +0 -1895
  29. package/dist/node.esm.js +0 -795
  30. package/dist/pbrBRDFFunctions.esm.js +0 -124
  31. package/dist/pbrMaterial.esm.js +8 -8739
  32. package/dist/productAnimations.esm.js +0 -182
  33. package/dist/productCamera.esm.js +0 -14
  34. package/dist/renderConstants.esm.js +0 -116
  35. package/dist/renderingPipeline.esm.js +0 -18
  36. package/dist/sceneLoaderFlags.esm.js +0 -51
  37. package/dist/types.esm.js +0 -30
  38. package/dist/variants.esm.js +0 -16
  39. package/dist/webRequest.esm.js +0 -7777
package/dist/index.esm.js CHANGED
@@ -1,38 +1,1575 @@
1
- export { MaterialEffectMode, ProductCameraRig } from './types.esm.js';
2
- export { SpiffCommerce3DPreviewService } from './core.esm.js';
3
- export { REFLECTION_PROBE_RESOLUTION, RenderingConfiguration, renderingPipelineDefaults } from './renderConstants.esm.js';
4
- import './_tslib.esm.js';
5
- import './productCamera.esm2.js';
6
- import './webRequest.esm.js';
7
- import './math.color.esm.js';
8
- import './node.esm.js';
9
- import './mesh.esm.js';
10
- import './engine.esm.js';
11
- import './material.esm2.js';
12
- import './compatibilityOptions.esm.js';
13
- import './sceneLoaderFlags.esm.js';
14
- import './math.axis.esm.js';
15
- import './easing.esm.js';
16
- import './math.path.esm.js';
17
- import './animation.esm.js';
18
- import './math.size.esm.js';
19
- import './helperFunctions.esm.js';
20
- import './pbrBRDFFunctions.esm.js';
21
- import './blurPostProcess.esm.js';
22
- import './glowLayer.esm.js';
23
- import './effectFallbacks.esm.js';
24
- import './assetCache.esm2.js';
25
- import './variants.esm2.js';
26
- import './hdrFilteringFunctions.esm.js';
27
- import './material.esm.js';
28
- import './renderingPipeline.esm2.js';
29
- import './bumpVertex.esm.js';
30
- import './dynamicTexture.esm2.js';
31
- import './pbrMaterial.esm.js';
32
- import './configuration.esm.js';
33
- import './glbLoaderExtensions.esm.js';
34
- import './glowLayerManager.esm.js';
35
- import './modelContainer.esm.js';
36
- import './dynamicTexture.esm.js';
37
- import './guid.esm.js';
38
- import './productAnimations.esm.js';
1
+ import { ArcRotateCamera as he } from "@babylonjs/core/Cameras/arcRotateCamera";
2
+ import { Engine as de } from "@babylonjs/core/Engines/engine";
3
+ import { NullEngine as pe } from "@babylonjs/core/Engines/nullEngine";
4
+ import { HighlightLayer as fe } from "@babylonjs/core/Layers/highlightLayer";
5
+ import { SceneLoader as ce } from "@babylonjs/core/Loading/sceneLoader";
6
+ import { CubeTexture as be } from "@babylonjs/core/Materials/Textures/cubeTexture";
7
+ import { Color4 as f, Color3 as w } from "@babylonjs/core/Maths/math.color";
8
+ import { Vector3 as g, Vector2 as J } from "@babylonjs/core/Maths/math.vector";
9
+ import { DracoCompression as ve } from "@babylonjs/core/Meshes/Compression/dracoCompression";
10
+ import { Observable as b } from "@babylonjs/core/Misc/observable";
11
+ import { Tools as we } from "@babylonjs/core/Misc/tools";
12
+ import { Scene as Ce } from "@babylonjs/core/scene";
13
+ import { GLTF2 as Pe } from "@babylonjs/loaders/glTF";
14
+ import { PBRMaterial as T } from "@babylonjs/core/Materials/PBR/pbrMaterial";
15
+ import { MirrorTexture as Me } from "@babylonjs/core/Materials/Textures/mirrorTexture";
16
+ import { Color3 as ye, Vector3 as ee, Plane as xe } from "@babylonjs/core/Maths/math";
17
+ import { ReflectionProbe as Le } from "@babylonjs/core/Probes/reflectionProbe";
18
+ import { GlowLayer as Ae } from "@babylonjs/core/Layers/glowLayer";
19
+ import { ActionManager as L } from "@babylonjs/core/Actions/actionManager";
20
+ import { ExecuteCodeAction as te } from "@babylonjs/core/Actions/directActions";
21
+ import { Mesh as Re } from "@babylonjs/core/Meshes/mesh";
22
+ import { TransformNode as Ee } from "@babylonjs/core/Meshes/transformNode";
23
+ import { DynamicTexture as Oe } from "@babylonjs/core/Materials/Textures/dynamicTexture";
24
+ import { Texture as Te } from "@babylonjs/core/Materials/Textures/texture";
25
+ import { Animation as v } from "@babylonjs/core/Animations/animation";
26
+ import { QuadraticEase as Ie, EasingFunction as Se } from "@babylonjs/core/Animations/easing";
27
+ import { AssetsManager as Fe } from "@babylonjs/core/Misc/assetsManager";
28
+ import { ColorCurves as ie } from "@babylonjs/core/Materials/colorCurves";
29
+ import { ImageProcessingConfiguration as M } from "@babylonjs/core/Materials/imageProcessingConfiguration";
30
+ import { DefaultRenderingPipeline as Be } from "@babylonjs/core/PostProcesses/RenderPipeline";
31
+ import { DepthOfFieldEffectBlurLevel as A } from "@babylonjs/core/PostProcesses/depthOfFieldEffect";
32
+ import "@babylonjs/core/Rendering/depthRendererSceneComponent";
33
+ import "@babylonjs/core/Engines/Extensions/engine.views";
34
+ import "@babylonjs/core/Meshes/instancedMesh";
35
+ import "@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader";
36
+ import "@babylonjs/core/Materials/Textures/Loaders/envTextureLoader";
37
+ import "@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader";
38
+ import "@babylonjs/core/Animations/animatable";
39
+ import "@babylonjs/core/Misc/screenshotTools";
40
+ import "@babylonjs/core/Rendering/boundingBoxRenderer";
41
+ import "@babylonjs/loaders/glTF/2.0/Extensions";
42
+ var E = /* @__PURE__ */ ((a) => (a[a.Orbit = 0] = "Orbit", a[a.Pan = 1] = "Pan", a))(E || {}), O = /* @__PURE__ */ ((a) => (a.None = "None", a.RemoveWhenSelected = "RemoveWhenSelected", a.ApplyWhenSelected = "ApplyWhenSelected", a))(O || {});
43
+ class De {
44
+ constructor(e) {
45
+ this.getSceneClearColor = () => {
46
+ var i, r, n, s;
47
+ const t = (i = this.customOptions) != null && i.transparentBackground || (r = this.customOptions) != null && r.backgroundImage ? 0 : 1;
48
+ if (this.customOptions && ((n = this.customOptions) != null && n.transparentBackground) || (s = this.customOptions) != null && s.backgroundImage)
49
+ return new f(0, 0, 0, t).toLinearSpace();
50
+ if (this.customOptions && this.customOptions.backgroundColor) {
51
+ const o = w.FromHexString(
52
+ this.customOptions.backgroundColor
53
+ );
54
+ return new f(
55
+ o.r,
56
+ o.g,
57
+ o.b,
58
+ t
59
+ ).toLinearSpace();
60
+ }
61
+ return new f(0.98, 0.98, 0.98, t).toLinearSpace();
62
+ }, this.highlightColorFromConfig = () => this.customOptions && this.customOptions.highlightColor ? this.hexToColor4(this.customOptions.highlightColor) : new f(0.98, 0.98, 0.98, 1).toLinearSpace(), this.hexToColor4 = (t, i = 1) => {
63
+ const r = w.FromHexString(t);
64
+ return new f(
65
+ r.r,
66
+ r.g,
67
+ r.b,
68
+ i
69
+ ).toLinearSpace();
70
+ }, this.customOptions = e;
71
+ }
72
+ createCanvas() {
73
+ return this.customOptions.createCanvas ? this.customOptions.createCanvas() : document.createElement("canvas");
74
+ }
75
+ get options() {
76
+ return this.customOptions;
77
+ }
78
+ /**
79
+ * Configuration related to the scene
80
+ */
81
+ get scene() {
82
+ var e, t, i;
83
+ return {
84
+ clearColor: this.getSceneClearColor(),
85
+ transparentBackground: ((e = this.customOptions) == null ? void 0 : e.transparentBackground) || ((t = this.customOptions) == null ? void 0 : t.backgroundImage),
86
+ environmentFile: ((i = this.customOptions) == null ? void 0 : i.environmentFile) ?? "assets/model-viewer/default.env"
87
+ };
88
+ }
89
+ /**
90
+ * Configuration related to the camera used to view and interact with the scene.
91
+ */
92
+ get camera() {
93
+ var e, t, i, r, n, s, o, l, d, c, u, m, p;
94
+ return {
95
+ autoOrientation: ((e = this.customOptions) == null ? void 0 : e.disableAutomaticOrientation) ?? !0,
96
+ autoRotation: {
97
+ enabled: ((t = this.customOptions) == null ? void 0 : t.autoRotation) ?? !1,
98
+ idleTimeMs: ((i = this.customOptions) == null ? void 0 : i.idleTimeBeforeRotation) ?? 5e3
99
+ },
100
+ limits: {
101
+ min: {
102
+ alpha: (r = this.customOptions) != null && r.lowerAlphaLimitDeg ? ((n = this.customOptions) == null ? void 0 : n.lowerAlphaLimitDeg) * Math.PI / 180 : void 0,
103
+ beta: (s = this.customOptions) != null && s.lowerBetaLimitDeg ? ((o = this.customOptions) == null ? void 0 : o.lowerBetaLimitDeg) * Math.PI / 180 : void 0,
104
+ radius: (l = this.customOptions) == null ? void 0 : l.minZoomOverride
105
+ },
106
+ max: {
107
+ alpha: (d = this.customOptions) != null && d.upperAlphaLimitDeg ? ((c = this.customOptions) == null ? void 0 : c.upperAlphaLimitDeg) * Math.PI / 180 : void 0,
108
+ beta: (u = this.customOptions) != null && u.upperBetaLimitDeg ? ((m = this.customOptions) == null ? void 0 : m.upperBetaLimitDeg) * Math.PI / 180 : void 0,
109
+ radius: (p = this.customOptions) == null ? void 0 : p.maxZoomOverride
110
+ }
111
+ }
112
+ };
113
+ }
114
+ /**
115
+ * Configuration related to the highlighting system. Highlights are used to add
116
+ * a visual cue to the user that something is moused over in the preview.
117
+ */
118
+ get highlights() {
119
+ var e;
120
+ return {
121
+ enabled: ((e = this.customOptions) == null ? void 0 : e.highlightOnMaterialHover) ?? !1,
122
+ color: this.highlightColorFromConfig()
123
+ };
124
+ }
125
+ get lighting() {
126
+ var e, t, i, r;
127
+ return {
128
+ exposure: ((t = (e = this.customOptions) == null ? void 0 : e.lighting) == null ? void 0 : t.exposure) ?? 0.9,
129
+ contrast: ((r = (i = this.customOptions) == null ? void 0 : i.lighting) == null ? void 0 : r.contrast) ?? 1.6
130
+ };
131
+ }
132
+ get emissiveGlowIntensity() {
133
+ var e;
134
+ return ((e = this.customOptions) == null ? void 0 : e.emissiveGlowIntensity) ?? 0.5;
135
+ }
136
+ }
137
+ class P {
138
+ /**
139
+ * Returns the resolution expected for generated textures.
140
+ */
141
+ static getDynamicTextureResolution() {
142
+ return this.getIsMobile() || !P.offscreenRenderingSupported() ? {
143
+ width: 1024,
144
+ height: 1024
145
+ } : {
146
+ width: 2048,
147
+ height: 2048
148
+ };
149
+ }
150
+ /**
151
+ * Returns true when textures should generate mip maps
152
+ */
153
+ static shouldMipMap() {
154
+ return !0;
155
+ }
156
+ /**
157
+ * Returns true when multithreaded rendering is supported.
158
+ */
159
+ static offscreenRenderingSupported() {
160
+ return navigator.userAgent.includes("SamsungBrowser") ? !1 : !!window.Worker && !!window.OffscreenCanvas;
161
+ }
162
+ /**
163
+ * Returns the resolution expected for mirror textures.
164
+ */
165
+ static getMirrorTextureResolution() {
166
+ return this.getIsMobile() ? 512 : 1024;
167
+ }
168
+ static getIsMobile() {
169
+ try {
170
+ return typeof window > "u" || !window.navigator ? !1 : /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
171
+ window.navigator.userAgent
172
+ ) || window.innerWidth <= 480;
173
+ } catch {
174
+ return !1;
175
+ }
176
+ }
177
+ }
178
+ const ze = 128, h = {
179
+ antiAliasing: {
180
+ samples: 4,
181
+ fxaaEnabled: !1
182
+ },
183
+ bloom: {
184
+ enabled: !1,
185
+ kernel: 64,
186
+ scale: 0.5,
187
+ threshold: 0.9,
188
+ weight: 0.15
189
+ },
190
+ chromaticAberration: {
191
+ enabled: !1,
192
+ aberrationAmount: 30,
193
+ direction: { x: 0, y: 0 },
194
+ radialIntensity: 0
195
+ },
196
+ colorCurves: {
197
+ enabled: !1
198
+ // Color curves values implicitly set to undefined
199
+ },
200
+ depthOfField: {
201
+ enabled: !1,
202
+ blurLevel: "Low",
203
+ focalLength: 50,
204
+ focusDistance: 2e3,
205
+ fStop: 1.4,
206
+ lensSize: 50
207
+ },
208
+ grain: {
209
+ enabled: !1,
210
+ animated: !1,
211
+ intensity: 30
212
+ },
213
+ misc: {
214
+ contrast: 1,
215
+ exposure: 1,
216
+ toneMappingEnabled: !1,
217
+ toneMappingType: "Standard"
218
+ },
219
+ sharpen: {
220
+ enabled: !1,
221
+ colorAmount: 1,
222
+ edgeAmount: 0.3
223
+ },
224
+ vignette: {
225
+ enabled: !1,
226
+ blendMode: "Multiply",
227
+ cameraFov: 0.5,
228
+ center: { x: 0, y: 0 },
229
+ colorHex: "#000000ff",
230
+ colorRgba: { r: 0, g: 0, b: 0, a: 1 },
231
+ stretch: 0,
232
+ weight: 1
233
+ }
234
+ };
235
+ class ke {
236
+ constructor(e) {
237
+ this.name = "glbPostProcessor", this.enabled = !0, this.loader = e;
238
+ }
239
+ onReady() {
240
+ this.applyReflections(this.loader.babylonScene);
241
+ }
242
+ /**
243
+ * Any custom properties set in blender on transform nodes will appear here. We can
244
+ * write the properties into the object metadata for retrieval at runtime.
245
+ */
246
+ loadNodeAsync(e, t, i) {
247
+ return this.loader.loadNodeAsync(
248
+ e,
249
+ t,
250
+ function(r) {
251
+ t.extras && Object.keys(t.extras).forEach((n) => {
252
+ const s = t.extras[n];
253
+ r.metadata[n] = s;
254
+ }), i(r);
255
+ }
256
+ );
257
+ }
258
+ /**
259
+ * Material properties can be set at load time as we don't depend
260
+ * on the entire scene graph being loaded (for reflection render lists).
261
+ * The need for these properties may go over time as the relevant exporters/importers are updated.
262
+ */
263
+ async loadMaterialPropertiesAsync(e, t, i) {
264
+ await this.loader.loadMaterialPropertiesAsync(
265
+ e,
266
+ t,
267
+ i
268
+ ), this.enableMaterialExtrasIfRequired(t, i), i.needDepthPrePass = !0;
269
+ }
270
+ dispose() {
271
+ }
272
+ /**
273
+ * With a given material descriptor and babylon material instance, looks for any
274
+ * metadata defined on the descriptor and applies to the babylon material.
275
+ * @param material A material descriptor
276
+ * @param babylonMaterial An instance of a material representation in babylon.
277
+ */
278
+ enableMaterialExtrasIfRequired(e, t) {
279
+ if (!(!e.extras || !(t instanceof T))) {
280
+ if (e.extras.sheen) {
281
+ const i = t;
282
+ i.sheen.isEnabled = !0, i.sheen.intensity = e.extras.sheen;
283
+ }
284
+ if (e.extras.translucency) {
285
+ const i = t;
286
+ i.subSurface.isTranslucencyEnabled = !0, i.subSurface.translucencyIntensity = e.extras.translucency, e.extras.translucencyR && e.extras.translucencyG && e.extras.translucencyB && (i.subSurface.tintColor = new ye(
287
+ e.extras.translucencyR,
288
+ e.extras.translucencyG,
289
+ e.extras.translucencyB
290
+ ));
291
+ }
292
+ if (e.extras.refractionIOR) {
293
+ const i = t;
294
+ i.subSurface.isRefractionEnabled = !0, i.subSurface.volumeIndexOfRefraction = e.extras.refractionIOR;
295
+ }
296
+ if (e.extras.useDepthPrePass) {
297
+ const i = t;
298
+ i.needDepthPrePass = !0, i.forceIrradianceInFragment = !0;
299
+ }
300
+ if (e.extras.useParallax) {
301
+ const i = t;
302
+ i.useParallax = !0, i.useParallaxOcclusion = !0, i.parallaxScaleBias = e.extras.useParallax;
303
+ }
304
+ }
305
+ }
306
+ /**
307
+ * Called with a loaded scene. Will finish initialization
308
+ * of any reflective properties within the scene.
309
+ * @param scene The scene to parse.
310
+ */
311
+ applyReflections(e) {
312
+ function t(n) {
313
+ const s = [];
314
+ return n.transformNodes.forEach((o) => {
315
+ o.metadata && o.metadata.reflective && s.push(...o.getChildMeshes());
316
+ }), n.meshes.forEach((o) => {
317
+ o.metadata && o.metadata.reflective && !s.includes(o) && s.push(o);
318
+ }), s;
319
+ }
320
+ function i(n, s = 1) {
321
+ const o = n.material;
322
+ if (!o)
323
+ return;
324
+ const l = new Me(
325
+ "mirror",
326
+ P.getMirrorTextureResolution(),
327
+ e,
328
+ !0
329
+ );
330
+ l.renderList = t(e);
331
+ const d = n.getVerticesData("normal");
332
+ if (!d)
333
+ throw new Error(
334
+ "Mirror attribute specified on: " + n.name + "But no normals exist to generate a mirror from!"
335
+ );
336
+ n.computeWorldMatrix(!0);
337
+ const c = n.getWorldMatrix(), u = ee.TransformNormal(
338
+ new ee(d[0], d[1], d[2]),
339
+ c
340
+ ).normalize(), m = xe.FromPositionAndNormal(
341
+ n.position,
342
+ u.scale(-1)
343
+ );
344
+ l.mirrorPlane = m, l.level = s, o.reflectionTexture = l;
345
+ }
346
+ function r(n) {
347
+ const s = n.material, o = new Le(
348
+ "probe-" + s.name,
349
+ ze,
350
+ e
351
+ );
352
+ o.attachToMesh(n), o.renderList && o.renderList.push(...t(e)), s.reflectionTexture = o.cubeTexture;
353
+ }
354
+ e.meshes.forEach((n) => {
355
+ const s = n.metadata;
356
+ s && (s.mirrorTexture && i(n, s.mirrorTexture), s.reflectionProbe && r(n));
357
+ });
358
+ }
359
+ }
360
+ class Ne {
361
+ constructor(e, t) {
362
+ this.scene = e, this.intensity = t, this.meshCount = 0;
363
+ }
364
+ includeMeshes(e) {
365
+ this.glowLayer || (this.glowLayer = new Ae("glow", this.scene), this.glowLayer.intensity = this.intensity), e.forEach((t) => {
366
+ this.glowLayer.hasMesh(t) || (this.glowLayer.addIncludedOnlyMesh(t), this.meshCount++);
367
+ });
368
+ }
369
+ removeMeshes(e) {
370
+ this.glowLayer && (e.forEach((t) => {
371
+ this.glowLayer.hasMesh(t) && (this.glowLayer.removeIncludedOnlyMesh(t), this.meshCount--);
372
+ }), this.meshCount === 0 && (this.glowLayer.dispose(), this.glowLayer = void 0));
373
+ }
374
+ }
375
+ const se = /* @__PURE__ */ new Map();
376
+ async function ue(a, e, t) {
377
+ return new Promise((i, r) => {
378
+ const n = se.get(a);
379
+ if (n && n.scene.uid === e.uid)
380
+ return i(n);
381
+ ce.LoadAssetContainerAsync(
382
+ a,
383
+ void 0,
384
+ e,
385
+ t
386
+ ).then((s) => {
387
+ se.set(a, s), i(s);
388
+ }).catch(r);
389
+ });
390
+ }
391
+ function Ve(a, e, t, i, r = "") {
392
+ t.forEach((n) => {
393
+ const s = n.getID(), o = n.getName(), l = P.getDynamicTextureResolution();
394
+ a.filter((c) => c.name === r + o).forEach((c) => {
395
+ const u = i.get(s), m = !1;
396
+ if (u)
397
+ ne(c, u), u.update(m);
398
+ else {
399
+ const p = Ge(
400
+ o,
401
+ e,
402
+ l.width,
403
+ l.height
404
+ );
405
+ i.set(s, p), n.setStaticContext(
406
+ p.getContext()
407
+ ), ne(c, p), p.onLoadObservable.addOnce(() => {
408
+ p.update(m);
409
+ });
410
+ }
411
+ });
412
+ });
413
+ }
414
+ function Ge(a, e, t, i) {
415
+ const r = new Oe(
416
+ a,
417
+ { width: t, height: i },
418
+ e,
419
+ P.shouldMipMap(),
420
+ Te.TRILINEAR_SAMPLINGMODE,
421
+ de.TEXTUREFORMAT_RGBA
422
+ ), n = r.getContext();
423
+ return n && (n.fillStyle = "#f5f5f5", n.fillRect(0, 0, t, i), r.update()), r;
424
+ }
425
+ function ne(a, e) {
426
+ if (a instanceof T) {
427
+ const t = a, i = t.albedoTexture;
428
+ i ? (e.wrapU = i.wrapU, e.wrapV = i.wrapV) : (e.wrapU = 1, e.wrapV = 1), t.albedoTexture = e;
429
+ } else {
430
+ const t = a, i = t.diffuseTexture;
431
+ i && (e.wrapU = i.wrapU, e.wrapV = i.wrapV), t.diffuseTexture = e;
432
+ }
433
+ }
434
+ function He() {
435
+ const a = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
436
+ return a() + a() + "-" + a() + "-" + a() + "-" + a() + "-" + a() + a() + a();
437
+ }
438
+ const C = 60, re = 1;
439
+ function ae(a) {
440
+ return a.targetedAnimations.map((t) => t.animation.framePerSecond).reduce((t, i) => t + i, 0) / a.targetedAnimations.length || 0;
441
+ }
442
+ function _e(a, e, t, i, r) {
443
+ const n = r ? a.filter((s) => s.name === r) : a;
444
+ if (n.length === 0) {
445
+ console.warn(`No animations found for name: ${r}`);
446
+ return;
447
+ }
448
+ if (i !== void 0 && t !== void 0 && i === t) {
449
+ n.forEach((s) => {
450
+ s.stop();
451
+ const o = ae(s), l = i * o;
452
+ s.start(e, re, l, l);
453
+ });
454
+ return;
455
+ }
456
+ n.forEach((s) => {
457
+ s.stop();
458
+ const o = ae(s), l = i !== void 0 ? i * o : void 0, d = t !== void 0 ? t * o : void 0;
459
+ s.start(e, re, l, d);
460
+ });
461
+ }
462
+ function ge(a) {
463
+ a.forEach((e) => {
464
+ e.stop();
465
+ });
466
+ }
467
+ function qe(a) {
468
+ const e = a.animationGroups;
469
+ ge(e);
470
+ }
471
+ function Ke(a, e, t) {
472
+ a.stopAnimation(e), e.animations = [], Math.abs(e.alpha) > 2 * Math.PI && (e.alpha = Ue(e.alpha, 0, 2 * Math.PI));
473
+ const i = [], r = t.target, n = 0, s = r ? 1 : 0;
474
+ if (t.target && Object.keys(t.target).length > 0 && i.push(
475
+ y(
476
+ "cameraTargetLerp",
477
+ "target",
478
+ new g().copyFrom(e.target),
479
+ new g(
480
+ t.target.x,
481
+ t.target.y,
482
+ t.target.z
483
+ ),
484
+ v.ANIMATIONTYPE_VECTOR3,
485
+ n
486
+ )
487
+ ), i.push(
488
+ y(
489
+ "cameraAlphaLerp",
490
+ "alpha",
491
+ e.alpha,
492
+ oe(t.lonDeg),
493
+ v.ANIMATIONTYPE_FLOAT,
494
+ s
495
+ )
496
+ ), i.push(
497
+ y(
498
+ "cameraBetaLerp",
499
+ "beta",
500
+ e.beta,
501
+ oe(t.latDeg),
502
+ v.ANIMATIONTYPE_FLOAT,
503
+ s
504
+ )
505
+ ), t.radius !== void 0) {
506
+ const d = Math.max(0.01, t.radius);
507
+ i.push(
508
+ y(
509
+ "cameraRadiusLerp",
510
+ "radius",
511
+ e.radius,
512
+ d,
513
+ v.ANIMATIONTYPE_FLOAT,
514
+ s
515
+ )
516
+ );
517
+ }
518
+ e.animations.push(...i);
519
+ const l = e.useAutoRotationBehavior;
520
+ e.disableAutoRotationBehavior(), a.beginAnimation(
521
+ e,
522
+ 0,
523
+ r ? C * 2 : C,
524
+ !1,
525
+ 1,
526
+ () => {
527
+ e.animations = [], l && e.enableAutoRotationBehavior();
528
+ }
529
+ );
530
+ }
531
+ function oe(a) {
532
+ return a * Math.PI / 180;
533
+ }
534
+ function y(a, e, t, i, r, n = 0, s = v.ANIMATIONLOOPMODE_CONSTANT) {
535
+ const o = new Ie();
536
+ o.setEasingMode(Se.EASINGMODE_EASEINOUT);
537
+ const l = new v(
538
+ a,
539
+ e,
540
+ C,
541
+ r,
542
+ s
543
+ ), d = [];
544
+ return n > 0 && d.push({ frame: 0, value: t }), d.push({ frame: C * n, value: t }), d.push({
545
+ frame: C * (n + 1),
546
+ value: i
547
+ }), l.setKeys(d), l.setEasingFunction(o), l;
548
+ }
549
+ function Ue(a, e, t) {
550
+ return a < e ? a = t - (e - a) % (t - e) : a = e + (a - e) % (t - e);
551
+ }
552
+ const We = {
553
+ albedoTexture: "albedoMap",
554
+ bumpTexture: "normalMap",
555
+ ambientTexture: "ambientMap",
556
+ emissiveTexture: "emissionMap",
557
+ opacityTexture: "alphaMap",
558
+ metallicTexture: "metallicMap",
559
+ refractionTexture: "refractionMap"
560
+ };
561
+ function Ze(a, e, t, i) {
562
+ [
563
+ "albedoTexture",
564
+ "bumpTexture",
565
+ "ambientTexture",
566
+ "emissiveTexture",
567
+ "opacityTexture",
568
+ "metallicTexture",
569
+ "refractionTexture"
570
+ ].forEach((n) => {
571
+ $e(
572
+ n,
573
+ a,
574
+ e,
575
+ t,
576
+ i
577
+ );
578
+ }), je(a, e);
579
+ }
580
+ function $e(a, e, t, i, r) {
581
+ const n = We[a];
582
+ if (!n)
583
+ throw new Error("Unexpected texture name encountered.");
584
+ const s = e[n], o = s == null ? void 0 : s.fileLink;
585
+ o ? i.addTextureTask(a, o, !1, !1) : r && t[a] && (t[a] && t[a].dispose(), t[a] = null, Ye(a, t));
586
+ }
587
+ function Ye(a, e) {
588
+ a === "opacityTexture" && (e.useAlphaFromAlbedoTexture = !0), a === "metallicTexture" && (e.useRoughnessFromMetallicTextureAlpha = !1, e.useRoughnessFromMetallicTextureGreen = !1, e.useMetallnessFromMetallicTextureBlue = !1), a === "refractionTexture" && (e.subSurface.isRefractionEnabled = !1, e.subSurface.refractionIntensity = 1), a === "emissiveTexture" && (e.emissiveIntensity = 0, e.emissiveColor = new w(0, 0, 0));
589
+ }
590
+ function Qe(a, e, t, i) {
591
+ a === "opacityTexture" && (e.useAlphaFromAlbedoTexture = !1), a === "metallicTexture" && (e.useRoughnessFromMetallicTextureAlpha = !1, e.useRoughnessFromMetallicTextureGreen = !0, e.useMetallnessFromMetallicTextureBlue = !0), a === "refractionTexture" && (e.subSurface.isRefractionEnabled = !0, e.subSurface.refractionIntensity = t.refractionIntensity || 1), e[a] = i, a === "emissiveTexture" && (e.emissiveColor = new w(1, 1, 1), e.emissiveIntensity = 1);
592
+ }
593
+ function je(a, e) {
594
+ a.clearCoat && (a.clearCoat === O.RemoveWhenSelected ? (e.clearCoat.isEnabled = !1, e.clearCoat.indexOfRefraction = 1.5) : a.clearCoat === O.ApplyWhenSelected && (e.clearCoat.isEnabled = !0, e.clearCoat.indexOfRefraction = a.clearCoatIOR || e.clearCoat.indexOfRefraction));
595
+ }
596
+ class Xe {
597
+ constructor(e, t, i) {
598
+ this.materialVariantMap = /* @__PURE__ */ new Map(), this.keysThatRemovedBaseModel = [], this.loadedContainerForKey = /* @__PURE__ */ new Map(), this.loadedMaterialsForKey = /* @__PURE__ */ new Map(), this.scene = e, this.renameClonedAsset = t, this.setBaseModelEnabled = i;
599
+ }
600
+ /**
601
+ * Apply a material variant to a given scene.
602
+ * @param targetMaterial The name of the material in the scene we should be targeting.
603
+ * @param material The material variant to apply.
604
+ * @param onProgress A progress callback function for loading bars and event timing.
605
+ * @param removeWhenUndefined material application is an additive process, setting this bool to true will
606
+ * instead remove material textures when they aren't defined. this is useful for material editor applications
607
+ * where we want to undo changes are remove effects from display.
608
+ */
609
+ async applyMaterial(e, t, i, r) {
610
+ return new Promise((n) => {
611
+ const s = this.materialVariantMap.get(e);
612
+ this.materialVariantMap.set(e, {
613
+ ...s,
614
+ ...t
615
+ });
616
+ const o = this.renameClonedAsset(e), l = this.scene.materials.filter(
617
+ (c) => c.name === o
618
+ );
619
+ if (l.length === 0) {
620
+ n();
621
+ return;
622
+ }
623
+ const d = new Fe(this.scene);
624
+ d.useDefaultLoadingScreen = !1, l.forEach(
625
+ (c) => Ze(
626
+ t,
627
+ c,
628
+ d,
629
+ r
630
+ )
631
+ ), d.onProgress = (c, u, m) => {
632
+ i && i(c / u * 100, 100, m.name);
633
+ }, d.onFinish = (c) => {
634
+ c.forEach((u) => {
635
+ const m = u;
636
+ i && i(100, 100, u.name), l.forEach(
637
+ (p) => Qe(
638
+ u.name,
639
+ p,
640
+ t,
641
+ m.texture
642
+ )
643
+ );
644
+ }), n();
645
+ }, d.loadAsync();
646
+ });
647
+ }
648
+ /**
649
+ * Applies a model variant.
650
+ * @param key The key to uniquely identify this model variant application.
651
+ * @param replaceProductModel When true, we should replace the base product model.
652
+ * @param model The details for the new model, when undefined we should remove the variant associated to the given key.
653
+ * @param onProgress A load progress callback that can be used for loading bars and event timing.
654
+ */
655
+ async applyModel(e, t, i, r) {
656
+ var l, d;
657
+ if (i && t && !this.keysThatRemovedBaseModel.includes(e) && this.keysThatRemovedBaseModel.push(e), !i)
658
+ return this.keysThatRemovedBaseModel.includes(e) && this.setBaseModelEnabled(!0), (l = this.loadedContainerForKey.get(e)) == null || l.dispose(), this.loadedContainerForKey.delete(e), this.loadedMaterialsForKey.delete(e), Promise.resolve(void 0);
659
+ this.loadedContainerForKey.has(e) && ((d = this.loadedContainerForKey.get(e)) == null || d.dispose(), this.loadedContainerForKey.delete(e), this.loadedMaterialsForKey.delete(e)), t && this.setBaseModelEnabled(!1);
660
+ const s = (await ue(i, this.scene, r)).instantiateModelsToScene(
661
+ this.renameClonedAsset,
662
+ !0
663
+ );
664
+ this.loadedContainerForKey.set(e, s), this.loadedMaterialsForKey.set(e, me(s));
665
+ const o = [];
666
+ return this.materialVariantMap.forEach(async (c, u) => {
667
+ o.push(this.applyMaterial(u, c));
668
+ }), await Promise.all(o), s;
669
+ }
670
+ dispose() {
671
+ this.loadedContainerForKey.forEach((e) => e == null ? void 0 : e.dispose()), this.loadedContainerForKey.clear(), this.loadedMaterialsForKey.forEach(
672
+ (e) => e.forEach((t) => t == null ? void 0 : t.dispose())
673
+ ), this.loadedMaterialsForKey.clear(), this.materialVariantMap.clear(), this.keysThatRemovedBaseModel = [];
674
+ }
675
+ getAllMaterials() {
676
+ const e = [];
677
+ return this.loadedMaterialsForKey.forEach((t) => {
678
+ t.forEach((i) => {
679
+ e.includes(i) || e.push(i);
680
+ });
681
+ }), e;
682
+ }
683
+ getAnimationGroups() {
684
+ const e = [];
685
+ return this.loadedContainerForKey.forEach((t) => {
686
+ e.push(...t.animationGroups);
687
+ }), e;
688
+ }
689
+ }
690
+ function me(a) {
691
+ const e = [];
692
+ return a.rootNodes.forEach((t) => {
693
+ t.getChildMeshes().forEach((i) => {
694
+ i.material && !e.includes(i.material) && e.push(i.material), i.subMeshes && i.subMeshes.forEach((r) => {
695
+ const n = r.getMaterial(!1);
696
+ n && !e.includes(n) && e.push(n);
697
+ });
698
+ });
699
+ }), e;
700
+ }
701
+ function le(a, e = "") {
702
+ return a.map((t) => ({
703
+ name: t.name.substring(e.length),
704
+ loop: t.loopAnimation,
705
+ to: t.to,
706
+ from: t.from
707
+ }));
708
+ }
709
+ class Je {
710
+ constructor(e) {
711
+ this.metadata = /* @__PURE__ */ new Map(), this.materialSelectedObservable = new b(), this.materialDeselectedObservable = new b(), this.materialVariantObservable = new b(), this.modelVariantObservable = new b(), this.materialReadyToLoadCallbacks = /* @__PURE__ */ new Map(), this.modelReadyToLoadCallbacks = /* @__PURE__ */ new Map(), this.dynamicTextures = /* @__PURE__ */ new Map(), this.queuedMaterialChanges = /* @__PURE__ */ new Map(), this.materialChangesInProgress = [], this.queuedModelChanges = /* @__PURE__ */ new Map(), this.modelChangesInProgress = [], this.animations = [], this.initialized = !1, this.materials = [];
712
+ const {
713
+ enablePicking: t,
714
+ modelDetails: i,
715
+ previewService: r,
716
+ progressHandler: n,
717
+ scene: s
718
+ } = e;
719
+ this.enablePicking = t, this.contextService = i.contextService, this.id = He(), this.previewService = r, this.scene = s, this.variantManager = new Xe(
720
+ s,
721
+ this.renameClonedAsset.bind(this),
722
+ this.setEnabled.bind(this)
723
+ ), this.previewService.registerInitializedListener(
724
+ async () => await this.processQueuedEvents()
725
+ ), this.transformRoot = new Ee("root", this.scene);
726
+ const o = async () => (this.assetContainer = await ue(
727
+ i.model,
728
+ s,
729
+ n
730
+ ), this.initialized = !0, this.instantiate(), this);
731
+ this.importPromise = o();
732
+ }
733
+ //#region Interface implementation
734
+ async applyMaterialVariant(e, t, i, r) {
735
+ if (this.previewService.getSceneInitializationProgress() !== 100 || !this.initialized) {
736
+ if (this.materialReadyToLoadCallbacks.has(e)) {
737
+ const s = this.materialReadyToLoadCallbacks.get(e);
738
+ s == null || s.set(
739
+ t,
740
+ this.applyMaterialVariant.bind(
741
+ this,
742
+ e,
743
+ t,
744
+ i,
745
+ r
746
+ )
747
+ );
748
+ } else {
749
+ this.materialReadyToLoadCallbacks.set(
750
+ e,
751
+ /* @__PURE__ */ new Map()
752
+ );
753
+ const s = this.materialReadyToLoadCallbacks.get(e);
754
+ s == null || s.set(
755
+ t,
756
+ this.applyMaterialVariant.bind(
757
+ this,
758
+ e,
759
+ t,
760
+ i,
761
+ r
762
+ )
763
+ );
764
+ }
765
+ return;
766
+ }
767
+ const n = async () => {
768
+ await this.variantManager.applyMaterial(
769
+ e,
770
+ i,
771
+ (s, o, l) => {
772
+ this.materialVariantObservable.notifyObservers({
773
+ remainingCount: s,
774
+ totalCount: o,
775
+ taskName: l
776
+ });
777
+ },
778
+ r
779
+ );
780
+ };
781
+ if (this.materialChangesInProgress.includes(e)) {
782
+ if (this.queuedMaterialChanges.has(e)) {
783
+ const s = this.queuedMaterialChanges.get(e);
784
+ s == null || s.set(t, n);
785
+ } else {
786
+ this.queuedMaterialChanges.set(
787
+ e,
788
+ /* @__PURE__ */ new Map()
789
+ );
790
+ const s = this.queuedMaterialChanges.get(e);
791
+ s == null || s.set(t, n);
792
+ }
793
+ return;
794
+ }
795
+ this.materialChangesInProgress.push(e), await n(), this.queuedMaterialChanges.has(e) && (this.queuedMaterialChanges.get(e).forEach(async (o) => {
796
+ await o();
797
+ }), this.queuedMaterialChanges.delete(e)), this.materialChangesInProgress.splice(
798
+ this.materialChangesInProgress.indexOf(e),
799
+ 1
800
+ ), this.configureGlowLayer();
801
+ }
802
+ async applyModelVariant(e, t, i) {
803
+ if (!this.previewService.getIsInitialized() || !this.initialized) {
804
+ this.modelReadyToLoadCallbacks.set(
805
+ e,
806
+ this.applyModelVariant.bind(
807
+ this,
808
+ e,
809
+ t,
810
+ i
811
+ )
812
+ );
813
+ return;
814
+ }
815
+ const r = () => this.variantManager.applyModel(
816
+ e,
817
+ i,
818
+ t == null ? void 0 : t.model,
819
+ (o) => {
820
+ this.modelVariantObservable.notifyObservers({
821
+ ...o,
822
+ key: e
823
+ });
824
+ }
825
+ );
826
+ if (this.modelChangesInProgress.includes(e)) {
827
+ this.queuedModelChanges.set(e, r);
828
+ return;
829
+ }
830
+ const s = await (async () => {
831
+ this.modelChangesInProgress.push(e);
832
+ let o = await r();
833
+ return this.queuedModelChanges.has(e) && (o = await this.queuedModelChanges.get(e)(), this.queuedModelChanges.delete(e)), this.modelChangesInProgress.splice(
834
+ this.modelChangesInProgress.indexOf(e),
835
+ 1
836
+ ), o;
837
+ })();
838
+ this.modelInstance && ge(this.modelInstance.animationGroups), this.contextService || (this.contextService = t == null ? void 0 : t.contextService), s ? this.configureModelInstance(s) : this.configureGlowLayer();
839
+ }
840
+ dispose() {
841
+ var e;
842
+ this.destroyInstance(), this.variantManager.dispose(), this.dynamicTextures.forEach((t) => t == null ? void 0 : t.dispose()), this.dynamicTextures.clear(), this.materials.forEach((t) => t && (t == null ? void 0 : t.dispose())), this.materials = [], (e = this.transformRoot) == null || e.dispose(), this.transformRoot = void 0, this.previewService.modelUnloaded(this);
843
+ }
844
+ executeAnimation(e) {
845
+ if (!this.previewService.getIsInitialized()) {
846
+ this.queuedModelAnimation = e;
847
+ return;
848
+ }
849
+ this.modelInstance && _e(
850
+ [
851
+ ...this.modelInstance.animationGroups,
852
+ ...this.variantManager.getAnimationGroups()
853
+ ],
854
+ e.loop,
855
+ e.to,
856
+ e.from,
857
+ e.name ? this.renameClonedAsset(e.name) : void 0
858
+ );
859
+ }
860
+ getAnimations(e) {
861
+ return [
862
+ ...this.animations,
863
+ ...e ? le(
864
+ this.variantManager.getAnimationGroups(),
865
+ this.renameClonedAsset("")
866
+ ) : []
867
+ ];
868
+ }
869
+ getId() {
870
+ return this.id;
871
+ }
872
+ listMaterials() {
873
+ var t;
874
+ const e = (t = this.scene) == null ? void 0 : t.materials.filter(
875
+ (i) => i.name.startsWith(this.id)
876
+ );
877
+ return e ? e.map((i) => ({
878
+ id: i.id,
879
+ name: this.stripIdFromName(i.name)
880
+ })) : [];
881
+ }
882
+ registerMaterialSelectedCallback(e) {
883
+ this.materialSelectedObservable.add(e);
884
+ }
885
+ unregisterMaterialSelectedCallback(e) {
886
+ this.materialSelectedObservable.removeCallback(e);
887
+ }
888
+ registerMaterialDeselectedCallback(e) {
889
+ this.materialDeselectedObservable.add(e);
890
+ }
891
+ unregisterMaterialDeselectedCallback(e) {
892
+ this.materialDeselectedObservable.removeCallback(e);
893
+ }
894
+ get position() {
895
+ return this.transformRoot.position;
896
+ }
897
+ set position(e) {
898
+ this.transformRoot.position = new g(e.x, e.y, e.z);
899
+ }
900
+ get rotation() {
901
+ return this.transformRoot.rotation;
902
+ }
903
+ set rotation(e) {
904
+ this.transformRoot.rotation = new g(e.x, e.y, e.z);
905
+ }
906
+ get scale() {
907
+ return this.transformRoot.scaling;
908
+ }
909
+ set scale(e) {
910
+ this.transformRoot.scaling = new g(e.x, e.y, e.z);
911
+ }
912
+ //#endregion
913
+ //#region Custom implementation functions
914
+ attachPickingHandler(e) {
915
+ e.rootNodes.forEach((t) => {
916
+ t.getChildMeshes(!1).forEach((i) => {
917
+ i.name === "targetcube_t" || i.name === "backgroundShell" || (i.actionManager || (i.actionManager = new L(this.scene)), i.actionManager.registerAction(
918
+ new te(L.OnPointerOverTrigger, (r) => {
919
+ r.meshUnderPointer && i.material && this.materialSelectedObservable.notifyObservers({
920
+ id: i.material.id,
921
+ name: this.stripIdFromName(i.material.name)
922
+ });
923
+ })
924
+ ), i.actionManager.registerAction(
925
+ new te(L.OnPointerOutTrigger, () => {
926
+ i.material && this.materialDeselectedObservable.notifyObservers({
927
+ id: i.material.id,
928
+ name: this.stripIdFromName(i.material.name)
929
+ });
930
+ })
931
+ ));
932
+ });
933
+ });
934
+ }
935
+ /**
936
+ * Returns a promise which resolves when the model has been initialized.
937
+ */
938
+ getInitializationPromise() {
939
+ return this.importPromise;
940
+ }
941
+ /**
942
+ * Returns true if the model has been initialized.
943
+ */
944
+ getIsInitialized() {
945
+ return this.initialized;
946
+ }
947
+ getQueuedMaterialVariantCount() {
948
+ return this.materialReadyToLoadCallbacks.size;
949
+ }
950
+ getQueuedModelVariantCount() {
951
+ return this.modelReadyToLoadCallbacks.size;
952
+ }
953
+ configureGlowLayer() {
954
+ const e = (i) => i instanceof T && i.emissiveTexture !== null;
955
+ this.materials.some(e) || this.variantManager.getAllMaterials().some(e) ? this.previewService.getGlowLayerManager().includeMeshes(this.getAllMeshes()) : this.previewService.getGlowLayerManager().removeMeshes(this.getAllMeshes());
956
+ }
957
+ configureModelInstance(e) {
958
+ var n;
959
+ const t = this.transformRoot.position, i = this.transformRoot.rotation, r = this.transformRoot.scaling;
960
+ this.transformRoot.position = g.Zero(), this.transformRoot.rotation = g.Zero(), this.transformRoot.scaling = g.One(), e.rootNodes.forEach((s) => {
961
+ s.parent = this.transformRoot;
962
+ }), this.transformRoot.position = t, this.transformRoot.rotation = i, this.transformRoot.scaling = r, this.canvasPanels = ((n = this.contextService) == null ? void 0 : n.getAll()) || /* @__PURE__ */ new Map(), Ve(
963
+ this.materials.concat(this.variantManager.getAllMaterials()),
964
+ this.scene,
965
+ this.canvasPanels,
966
+ this.dynamicTextures,
967
+ `${this.id}_`
968
+ ), this.enablePicking && this.attachPickingHandler(e), this.configureGlowLayer();
969
+ }
970
+ /**
971
+ * Destroys the model instance.
972
+ */
973
+ destroyInstance() {
974
+ var e;
975
+ (e = this.modelInstance) == null || e.dispose(), this.modelInstance = void 0;
976
+ }
977
+ getAllMeshes() {
978
+ var e;
979
+ return (e = this.modelInstance) == null ? void 0 : e.rootNodes.map(
980
+ (t) => t.getChildMeshes(!1).filter((i) => i instanceof Re)
981
+ ).flat();
982
+ }
983
+ instantiate() {
984
+ this.modelInstance = this.assetContainer.instantiateModelsToScene(
985
+ this.renameClonedAsset.bind(this),
986
+ !0
987
+ ), this.materials = me(this.modelInstance), this.configureModelInstance(this.modelInstance), this.animations = le(
988
+ this.modelInstance.animationGroups,
989
+ this.renameClonedAsset("")
990
+ ), this.processQueuedEvents();
991
+ }
992
+ renameClonedAsset(e) {
993
+ return `${this.id}_${e}`;
994
+ }
995
+ setEnabled(e) {
996
+ e && !this.modelInstance ? this.instantiate() : !e && this.modelInstance && this.destroyInstance();
997
+ }
998
+ updateDynamicTextures() {
999
+ var e;
1000
+ (e = this.canvasPanels) == null || e.forEach(
1001
+ (t, i) => {
1002
+ const r = this.dynamicTextures.get(i);
1003
+ r && t.getStaticContextDirty() && r.isReady() && (r.update(!1), t.setStaticContextDirty(!1));
1004
+ }
1005
+ );
1006
+ }
1007
+ //#region Listeners
1008
+ registerMaterialVariantListener(e) {
1009
+ this.materialVariantObservable.add(e);
1010
+ }
1011
+ unregisterMaterialVariantListener(e) {
1012
+ this.materialVariantObservable.removeCallback(e);
1013
+ }
1014
+ registerModelVariantListener(e) {
1015
+ this.modelVariantObservable.add(e);
1016
+ }
1017
+ unregisterModelVariantListener(e) {
1018
+ this.modelVariantObservable.removeCallback(e);
1019
+ }
1020
+ //#endregion
1021
+ stripIdFromName(e) {
1022
+ return e.substring(this.id.length + 1);
1023
+ }
1024
+ async processQueuedEvents() {
1025
+ this.previewService.getIsInitialized() && (await Promise.all(
1026
+ Array.from(this.materialReadyToLoadCallbacks.values()).map(
1027
+ (e) => Array.from(e.values()).map((t) => t())
1028
+ )
1029
+ ), this.materialReadyToLoadCallbacks.clear(), await Promise.all(
1030
+ Array.from(this.modelReadyToLoadCallbacks.values()).map(
1031
+ (e) => e()
1032
+ )
1033
+ ), this.modelReadyToLoadCallbacks.clear(), this.queuedModelAnimation && (this.executeAnimation(this.queuedModelAnimation), this.queuedModelAnimation = void 0));
1034
+ }
1035
+ //#endregion
1036
+ }
1037
+ class I extends he {
1038
+ constructor(e, t, i, r, n, s, o, l) {
1039
+ super(
1040
+ e,
1041
+ t,
1042
+ i,
1043
+ r,
1044
+ n,
1045
+ s,
1046
+ l
1047
+ ), this.lastFocus = new g(0, 0, 0), this.panDenominator = 1, this.minZ = 0.01, this.setRadius(this.radius), this.enableFramingBehavior(), this.wheelDeltaPercentage = 0.01, this.pinchDeltaPercentage = 5e-3, this.useNaturalPinchZoom = !0, o.camera.autoOrientation && (this.alpha += Math.PI), o && (o.camera.limits.min.beta && (this.lowerBetaLimit = o.camera.limits.min.beta), o.camera.limits.max.beta && (this.upperBetaLimit = o.camera.limits.max.beta), o.camera.limits.min.alpha && (this.lowerAlphaLimit = o.camera.limits.min.alpha), o.camera.limits.max.alpha && (this.upperAlphaLimit = o.camera.limits.max.alpha), o.camera.limits.min.radius && (this.lowerRadiusLimit = o.camera.limits.min.radius), o.camera.limits.max.radius && (this.upperRadiusLimit = o.camera.limits.max.radius), o.camera.autoRotation.enabled && this.enableAutoRotationBehavior(
1048
+ o.camera.autoRotation.idleTimeMs
1049
+ ));
1050
+ }
1051
+ /**
1052
+ * Returns the framing behavior of this camera.
1053
+ */
1054
+ getFramingBehavior() {
1055
+ return this.getBehaviorByName("Framing");
1056
+ }
1057
+ /**
1058
+ * Returns the auto rotation behavior of this camera, this may
1059
+ * not always be available.
1060
+ */
1061
+ getAutoRotationBehavior() {
1062
+ const e = this.getBehaviorByName("AutoRotation");
1063
+ if (e)
1064
+ return e;
1065
+ }
1066
+ /**
1067
+ * Activates framing on this camera causing the camera to focus on
1068
+ * the scene and bound itself in a sensible fashion to the scene content.
1069
+ */
1070
+ enableFramingBehavior() {
1071
+ this.useFramingBehavior = !0;
1072
+ const e = this.getFramingBehavior();
1073
+ e.attach(this), e.framingTime = 0, e.elevationReturnTime = -1, e.zoomStopsAnimation = !1, this.lowerRadiusLimit = null;
1074
+ const t = R(this._scene);
1075
+ return e.zoomOnBoundingInfo(t.min, t.max), this.wheelPrecision = 100 / this.radius, this.lowerRadiusLimit === null && (this.lowerRadiusLimit = 0.1), this.lastFocus.copyFrom(this.target), e;
1076
+ }
1077
+ /**
1078
+ * Animates the camera back to the initial target when it has drifted to another position.
1079
+ * @param onAnimationComplete A callback when the camera has finished animating.
1080
+ * @param time The time in milliseconds the animation should take.
1081
+ */
1082
+ rerunFramingBehavior(e, t) {
1083
+ const i = this.getFramingBehavior();
1084
+ i.framingTime = t || 800;
1085
+ const r = () => {
1086
+ e && e();
1087
+ }, n = R(this._scene), s = n.max.subtract(n.min), o = n.min.add(s.scale(0.5));
1088
+ this.setRadius(s.length() * 1.5), this.wheelPrecision = 100 / this.radius, this.panningInertia = 0, this.panningOriginTarget.copyFrom(o), this.panDenominator = s.length(), i.zoomOnBoundingInfo(
1089
+ n.min,
1090
+ n.max,
1091
+ void 0,
1092
+ r
1093
+ ), i.framingTime = 0;
1094
+ }
1095
+ /**
1096
+ * Activates the auto rotation behavior causing the camera to rotate slowly around
1097
+ * it's target.
1098
+ * @param idleTime The number of milliseconds before the camera starts rotating after the user last interacted.
1099
+ */
1100
+ enableAutoRotationBehavior(e = 5e3) {
1101
+ this.useAutoRotationBehavior = !0;
1102
+ const t = this.getAutoRotationBehavior();
1103
+ t && (t.idleRotationWaitTime = e);
1104
+ }
1105
+ /**
1106
+ * Stops the auto rotation functionality immediately.
1107
+ */
1108
+ disableAutoRotationBehavior() {
1109
+ this.useAutoRotationBehavior = !1;
1110
+ }
1111
+ setRadius(e) {
1112
+ this.radius = e, this.maxZ = this.radius * 1e3, this.lowerRadiusLimit = this.radius * 0.01, this.upperRadiusLimit = 1.5 * this.radius, this.wheelPrecision = 100 / this.radius, this.pinchPrecision = 300 / this.radius;
1113
+ }
1114
+ /**
1115
+ * A static function used to instantiate a single product camera instance on a scene. This camera will assume
1116
+ * the active camera role on the scene and any existing active camera will be disposed.
1117
+ * @param scene The scene to attach the camera to.
1118
+ * @param configuration A configuration object to define the cameras limitations.
1119
+ * @param assignActive If true the camera will be assigned as the active camera on the scene.
1120
+ */
1121
+ static create(e, t, i) {
1122
+ const r = R(e), n = r.max.subtract(r.min), s = r.min.add(n.scale(0.5)), o = new I(
1123
+ "ProductCamera",
1124
+ -(Math.PI / 2),
1125
+ Math.PI / 2,
1126
+ n.length() * 1.5,
1127
+ s,
1128
+ e,
1129
+ t
1130
+ );
1131
+ return o.panningInertia = 0, o.panningOriginTarget.copyFrom(s), o.panDenominator = n.length(), o.onAfterCheckInputsObservable.add(() => {
1132
+ o.panningSensibility = 1e3 / o.panDenominator;
1133
+ }), i && (e.activeCamera = o), o;
1134
+ }
1135
+ }
1136
+ function R(a) {
1137
+ if (a.meshes.length === 0)
1138
+ return {
1139
+ min: new g(-1, -1, -1),
1140
+ max: new g(1, 1, 1)
1141
+ };
1142
+ const e = a.meshes.filter((t) => t.name.toLowerCase().endsWith("_t") || t.name.toLowerCase().includes("_t_"));
1143
+ return a.getWorldExtends((t) => t.isVisible && t.isEnabled() && (e.length === 0 || e.includes(t)));
1144
+ }
1145
+ class et {
1146
+ constructor(e, t = !1, i = void 0) {
1147
+ this.renderingPipeline = new Be(
1148
+ "default",
1149
+ t,
1150
+ e,
1151
+ i ? [i] : void 0,
1152
+ !1
1153
+ // Disable automatic build
1154
+ ), this.renderingPipeline.isSupported && (this.renderingPipeline.prepare(), this.setConfiguration(h));
1155
+ }
1156
+ dispose() {
1157
+ this.renderingPipeline.dispose();
1158
+ }
1159
+ getConfiguration() {
1160
+ return this.currentConfiguration;
1161
+ }
1162
+ setConfiguration(e) {
1163
+ var t, i, r, n, s, o, l, d, c, u, m, p, S, F, B, D, z, k, N, V, G, H, _, q, K, U, W, Z, $, Y, Q, j, X;
1164
+ if (this.renderingPipeline.isSupported) {
1165
+ if (this.renderingPipeline.samples = ((t = e.antiAliasing) == null ? void 0 : t.samples) ?? h.antiAliasing.samples, this.renderingPipeline.fxaaEnabled = ((i = e.antiAliasing) == null ? void 0 : i.fxaaEnabled) ?? h.antiAliasing.fxaaEnabled, this.renderingPipeline.bloomEnabled = ((r = e.bloom) == null ? void 0 : r.enabled) ?? h.bloom.enabled, this.renderingPipeline.bloomKernel = ((n = e.bloom) == null ? void 0 : n.kernel) ?? h.bloom.kernel, this.renderingPipeline.bloomScale = ((s = e.bloom) == null ? void 0 : s.scale) ?? h.bloom.scale, this.renderingPipeline.bloomThreshold = ((o = e.bloom) == null ? void 0 : o.threshold) ?? h.bloom.threshold, this.renderingPipeline.bloomWeight = ((l = e.bloom) == null ? void 0 : l.weight) ?? h.bloom.weight, this.renderingPipeline.chromaticAberrationEnabled = ((d = e.chromaticAberration) == null ? void 0 : d.enabled) ?? h.chromaticAberration.enabled, this.renderingPipeline.chromaticAberration.aberrationAmount = ((c = e.chromaticAberration) == null ? void 0 : c.aberrationAmount) ?? h.chromaticAberration.aberrationAmount, this.renderingPipeline.chromaticAberration.radialIntensity = ((u = e.chromaticAberration) == null ? void 0 : u.radialIntensity) ?? h.chromaticAberration.radialIntensity, this.renderingPipeline.chromaticAberration.direction = (m = e.chromaticAberration) != null && m.direction ? new J(
1166
+ e.chromaticAberration.direction.x,
1167
+ e.chromaticAberration.direction.y
1168
+ ) : new J(
1169
+ h.chromaticAberration.direction.x,
1170
+ h.chromaticAberration.direction.y
1171
+ ), this.renderingPipeline.imageProcessing.colorCurvesEnabled = ((p = e.colorCurves) == null ? void 0 : p.enabled) ?? h.colorCurves.enabled, this.renderingPipeline.imageProcessing.colorCurves = e.colorCurves ? this.updateColorCurve(e.colorCurves) : new ie(), this.renderingPipeline.depthOfFieldEnabled = ((S = e.depthOfField) == null ? void 0 : S.enabled) ?? h.depthOfField.enabled, e.depthOfField)
1172
+ switch (e.depthOfField.blurLevel ?? h.depthOfField.blurLevel) {
1173
+ case "Low":
1174
+ this.renderingPipeline.depthOfFieldBlurLevel = A.Low;
1175
+ break;
1176
+ case "Medium":
1177
+ this.renderingPipeline.depthOfFieldBlurLevel = A.Medium;
1178
+ break;
1179
+ case "High":
1180
+ this.renderingPipeline.depthOfFieldBlurLevel = A.High;
1181
+ break;
1182
+ }
1183
+ if (this.renderingPipeline.depthOfField.focalLength = ((F = e.depthOfField) == null ? void 0 : F.focalLength) ?? h.depthOfField.focalLength, this.renderingPipeline.depthOfField.fStop = ((B = e.depthOfField) == null ? void 0 : B.fStop) ?? h.depthOfField.fStop, this.renderingPipeline.depthOfField.focusDistance = ((D = e.depthOfField) == null ? void 0 : D.focusDistance) ?? h.depthOfField.focusDistance, this.renderingPipeline.depthOfField.lensSize = ((z = e.depthOfField) == null ? void 0 : z.lensSize) ?? h.depthOfField.lensSize, this.renderingPipeline.grainEnabled = ((k = e.grain) == null ? void 0 : k.enabled) ?? h.grain.enabled, this.renderingPipeline.grain.animated = ((N = e.grain) == null ? void 0 : N.animated) ?? h.grain.animated, this.renderingPipeline.grain.intensity = ((V = e.grain) == null ? void 0 : V.intensity) ?? h.grain.intensity, this.renderingPipeline.imageProcessing.contrast = ((G = e.misc) == null ? void 0 : G.contrast) ?? h.misc.contrast, this.renderingPipeline.imageProcessing.exposure = ((H = e.misc) == null ? void 0 : H.exposure) ?? h.misc.exposure, this.renderingPipeline.imageProcessing.toneMappingEnabled = ((_ = e.misc) == null ? void 0 : _.toneMappingEnabled) ?? h.misc.toneMappingEnabled, this.renderingPipeline.imageProcessing.toneMappingEnabled)
1184
+ switch (e.misc.toneMappingType ?? h.misc.toneMappingType) {
1185
+ case "Standard":
1186
+ this.renderingPipeline.imageProcessing.toneMappingType = M.TONEMAPPING_STANDARD;
1187
+ break;
1188
+ case "ACES":
1189
+ this.renderingPipeline.imageProcessing.toneMappingType = M.TONEMAPPING_ACES;
1190
+ break;
1191
+ }
1192
+ if (this.renderingPipeline.sharpenEnabled = ((q = e.sharpen) == null ? void 0 : q.enabled) ?? h.sharpen.enabled, this.renderingPipeline.sharpen.colorAmount = ((K = e.sharpen) == null ? void 0 : K.colorAmount) ?? h.sharpen.colorAmount, this.renderingPipeline.sharpen.edgeAmount = ((U = e.sharpen) == null ? void 0 : U.edgeAmount) ?? h.sharpen.edgeAmount, this.renderingPipeline.imageProcessing.vignetteEnabled = ((W = e.vignette) == null ? void 0 : W.enabled) ?? h.vignette.enabled, (Z = e.vignette) != null && Z.center ? (this.renderingPipeline.imageProcessing.vignetteCenterX = e.vignette.center.x, this.renderingPipeline.imageProcessing.vignetteCenterY = e.vignette.center.y) : (this.renderingPipeline.imageProcessing.vignetteCenterX = h.vignette.center.x, this.renderingPipeline.imageProcessing.vignetteCenterY = h.vignette.center.y), e.vignette)
1193
+ switch ((($ = e.vignette) == null ? void 0 : $.blendMode) ?? h.vignette.blendMode) {
1194
+ case "Multiply":
1195
+ this.renderingPipeline.imageProcessing.vignetteBlendMode = M.VIGNETTEMODE_MULTIPLY;
1196
+ break;
1197
+ case "Opaque":
1198
+ this.renderingPipeline.imageProcessing.vignetteBlendMode = M.VIGNETTEMODE_OPAQUE;
1199
+ break;
1200
+ }
1201
+ (Y = e.vignette) != null && Y.colorRgba ? this.renderingPipeline.imageProcessing.vignetteColor = new f(
1202
+ e.vignette.colorRgba.r,
1203
+ e.vignette.colorRgba.g,
1204
+ e.vignette.colorRgba.b,
1205
+ e.vignette.colorRgba.a
1206
+ ) : (Q = e.vignette) != null && Q.colorHex ? this.renderingPipeline.imageProcessing.vignetteColor = f.FromHexString(e.vignette.colorHex) : this.renderingPipeline.imageProcessing.vignetteColor = new f(
1207
+ h.vignette.colorRgba.r,
1208
+ h.vignette.colorRgba.g,
1209
+ h.vignette.colorRgba.b,
1210
+ h.vignette.colorRgba.a
1211
+ ), this.renderingPipeline.imageProcessing.vignetteStretch = ((j = e.vignette) == null ? void 0 : j.stretch) ?? h.vignette.stretch, this.renderingPipeline.imageProcessing.vignetteWeight = ((X = e.vignette) == null ? void 0 : X.weight) ?? h.vignette.weight, this.renderingPipeline.prepare(), this.currentConfiguration = e;
1212
+ }
1213
+ }
1214
+ updateColorCurve(e) {
1215
+ const t = new ie();
1216
+ return t.globalDensity = e.globalDensity ?? t.globalDensity, t.globalExposure = e.globalExposure ?? t.globalExposure, t.globalHue = e.globalHue ?? t.globalHue, t.globalSaturation = e.globalSaturation ?? t.globalSaturation, t.highlightsDensity = e.highlightsDensity ?? t.highlightsDensity, t.highlightsExposure = e.highlightsExposure ?? t.highlightsExposure, t.highlightsHue = e.highlightsHue ?? t.highlightsHue, t.highlightsSaturation = e.highlightsSaturation ?? t.highlightsSaturation, t.midtonesDensity = e.midtonesDensity ?? t.midtonesDensity, t.midtonesExposure = e.midtonesExposure ?? t.midtonesExposure, t.midtonesHue = e.midtonesHue ?? t.midtonesHue, t.midtonesSaturation = e.midtonesSaturation ?? t.midtonesSaturation, t.shadowsDensity = e.shadowsDensity ?? t.shadowsDensity, t.shadowsExposure = e.shadowsExposure ?? t.shadowsExposure, t.shadowsHue = e.shadowsHue ?? t.shadowsHue, t.shadowsSaturation = e.shadowsSaturation ?? t.shadowsSaturation, t;
1217
+ }
1218
+ }
1219
+ Pe.GLTFLoader.RegisterExtension("glbPostProcessor", function(a) {
1220
+ return new ke(a);
1221
+ });
1222
+ ce.OnPluginActivatedObservable.add((a) => {
1223
+ if (a.name === "gltf") {
1224
+ const e = a;
1225
+ e.transparencyAsCoverage = !0;
1226
+ }
1227
+ });
1228
+ const x = "initialScene";
1229
+ class _t {
1230
+ constructor(e) {
1231
+ this.loadProgress = /* @__PURE__ */ new Map([
1232
+ [x, 0]
1233
+ ]), this.focusLostNotified = !1, this.loadObservable = new b(), this.focusLostObservable = new b(), this.initializedCallbacks = [], this.isInitialized = !1, this.modelLoadEventCallbacks = [], this.modelContainers = /* @__PURE__ */ new Map(), this.plugins = [], this.configuration = new De(e);
1234
+ const i = (() => {
1235
+ if (!(e != null && e.noRender))
1236
+ return this.configuration.createCanvas();
1237
+ })(), r = "1.5.6";
1238
+ ve.Configuration = {
1239
+ decoder: {
1240
+ wasmUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_wasm_wrapper_gltf.js`,
1241
+ wasmBinaryUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_decoder_gltf.wasm`,
1242
+ fallbackUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_decoder_gltf.js`
1243
+ }
1244
+ }, i && (i.getContext("webgl2") || i.getContext("webgl"));
1245
+ const n = console.log;
1246
+ console.log = () => {
1247
+ };
1248
+ const s = i ? new de(i, !0, {
1249
+ adaptToDeviceRatio: !0,
1250
+ limitDeviceRatio: 2,
1251
+ premultipliedAlpha: !1,
1252
+ preserveDrawingBuffer: !!(e != null && e.backgroundImage),
1253
+ audioEngine: !1,
1254
+ stencil: this.configuration.highlights.enabled,
1255
+ forceSRGBBufferSupportState: !0
1256
+ }) : new pe();
1257
+ console.log = n, s.hideLoadingUI(), window.addEventListener("resize", this.fireResizeEvent.bind(this)), this.engine = s, this.scene = new Ce(s), this.camera = I.create(this.scene, this.configuration), this.renderingPipeline = new et(
1258
+ this.scene,
1259
+ !1,
1260
+ this.camera
1261
+ ), this.scene.imageProcessingConfiguration.exposure = this.configuration.lighting.exposure, this.scene.imageProcessingConfiguration.contrast = this.configuration.lighting.contrast, this.glowLayerManager = new Ne(
1262
+ this.scene,
1263
+ this.configuration.emissiveGlowIntensity
1264
+ );
1265
+ }
1266
+ getEngineContext() {
1267
+ return {
1268
+ engine: this.engine,
1269
+ scene: this.scene,
1270
+ camera: this.camera
1271
+ };
1272
+ }
1273
+ registerFocusLostListener(e) {
1274
+ this.focusLostObservable.add(e);
1275
+ }
1276
+ unregisterFocusLostListener(e) {
1277
+ this.focusLostObservable.removeCallback(e);
1278
+ }
1279
+ registerLoadProgressListener(e) {
1280
+ this.loadObservable.add(e), e(this.getLoadListenerEvent());
1281
+ }
1282
+ unregisterLoadProgressListener(e) {
1283
+ this.loadObservable.removeCallback(e);
1284
+ }
1285
+ registerInitializedListener(e) {
1286
+ this.isInitialized || !this.isInitialized && this.initializedCallbacks.push(e);
1287
+ }
1288
+ unregisterInitializedListener(e) {
1289
+ if (this.isInitialized)
1290
+ return;
1291
+ const t = this.initializedCallbacks.indexOf(e);
1292
+ t > -1 && this.initializedCallbacks.splice(t, 1);
1293
+ }
1294
+ getIsInitialized() {
1295
+ return this.isInitialized;
1296
+ }
1297
+ registerModelLoadEventListener(e) {
1298
+ this.modelLoadEventCallbacks.push(e);
1299
+ }
1300
+ unregisterModelLoadEventListener(e) {
1301
+ const t = this.modelLoadEventCallbacks.indexOf(e);
1302
+ t > -1 && this.modelLoadEventCallbacks.splice(t, 1);
1303
+ }
1304
+ registerView(e) {
1305
+ const t = e.height, i = e.width;
1306
+ this.engine.registerView(e), e.setAttribute("height", t.toString()), e.setAttribute("width", i.toString()), this.orbitEnabled() || this.setCameraState(E.Pan), this.reattachControls(e);
1307
+ }
1308
+ getNumViewports() {
1309
+ var e;
1310
+ return ((e = this.engine.views) == null ? void 0 : e.length) || 0;
1311
+ }
1312
+ unregisterView(e) {
1313
+ this.engine.unRegisterView(e);
1314
+ }
1315
+ shutdown() {
1316
+ this.plugins.forEach((e) => e.dispose(!0)), this.renderingPipeline.dispose(), this.engine && this.engine.dispose(), window.removeEventListener("resize", this.fireResizeEvent);
1317
+ }
1318
+ getSceneInitializationProgress() {
1319
+ return this.loadProgress.get(x);
1320
+ }
1321
+ async initialize(e) {
1322
+ var i, r;
1323
+ this.scene.clearColor = this.configuration.scene.clearColor, this.scene.environmentTexture = be.CreateFromPrefilteredData(
1324
+ this.configuration.scene.environmentFile,
1325
+ this.scene
1326
+ );
1327
+ let t;
1328
+ return e && (t = await this.loadModel(
1329
+ e,
1330
+ (s) => {
1331
+ this.loadProgress.set(
1332
+ x,
1333
+ s.loaded * 100 / s.total
1334
+ ), this.notifyLoadHandlers();
1335
+ }
1336
+ ).getInitializationPromise()), this.loadProgress.set(x, 100), this.notifyLoadHandlers(), this.scene.activeCamera = this.camera, this.camera.rerunFramingBehavior(void 0, 1), qe(this.scene), ((i = this.engine.views) == null ? void 0 : i.length) >= 1 && this.reattachControls(
1337
+ this.engine.views[this.engine.views.length - 1].target
1338
+ ), this.queuedCameraAnimation && (this.executeCameraAnimation(this.queuedCameraAnimation), this.queuedCameraAnimation = void 0), this.isInitialized = !0, await Promise.all(this.initializedCallbacks.map((n) => n())), this.initializedCallbacks = [], (r = this.configuration.options) != null && r.renderingPipelineConfiguration && this.renderingPipeline.setConfiguration(
1339
+ this.configuration.options.renderingPipelineConfiguration
1340
+ ), this.engine.runRenderLoop(() => {
1341
+ this.engine.views && (this.modelContainers.forEach((n) => {
1342
+ n.updateDynamicTextures();
1343
+ }), this.configuration.scene.transparentBackground && this.engine.views.forEach((n) => {
1344
+ const s = this.engine.getRenderingCanvas();
1345
+ n.target.getContext("2d").clearRect(
1346
+ 0,
1347
+ 0,
1348
+ s.width,
1349
+ s.height
1350
+ );
1351
+ }), this.scene.render(), !this.camera.target.equalsWithEpsilon(this.camera.lastFocus, 0.1) && !this.focusLostNotified && (this.focusLostObservable.notifyObservers(void 0), this.focusLostNotified = !0), this.screenshotPrepareResolve && (this.screenshotPrepareResolve(), this.screenshotPrepareResolve = void 0));
1352
+ }), t;
1353
+ }
1354
+ executeCameraAnimation(e) {
1355
+ if (this.getSceneInitializationProgress() !== 100 || !this.camera || this.scene.activeCamera !== this.camera) {
1356
+ this.queuedCameraAnimation = e;
1357
+ return;
1358
+ }
1359
+ Ke(
1360
+ this.scene,
1361
+ this.scene.activeCamera,
1362
+ e
1363
+ );
1364
+ }
1365
+ getCameraPose() {
1366
+ if (this.scene && this.camera)
1367
+ return {
1368
+ lonDeg: Math.round(this.camera.alpha * 180 / Math.PI),
1369
+ latDeg: Math.round(this.camera.beta * 180 / Math.PI),
1370
+ radius: Math.round((this.camera.radius + Number.EPSILON) * 1e4) / 1e4,
1371
+ target: {
1372
+ x: this.camera.target.x,
1373
+ y: this.camera.target.y,
1374
+ z: this.camera.target.z
1375
+ }
1376
+ };
1377
+ }
1378
+ setCameraPose(e) {
1379
+ this.scene && this.camera && (this.camera.target = new g(
1380
+ e.target.x,
1381
+ e.target.y,
1382
+ e.target.z
1383
+ ), this.camera.radius = e.radius, this.camera.alpha = e.latDeg, this.camera.beta = e.lonDeg);
1384
+ }
1385
+ setCameraState(e) {
1386
+ var t, i;
1387
+ if (!((t = this.engine) != null && t.views) || !((i = this.engine) != null && i.views[0]))
1388
+ throw new Error(
1389
+ "No views attached, camera state requires a view to attach controls onto."
1390
+ );
1391
+ e === E.Orbit ? this.reattachControls(this.engine.views[0].target, 2) : this.reattachControls(this.engine.views[0].target, 0);
1392
+ }
1393
+ animateToLastCameraFocus() {
1394
+ return new Promise((e) => {
1395
+ const t = this.configuration;
1396
+ this.camera.rerunFramingBehavior(() => {
1397
+ this.focusLostNotified = !1, t.camera.limits.min.radius && (this.camera.lowerRadiusLimit = t.camera.limits.min.radius), t.camera.limits.max.radius && (this.camera.upperRadiusLimit = t.camera.limits.max.radius), e();
1398
+ });
1399
+ });
1400
+ }
1401
+ setAutoRotation(e) {
1402
+ !this.configuration.camera.autoRotation.enabled || !this.camera || (e ? this.camera.enableAutoRotationBehavior(
1403
+ this.configuration.camera.autoRotation.idleTimeMs
1404
+ ) : this.camera.disableAutoRotationBehavior());
1405
+ }
1406
+ getCurrentConfiguration() {
1407
+ return this.configuration.options;
1408
+ }
1409
+ async renderSceneScreenshot(e, t) {
1410
+ if (!this.camera)
1411
+ throw new Error("Missing product camera, cannot render screenshot!");
1412
+ const i = new he(
1413
+ "screenshotCamera",
1414
+ 0,
1415
+ 0,
1416
+ 0,
1417
+ g.Zero(),
1418
+ this.scene
1419
+ );
1420
+ try {
1421
+ const r = t.latDeg * Math.PI / 180, n = t.lonDeg * Math.PI / 180;
1422
+ i.target = t.target ? new g(t.target.x, t.target.y, t.target.z) : g.Zero(), i.alpha = n, i.beta = r, i.radius = t.radius || this.camera.radius, i.minZ = 0.01, this.scene.render();
1423
+ const s = await we.CreateScreenshotUsingRenderTargetAsync(
1424
+ this.engine,
1425
+ i,
1426
+ e,
1427
+ "image/png",
1428
+ 2,
1429
+ !0
1430
+ );
1431
+ return i.dispose(), s;
1432
+ } catch {
1433
+ throw i.isDisposed() || i.dispose(), new Error("Failed to render screenshot");
1434
+ }
1435
+ }
1436
+ orbitEnabled() {
1437
+ const e = this.configuration;
1438
+ if (!e)
1439
+ return !0;
1440
+ const t = e.camera.limits.min.alpha, i = e.camera.limits.max.alpha, r = e.camera.limits.min.beta, n = e.camera.limits.max.beta;
1441
+ if (t === void 0 || i === void 0 || r === void 0 || n === void 0)
1442
+ return !0;
1443
+ const s = [t, i], o = [r, n], l = s.every((c) => c === t), d = o.every((c) => c === r);
1444
+ return !l && !d;
1445
+ }
1446
+ fireResizeEvent() {
1447
+ this.getNumViewports() > 0 && this.engine.resize();
1448
+ }
1449
+ setHighlights(e, t) {
1450
+ var r;
1451
+ e.length === 0 && ((r = this.highlightLayer) == null || r.dispose(), this.highlightLayer = void 0), this.highlightLayer || (this.highlightLayer = new fe("highlights", this.scene, {
1452
+ isStroke: !0,
1453
+ blurVerticalSize: 0.85,
1454
+ blurHorizontalSize: 0.85
1455
+ }), this.highlightLayer.innerGlow = !0, this.highlightLayer.outerGlow = !1), this.highlightLayer.removeAllMeshes();
1456
+ const i = t ? new w(t[0], t[1], t[2]).toLinearSpace() : void 0;
1457
+ e.forEach((n) => {
1458
+ const s = this.scene.materials.find(
1459
+ (o) => o.name === n.name && o.id === n.id
1460
+ );
1461
+ s && s.getBindedMeshes().forEach(
1462
+ (o) => {
1463
+ var l;
1464
+ return (l = this.highlightLayer) == null ? void 0 : l.addMesh(
1465
+ o,
1466
+ i || w.FromHexString("#fcba03")
1467
+ );
1468
+ }
1469
+ );
1470
+ });
1471
+ }
1472
+ setRenderingPipelineConfiguration(e) {
1473
+ this.renderingPipeline && this.renderingPipeline.setConfiguration(e);
1474
+ }
1475
+ loadModel(e, t) {
1476
+ const i = new Je({
1477
+ enablePicking: this.configuration.highlights.enabled,
1478
+ modelDetails: e,
1479
+ scene: this.scene,
1480
+ previewService: this,
1481
+ progressHandler: t
1482
+ });
1483
+ return i.registerMaterialVariantListener(
1484
+ (r) => this.handleMaterialProgressCallback(
1485
+ r.remainingCount,
1486
+ r.totalCount,
1487
+ r.taskName
1488
+ )
1489
+ ), i.registerModelVariantListener(
1490
+ (r) => this.handleModelProgressCallback(r, r.key)
1491
+ ), this.configuration.highlights.enabled && (i.registerMaterialSelectedCallback((r) => {
1492
+ this.setHighlights([r]);
1493
+ }), i.registerMaterialDeselectedCallback(() => {
1494
+ this.setHighlights([]);
1495
+ })), this.modelContainers.set(i.getId(), i), this.triggerModelLoadEvent({
1496
+ eventType: "load",
1497
+ modelContainer: i
1498
+ }), i;
1499
+ }
1500
+ getAllModels() {
1501
+ return Array.from(this.modelContainers.values());
1502
+ }
1503
+ getModelById(e) {
1504
+ return this.modelContainers.get(e);
1505
+ }
1506
+ registerPlugin(e) {
1507
+ this.plugins.push(e), e.initialize(this, {
1508
+ camera: this.camera,
1509
+ engine: this.engine,
1510
+ scene: this.scene
1511
+ });
1512
+ }
1513
+ unregisterPlugin(e) {
1514
+ const t = this.plugins.indexOf(e);
1515
+ t > -1 && this.plugins.splice(t, 1).forEach((r) => r.dispose(!1));
1516
+ }
1517
+ getGlowLayerManager() {
1518
+ return this.glowLayerManager;
1519
+ }
1520
+ modelUnloaded(e) {
1521
+ this.modelContainers.delete(e.getId()), this.triggerModelLoadEvent({
1522
+ eventType: "unload",
1523
+ modelContainer: e
1524
+ });
1525
+ }
1526
+ triggerModelLoadEvent(e) {
1527
+ this.modelLoadEventCallbacks.forEach((t) => t(e));
1528
+ }
1529
+ handleMaterialProgressCallback(e, t, i) {
1530
+ this.loadProgress.set(`key_${i}`, e / t * 100), this.notifyLoadHandlers();
1531
+ }
1532
+ handleModelProgressCallback(e, t) {
1533
+ this.loadProgress.set(t, e.loaded * 100 / e.total), this.notifyLoadHandlers();
1534
+ }
1535
+ /**
1536
+ * Given a valid canvas element, will remove any existing input controls
1537
+ * and re-attach them to the given canvas. The pan mouse button can be set
1538
+ * to either 0 (left mouse) or 2 (right mouse).
1539
+ */
1540
+ reattachControls(e, t = 2) {
1541
+ if (this.scene.detachControl(), this.engine.inputElement = e, this.camera) {
1542
+ this.camera.attachControl(!0, !1, t);
1543
+ const i = this.camera.inputs.attached.pointers;
1544
+ i.multiTouchPanning = !1;
1545
+ }
1546
+ this.scene.attachControl(!0, !0, !0);
1547
+ }
1548
+ /**
1549
+ * Computes a load listener event based on current state of scene.
1550
+ */
1551
+ getLoadListenerEvent() {
1552
+ const e = Array.from(this.loadProgress.values()).filter(
1553
+ (r) => r < 100
1554
+ ), i = e.reduce((r, n) => r + n, 0) / e.length || 0;
1555
+ return {
1556
+ loadValue: e.length === 0 ? 100 : i,
1557
+ sceneInitialized: this.getSceneInitializationProgress() === 100
1558
+ };
1559
+ }
1560
+ /**
1561
+ * Computes the average loading time across all loading events and notifies
1562
+ * listeners of the current load progress.
1563
+ */
1564
+ notifyLoadHandlers() {
1565
+ this.loadObservable.notifyObservers(this.getLoadListenerEvent());
1566
+ }
1567
+ }
1568
+ export {
1569
+ O as MaterialEffectMode,
1570
+ E as ProductCameraRig,
1571
+ ze as REFLECTION_PROBE_RESOLUTION,
1572
+ P as RenderingConfiguration,
1573
+ _t as SpiffCommerce3DPreviewService,
1574
+ h as renderingPipelineDefaults
1575
+ };