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