@spiffcommerce/preview 5.7.9-4 → 5.7.9-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -6,10 +6,10 @@ import { SceneLoader as S } from "@babylonjs/core/Loading/sceneLoader";
6
6
  import { CubeTexture as ne } from "@babylonjs/core/Materials/Textures/cubeTexture";
7
7
  import { Color4 as b, Color3 as w } from "@babylonjs/core/Maths/math.color";
8
8
  import { Vector3 as p, Quaternion as y, Vector2 as se, Matrix as re } from "@babylonjs/core/Maths/math.vector";
9
- import { DracoCompression as xe } from "@babylonjs/core/Meshes/Compression/dracoCompression";
9
+ import { DracoCompression as Ae } from "@babylonjs/core/Meshes/Compression/dracoCompression";
10
10
  import { Observable as C } from "@babylonjs/core/Misc/observable";
11
- import { Tools as Ae } from "@babylonjs/core/Misc/tools";
12
- import { Scene as Me } from "@babylonjs/core/scene";
11
+ import { Tools as Me } from "@babylonjs/core/Misc/tools";
12
+ import { Scene as xe } from "@babylonjs/core/scene";
13
13
  import { GLTF2 as Pe } from "@babylonjs/loaders/glTF";
14
14
  import { GLTFLoaderAnimationStartMode as Re } from "@babylonjs/loaders/glTF/glTFFileLoader";
15
15
  import { PBRMaterial as B } from "@babylonjs/core/Materials/PBR/pbrMaterial";
@@ -27,7 +27,7 @@ import { Animation as v } from "@babylonjs/core/Animations/animation";
27
27
  import { QuadraticEase as ke, EasingFunction as ze } from "@babylonjs/core/Animations/easing";
28
28
  import { AssetsManager as Ne } from "@babylonjs/core/Misc/assetsManager";
29
29
  import { ColorCurves as le } from "@babylonjs/core/Materials/colorCurves";
30
- import { ImageProcessingConfiguration as M } from "@babylonjs/core/Materials/imageProcessingConfiguration";
30
+ import { ImageProcessingConfiguration as x } from "@babylonjs/core/Materials/imageProcessingConfiguration";
31
31
  import { DefaultRenderingPipeline as qe } from "@babylonjs/core/PostProcesses/RenderPipeline";
32
32
  import { DepthOfFieldEffectBlurLevel as E } from "@babylonjs/core/PostProcesses/depthOfFieldEffect";
33
33
  import "@babylonjs/core/Rendering/depthRendererSceneComponent";
@@ -113,7 +113,7 @@ class ce {
113
113
  * Configuration related to the camera used to view and interact with the scene.
114
114
  */
115
115
  get camera() {
116
- var e, t, i, n, s, o, a, h, l, c, u, m, g;
116
+ var e, t, i, n, s, o, a, l, h, c, u, m, g;
117
117
  return {
118
118
  autoOrientation: ((e = this.customOptions) == null ? void 0 : e.disableAutomaticOrientation) ?? !0,
119
119
  autoRotation: {
@@ -124,10 +124,10 @@ class ce {
124
124
  min: {
125
125
  alpha: (n = this.customOptions) != null && n.lowerAlphaLimitDeg ? ((s = this.customOptions) == null ? void 0 : s.lowerAlphaLimitDeg) * Math.PI / 180 : void 0,
126
126
  beta: (o = this.customOptions) != null && o.lowerBetaLimitDeg ? ((a = this.customOptions) == null ? void 0 : a.lowerBetaLimitDeg) * Math.PI / 180 : void 0,
127
- radius: (h = this.customOptions) == null ? void 0 : h.minZoomOverride
127
+ radius: (l = this.customOptions) == null ? void 0 : l.minZoomOverride
128
128
  },
129
129
  max: {
130
- alpha: (l = this.customOptions) != null && l.upperAlphaLimitDeg ? ((c = this.customOptions) == null ? void 0 : c.upperAlphaLimitDeg) * Math.PI / 180 : void 0,
130
+ alpha: (h = this.customOptions) != null && h.upperAlphaLimitDeg ? ((c = this.customOptions) == null ? void 0 : c.upperAlphaLimitDeg) * Math.PI / 180 : void 0,
131
131
  beta: (u = this.customOptions) != null && u.upperBetaLimitDeg ? ((m = this.customOptions) == null ? void 0 : m.upperBetaLimitDeg) * Math.PI / 180 : void 0,
132
132
  radius: (g = this.customOptions) == null ? void 0 : g.maxZoomOverride
133
133
  }
@@ -157,12 +157,12 @@ class ce {
157
157
  return ((e = this.customOptions) == null ? void 0 : e.emissiveGlowIntensity) ?? 0.5;
158
158
  }
159
159
  }
160
- class A {
160
+ class M {
161
161
  /**
162
162
  * Returns the resolution expected for generated textures.
163
163
  */
164
164
  static getDynamicTextureResolution() {
165
- return this.getIsMobile() || !A.offscreenRenderingSupported() ? {
165
+ return this.getIsMobile() || !M.offscreenRenderingSupported() ? {
166
166
  width: 1024,
167
167
  height: 1024
168
168
  } : {
@@ -344,27 +344,27 @@ class _e {
344
344
  const a = s.material;
345
345
  if (!a)
346
346
  return;
347
- const h = new Ee(
347
+ const l = new Ee(
348
348
  "mirror",
349
- A.getMirrorTextureResolution(),
349
+ M.getMirrorTextureResolution(),
350
350
  e,
351
351
  !0
352
352
  );
353
- h.renderList = t(e);
354
- const l = s.getVerticesData("normal");
355
- if (!l)
353
+ l.renderList = t(e);
354
+ const h = s.getVerticesData("normal");
355
+ if (!h)
356
356
  throw new Error(
357
357
  "Mirror attribute specified on: " + s.name + "But no normals exist to generate a mirror from!"
358
358
  );
359
359
  s.computeWorldMatrix(!0);
360
360
  const c = s.getWorldMatrix(), u = ae.TransformNormal(
361
- new ae(l[0], l[1], l[2]),
361
+ new ae(h[0], h[1], h[2]),
362
362
  c
363
363
  ).normalize(), m = Oe.FromPositionAndNormal(
364
364
  s.position,
365
365
  u.scale(-1)
366
366
  );
367
- h.mirrorPlane = m, h.level = o, a.reflectionTexture = h;
367
+ l.mirrorPlane = m, l.level = o, a.reflectionTexture = l;
368
368
  }
369
369
  function n(s) {
370
370
  const o = s.material, a = new Le(
@@ -404,7 +404,7 @@ class Ge {
404
404
  }
405
405
  function He(r, e, t, i, n = "") {
406
406
  t.forEach((s) => {
407
- const o = s.getID(), a = s.getName(), h = A.getDynamicTextureResolution();
407
+ const o = s.getID(), a = s.getName(), l = M.getDynamicTextureResolution();
408
408
  r.filter((c) => c.name === n + a).forEach((c) => {
409
409
  console.log(`attaching textures to material ${c.name}`);
410
410
  const u = i.get(o), m = !1;
@@ -414,8 +414,8 @@ function He(r, e, t, i, n = "") {
414
414
  const g = Ke(
415
415
  a,
416
416
  e,
417
- h.width,
418
- h.height
417
+ l.width,
418
+ l.height
419
419
  );
420
420
  console.log(`created new texture ${g.name}`), i.set(o, g), s.setStaticContext(
421
421
  g.getContext()
@@ -428,10 +428,10 @@ function He(r, e, t, i, n = "") {
428
428
  }
429
429
  const Ue = (r) => {
430
430
  const e = () => r.textures.reduce((i, n) => {
431
- var o;
431
+ var o, a;
432
432
  return !r.meshes.some(
433
- (a) => a.material && a.material.hasTexture(n)
434
- ) && !((o = n == null ? void 0 : n.url) != null && o.includes("data:")) && !n.name.endsWith(".env") && i.push(n), i;
433
+ (l) => l.material && l.material.hasTexture(n)
434
+ ) && !((o = n == null ? void 0 : n.url) != null && o.includes("data:")) && !((a = n == null ? void 0 : n.url) != null && a.endsWith(".env")) && i.push(n), i;
435
435
  }, []), t = () => r.materials.reduce((i, n) => (n.getBindedMeshes().length == 0 && i.push(n), i), []);
436
436
  e().forEach((i) => {
437
437
  try {
@@ -452,7 +452,7 @@ function Ke(r, e, t, i) {
452
452
  r,
453
453
  { width: t, height: i },
454
454
  e,
455
- A.shouldMipMap(),
455
+ M.shouldMipMap(),
456
456
  De.TRILINEAR_SAMPLINGMODE,
457
457
  be.TEXTUREFORMAT_RGBA
458
458
  ), s = n.getContext();
@@ -471,7 +471,7 @@ function We() {
471
471
  const r = () => Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
472
472
  return r() + r() + "-" + r() + "-" + r() + "-" + r() + "-" + r() + r() + r();
473
473
  }
474
- const x = 60, ue = 1;
474
+ const A = 60, ue = 1;
475
475
  function me(r) {
476
476
  return r.targetedAnimations.map((t) => t.animation.framePerSecond).reduce((t, i) => t + i, 0) / r.targetedAnimations.length || 0;
477
477
  }
@@ -482,25 +482,25 @@ function ve(r, e, t, i, n, s) {
482
482
  return;
483
483
  }
484
484
  let a = 0;
485
- const h = () => {
485
+ const l = () => {
486
486
  a++, a === o.length && s && s();
487
- }, l = (c, u, m, g, f) => {
487
+ }, h = (c, u, m, g, f) => {
488
488
  c.stop(), c.start(u, m, g, f), s && (u == !1 || u === void 0 && !c.loopAnimation ? c.onAnimationGroupEndObservable.addOnce(() => {
489
- h();
489
+ l();
490
490
  }) : c.onAnimationLoopObservable.addOnce(() => {
491
- h();
491
+ l();
492
492
  }));
493
493
  };
494
494
  if (i !== void 0 && t !== void 0 && i === t) {
495
495
  o.forEach((c) => {
496
496
  const u = me(c), m = i * u;
497
- l(c, !1, ue, m, m);
497
+ h(c, !1, ue, m, m);
498
498
  });
499
499
  return;
500
500
  }
501
501
  o.forEach((c) => {
502
502
  const u = me(c), m = i !== void 0 ? i * u : void 0, g = t !== void 0 ? t * u : void 0;
503
- l(c, e, ue, m, g);
503
+ h(c, e, ue, m, g);
504
504
  });
505
505
  }
506
506
  function $e(r, e, t) {
@@ -552,15 +552,15 @@ function $e(r, e, t) {
552
552
  );
553
553
  }
554
554
  e.animations.push(...n);
555
- const l = e.useAutoRotationBehavior;
555
+ const h = e.useAutoRotationBehavior;
556
556
  e.disableAutoRotationBehavior(), r.beginAnimation(
557
557
  e,
558
558
  0,
559
- s ? x * 2 : x,
559
+ s ? A * 2 : A,
560
560
  !1,
561
561
  1,
562
562
  () => {
563
- e.animations = [], l && e.enableAutoRotationBehavior(), i();
563
+ e.animations = [], h && e.enableAutoRotationBehavior(), i();
564
564
  }
565
565
  );
566
566
  });
@@ -571,17 +571,17 @@ function ge(r) {
571
571
  function P(r, e, t, i, n, s = 0, o = v.ANIMATIONLOOPMODE_CONSTANT) {
572
572
  const a = new ke();
573
573
  a.setEasingMode(ze.EASINGMODE_EASEINOUT);
574
- const h = new v(
574
+ const l = new v(
575
575
  r,
576
576
  e,
577
- x,
577
+ A,
578
578
  n,
579
579
  o
580
- ), l = [];
581
- return s > 0 && l.push({ frame: 0, value: t }), l.push({ frame: x * s, value: t }), l.push({
582
- frame: x * (s + 1),
580
+ ), h = [];
581
+ return s > 0 && h.push({ frame: 0, value: t }), h.push({ frame: A * s, value: t }), h.push({
582
+ frame: A * (s + 1),
583
583
  value: i
584
- }), h.setKeys(l), h.setEasingFunction(a), h;
584
+ }), l.setKeys(h), l.setEasingFunction(a), l;
585
585
  }
586
586
  function Ye(r, e, t) {
587
587
  return r < e ? r = t - (e - r) % (t - e) : r = e + (r - e) % (t - e);
@@ -675,24 +675,24 @@ class it {
675
675
  ...o,
676
676
  ...t
677
677
  });
678
- const a = this.renameClonedAsset(e), h = this.scene.materials.filter(
678
+ const a = this.renameClonedAsset(e), l = this.scene.materials.filter(
679
679
  (c) => c.name === a
680
680
  );
681
- if (h.length === 0) {
681
+ if (l.length === 0) {
682
682
  s();
683
683
  return;
684
684
  }
685
- const l = new Ne(this.scene);
686
- l.useDefaultLoadingScreen = !1, h.forEach(
685
+ const h = new Ne(this.scene);
686
+ h.useDefaultLoadingScreen = !1, l.forEach(
687
687
  (c) => je(
688
688
  t,
689
689
  c,
690
- l,
690
+ h,
691
691
  n
692
692
  )
693
- ), l.onProgress = (c, u, m) => {
693
+ ), h.onProgress = (c, u, m) => {
694
694
  i && i(c / u * 100, 100, m.name);
695
- }, l.onFinish = (c) => {
695
+ }, h.onFinish = (c) => {
696
696
  c.forEach((u) => {
697
697
  const m = u;
698
698
  i && i(100, 100, u.name), this.scene.materials.filter(
@@ -706,7 +706,7 @@ class it {
706
706
  );
707
707
  });
708
708
  }), s();
709
- }, l.loadAsync();
709
+ }, h.loadAsync();
710
710
  });
711
711
  }
712
712
  /**
@@ -725,14 +725,14 @@ class it {
725
725
  return this.keysThatRemovedBaseModel.includes(e) && this.keysThatRemovedBaseModel.length === 1 && await this.setBaseModelEnabled(!0), (u = this.loadedContainerForKey.get(e)) == null || u.dispose(), this.loadedContainerForKey.delete(e), this.loadedMaterialsForKey.delete(e), this.keysThatRemovedBaseModel = this.keysThatRemovedBaseModel.filter(
726
726
  (m) => m !== e
727
727
  ), Promise.resolve(void 0);
728
- const l = (await D(i, this.scene, n)).instantiateModelsToScene(
728
+ const h = (await D(i, this.scene, n)).instantiateModelsToScene(
729
729
  this.renameClonedAsset,
730
730
  !0
731
731
  );
732
732
  if (this.loadedContainerForKey.has(e) && (this.loadedContainerForKey.get(e).dispose(), this.loadedContainerForKey.delete(e), this.loadedMaterialsForKey.delete(e)), s) {
733
733
  const m = o && o(), g = s.name ? this.renameClonedAsset(s.name) : void 0;
734
734
  if (ve(
735
- l.animationGroups,
735
+ h.animationGroups,
736
736
  s.loop,
737
737
  s.to,
738
738
  s.from,
@@ -740,17 +740,17 @@ class it {
740
740
  ), m != null) {
741
741
  const f = a && a() || !0;
742
742
  Qe(
743
- l.animationGroups,
743
+ h.animationGroups,
744
744
  m + (f ? 2 : 0),
745
745
  g
746
746
  );
747
747
  }
748
748
  }
749
- t && await this.setBaseModelEnabled(!1), this.loadedContainerForKey.set(e, l), this.loadedMaterialsForKey.set(e, we(l));
749
+ t && await this.setBaseModelEnabled(!1), this.loadedContainerForKey.set(e, h), this.loadedMaterialsForKey.set(e, we(h));
750
750
  const c = [];
751
751
  return this.materialVariantMap.forEach(async (m, g) => {
752
752
  c.push(this.applyMaterial(g, m));
753
- }), await Promise.all(c), l;
753
+ }), await Promise.all(c), h;
754
754
  }
755
755
  dispose() {
756
756
  this.loadedContainerForKey.forEach((e) => e == null ? void 0 : e.dispose()), this.loadedContainerForKey.clear(), this.loadedMaterialsForKey.forEach(
@@ -857,11 +857,11 @@ class nt {
857
857
  await this.variantManager.applyMaterial(
858
858
  e,
859
859
  i,
860
- (o, a, h) => {
860
+ (o, a, l) => {
861
861
  this.materialVariantObservable.notifyObservers({
862
862
  remainingCount: o,
863
863
  totalCount: a,
864
- taskName: h
864
+ taskName: l
865
865
  });
866
866
  },
867
867
  n
@@ -929,10 +929,10 @@ class nt {
929
929
  this.modelChangesInProgress.push(e);
930
930
  let a = await n();
931
931
  if (this.queuedModelChanges.has(e)) {
932
- const h = this.queuedModelChanges.get(e);
933
- if (!h)
932
+ const l = this.queuedModelChanges.get(e);
933
+ if (!l)
934
934
  throw new Error("Queued change resolved undefined");
935
- a = await h(), this.queuedModelChanges.delete(e);
935
+ a = await l(), this.queuedModelChanges.delete(e);
936
936
  }
937
937
  return this.modelChangesInProgress.splice(
938
938
  this.modelChangesInProgress.indexOf(e),
@@ -1202,7 +1202,7 @@ class nt {
1202
1202
  //#endregion
1203
1203
  }
1204
1204
  class k extends fe {
1205
- constructor(e, t, i, n, s, o, a, h) {
1205
+ constructor(e, t, i, n, s, o, a, l) {
1206
1206
  super(
1207
1207
  e,
1208
1208
  t,
@@ -1210,7 +1210,7 @@ class k extends fe {
1210
1210
  n,
1211
1211
  s,
1212
1212
  o,
1213
- h
1213
+ l
1214
1214
  ), this.lastFocus = new p(0, 0, 0), this._isRunningFramingBehavior = !1, this.panDenominator = 1, this.panEnabled = !0, this.minZ = 0.01, this.updateRadiusBounds(this.radius), this.enableFramingBehavior(), this.wheelDeltaPercentage = 0.01, this.pinchDeltaPercentage = 5e-3, this.useNaturalPinchZoom = !0, a.camera.autoOrientation && (this.alpha += Math.PI), a && (a.camera.limits.min.beta && (this.lowerBetaLimit = a.camera.limits.min.beta), a.camera.limits.max.beta && (this.upperBetaLimit = a.camera.limits.max.beta), a.camera.limits.min.alpha && (this.lowerAlphaLimit = a.camera.limits.min.alpha), a.camera.limits.max.alpha && (this.upperAlphaLimit = a.camera.limits.max.alpha), a.camera.limits.min.radius && (this.lowerRadiusLimit = a.camera.limits.min.radius), a.camera.limits.max.radius && (this.upperRadiusLimit = a.camera.limits.max.radius), a.camera.autoRotation.enabled && this.enableAutoRotationBehavior(
1215
1215
  a.camera.autoRotation.idleTimeMs
1216
1216
  ));
@@ -1302,7 +1302,7 @@ class k extends fe {
1302
1302
  * @param disablePan If true the camera will not allow panning.
1303
1303
  */
1304
1304
  static create(e, t, i) {
1305
- var h;
1305
+ var l;
1306
1306
  const n = T(e), s = n.max.subtract(n.min), o = n.min.add(s.scale(0.5)), a = new k(
1307
1307
  "ProductCamera",
1308
1308
  -(Math.PI / 2),
@@ -1313,7 +1313,7 @@ class k extends fe {
1313
1313
  t
1314
1314
  );
1315
1315
  return a.setPanEnabled(
1316
- ((h = t.options) == null ? void 0 : h.noPan) !== void 0 ? !t.options.noPan : !0
1316
+ ((l = t.options) == null ? void 0 : l.noPan) !== void 0 ? !t.options.noPan : !0
1317
1317
  ), a.panningInertia = 0, a.panningOriginTarget.copyFrom(o), a.panDenominator = s.length(), a.onAfterCheckInputsObservable.addOnce(() => {
1318
1318
  a.setPanEnabled(a.panEnabled);
1319
1319
  }), i && (e.activeCamera = a), a;
@@ -1346,9 +1346,9 @@ class st {
1346
1346
  return this.currentConfiguration;
1347
1347
  }
1348
1348
  setConfiguration(e) {
1349
- var t, i, n, s, o, a, h, l, c, u, m, g, f, z, N, q, V, _, G, H, U, K, W, $, Y, Q, Z, j, X, J, ee, te, ie;
1349
+ var t, i, n, s, o, a, l, h, c, u, m, g, f, z, N, q, V, _, G, H, U, K, W, $, Y, Q, Z, j, X, J, ee, te, ie;
1350
1350
  if (this.renderingPipeline.isSupported) {
1351
- if (this.renderingPipeline.samples = ((t = e.antiAliasing) == null ? void 0 : t.samples) ?? d.antiAliasing.samples, this.renderingPipeline.fxaaEnabled = ((i = e.antiAliasing) == null ? void 0 : i.fxaaEnabled) ?? d.antiAliasing.fxaaEnabled, this.renderingPipeline.bloomEnabled = ((n = e.bloom) == null ? void 0 : n.enabled) ?? d.bloom.enabled, this.renderingPipeline.bloomKernel = ((s = e.bloom) == null ? void 0 : s.kernel) ?? d.bloom.kernel, this.renderingPipeline.bloomScale = ((o = e.bloom) == null ? void 0 : o.scale) ?? d.bloom.scale, this.renderingPipeline.bloomThreshold = ((a = e.bloom) == null ? void 0 : a.threshold) ?? d.bloom.threshold, this.renderingPipeline.bloomWeight = ((h = e.bloom) == null ? void 0 : h.weight) ?? d.bloom.weight, this.renderingPipeline.chromaticAberrationEnabled = ((l = e.chromaticAberration) == null ? void 0 : l.enabled) ?? d.chromaticAberration.enabled, this.renderingPipeline.chromaticAberration.aberrationAmount = ((c = e.chromaticAberration) == null ? void 0 : c.aberrationAmount) ?? d.chromaticAberration.aberrationAmount, this.renderingPipeline.chromaticAberration.radialIntensity = ((u = e.chromaticAberration) == null ? void 0 : u.radialIntensity) ?? d.chromaticAberration.radialIntensity, this.renderingPipeline.chromaticAberration.direction = (m = e.chromaticAberration) != null && m.direction ? new se(
1351
+ if (this.renderingPipeline.samples = ((t = e.antiAliasing) == null ? void 0 : t.samples) ?? d.antiAliasing.samples, this.renderingPipeline.fxaaEnabled = ((i = e.antiAliasing) == null ? void 0 : i.fxaaEnabled) ?? d.antiAliasing.fxaaEnabled, this.renderingPipeline.bloomEnabled = ((n = e.bloom) == null ? void 0 : n.enabled) ?? d.bloom.enabled, this.renderingPipeline.bloomKernel = ((s = e.bloom) == null ? void 0 : s.kernel) ?? d.bloom.kernel, this.renderingPipeline.bloomScale = ((o = e.bloom) == null ? void 0 : o.scale) ?? d.bloom.scale, this.renderingPipeline.bloomThreshold = ((a = e.bloom) == null ? void 0 : a.threshold) ?? d.bloom.threshold, this.renderingPipeline.bloomWeight = ((l = e.bloom) == null ? void 0 : l.weight) ?? d.bloom.weight, this.renderingPipeline.chromaticAberrationEnabled = ((h = e.chromaticAberration) == null ? void 0 : h.enabled) ?? d.chromaticAberration.enabled, this.renderingPipeline.chromaticAberration.aberrationAmount = ((c = e.chromaticAberration) == null ? void 0 : c.aberrationAmount) ?? d.chromaticAberration.aberrationAmount, this.renderingPipeline.chromaticAberration.radialIntensity = ((u = e.chromaticAberration) == null ? void 0 : u.radialIntensity) ?? d.chromaticAberration.radialIntensity, this.renderingPipeline.chromaticAberration.direction = (m = e.chromaticAberration) != null && m.direction ? new se(
1352
1352
  e.chromaticAberration.direction.x,
1353
1353
  e.chromaticAberration.direction.y
1354
1354
  ) : new se(
@@ -1369,19 +1369,19 @@ class st {
1369
1369
  if (this.renderingPipeline.depthOfField.focalLength = ((z = e.depthOfField) == null ? void 0 : z.focalLength) ?? d.depthOfField.focalLength, this.renderingPipeline.depthOfField.fStop = ((N = e.depthOfField) == null ? void 0 : N.fStop) ?? d.depthOfField.fStop, this.renderingPipeline.depthOfField.focusDistance = ((q = e.depthOfField) == null ? void 0 : q.focusDistance) ?? d.depthOfField.focusDistance, this.renderingPipeline.depthOfField.lensSize = ((V = e.depthOfField) == null ? void 0 : V.lensSize) ?? d.depthOfField.lensSize, this.renderingPipeline.grainEnabled = ((_ = e.grain) == null ? void 0 : _.enabled) ?? d.grain.enabled, this.renderingPipeline.grain.animated = ((G = e.grain) == null ? void 0 : G.animated) ?? d.grain.animated, this.renderingPipeline.grain.intensity = ((H = e.grain) == null ? void 0 : H.intensity) ?? d.grain.intensity, this.renderingPipeline.imageProcessing.contrast = ((U = e.misc) == null ? void 0 : U.contrast) ?? d.misc.contrast, this.renderingPipeline.imageProcessing.exposure = ((K = e.misc) == null ? void 0 : K.exposure) ?? d.misc.exposure, this.renderingPipeline.imageProcessing.toneMappingEnabled = ((W = e.misc) == null ? void 0 : W.toneMappingEnabled) ?? d.misc.toneMappingEnabled, this.renderingPipeline.imageProcessing.toneMappingEnabled)
1370
1370
  switch (e.misc.toneMappingType ?? d.misc.toneMappingType) {
1371
1371
  case "Standard":
1372
- this.renderingPipeline.imageProcessing.toneMappingType = M.TONEMAPPING_STANDARD;
1372
+ this.renderingPipeline.imageProcessing.toneMappingType = x.TONEMAPPING_STANDARD;
1373
1373
  break;
1374
1374
  case "ACES":
1375
- this.renderingPipeline.imageProcessing.toneMappingType = M.TONEMAPPING_ACES;
1375
+ this.renderingPipeline.imageProcessing.toneMappingType = x.TONEMAPPING_ACES;
1376
1376
  break;
1377
1377
  }
1378
1378
  if (this.renderingPipeline.sharpenEnabled = (($ = e.sharpen) == null ? void 0 : $.enabled) ?? d.sharpen.enabled, this.renderingPipeline.sharpen.colorAmount = ((Y = e.sharpen) == null ? void 0 : Y.colorAmount) ?? d.sharpen.colorAmount, this.renderingPipeline.sharpen.edgeAmount = ((Q = e.sharpen) == null ? void 0 : Q.edgeAmount) ?? d.sharpen.edgeAmount, this.renderingPipeline.imageProcessing.vignetteEnabled = ((Z = e.vignette) == null ? void 0 : Z.enabled) ?? d.vignette.enabled, (j = e.vignette) != null && j.center ? (this.renderingPipeline.imageProcessing.vignetteCenterX = e.vignette.center.x, this.renderingPipeline.imageProcessing.vignetteCenterY = e.vignette.center.y) : (this.renderingPipeline.imageProcessing.vignetteCenterX = d.vignette.center.x, this.renderingPipeline.imageProcessing.vignetteCenterY = d.vignette.center.y), e.vignette)
1379
1379
  switch (((X = e.vignette) == null ? void 0 : X.blendMode) ?? d.vignette.blendMode) {
1380
1380
  case "Multiply":
1381
- this.renderingPipeline.imageProcessing.vignetteBlendMode = M.VIGNETTEMODE_MULTIPLY;
1381
+ this.renderingPipeline.imageProcessing.vignetteBlendMode = x.VIGNETTEMODE_MULTIPLY;
1382
1382
  break;
1383
1383
  case "Opaque":
1384
- this.renderingPipeline.imageProcessing.vignetteBlendMode = M.VIGNETTEMODE_OPAQUE;
1384
+ this.renderingPipeline.imageProcessing.vignetteBlendMode = x.VIGNETTEMODE_OPAQUE;
1385
1385
  break;
1386
1386
  }
1387
1387
  (J = e.vignette) != null && J.colorRgba ? this.renderingPipeline.imageProcessing.vignetteColor = new b(
@@ -1419,22 +1419,22 @@ function L(r) {
1419
1419
  }
1420
1420
  class $t {
1421
1421
  constructor(e) {
1422
- var h;
1422
+ var l;
1423
1423
  this.focusLostNotified = !1, this.focusLostObservable = new C(), this.modelLoadEventCallbacks = [], this.modelContainers = /* @__PURE__ */ new Map(), this.plugins = [], this.initComplete = !1, this.isAnimatingCamera = !1, this.renderLoop = () => {
1424
1424
  if (!this.engine.views)
1425
1425
  return;
1426
1426
  this.modelContainers.forEach((u) => {
1427
1427
  u.updateDynamicTextures();
1428
1428
  }), this.scene.autoClear = !0, this.scene.autoClearDepthAndStencil = !0;
1429
- const l = this.engine.getRenderingCanvas();
1430
- if (l)
1431
- if (l.getContext("webgl2") ?? l.getContext("webgl")) {
1432
- const u = this.configuration.scene.clearColor, m = l.getContext("webgl2") ?? l.getContext("webgl");
1429
+ const h = this.engine.getRenderingCanvas();
1430
+ if (h)
1431
+ if (h.getContext("webgl2") ?? h.getContext("webgl")) {
1432
+ const u = this.configuration.scene.clearColor, m = h.getContext("webgl2") ?? h.getContext("webgl");
1433
1433
  m.clearDepth(1), m.depthFunc(m.LEQUAL), m.clearStencil(0), m.clearColor(u.r, u.g, u.b, u.a), m.clear(
1434
1434
  m.COLOR_BUFFER_BIT | m.DEPTH_BUFFER_BIT | m.STENCIL_BUFFER_BIT
1435
1435
  );
1436
1436
  } else
1437
- l.getContext("2d") ? l.getContext("2d").clearRect(0, 0, l.width, l.height) : console.error(
1437
+ h.getContext("2d") ? h.getContext("2d").clearRect(0, 0, h.width, h.height) : console.error(
1438
1438
  "SpiffCommerce: Failed to get any context on the rendering canvas."
1439
1439
  );
1440
1440
  this.scene.render(), this.camera.isRunningFramingBehavior && this.camera.getFramingBehavior().isUserIsMoving && (this.camera.isRunningFramingBehavior = !1);
@@ -1445,7 +1445,7 @@ class $t {
1445
1445
  if (!(e != null && e.noRender))
1446
1446
  return this.configuration.createCanvas();
1447
1447
  })(), n = "1.5.6";
1448
- xe.Configuration = {
1448
+ Ae.Configuration = {
1449
1449
  decoder: {
1450
1450
  wasmUrl: `https://www.gstatic.com/draco/versioned/decoders/${n}/draco_wasm_wrapper_gltf.js`,
1451
1451
  wasmBinaryUrl: `https://www.gstatic.com/draco/versioned/decoders/${n}/draco_decoder_gltf.wasm`,
@@ -1464,7 +1464,7 @@ class $t {
1464
1464
  stencil: this.configuration.highlights.enabled,
1465
1465
  forceSRGBBufferSupportState: !0
1466
1466
  }) : new Ce();
1467
- console.log = s, o.hideLoadingUI(), window.addEventListener("resize", this.fireResizeEvent.bind(this)), this.engine = o, this.scene = new Me(o), this.camera = k.create(this.scene, this.configuration), this.scene.activeCamera = this.camera, this.renderingPipeline = new st(
1467
+ console.log = s, o.hideLoadingUI(), window.addEventListener("resize", this.fireResizeEvent.bind(this)), this.engine = o, this.scene = new xe(o), this.camera = k.create(this.scene, this.configuration), this.scene.activeCamera = this.camera, this.renderingPipeline = new st(
1468
1468
  this.scene,
1469
1469
  !1,
1470
1470
  this.camera
@@ -1473,14 +1473,14 @@ class $t {
1473
1473
  this.configuration.scene.environment.file,
1474
1474
  this.scene
1475
1475
  );
1476
- a.name = "initial-environment-cube", a.rotationY = this.configuration.scene.environment.rotationY, this.scene.environmentTexture = a, this.scene.environmentIntensity = this.configuration.scene.environment.intensity, (h = this.configuration.options) != null && h.renderingPipelineConfiguration ? this.renderingPipeline.setConfiguration(
1476
+ a.name = "initial-environment-cube", a.rotationY = this.configuration.scene.environment.rotationY, this.scene.environmentTexture = a, this.scene.environmentIntensity = this.configuration.scene.environment.intensity, (l = this.configuration.options) != null && l.renderingPipelineConfiguration ? this.renderingPipeline.setConfiguration(
1477
1477
  this.configuration.options.renderingPipelineConfiguration
1478
1478
  ) : (this.scene.imageProcessingConfiguration.exposure = this.configuration.lighting.exposure, this.scene.imageProcessingConfiguration.contrast = this.configuration.lighting.contrast), this.glowLayerManager = new Ge(
1479
1479
  this.scene,
1480
1480
  this.configuration.emissiveGlowIntensity
1481
- ), this.initPromise = new Promise((l) => {
1481
+ ), this.initPromise = new Promise((h) => {
1482
1482
  this.scene.onReadyObservable.addOnce(() => {
1483
- this.initComplete = !0, l();
1483
+ this.initComplete = !0, h();
1484
1484
  });
1485
1485
  }), this.engine.runRenderLoop(this.renderLoop);
1486
1486
  }
@@ -1613,7 +1613,7 @@ class $t {
1613
1613
  try {
1614
1614
  const n = t.latDeg * Math.PI / 180, s = t.lonDeg * Math.PI / 180;
1615
1615
  i.target = t.target ? new p(t.target.x, t.target.y, t.target.z) : p.Zero(), i.alpha = s, i.beta = n, i.radius = t.radius || this.camera.radius, i.minZ = 0.01, this.scene.render();
1616
- const o = await Ae.CreateScreenshotUsingRenderTargetAsync(
1616
+ const o = await Me.CreateScreenshotUsingRenderTargetAsync(
1617
1617
  this.engine,
1618
1618
  i,
1619
1619
  e,
@@ -1633,8 +1633,8 @@ class $t {
1633
1633
  const t = e.camera.limits.min.alpha, i = e.camera.limits.max.alpha, n = e.camera.limits.min.beta, s = e.camera.limits.max.beta;
1634
1634
  if (t === void 0 || i === void 0 || n === void 0 || s === void 0)
1635
1635
  return !0;
1636
- const o = [t, i], a = [n, s], h = o.every((c) => c === t), l = a.every((c) => c === n);
1637
- return !h && !l;
1636
+ const o = [t, i], a = [n, s], l = o.every((c) => c === t), h = a.every((c) => c === n);
1637
+ return !l && !h;
1638
1638
  }
1639
1639
  fireResizeEvent() {
1640
1640
  this.getNumViewports() > 0 && this.engine.resize();
@@ -1653,8 +1653,8 @@ class $t {
1653
1653
  );
1654
1654
  o && o.getBindedMeshes().forEach(
1655
1655
  (a) => {
1656
- var h;
1657
- return (h = this.highlightLayer) == null ? void 0 : h.addMesh(
1656
+ var l;
1657
+ return (l = this.highlightLayer) == null ? void 0 : l.addMesh(
1658
1658
  a,
1659
1659
  i || w.FromHexString("#fcba03")
1660
1660
  );
@@ -1733,11 +1733,11 @@ class $t {
1733
1733
  O(t || { x: 0, y: 0, z: 0 })
1734
1734
  ),
1735
1735
  O(e || { x: 0, y: 0, z: 0 })
1736
- ), s = re.RotationAxis(p.Up(), Math.PI), o = n.multiply(s), a = p.Zero(), h = y.Identity(), l = p.Zero();
1737
- return o.decompose(l, h, a), h.multiplyInPlace(y.FromEulerAngles(0, Math.PI, 0)), {
1736
+ ), s = re.RotationAxis(p.Up(), Math.PI), o = n.multiply(s), a = p.Zero(), l = y.Identity(), h = p.Zero();
1737
+ return o.decompose(h, l, a), l.multiplyInPlace(y.FromEulerAngles(0, Math.PI, 0)), {
1738
1738
  position: L(a),
1739
- rotation: L(h.toEulerAngles()),
1740
- scale: L(l)
1739
+ rotation: L(l.toEulerAngles()),
1740
+ scale: L(h)
1741
1741
  };
1742
1742
  }
1743
1743
  updatePreviewOptions(e) {
@@ -1772,7 +1772,7 @@ export {
1772
1772
  F as MaterialEffectMode,
1773
1773
  I as ProductCameraRig,
1774
1774
  Ve as REFLECTION_PROBE_RESOLUTION,
1775
- A as RenderingConfiguration,
1775
+ M as RenderingConfiguration,
1776
1776
  $t as SpiffCommerce3DPreviewService,
1777
1777
  d as renderingPipelineDefaults
1778
1778
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("@babylonjs/core/Cameras/arcRotateCamera"),require("@babylonjs/core/Engines/engine"),require("@babylonjs/core/Engines/nullEngine"),require("@babylonjs/core/Layers/highlightLayer"),require("@babylonjs/core/Loading/sceneLoader"),require("@babylonjs/core/Materials/Textures/cubeTexture"),require("@babylonjs/core/Maths/math.color"),require("@babylonjs/core/Maths/math.vector"),require("@babylonjs/core/Meshes/Compression/dracoCompression"),require("@babylonjs/core/Misc/observable"),require("@babylonjs/core/Misc/tools"),require("@babylonjs/core/scene"),require("@babylonjs/loaders/glTF"),require("@babylonjs/loaders/glTF/glTFFileLoader"),require("@babylonjs/core/Materials/PBR/pbrMaterial"),require("@babylonjs/core/Materials/Textures/mirrorTexture"),require("@babylonjs/core/Maths/math"),require("@babylonjs/core/Probes/reflectionProbe"),require("@babylonjs/core/Layers/glowLayer"),require("@babylonjs/core/Actions/actionManager"),require("@babylonjs/core/Actions/directActions"),require("@babylonjs/core/Meshes/mesh"),require("@babylonjs/core/Meshes/transformNode"),require("@babylonjs/core/Materials/Textures/dynamicTexture"),require("@babylonjs/core/Materials/Textures/texture"),require("@babylonjs/core/Animations/animation"),require("@babylonjs/core/Animations/easing"),require("@babylonjs/core/Misc/assetsManager"),require("@babylonjs/core/Materials/colorCurves"),require("@babylonjs/core/Materials/imageProcessingConfiguration"),require("@babylonjs/core/PostProcesses/RenderPipeline"),require("@babylonjs/core/PostProcesses/depthOfFieldEffect"),require("@babylonjs/core/Rendering/depthRendererSceneComponent"),require("@babylonjs/core/Engines/Extensions/engine.views"),require("@babylonjs/core/Meshes/instancedMesh"),require("@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/envTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader"),require("@babylonjs/core/Animations/animatable"),require("@babylonjs/core/Misc/screenshotTools"),require("@babylonjs/core/Rendering/boundingBoxRenderer"),require("@babylonjs/loaders/glTF/2.0/Extensions")):typeof define=="function"&&define.amd?define(["exports","@babylonjs/core/Cameras/arcRotateCamera","@babylonjs/core/Engines/engine","@babylonjs/core/Engines/nullEngine","@babylonjs/core/Layers/highlightLayer","@babylonjs/core/Loading/sceneLoader","@babylonjs/core/Materials/Textures/cubeTexture","@babylonjs/core/Maths/math.color","@babylonjs/core/Maths/math.vector","@babylonjs/core/Meshes/Compression/dracoCompression","@babylonjs/core/Misc/observable","@babylonjs/core/Misc/tools","@babylonjs/core/scene","@babylonjs/loaders/glTF","@babylonjs/loaders/glTF/glTFFileLoader","@babylonjs/core/Materials/PBR/pbrMaterial","@babylonjs/core/Materials/Textures/mirrorTexture","@babylonjs/core/Maths/math","@babylonjs/core/Probes/reflectionProbe","@babylonjs/core/Layers/glowLayer","@babylonjs/core/Actions/actionManager","@babylonjs/core/Actions/directActions","@babylonjs/core/Meshes/mesh","@babylonjs/core/Meshes/transformNode","@babylonjs/core/Materials/Textures/dynamicTexture","@babylonjs/core/Materials/Textures/texture","@babylonjs/core/Animations/animation","@babylonjs/core/Animations/easing","@babylonjs/core/Misc/assetsManager","@babylonjs/core/Materials/colorCurves","@babylonjs/core/Materials/imageProcessingConfiguration","@babylonjs/core/PostProcesses/RenderPipeline","@babylonjs/core/PostProcesses/depthOfFieldEffect","@babylonjs/core/Rendering/depthRendererSceneComponent","@babylonjs/core/Engines/Extensions/engine.views","@babylonjs/core/Meshes/instancedMesh","@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader","@babylonjs/core/Materials/Textures/Loaders/envTextureLoader","@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader","@babylonjs/core/Animations/animatable","@babylonjs/core/Misc/screenshotTools","@babylonjs/core/Rendering/boundingBoxRenderer","@babylonjs/loaders/glTF/2.0/Extensions"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.Preview={},d.arcRotateCamera,d.engine,d.nullEngine,d.highlightLayer,d.sceneLoader,d.cubeTexture,d.math_color,d.math_vector,d.dracoCompression,d.observable,d.tools,d.scene,d.glTF,d.glTFFileLoader,d.pbrMaterial,d.mirrorTexture,d.math,d.reflectionProbe,d.glowLayer,d.actionManager,d.directActions,d.mesh,d.transformNode,d.dynamicTexture,d.texture,d.animation,d.easing,d.assetsManager,d.colorCurves,d.imageProcessingConfiguration,d.RenderPipeline,d.depthOfFieldEffect))})(this,function(d,y,V,ye,Ce,L,k,b,p,we,M,Me,xe,Ae,Pe,O,Te,A,Re,Ee,F,N,Le,Oe,Fe,Ie,C,z,Se,G,P,Be,I){"use strict";var T=(r=>(r[r.Orbit=0]="Orbit",r[r.Pan=1]="Pan",r))(T||{}),R=(r=>(r.None="None",r.RemoveWhenSelected="RemoveWhenSelected",r.ApplyWhenSelected="ApplyWhenSelected",r))(R||{});const H=new Map;async function S(r,e,t){const i=await H.get(r);if(i&&i.scene.uid===e.uid)return i;const n=L.SceneLoader.LoadAssetContainerAsync(r,void 0,e,t);return H.set(r,n),n}L.SceneLoader.OnPluginActivatedObservable.add(r=>{r.name==="gltf"&&(r.animationStartMode=Pe.GLTFLoaderAnimationStartMode.NONE)});class U{constructor(e){this.getSceneClearColor=()=>{var i,n,s,o;const t=(i=this.customOptions)!=null&&i.transparentBackground||(n=this.customOptions)!=null&&n.backgroundImage?0:1;if(this.customOptions&&((s=this.customOptions)!=null&&s.transparentBackground)||(o=this.customOptions)!=null&&o.backgroundImage)return new b.Color4(0,0,0,t).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const a=b.Color3.FromHexString(this.customOptions.backgroundColor);return new b.Color4(a.r,a.g,a.b,t).toLinearSpace()}return new b.Color4(.98,.98,.98,t).toLinearSpace()},this.highlightColorFromConfig=()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new b.Color4(.98,.98,.98,1).toLinearSpace(),this.hexToColor4=(t,i=1)=>{const n=b.Color3.FromHexString(t);return new b.Color4(n.r,n.g,n.b,i).toLinearSpace()},this.customOptions=e}createCanvas(){var e;return(e=this.customOptions)!=null&&e.createCanvas?this.customOptions.createCanvas():document.createElement("canvas")}get options(){return this.customOptions}get scene(){var e,t,i,n,s;return{clearColor:this.getSceneClearColor(),transparentBackground:((e=this.customOptions)==null?void 0:e.transparentBackground)||((t=this.customOptions)==null?void 0:t.backgroundImage),environment:{file:((i=this.customOptions)==null?void 0:i.environmentFile)??"assets/model-viewer/default.env",intensity:((n=this.customOptions)==null?void 0:n.environmentIntensity)??1,rotationY:(((s=this.customOptions)==null?void 0:s.environmentRotationY)??0)*(Math.PI/180)}}}get camera(){var e,t,i,n,s,o,a,h,l,c,g,m,f;return{autoOrientation:((e=this.customOptions)==null?void 0:e.disableAutomaticOrientation)??!0,autoRotation:{enabled:((t=this.customOptions)==null?void 0:t.autoRotation)??!1,idleTimeMs:((i=this.customOptions)==null?void 0:i.idleTimeBeforeRotation)??5e3},limits:{min:{alpha:(n=this.customOptions)!=null&&n.lowerAlphaLimitDeg?((s=this.customOptions)==null?void 0:s.lowerAlphaLimitDeg)*Math.PI/180:void 0,beta:(o=this.customOptions)!=null&&o.lowerBetaLimitDeg?((a=this.customOptions)==null?void 0:a.lowerBetaLimitDeg)*Math.PI/180:void 0,radius:(h=this.customOptions)==null?void 0:h.minZoomOverride},max:{alpha:(l=this.customOptions)!=null&&l.upperAlphaLimitDeg?((c=this.customOptions)==null?void 0:c.upperAlphaLimitDeg)*Math.PI/180:void 0,beta:(g=this.customOptions)!=null&&g.upperBetaLimitDeg?((m=this.customOptions)==null?void 0:m.upperBetaLimitDeg)*Math.PI/180:void 0,radius:(f=this.customOptions)==null?void 0:f.maxZoomOverride}}}}get highlights(){var e;return{enabled:((e=this.customOptions)==null?void 0:e.highlightOnMaterialHover)??!1,color:this.highlightColorFromConfig()}}get lighting(){var e,t,i,n;return{exposure:((t=(e=this.customOptions)==null?void 0:e.lighting)==null?void 0:t.exposure)??.9,contrast:((n=(i=this.customOptions)==null?void 0:i.lighting)==null?void 0:n.contrast)??1.6}}get emissiveGlowIntensity(){var e;return((e=this.customOptions)==null?void 0:e.emissiveGlowIntensity)??.5}}class w{static getDynamicTextureResolution(){return this.getIsMobile()||!w.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return navigator.userAgent.includes("SamsungBrowser")?!1:!!window.Worker&&!!window.OffscreenCanvas}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){try{return typeof window>"u"||!window.navigator?!1:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent)||window.innerWidth/window.devicePixelRatio<=480}catch{return!1}}}const K=128,u={antiAliasing:{samples:4,fxaaEnabled:!1},bloom:{enabled:!1,kernel:64,scale:.5,threshold:.9,weight:.15},chromaticAberration:{enabled:!1,aberrationAmount:30,direction:{x:0,y:0},radialIntensity:0},colorCurves:{enabled:!1},depthOfField:{enabled:!1,blurLevel:"Low",focalLength:50,focusDistance:2e3,fStop:1.4,lensSize:50},grain:{enabled:!1,animated:!1,intensity:30},misc:{contrast:1,exposure:1,toneMappingEnabled:!1,toneMappingType:"Standard"},sharpen:{enabled:!1,colorAmount:1,edgeAmount:.3},vignette:{enabled:!1,blendMode:"Multiply",cameraFov:.5,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};class je{constructor(e){this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,t,i){return this.loader.loadNodeAsync(e,t,function(n){t.extras&&Object.keys(t.extras).forEach(s=>{const o=t.extras[s];n.metadata[s]=o}),i(n)})}async loadMaterialPropertiesAsync(e,t,i){await this.loader.loadMaterialPropertiesAsync(e,t,i),this.enableMaterialExtrasIfRequired(t,i),i.needDepthPrePass=!0}dispose(){}enableMaterialExtrasIfRequired(e,t){if(!(!e.extras||!(t instanceof O.PBRMaterial))){if(e.extras.sheen){const i=t;i.sheen.isEnabled=!0,i.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const i=t;i.subSurface.isTranslucencyEnabled=!0,i.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(i.subSurface.tintColor=new A.Color3(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const i=t;i.subSurface.isRefractionEnabled=!0,i.subSurface.volumeIndexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const i=t;i.needDepthPrePass=!0,i.forceIrradianceInFragment=!0}if(e.extras.useParallax){const i=t;i.useParallax=!0,i.useParallaxOcclusion=!0,i.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function t(s){const o=[];return s.transformNodes.forEach(a=>{a.metadata&&a.metadata.reflective&&o.push(...a.getChildMeshes())}),s.meshes.forEach(a=>{a.metadata&&a.metadata.reflective&&!o.includes(a)&&o.push(a)}),o}function i(s,o=1){const a=s.material;if(!a)return;const h=new Te.MirrorTexture("mirror",w.getMirrorTextureResolution(),e,!0);h.renderList=t(e);const l=s.getVerticesData("normal");if(!l)throw new Error("Mirror attribute specified on: "+s.name+"But no normals exist to generate a mirror from!");s.computeWorldMatrix(!0);const c=s.getWorldMatrix(),g=A.Vector3.TransformNormal(new A.Vector3(l[0],l[1],l[2]),c).normalize(),m=A.Plane.FromPositionAndNormal(s.position,g.scale(-1));h.mirrorPlane=m,h.level=o,a.reflectionTexture=h}function n(s){const o=s.material,a=new Re.ReflectionProbe("probe-"+o.name,K,e);a.cubeTexture.name="reflection-probe-cube-texture",a.attachToMesh(s),a.renderList&&a.renderList.push(...t(e)),o.reflectionTexture=a.cubeTexture}e.meshes.forEach(s=>{const o=s.metadata;o&&(o.mirrorTexture&&i(s,o.mirrorTexture),o.reflectionProbe&&n(s))})}}class qe{constructor(e,t){this.scene=e,this.intensity=t,this.meshCount=0}setIntensity(e){this.intensity=e,this.glowLayer&&(this.glowLayer.intensity=e)}includeMeshes(e){if(e){this.glowLayer||(this.glowLayer=new Ee.GlowLayer("glow",this.scene),this.glowLayer.intensity=this.intensity);for(const t of e)this.glowLayer.hasMesh(t)||(this.glowLayer.addIncludedOnlyMesh(t),this.meshCount++)}}removeMeshes(e){if(!(!this.glowLayer||!e)){for(const t of e)this.glowLayer.hasMesh(t)&&(this.glowLayer.removeIncludedOnlyMesh(t),this.meshCount--);this.meshCount===0&&(this.glowLayer.dispose(),this.glowLayer=void 0)}}}function De(r,e,t,i,n=""){t.forEach(s=>{const o=s.getID(),a=s.getName(),h=w.getDynamicTextureResolution();r.filter(c=>c.name===n+a).forEach(c=>{console.log(`attaching textures to material ${c.name}`);const g=i.get(o),m=!1;if(g)W(c,g),console.log(`applying current texture ${g.name}`),g.update(m);else{const f=ke(a,e,h.width,h.height);console.log(`created new texture ${f.name}`),i.set(o,f),s.setStaticContext(f.getContext()),W(c,f),f.onLoadObservable.addOnce(()=>{f.update(m)})}})}),Ve(e)}const Ve=r=>{const e=()=>r.textures.reduce((i,n)=>{var o;return!r.meshes.some(a=>a.material&&a.material.hasTexture(n))&&!((o=n==null?void 0:n.url)!=null&&o.includes("data:"))&&!n.name.endsWith(".env")&&i.push(n),i},[]),t=()=>r.materials.reduce((i,n)=>(n.getBindedMeshes().length==0&&i.push(n),i),[]);e().forEach(i=>{try{console.log(`disposing texture ${i.name} (${i.url})`),i.dispose()}catch{console.log(`Failed to dispose texture ${i.name}`)}}),t().forEach(i=>{try{console.log(`disposing material ${i.name}`),i.dispose(!0,!0)}catch{console.log(`Failed to dispose material ${i.name}`)}})};function ke(r,e,t,i){const n=new Fe.DynamicTexture(r,{width:t,height:i},e,w.shouldMipMap(),Ie.Texture.TRILINEAR_SAMPLINGMODE,V.Engine.TEXTUREFORMAT_RGBA),s=n.getContext();return s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,t,i),n.update()),n}function W(r,e){if(r instanceof O.PBRMaterial){const t=r,i=t.albedoTexture;i?(e.wrapU=i.wrapU,e.wrapV=i.wrapV):(e.wrapU=1,e.wrapV=1),t.albedoTexture=e}else{const t=r,i=t.diffuseTexture;i&&(e.wrapU=i.wrapU,e.wrapV=i.wrapV),t.diffuseTexture=e}}function Ne(){const r=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);return r()+r()+"-"+r()+"-"+r()+"-"+r()+"-"+r()+r()+r()}const x=60,Q=1;function $(r){return r.targetedAnimations.map(t=>t.animation.framePerSecond).reduce((t,i)=>t+i,0)/r.targetedAnimations.length||0}function Y(r,e,t,i,n,s){const o=n?r.filter(c=>c.name===n):r;if(o.length===0){console.warn(`No animations found for name: ${n}`);return}let a=0;const h=()=>{a++,a===o.length&&s&&s()},l=(c,g,m,f,v)=>{c.stop(),c.start(g,m,f,v),s&&(g==!1||g===void 0&&!c.loopAnimation?c.onAnimationGroupEndObservable.addOnce(()=>{h()}):c.onAnimationLoopObservable.addOnce(()=>{h()}))};if(i!==void 0&&t!==void 0&&i===t){o.forEach(c=>{const g=$(c),m=i*g;l(c,!1,Q,m,m)});return}o.forEach(c=>{const g=$(c),m=i!==void 0?i*g:void 0,f=t!==void 0?t*g:void 0;l(c,e,Q,m,f)})}function ze(r,e,t){return new Promise(i=>{r.stopAnimation(e),e.animations=[],Math.abs(e.alpha)>2*Math.PI&&(e.alpha=Ge(e.alpha,0,2*Math.PI));const n=[],s=t.target,o=0,a=s?1:0;if(t.target&&Object.keys(t.target).length>0&&n.push(E("cameraTargetLerp","target",new p.Vector3().copyFrom(e.target),new p.Vector3(t.target.x,t.target.y,t.target.z),C.Animation.ANIMATIONTYPE_VECTOR3,o)),n.push(E("cameraAlphaLerp","alpha",e.alpha,Z(t.lonDeg),C.Animation.ANIMATIONTYPE_FLOAT,a)),n.push(E("cameraBetaLerp","beta",e.beta,Z(t.latDeg),C.Animation.ANIMATIONTYPE_FLOAT,a)),t.radius!==void 0){const c=Math.max(.01,t.radius);n.push(E("cameraRadiusLerp","radius",e.radius,c,C.Animation.ANIMATIONTYPE_FLOAT,a))}e.animations.push(...n);const l=e.useAutoRotationBehavior;e.disableAutoRotationBehavior(),r.beginAnimation(e,0,s?x*2:x,!1,1,()=>{e.animations=[],l&&e.enableAutoRotationBehavior(),i()})})}function Z(r){return r*Math.PI/180}function E(r,e,t,i,n,s=0,o=C.Animation.ANIMATIONLOOPMODE_CONSTANT){const a=new z.QuadraticEase;a.setEasingMode(z.EasingFunction.EASINGMODE_EASEINOUT);const h=new C.Animation(r,e,x,n,o),l=[];return s>0&&l.push({frame:0,value:t}),l.push({frame:x*s,value:t}),l.push({frame:x*(s+1),value:i}),h.setKeys(l),h.setEasingFunction(a),h}function Ge(r,e,t){return r<e?r=t-(e-r)%(t-e):r=e+(r-e)%(t-e)}function He(r,e,t){r.forEach(i=>{t&&i.name!==t||i.goToFrame(e)})}const Ue={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap",reflectionTexture:"reflectionMap"};function Ke(r,e,t,i){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture","reflectionTexture"].forEach(s=>{We(s,r,e,t,i)}),Ye(r,e)}function We(r,e,t,i,n){const s=Ue[r];if(!s)throw new Error("Unexpected texture name encountered.");const o=e[s],a=o==null?void 0:o.fileLink;a?r==="reflectionTexture"?a.endsWith(".env")||a.endsWith(".dds")?i.addCubeTextureTask(r,a,void 0,!1,void 0,!0):a.endsWith(".hdr")?i.addHDRCubeTextureTask(r,a,128,!1,!0,!1):i.addTextureTask(r,a,!1,!1):i.addTextureTask(r,a,!1,!1):n&&t[r]&&(t[r]&&t[r].dispose(),t[r]=null,Qe(r,t))}function Qe(r,e){r==="opacityTexture"&&(e.useAlphaFromAlbedoTexture=!0),r==="metallicTexture"&&(e.useRoughnessFromMetallicTextureAlpha=!1,e.useRoughnessFromMetallicTextureGreen=!1,e.useMetallnessFromMetallicTextureBlue=!1),r==="refractionTexture"&&(e.subSurface.isRefractionEnabled=!1,e.subSurface.refractionIntensity=1),r==="reflectionTexture"&&(e.environmentIntensity=1),r==="emissiveTexture"&&(e.emissiveIntensity=0,e.emissiveColor=new b.Color3(0,0,0),e.reflectionTexture)}function $e(r,e,t,i){if(!e){console.error("Failed to apply texture to material: material is null.");return}r==="opacityTexture"&&(e.useAlphaFromAlbedoTexture=!1),r==="metallicTexture"&&(e.useRoughnessFromMetallicTextureAlpha=!1,e.useRoughnessFromMetallicTextureGreen=!0,e.useMetallnessFromMetallicTextureBlue=!0),r==="refractionTexture"&&(e.subSurface.isRefractionEnabled=!0,e.subSurface.refractionIntensity=t.refractionIntensity||1),r==="reflectionTexture"&&(e.environmentIntensity=t.reflectionIntensity||1,i.isCube&&(i.rotationY=t.reflectionRotation?t.reflectionRotation*Math.PI/180:0)),e[r]=i,r==="emissiveTexture"&&(e.emissiveColor=new b.Color3(1,1,1),e.emissiveIntensity=1)}function Ye(r,e){r.clearCoat&&(r.clearCoat===R.RemoveWhenSelected?(e.clearCoat.isEnabled=!1,e.clearCoat.indexOfRefraction=1.5):r.clearCoat===R.ApplyWhenSelected&&(e.clearCoat.isEnabled=!0,e.clearCoat.indexOfRefraction=r.clearCoatIOR||e.clearCoat.indexOfRefraction))}class Ze{constructor(e,t,i){this.materialVariantMap=new Map,this.keysThatRemovedBaseModel=[],this.loadedContainerForKey=new Map,this.loadedMaterialsForKey=new Map,this.scene=e,this.renameClonedAsset=t,this.setBaseModelEnabled=i}async applyMaterial(e,t,i,n){return new Promise(s=>{const o=this.materialVariantMap.get(e);this.materialVariantMap.set(e,{...o,...t});const a=this.renameClonedAsset(e),h=this.scene.materials.filter(c=>c.name===a);if(h.length===0){s();return}const l=new Se.AssetsManager(this.scene);l.useDefaultLoadingScreen=!1,h.forEach(c=>Ke(t,c,l,n)),l.onProgress=(c,g,m)=>{i&&i(c/g*100,100,m.name)},l.onFinish=c=>{c.forEach(g=>{const m=g;i&&i(100,100,g.name),this.scene.materials.filter(v=>v.name===a).forEach(v=>{console.log(`asset manager applying texture ${g.name}`),$e(g.name,v,t,m.texture)})}),s()},l.loadAsync()})}async applyModel(e,t,i,n,s,o,a){var g;if(i&&t&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!i)return this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.length===1&&await this.setBaseModelEnabled(!0),(g=this.loadedContainerForKey.get(e))==null||g.dispose(),this.loadedContainerForKey.delete(e),this.loadedMaterialsForKey.delete(e),this.keysThatRemovedBaseModel=this.keysThatRemovedBaseModel.filter(m=>m!==e),Promise.resolve(void 0);const l=(await S(i,this.scene,n)).instantiateModelsToScene(this.renameClonedAsset,!0);if(this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e).dispose(),this.loadedContainerForKey.delete(e),this.loadedMaterialsForKey.delete(e)),s){const m=o&&o(),f=s.name?this.renameClonedAsset(s.name):void 0;if(Y(l.animationGroups,s.loop,s.to,s.from,f),m!=null){const v=a&&a()||!0;He(l.animationGroups,m+(v?2:0),f)}}t&&await this.setBaseModelEnabled(!1),this.loadedContainerForKey.set(e,l),this.loadedMaterialsForKey.set(e,_(l));const c=[];return this.materialVariantMap.forEach(async(m,f)=>{c.push(this.applyMaterial(f,m))}),await Promise.all(c),l}dispose(){this.loadedContainerForKey.forEach(e=>e==null?void 0:e.dispose()),this.loadedContainerForKey.clear(),this.loadedMaterialsForKey.forEach(e=>e.forEach(t=>t==null?void 0:t.dispose())),this.loadedMaterialsForKey.clear(),this.materialVariantMap.clear(),this.keysThatRemovedBaseModel=[]}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach(t=>{t.forEach(i=>{e.includes(i)||e.push(i)})}),e}getAnimationGroups(){const e=[];return this.loadedContainerForKey.forEach(t=>{e.push(...t.animationGroups)}),e}}function _(r){const e=[];return r.rootNodes.forEach(t=>{t.getChildMeshes().forEach(i=>{i.material&&!e.includes(i.material)&&e.push(i.material),i.subMeshes&&i.subMeshes.forEach(n=>{const s=n.getMaterial(!1);s&&!e.includes(s)&&e.push(s)})})}),e}function X(r,e=""){return r.map(t=>({name:t.name.substring(e.length),loop:t.loopAnimation,to:t.to,from:t.from}))}class _e{constructor(e){this.metadata=new Map,this.materialSelectedObservable=new M.Observable,this.materialDeselectedObservable=new M.Observable,this.materialVariantObservable=new M.Observable,this.modelVariantObservable=new M.Observable,this.materialReadyToLoadCallbacks=new Map,this.modelReadyToLoadCallbacks=new Map,this.dynamicTextures=new Map,this.queuedMaterialChanges=new Map,this.materialChangesInProgress=[],this.queuedModelChanges=new Map,this.modelChangesInProgress=[],this.isExecutingAnimation=!1,this.animations=[],this.initialized=!1,this.materials=[];const{enablePicking:t,modelDetails:i,previewService:n,progressHandler:s,scene:o}=e;this.enablePicking=t,this.contextService=i.contextService,this.id=Ne(),this.previewService=n,this.scene=o,this.variantManager=new Ze(o,this.renameClonedAsset.bind(this),this.setBaseModelEnabled.bind(this)),this.transformRoot=new Oe.TransformNode("root",this.scene);const a=async()=>{if(!i.model)throw new Error("Model container constructed with no URL. This is currently unsupported.");return this.assetContainer=await S(i.model,o,s),await this.instantiate(),this};this.importPromise=a()}async applyMaterialVariant(e,t,i,n){if(!this.initialized){if(this.materialReadyToLoadCallbacks.has(e)){const o=this.materialReadyToLoadCallbacks.get(e);o==null||o.set(t,this.applyMaterialVariant.bind(this,e,t,i,n))}else{this.materialReadyToLoadCallbacks.set(e,new Map);const o=this.materialReadyToLoadCallbacks.get(e);o==null||o.set(t,this.applyMaterialVariant.bind(this,e,t,i,n))}return}const s=async()=>{await this.variantManager.applyMaterial(e,i,(o,a,h)=>{this.materialVariantObservable.notifyObservers({remainingCount:o,totalCount:a,taskName:h})},n)};if(this.materialChangesInProgress.includes(e)){if(this.queuedMaterialChanges.has(e)){const o=this.queuedMaterialChanges.get(e);o==null||o.set(t,s)}else{this.queuedMaterialChanges.set(e,new Map);const o=this.queuedMaterialChanges.get(e);o==null||o.set(t,s)}return}if(this.materialChangesInProgress.push(e),await s(),this.queuedMaterialChanges.has(e)){const o=this.queuedMaterialChanges.get(e);if(!o)throw new Error("Target material is undefined");o.forEach(async a=>{await a()}),this.queuedMaterialChanges.delete(e)}this.materialChangesInProgress.splice(this.materialChangesInProgress.indexOf(e),1),this.configureGlowLayer()}async applyModelVariant(e,t,i){if(!this.initialized){this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,t,i));return}const n=()=>this.variantManager.applyModel(e,i,t==null?void 0:t.model,a=>{this.modelVariantObservable.notifyObservers({...a,key:e})},this.lastPlayedAnimation,this.getCurrentAnimationFrame.bind(this),this.getAnimationIsPlaying.bind(this));if(this.modelChangesInProgress.includes(e)){this.queuedModelChanges.set(e,n);return}const o=await(async()=>{this.modelChangesInProgress.push(e);let a=await n();if(this.queuedModelChanges.has(e)){const h=this.queuedModelChanges.get(e);if(!h)throw new Error("Queued change resolved undefined");a=await h(),this.queuedModelChanges.delete(e)}return this.modelChangesInProgress.splice(this.modelChangesInProgress.indexOf(e),1),a})();this.contextService||(this.contextService=t==null?void 0:t.contextService),o?this.configureModelInstance(o):this.configureGlowLayer()}dispose(){var e;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)}executeAnimation(e){if(!this.initialized)return this.queuedModelAnimation=e,Promise.resolve();let t=()=>{};const i=async()=>{this.lastPlayedAnimation=e,this.isExecutingAnimation=!0,await new Promise(n=>{var o;const s=[...((o=this.modelInstance)==null?void 0:o.animationGroups)||[],...this.variantManager.getAnimationGroups()];Y(s,e.loop,e.to,e.from,e.name?this.renameClonedAsset(e.name):void 0,n)}),this.isExecutingAnimation=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,t()};return this.isExecutingAnimation?(this.queuedAnimationFunction=i,new Promise(n=>{t=n})):i()}getAnimations(e){return[...this.animations,...e?X(this.variantManager.getAnimationGroups(),this.renameClonedAsset("")):[]].map((t,i)=>({...t,name:t.name||`UNNAMED_ANIMATION_${i}`})).filter((t,i,n)=>n.indexOf(n.find(s=>s.name===t.name))==i)}getId(){return this.id}listMaterials(){var t;const e=(t=this.scene)==null?void 0:t.materials.filter(i=>i.name.startsWith(this.id));return e?e.map(i=>({id:i.id,name:this.stripIdFromName(i.name)})):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to requesting position!");return this.transformRoot.position}set position(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting position!");this.transformRoot.position=new p.Vector3(e.x,e.y,e.z)}get rotation(){var e;if(!((e=this.transformRoot)!=null&&e.rotationQuaternion))throw new Error("ModelContainer disposed prior to requesting rotation!");return this.transformRoot.rotationQuaternion.toEulerAngles()}set rotation(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting rotation!");this.transformRoot.rotationQuaternion=p.Quaternion.FromEulerAngles(e.x,e.y,e.z)}get scale(){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to requesting scale!");return this.transformRoot.scaling}set scale(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting scale!");this.transformRoot.scaling=new p.Vector3(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach(t=>{t.getChildMeshes(!1).forEach(i=>{i.name==="targetcube_t"||i.name==="backgroundShell"||(i.actionManager||(i.actionManager=new F.ActionManager(this.scene)),i.actionManager.registerAction(new N.ExecuteCodeAction(F.ActionManager.OnPointerOverTrigger,n=>{n.meshUnderPointer&&i.material&&this.materialSelectedObservable.notifyObservers({id:i.material.id,name:this.stripIdFromName(i.material.name)})})),i.actionManager.registerAction(new N.ExecuteCodeAction(F.ActionManager.OnPointerOutTrigger,()=>{i.material&&this.materialDeselectedObservable.notifyObservers({id:i.material.id,name:this.stripIdFromName(i.material.name)})})))})})}getInitializationPromise(){return this.importPromise}getIsInitialized(){return this.initialized}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureGlowLayer(){const e=i=>i instanceof O.PBRMaterial&&i.emissiveTexture!==null;this.materials.some(e)||this.variantManager.getAllMaterials().some(e)?this.previewService.getGlowLayerManager().includeMeshes(this.getAllMeshes()):this.previewService.getGlowLayerManager().removeMeshes(this.getAllMeshes())}configureModelInstance(e){var s;if(!this.transformRoot)throw new Error("Transform disposed! This should never happen unless there is a race condition present!");const t=this.transformRoot.position,i=this.transformRoot.rotationQuaternion,n=this.transformRoot.scaling;this.transformRoot.position=p.Vector3.Zero(),this.transformRoot.rotationQuaternion=p.Quaternion.Identity(),this.transformRoot.scaling=p.Vector3.One();for(const o of e.rootNodes){o.parent=this.transformRoot;for(const a of o.getChildMeshes(!1))a.alwaysSelectAsActiveMesh=!0}this.transformRoot.position=t,this.transformRoot.rotationQuaternion=i,this.transformRoot.scaling=n,this.canvasPanels=((s=this.contextService)==null?void 0:s.getAll())||new Map,De(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.enablePicking&&this.attachPickingHandler(e),this.configureGlowLayer()}destroyInstance(){var e;(e=this.modelInstance)==null||e.dispose(),this.modelInstance=void 0}getAllMeshes(){var e;return(e=this.modelInstance)==null?void 0:e.rootNodes.map(t=>t.getChildMeshes(!1).filter(i=>i instanceof Le.Mesh)).flat()}async instantiate(){if(!this.assetContainer)throw new Error("Attempted to instantiate ModelContainer without an AssetContainer");this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=_(this.modelInstance),this.configureModelInstance(this.modelInstance),this.animations=X(this.modelInstance.animationGroups,this.renameClonedAsset("")),this.initialized=!0,await this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}async setBaseModelEnabled(e){e&&!this.modelInstance?await this.instantiate():!e&&this.modelInstance&&this.destroyInstance()}updateDynamicTextures(){var e;(e=this.canvasPanels)==null||e.forEach((t,i)=>{const n=this.dynamicTextures.get(i);n&&t.getStaticContextDirty()&&n.isReady()&&(n.update(!1),t.setStaticContextDirty(!1))})}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}getCurrentAnimationFrame(){var t;const e=[...((t=this.modelInstance)==null?void 0:t.animationGroups)||[],...this.variantManager.getAnimationGroups()];for(const i of e)if(i.animatables.length>0&&i.animatables[0].masterFrame!==void 0&&i.animatables[0].masterFrame!==null)return i.animatables[0].masterFrame;return 0}getAnimationIsPlaying(){var t;const e=[...((t=this.modelInstance)==null?void 0:t.animationGroups)||[],...this.variantManager.getAnimationGroups()];for(const i of e)if(i.isPlaying)return!0;return!1}stripIdFromName(e){return e.substring(this.id.length+1)}async processQueuedEvents(){await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).flatMap(e=>Array.from(e.values()).map(t=>t()))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map(e=>e())),this.modelReadyToLoadCallbacks.clear(),this.scene.onAfterRenderObservable.addOnce(()=>{this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0)})}}class B extends y.ArcRotateCamera{constructor(e,t,i,n,s,o,a,h){super(e,t,i,n,s,o,h),this.lastFocus=new p.Vector3(0,0,0),this._isRunningFramingBehavior=!1,this.panDenominator=1,this.panEnabled=!0,this.minZ=.01,this.updateRadiusBounds(this.radius),this.enableFramingBehavior(),this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,a.camera.autoOrientation&&(this.alpha+=Math.PI),a&&(a.camera.limits.min.beta&&(this.lowerBetaLimit=a.camera.limits.min.beta),a.camera.limits.max.beta&&(this.upperBetaLimit=a.camera.limits.max.beta),a.camera.limits.min.alpha&&(this.lowerAlphaLimit=a.camera.limits.min.alpha),a.camera.limits.max.alpha&&(this.upperAlphaLimit=a.camera.limits.max.alpha),a.camera.limits.min.radius&&(this.lowerRadiusLimit=a.camera.limits.min.radius),a.camera.limits.max.radius&&(this.upperRadiusLimit=a.camera.limits.max.radius),a.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(a.camera.autoRotation.idleTimeMs))}updateConfiguration(e){e&&(this.lowerBetaLimit=e.camera.limits.min.beta??null,this.upperBetaLimit=e.camera.limits.max.beta??null,this.lowerAlphaLimit=e.camera.limits.min.alpha??null,this.upperAlphaLimit=e.camera.limits.max.alpha??null,e.camera.autoRotation.enabled?this.enableAutoRotationBehavior(e.camera.autoRotation.idleTimeMs):this.disableAutoRotationBehavior())}get isRunningFramingBehavior(){return this._isRunningFramingBehavior}set isRunningFramingBehavior(e){this._isRunningFramingBehavior=e,!e&&this.framingBehaviourCallback&&(this.framingBehaviourCallback(),this.framingBehaviourCallback=void 0)}setPanEnabled(e){this.panEnabled=e,this.panningSensibility=1e3/this.panDenominator,this.panningAxis=e?new p.Vector3(1,1,0):new p.Vector3(0,0,0)}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");if(e)return e}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const t=j(this._scene);return e.zoomOnBoundingInfo(t.min,t.max),this.wheelPrecision=100/this.radius,this.lowerRadiusLimit===null&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e,t){this._isRunningFramingBehavior=!0,this.framingBehaviourCallback=e;const i=this.getFramingBehavior();i.framingTime=t||800;const n=()=>{this.isRunningFramingBehavior=!1},s=j(this._scene),o=s.max.subtract(s.min),a=s.min.add(o.scale(.5));this.updateRadiusBounds(o.length()*1.5),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(a),this.panDenominator=o.length(),this.lastFocus.copyFrom(a),i.zoomOnBoundingInfo(s.min,s.max,void 0,n),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}updateRadiusBounds(e){this.maxZ=e*1e3,this.lowerRadiusLimit=e*.01,this.upperRadiusLimit=1.5*e,this.wheelPrecision=100/e,this.pinchPrecision=300/e}static create(e,t,i){var h;const n=j(e),s=n.max.subtract(n.min),o=n.min.add(s.scale(.5)),a=new B("ProductCamera",-(Math.PI/2),Math.PI/2,s.length()*1.5,o,e,t);return a.setPanEnabled(((h=t.options)==null?void 0:h.noPan)!==void 0?!t.options.noPan:!0),a.panningInertia=0,a.panningOriginTarget.copyFrom(o),a.panDenominator=s.length(),a.onAfterCheckInputsObservable.addOnce(()=>{a.setPanEnabled(a.panEnabled)}),i&&(e.activeCamera=a),a}}function j(r){if(r.meshes.length===0)return{min:new p.Vector3(-1,-1,-1),max:new p.Vector3(1,1,1)};const e=r.meshes.filter(t=>t.name.toLowerCase().endsWith("_t")||t.name.toLowerCase().includes("_t_"));return r.getWorldExtends(t=>t.isVisible&&t.isEnabled()&&(e.length===0||e.includes(t)))}class Xe{constructor(e,t=!1,i=void 0){this.renderingPipeline=new Be.DefaultRenderingPipeline("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.isSupported&&(this.renderingPipeline.prepare(),this.setConfiguration(u))}dispose(){this.renderingPipeline.dispose()}getConfiguration(){return this.currentConfiguration}setConfiguration(e){var t,i,n,s,o,a,h,l,c,g,m,f,v,J,ee,te,ie,ne,se,re,ae,oe,le,he,ce,de,ue,ge,me,pe,fe,be,ve;if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=((t=e.antiAliasing)==null?void 0:t.samples)??u.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=((i=e.antiAliasing)==null?void 0:i.fxaaEnabled)??u.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=((n=e.bloom)==null?void 0:n.enabled)??u.bloom.enabled,this.renderingPipeline.bloomKernel=((s=e.bloom)==null?void 0:s.kernel)??u.bloom.kernel,this.renderingPipeline.bloomScale=((o=e.bloom)==null?void 0:o.scale)??u.bloom.scale,this.renderingPipeline.bloomThreshold=((a=e.bloom)==null?void 0:a.threshold)??u.bloom.threshold,this.renderingPipeline.bloomWeight=((h=e.bloom)==null?void 0:h.weight)??u.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=((l=e.chromaticAberration)==null?void 0:l.enabled)??u.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=((c=e.chromaticAberration)==null?void 0:c.aberrationAmount)??u.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=((g=e.chromaticAberration)==null?void 0:g.radialIntensity)??u.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=(m=e.chromaticAberration)!=null&&m.direction?new p.Vector2(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new p.Vector2(u.chromaticAberration.direction.x,u.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=((f=e.colorCurves)==null?void 0:f.enabled)??u.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new G.ColorCurves,this.renderingPipeline.depthOfFieldEnabled=((v=e.depthOfField)==null?void 0:v.enabled)??u.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??u.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.High;break}if(this.renderingPipeline.depthOfField.focalLength=((J=e.depthOfField)==null?void 0:J.focalLength)??u.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=((ee=e.depthOfField)==null?void 0:ee.fStop)??u.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=((te=e.depthOfField)==null?void 0:te.focusDistance)??u.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=((ie=e.depthOfField)==null?void 0:ie.lensSize)??u.depthOfField.lensSize,this.renderingPipeline.grainEnabled=((ne=e.grain)==null?void 0:ne.enabled)??u.grain.enabled,this.renderingPipeline.grain.animated=((se=e.grain)==null?void 0:se.animated)??u.grain.animated,this.renderingPipeline.grain.intensity=((re=e.grain)==null?void 0:re.intensity)??u.grain.intensity,this.renderingPipeline.imageProcessing.contrast=((ae=e.misc)==null?void 0:ae.contrast)??u.misc.contrast,this.renderingPipeline.imageProcessing.exposure=((oe=e.misc)==null?void 0:oe.exposure)??u.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=((le=e.misc)==null?void 0:le.toneMappingEnabled)??u.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??u.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=P.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=P.ImageProcessingConfiguration.TONEMAPPING_ACES;break}if(this.renderingPipeline.sharpenEnabled=((he=e.sharpen)==null?void 0:he.enabled)??u.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=((ce=e.sharpen)==null?void 0:ce.colorAmount)??u.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=((de=e.sharpen)==null?void 0:de.edgeAmount)??u.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=((ue=e.vignette)==null?void 0:ue.enabled)??u.vignette.enabled,(ge=e.vignette)!=null&&ge.center?(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y):(this.renderingPipeline.imageProcessing.vignetteCenterX=u.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=u.vignette.center.y),e.vignette)switch(((me=e.vignette)==null?void 0:me.blendMode)??u.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=P.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=P.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE;break}(pe=e.vignette)!=null&&pe.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new b.Color4(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):(fe=e.vignette)!=null&&fe.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=b.Color4.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new b.Color4(u.vignette.colorRgba.r,u.vignette.colorRgba.g,u.vignette.colorRgba.b,u.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=((be=e.vignette)==null?void 0:be.stretch)??u.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=((ve=e.vignette)==null?void 0:ve.weight)??u.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const t=new G.ColorCurves;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}}Ae.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",function(r){return new je(r)}),L.SceneLoader.OnPluginActivatedObservable.add(r=>{if(r.name==="gltf"){const e=r;e.transparencyAsCoverage=!0}});function q(r){return new p.Vector3(r.x,r.y,r.z)}function D(r){return{x:r.x,y:r.y,z:r.z}}class Je{constructor(e){var h;this.focusLostNotified=!1,this.focusLostObservable=new M.Observable,this.modelLoadEventCallbacks=[],this.modelContainers=new Map,this.plugins=[],this.initComplete=!1,this.isAnimatingCamera=!1,this.renderLoop=()=>{if(!this.engine.views)return;this.modelContainers.forEach(g=>{g.updateDynamicTextures()}),this.scene.autoClear=!0,this.scene.autoClearDepthAndStencil=!0;const l=this.engine.getRenderingCanvas();if(l)if(l.getContext("webgl2")??l.getContext("webgl")){const g=this.configuration.scene.clearColor,m=l.getContext("webgl2")??l.getContext("webgl");m.clearDepth(1),m.depthFunc(m.LEQUAL),m.clearStencil(0),m.clearColor(g.r,g.g,g.b,g.a),m.clear(m.COLOR_BUFFER_BIT|m.DEPTH_BUFFER_BIT|m.STENCIL_BUFFER_BIT)}else l.getContext("2d")?l.getContext("2d").clearRect(0,0,l.width,l.height):console.error("SpiffCommerce: Failed to get any context on the rendering canvas.");this.scene.render(),this.camera.isRunningFramingBehavior&&this.camera.getFramingBehavior().isUserIsMoving&&(this.camera.isRunningFramingBehavior=!1);const c=Math.max((this.camera.lowerRadiusLimit??1)*.01,.001);!this.camera.isRunningFramingBehavior&&!this.camera.target.equalsWithEpsilon(this.camera.lastFocus,c)&&!this.focusLostNotified&&(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0),this.screenshotPrepareResolve&&(this.screenshotPrepareResolve(),this.screenshotPrepareResolve=void 0)},this.configuration=new U(e);const i=(()=>{if(!(e!=null&&e.noRender))return this.configuration.createCanvas()})(),n="1.5.6";we.DracoCompression.Configuration={decoder:{wasmUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_wasm_wrapper_gltf.js`,wasmBinaryUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_decoder_gltf.wasm`,fallbackUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_decoder_gltf.js`}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const s=console.log;console.log=()=>{};const o=i?new V.Engine(i,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!(e!=null&&e.backgroundImage),audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new ye.NullEngine;console.log=s,o.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=o,this.scene=new xe.Scene(o),this.camera=B.create(this.scene,this.configuration),this.scene.activeCamera=this.camera,this.renderingPipeline=new Xe(this.scene,!1,this.camera),this.scene.clearColor=this.configuration.scene.clearColor;const a=k.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environment.file,this.scene);a.name="initial-environment-cube",a.rotationY=this.configuration.scene.environment.rotationY,this.scene.environmentTexture=a,this.scene.environmentIntensity=this.configuration.scene.environment.intensity,(h=this.configuration.options)!=null&&h.renderingPipelineConfiguration?this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration):(this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast),this.glowLayerManager=new qe(this.scene,this.configuration.emissiveGlowIntensity),this.initPromise=new Promise(l=>{this.scene.onReadyObservable.addOnce(()=>{this.initComplete=!0,l()})}),this.engine.runRenderLoop(this.renderLoop)}getInitializationPromise(){return this.initPromise}getInitializationComplete(){return this.initComplete}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerModelLoadEventListener(e){this.modelLoadEventCallbacks.push(e)}unregisterModelLoadEventListener(e){const t=this.modelLoadEventCallbacks.indexOf(e);t>-1&&this.modelLoadEventCallbacks.splice(t,1)}registerView(e){const t=e.height,i=e.width;this.engine.registerView(e,void 0,!0),e.setAttribute("height",t.toString()),e.setAttribute("width",i.toString()),this.orbitEnabled()||this.setCameraState(T.Pan),this.reattachControls(e)}getNumViewports(){var e;return((e=this.engine.views)==null?void 0:e.length)||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.plugins.forEach(e=>e.dispose(!0)),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}executeCameraAnimation(e){if(!this.camera||this.scene.activeCamera!==this.camera||this.getAllModels().length===0||!this.getAllModels().some(n=>n.getIsInitialized()))return this.queuedCameraAnimation=e,Promise.resolve();let t=()=>{};const i=async()=>{this.isAnimatingCamera=!0,await ze(this.scene,this.scene.activeCamera,e),this.isAnimatingCamera=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,t()};return this.isAnimatingCamera?(this.queuedAnimationFunction=i,new Promise(n=>{t=n})):i()}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(this.camera.alpha*180/Math.PI),latDeg:Math.round(this.camera.beta*180/Math.PI),radius:Math.round((this.camera.radius+Number.EPSILON)*1e4)/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new p.Vector3(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}setCameraState(e){var t,i;if(!((t=this.engine)!=null&&t.views)||!((i=this.engine)!=null&&i.views[0]))throw new Error("No views attached, camera state requires a view to attach controls onto.");e===T.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){let e=()=>{};const t=async()=>{this.isAnimatingCamera=!0,await new Promise(i=>{this.focusLostNotified=!1;const n=()=>{const s=this.configuration;this.camera.rerunFramingBehavior(()=>{s.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.camera.upperRadiusLimit=s.camera.limits.max.radius),i()})};this.scene.onAfterRenderObservable.addOnce(n)}),this.isAnimatingCamera=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,e()};return this.isAnimatingCamera?(this.queuedAnimationFunction=t,new Promise(i=>{e=i})):t()}forceStopCameraAnimations(){var e;this.queuedAnimationFunction=void 0,this.queuedCameraAnimation=void 0,this.isAnimatingCamera=!1,(e=this.camera.framingBehavior)==null||e.stopAllAnimations(),this.scene.stopAnimation(this.camera)}setAutoRotation(e){!this.configuration.camera.autoRotation.enabled||!this.camera||(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");const i=new y.ArcRotateCamera("screenshotCamera",0,0,0,p.Vector3.Zero(),this.scene);try{const n=t.latDeg*Math.PI/180,s=t.lonDeg*Math.PI/180;i.target=t.target?new p.Vector3(t.target.x,t.target.y,t.target.z):p.Vector3.Zero(),i.alpha=s,i.beta=n,i.radius=t.radius||this.camera.radius,i.minZ=.01,this.scene.render();const o=await Me.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,i,e,"image/png",2,!0);return i.dispose(),o}catch{throw i.isDisposed()||i.dispose(),new Error("Failed to render screenshot")}}orbitEnabled(){const e=this.configuration;if(!e)return!0;const t=e.camera.limits.min.alpha,i=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,s=e.camera.limits.max.beta;if(t===void 0||i===void 0||n===void 0||s===void 0)return!0;const o=[t,i],a=[n,s],h=o.every(c=>c===t),l=a.every(c=>c===n);return!h&&!l}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}setHighlights(e,t){var n;e.length===0&&((n=this.highlightLayer)==null||n.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new Ce.HighlightLayer("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const i=t?new b.Color3(t[0],t[1],t[2]).toLinearSpace():void 0;e.forEach(s=>{const o=this.scene.materials.find(a=>a.name===s.name&&a.id===s.id);o&&o.getBindedMeshes().forEach(a=>{var h;return(h=this.highlightLayer)==null?void 0:h.addMesh(a,i||b.Color3.FromHexString("#fcba03"))})})}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}loadModel(e,t){const{refocusCamera:i=!0,progressHandler:n}=t??{},s=new _e({enablePicking:this.configuration.highlights.enabled,modelDetails:e,scene:this.scene,previewService:this,progressHandler:n});return s.getInitializationPromise().then(()=>{if(this.modelContainers.size<=1&&i){const o=this.queuedCameraAnimation;this.forceStopCameraAnimations(),this.camera.rerunFramingBehavior(()=>{this.scene.onAfterRenderObservable.addOnce(()=>{o&&(this.executeCameraAnimation(o),this.queuedCameraAnimation=void 0)})},1)}}),this.configuration.highlights.enabled&&(s.registerMaterialSelectedCallback(o=>{this.setHighlights([o])}),s.registerMaterialDeselectedCallback(()=>{this.setHighlights([])})),this.modelContainers.set(s.getId(),s),this.triggerModelLoadEvent({eventType:"load",modelContainer:s}),s}async preloadModel(e){await S(e,this.scene)}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const t=this.plugins.indexOf(e);t>-1&&this.plugins.splice(t,1).forEach(n=>n.dispose(!1))}getGlowLayerManager(){return this.glowLayerManager}modelUnloaded(e){this.modelContainers.delete(e.getId()),this.triggerModelLoadEvent({eventType:"unload",modelContainer:e})}triggerModelLoadEvent(e){this.modelLoadEventCallbacks.forEach(t=>t(e))}flipTransform(e,t,i){const n=p.Matrix.Compose(q(i||{x:1,y:1,z:1}),p.Quaternion.FromEulerVector(q(t||{x:0,y:0,z:0})),q(e||{x:0,y:0,z:0})),s=p.Matrix.RotationAxis(p.Vector3.Up(),Math.PI),o=n.multiply(s),a=p.Vector3.Zero(),h=p.Quaternion.Identity(),l=p.Vector3.Zero();return o.decompose(l,h,a),h.multiplyInPlace(p.Quaternion.FromEulerAngles(0,Math.PI,0)),{position:D(a),rotation:D(h.toEulerAngles()),scale:D(l)}}updatePreviewOptions(e){var n,s;const t=new U(e);this.configuration.highlights.enabled!==t.highlights.enabled&&this.engine.setStencilBuffer(t.highlights.enabled),this.scene.clearColor=t.scene.clearColor;let i=this.scene.environmentTexture;this.configuration.scene.environment.file!==t.scene.environment.file&&(i=k.CubeTexture.CreateFromPrefilteredData(t.scene.environment.file,this.scene),i.name="updated-environment-cube",i.rotationY=this.configuration.scene.environment.rotationY,this.scene.environmentTexture=i),i.rotationY=t.scene.environment.rotationY,this.scene.environmentIntensity=t.scene.environment.intensity,(n=t.options)!=null&&n.renderingPipelineConfiguration?this.renderingPipeline.setConfiguration(t.options.renderingPipelineConfiguration):(this.scene.imageProcessingConfiguration.exposure=t.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=t.lighting.contrast),this.glowLayerManager.setIntensity(t.emissiveGlowIntensity),this.camera.updateConfiguration(t),this.camera.setPanEnabled(((s=t.options)==null?void 0:s.noPan)!==void 0?!t.options.noPan:!0),this.configuration=t}reattachControls(e,t=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,t);const i=this.camera.inputs.attached.pointers;i.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}}d.MaterialEffectMode=R,d.ProductCameraRig=T,d.REFLECTION_PROBE_RESOLUTION=K,d.RenderingConfiguration=w,d.SpiffCommerce3DPreviewService=Je,d.renderingPipelineDefaults=u,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("@babylonjs/core/Cameras/arcRotateCamera"),require("@babylonjs/core/Engines/engine"),require("@babylonjs/core/Engines/nullEngine"),require("@babylonjs/core/Layers/highlightLayer"),require("@babylonjs/core/Loading/sceneLoader"),require("@babylonjs/core/Materials/Textures/cubeTexture"),require("@babylonjs/core/Maths/math.color"),require("@babylonjs/core/Maths/math.vector"),require("@babylonjs/core/Meshes/Compression/dracoCompression"),require("@babylonjs/core/Misc/observable"),require("@babylonjs/core/Misc/tools"),require("@babylonjs/core/scene"),require("@babylonjs/loaders/glTF"),require("@babylonjs/loaders/glTF/glTFFileLoader"),require("@babylonjs/core/Materials/PBR/pbrMaterial"),require("@babylonjs/core/Materials/Textures/mirrorTexture"),require("@babylonjs/core/Maths/math"),require("@babylonjs/core/Probes/reflectionProbe"),require("@babylonjs/core/Layers/glowLayer"),require("@babylonjs/core/Actions/actionManager"),require("@babylonjs/core/Actions/directActions"),require("@babylonjs/core/Meshes/mesh"),require("@babylonjs/core/Meshes/transformNode"),require("@babylonjs/core/Materials/Textures/dynamicTexture"),require("@babylonjs/core/Materials/Textures/texture"),require("@babylonjs/core/Animations/animation"),require("@babylonjs/core/Animations/easing"),require("@babylonjs/core/Misc/assetsManager"),require("@babylonjs/core/Materials/colorCurves"),require("@babylonjs/core/Materials/imageProcessingConfiguration"),require("@babylonjs/core/PostProcesses/RenderPipeline"),require("@babylonjs/core/PostProcesses/depthOfFieldEffect"),require("@babylonjs/core/Rendering/depthRendererSceneComponent"),require("@babylonjs/core/Engines/Extensions/engine.views"),require("@babylonjs/core/Meshes/instancedMesh"),require("@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/envTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader"),require("@babylonjs/core/Animations/animatable"),require("@babylonjs/core/Misc/screenshotTools"),require("@babylonjs/core/Rendering/boundingBoxRenderer"),require("@babylonjs/loaders/glTF/2.0/Extensions")):typeof define=="function"&&define.amd?define(["exports","@babylonjs/core/Cameras/arcRotateCamera","@babylonjs/core/Engines/engine","@babylonjs/core/Engines/nullEngine","@babylonjs/core/Layers/highlightLayer","@babylonjs/core/Loading/sceneLoader","@babylonjs/core/Materials/Textures/cubeTexture","@babylonjs/core/Maths/math.color","@babylonjs/core/Maths/math.vector","@babylonjs/core/Meshes/Compression/dracoCompression","@babylonjs/core/Misc/observable","@babylonjs/core/Misc/tools","@babylonjs/core/scene","@babylonjs/loaders/glTF","@babylonjs/loaders/glTF/glTFFileLoader","@babylonjs/core/Materials/PBR/pbrMaterial","@babylonjs/core/Materials/Textures/mirrorTexture","@babylonjs/core/Maths/math","@babylonjs/core/Probes/reflectionProbe","@babylonjs/core/Layers/glowLayer","@babylonjs/core/Actions/actionManager","@babylonjs/core/Actions/directActions","@babylonjs/core/Meshes/mesh","@babylonjs/core/Meshes/transformNode","@babylonjs/core/Materials/Textures/dynamicTexture","@babylonjs/core/Materials/Textures/texture","@babylonjs/core/Animations/animation","@babylonjs/core/Animations/easing","@babylonjs/core/Misc/assetsManager","@babylonjs/core/Materials/colorCurves","@babylonjs/core/Materials/imageProcessingConfiguration","@babylonjs/core/PostProcesses/RenderPipeline","@babylonjs/core/PostProcesses/depthOfFieldEffect","@babylonjs/core/Rendering/depthRendererSceneComponent","@babylonjs/core/Engines/Extensions/engine.views","@babylonjs/core/Meshes/instancedMesh","@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader","@babylonjs/core/Materials/Textures/Loaders/envTextureLoader","@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader","@babylonjs/core/Animations/animatable","@babylonjs/core/Misc/screenshotTools","@babylonjs/core/Rendering/boundingBoxRenderer","@babylonjs/loaders/glTF/2.0/Extensions"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.Preview={},d.arcRotateCamera,d.engine,d.nullEngine,d.highlightLayer,d.sceneLoader,d.cubeTexture,d.math_color,d.math_vector,d.dracoCompression,d.observable,d.tools,d.scene,d.glTF,d.glTFFileLoader,d.pbrMaterial,d.mirrorTexture,d.math,d.reflectionProbe,d.glowLayer,d.actionManager,d.directActions,d.mesh,d.transformNode,d.dynamicTexture,d.texture,d.animation,d.easing,d.assetsManager,d.colorCurves,d.imageProcessingConfiguration,d.RenderPipeline,d.depthOfFieldEffect))})(this,function(d,y,V,ye,Ce,L,k,b,p,we,M,Me,xe,Ae,Pe,O,Te,A,Re,Ee,F,N,Le,Oe,Fe,Ie,C,z,Se,G,P,Be,I){"use strict";var T=(r=>(r[r.Orbit=0]="Orbit",r[r.Pan=1]="Pan",r))(T||{}),R=(r=>(r.None="None",r.RemoveWhenSelected="RemoveWhenSelected",r.ApplyWhenSelected="ApplyWhenSelected",r))(R||{});const H=new Map;async function S(r,e,t){const i=await H.get(r);if(i&&i.scene.uid===e.uid)return i;const n=L.SceneLoader.LoadAssetContainerAsync(r,void 0,e,t);return H.set(r,n),n}L.SceneLoader.OnPluginActivatedObservable.add(r=>{r.name==="gltf"&&(r.animationStartMode=Pe.GLTFLoaderAnimationStartMode.NONE)});class U{constructor(e){this.getSceneClearColor=()=>{var i,n,s,o;const t=(i=this.customOptions)!=null&&i.transparentBackground||(n=this.customOptions)!=null&&n.backgroundImage?0:1;if(this.customOptions&&((s=this.customOptions)!=null&&s.transparentBackground)||(o=this.customOptions)!=null&&o.backgroundImage)return new b.Color4(0,0,0,t).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const a=b.Color3.FromHexString(this.customOptions.backgroundColor);return new b.Color4(a.r,a.g,a.b,t).toLinearSpace()}return new b.Color4(.98,.98,.98,t).toLinearSpace()},this.highlightColorFromConfig=()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new b.Color4(.98,.98,.98,1).toLinearSpace(),this.hexToColor4=(t,i=1)=>{const n=b.Color3.FromHexString(t);return new b.Color4(n.r,n.g,n.b,i).toLinearSpace()},this.customOptions=e}createCanvas(){var e;return(e=this.customOptions)!=null&&e.createCanvas?this.customOptions.createCanvas():document.createElement("canvas")}get options(){return this.customOptions}get scene(){var e,t,i,n,s;return{clearColor:this.getSceneClearColor(),transparentBackground:((e=this.customOptions)==null?void 0:e.transparentBackground)||((t=this.customOptions)==null?void 0:t.backgroundImage),environment:{file:((i=this.customOptions)==null?void 0:i.environmentFile)??"assets/model-viewer/default.env",intensity:((n=this.customOptions)==null?void 0:n.environmentIntensity)??1,rotationY:(((s=this.customOptions)==null?void 0:s.environmentRotationY)??0)*(Math.PI/180)}}}get camera(){var e,t,i,n,s,o,a,l,h,c,g,m,f;return{autoOrientation:((e=this.customOptions)==null?void 0:e.disableAutomaticOrientation)??!0,autoRotation:{enabled:((t=this.customOptions)==null?void 0:t.autoRotation)??!1,idleTimeMs:((i=this.customOptions)==null?void 0:i.idleTimeBeforeRotation)??5e3},limits:{min:{alpha:(n=this.customOptions)!=null&&n.lowerAlphaLimitDeg?((s=this.customOptions)==null?void 0:s.lowerAlphaLimitDeg)*Math.PI/180:void 0,beta:(o=this.customOptions)!=null&&o.lowerBetaLimitDeg?((a=this.customOptions)==null?void 0:a.lowerBetaLimitDeg)*Math.PI/180:void 0,radius:(l=this.customOptions)==null?void 0:l.minZoomOverride},max:{alpha:(h=this.customOptions)!=null&&h.upperAlphaLimitDeg?((c=this.customOptions)==null?void 0:c.upperAlphaLimitDeg)*Math.PI/180:void 0,beta:(g=this.customOptions)!=null&&g.upperBetaLimitDeg?((m=this.customOptions)==null?void 0:m.upperBetaLimitDeg)*Math.PI/180:void 0,radius:(f=this.customOptions)==null?void 0:f.maxZoomOverride}}}}get highlights(){var e;return{enabled:((e=this.customOptions)==null?void 0:e.highlightOnMaterialHover)??!1,color:this.highlightColorFromConfig()}}get lighting(){var e,t,i,n;return{exposure:((t=(e=this.customOptions)==null?void 0:e.lighting)==null?void 0:t.exposure)??.9,contrast:((n=(i=this.customOptions)==null?void 0:i.lighting)==null?void 0:n.contrast)??1.6}}get emissiveGlowIntensity(){var e;return((e=this.customOptions)==null?void 0:e.emissiveGlowIntensity)??.5}}class w{static getDynamicTextureResolution(){return this.getIsMobile()||!w.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return navigator.userAgent.includes("SamsungBrowser")?!1:!!window.Worker&&!!window.OffscreenCanvas}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){try{return typeof window>"u"||!window.navigator?!1:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent)||window.innerWidth/window.devicePixelRatio<=480}catch{return!1}}}const K=128,u={antiAliasing:{samples:4,fxaaEnabled:!1},bloom:{enabled:!1,kernel:64,scale:.5,threshold:.9,weight:.15},chromaticAberration:{enabled:!1,aberrationAmount:30,direction:{x:0,y:0},radialIntensity:0},colorCurves:{enabled:!1},depthOfField:{enabled:!1,blurLevel:"Low",focalLength:50,focusDistance:2e3,fStop:1.4,lensSize:50},grain:{enabled:!1,animated:!1,intensity:30},misc:{contrast:1,exposure:1,toneMappingEnabled:!1,toneMappingType:"Standard"},sharpen:{enabled:!1,colorAmount:1,edgeAmount:.3},vignette:{enabled:!1,blendMode:"Multiply",cameraFov:.5,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};class je{constructor(e){this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,t,i){return this.loader.loadNodeAsync(e,t,function(n){t.extras&&Object.keys(t.extras).forEach(s=>{const o=t.extras[s];n.metadata[s]=o}),i(n)})}async loadMaterialPropertiesAsync(e,t,i){await this.loader.loadMaterialPropertiesAsync(e,t,i),this.enableMaterialExtrasIfRequired(t,i),i.needDepthPrePass=!0}dispose(){}enableMaterialExtrasIfRequired(e,t){if(!(!e.extras||!(t instanceof O.PBRMaterial))){if(e.extras.sheen){const i=t;i.sheen.isEnabled=!0,i.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const i=t;i.subSurface.isTranslucencyEnabled=!0,i.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(i.subSurface.tintColor=new A.Color3(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const i=t;i.subSurface.isRefractionEnabled=!0,i.subSurface.volumeIndexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const i=t;i.needDepthPrePass=!0,i.forceIrradianceInFragment=!0}if(e.extras.useParallax){const i=t;i.useParallax=!0,i.useParallaxOcclusion=!0,i.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function t(s){const o=[];return s.transformNodes.forEach(a=>{a.metadata&&a.metadata.reflective&&o.push(...a.getChildMeshes())}),s.meshes.forEach(a=>{a.metadata&&a.metadata.reflective&&!o.includes(a)&&o.push(a)}),o}function i(s,o=1){const a=s.material;if(!a)return;const l=new Te.MirrorTexture("mirror",w.getMirrorTextureResolution(),e,!0);l.renderList=t(e);const h=s.getVerticesData("normal");if(!h)throw new Error("Mirror attribute specified on: "+s.name+"But no normals exist to generate a mirror from!");s.computeWorldMatrix(!0);const c=s.getWorldMatrix(),g=A.Vector3.TransformNormal(new A.Vector3(h[0],h[1],h[2]),c).normalize(),m=A.Plane.FromPositionAndNormal(s.position,g.scale(-1));l.mirrorPlane=m,l.level=o,a.reflectionTexture=l}function n(s){const o=s.material,a=new Re.ReflectionProbe("probe-"+o.name,K,e);a.cubeTexture.name="reflection-probe-cube-texture",a.attachToMesh(s),a.renderList&&a.renderList.push(...t(e)),o.reflectionTexture=a.cubeTexture}e.meshes.forEach(s=>{const o=s.metadata;o&&(o.mirrorTexture&&i(s,o.mirrorTexture),o.reflectionProbe&&n(s))})}}class qe{constructor(e,t){this.scene=e,this.intensity=t,this.meshCount=0}setIntensity(e){this.intensity=e,this.glowLayer&&(this.glowLayer.intensity=e)}includeMeshes(e){if(e){this.glowLayer||(this.glowLayer=new Ee.GlowLayer("glow",this.scene),this.glowLayer.intensity=this.intensity);for(const t of e)this.glowLayer.hasMesh(t)||(this.glowLayer.addIncludedOnlyMesh(t),this.meshCount++)}}removeMeshes(e){if(!(!this.glowLayer||!e)){for(const t of e)this.glowLayer.hasMesh(t)&&(this.glowLayer.removeIncludedOnlyMesh(t),this.meshCount--);this.meshCount===0&&(this.glowLayer.dispose(),this.glowLayer=void 0)}}}function De(r,e,t,i,n=""){t.forEach(s=>{const o=s.getID(),a=s.getName(),l=w.getDynamicTextureResolution();r.filter(c=>c.name===n+a).forEach(c=>{console.log(`attaching textures to material ${c.name}`);const g=i.get(o),m=!1;if(g)W(c,g),console.log(`applying current texture ${g.name}`),g.update(m);else{const f=ke(a,e,l.width,l.height);console.log(`created new texture ${f.name}`),i.set(o,f),s.setStaticContext(f.getContext()),W(c,f),f.onLoadObservable.addOnce(()=>{f.update(m)})}})}),Ve(e)}const Ve=r=>{const e=()=>r.textures.reduce((i,n)=>{var o,a;return!r.meshes.some(l=>l.material&&l.material.hasTexture(n))&&!((o=n==null?void 0:n.url)!=null&&o.includes("data:"))&&!((a=n==null?void 0:n.url)!=null&&a.endsWith(".env"))&&i.push(n),i},[]),t=()=>r.materials.reduce((i,n)=>(n.getBindedMeshes().length==0&&i.push(n),i),[]);e().forEach(i=>{try{console.log(`disposing texture ${i.name} (${i.url})`),i.dispose()}catch{console.log(`Failed to dispose texture ${i.name}`)}}),t().forEach(i=>{try{console.log(`disposing material ${i.name}`),i.dispose(!0,!0)}catch{console.log(`Failed to dispose material ${i.name}`)}})};function ke(r,e,t,i){const n=new Fe.DynamicTexture(r,{width:t,height:i},e,w.shouldMipMap(),Ie.Texture.TRILINEAR_SAMPLINGMODE,V.Engine.TEXTUREFORMAT_RGBA),s=n.getContext();return s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,t,i),n.update()),n}function W(r,e){if(r instanceof O.PBRMaterial){const t=r,i=t.albedoTexture;i?(e.wrapU=i.wrapU,e.wrapV=i.wrapV):(e.wrapU=1,e.wrapV=1),t.albedoTexture=e}else{const t=r,i=t.diffuseTexture;i&&(e.wrapU=i.wrapU,e.wrapV=i.wrapV),t.diffuseTexture=e}}function Ne(){const r=()=>Math.floor((1+Math.random())*65536).toString(16).substring(1);return r()+r()+"-"+r()+"-"+r()+"-"+r()+"-"+r()+r()+r()}const x=60,Q=1;function $(r){return r.targetedAnimations.map(t=>t.animation.framePerSecond).reduce((t,i)=>t+i,0)/r.targetedAnimations.length||0}function Y(r,e,t,i,n,s){const o=n?r.filter(c=>c.name===n):r;if(o.length===0){console.warn(`No animations found for name: ${n}`);return}let a=0;const l=()=>{a++,a===o.length&&s&&s()},h=(c,g,m,f,v)=>{c.stop(),c.start(g,m,f,v),s&&(g==!1||g===void 0&&!c.loopAnimation?c.onAnimationGroupEndObservable.addOnce(()=>{l()}):c.onAnimationLoopObservable.addOnce(()=>{l()}))};if(i!==void 0&&t!==void 0&&i===t){o.forEach(c=>{const g=$(c),m=i*g;h(c,!1,Q,m,m)});return}o.forEach(c=>{const g=$(c),m=i!==void 0?i*g:void 0,f=t!==void 0?t*g:void 0;h(c,e,Q,m,f)})}function ze(r,e,t){return new Promise(i=>{r.stopAnimation(e),e.animations=[],Math.abs(e.alpha)>2*Math.PI&&(e.alpha=Ge(e.alpha,0,2*Math.PI));const n=[],s=t.target,o=0,a=s?1:0;if(t.target&&Object.keys(t.target).length>0&&n.push(E("cameraTargetLerp","target",new p.Vector3().copyFrom(e.target),new p.Vector3(t.target.x,t.target.y,t.target.z),C.Animation.ANIMATIONTYPE_VECTOR3,o)),n.push(E("cameraAlphaLerp","alpha",e.alpha,Z(t.lonDeg),C.Animation.ANIMATIONTYPE_FLOAT,a)),n.push(E("cameraBetaLerp","beta",e.beta,Z(t.latDeg),C.Animation.ANIMATIONTYPE_FLOAT,a)),t.radius!==void 0){const c=Math.max(.01,t.radius);n.push(E("cameraRadiusLerp","radius",e.radius,c,C.Animation.ANIMATIONTYPE_FLOAT,a))}e.animations.push(...n);const h=e.useAutoRotationBehavior;e.disableAutoRotationBehavior(),r.beginAnimation(e,0,s?x*2:x,!1,1,()=>{e.animations=[],h&&e.enableAutoRotationBehavior(),i()})})}function Z(r){return r*Math.PI/180}function E(r,e,t,i,n,s=0,o=C.Animation.ANIMATIONLOOPMODE_CONSTANT){const a=new z.QuadraticEase;a.setEasingMode(z.EasingFunction.EASINGMODE_EASEINOUT);const l=new C.Animation(r,e,x,n,o),h=[];return s>0&&h.push({frame:0,value:t}),h.push({frame:x*s,value:t}),h.push({frame:x*(s+1),value:i}),l.setKeys(h),l.setEasingFunction(a),l}function Ge(r,e,t){return r<e?r=t-(e-r)%(t-e):r=e+(r-e)%(t-e)}function He(r,e,t){r.forEach(i=>{t&&i.name!==t||i.goToFrame(e)})}const Ue={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap",reflectionTexture:"reflectionMap"};function Ke(r,e,t,i){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture","reflectionTexture"].forEach(s=>{We(s,r,e,t,i)}),Ye(r,e)}function We(r,e,t,i,n){const s=Ue[r];if(!s)throw new Error("Unexpected texture name encountered.");const o=e[s],a=o==null?void 0:o.fileLink;a?r==="reflectionTexture"?a.endsWith(".env")||a.endsWith(".dds")?i.addCubeTextureTask(r,a,void 0,!1,void 0,!0):a.endsWith(".hdr")?i.addHDRCubeTextureTask(r,a,128,!1,!0,!1):i.addTextureTask(r,a,!1,!1):i.addTextureTask(r,a,!1,!1):n&&t[r]&&(t[r]&&t[r].dispose(),t[r]=null,Qe(r,t))}function Qe(r,e){r==="opacityTexture"&&(e.useAlphaFromAlbedoTexture=!0),r==="metallicTexture"&&(e.useRoughnessFromMetallicTextureAlpha=!1,e.useRoughnessFromMetallicTextureGreen=!1,e.useMetallnessFromMetallicTextureBlue=!1),r==="refractionTexture"&&(e.subSurface.isRefractionEnabled=!1,e.subSurface.refractionIntensity=1),r==="reflectionTexture"&&(e.environmentIntensity=1),r==="emissiveTexture"&&(e.emissiveIntensity=0,e.emissiveColor=new b.Color3(0,0,0),e.reflectionTexture)}function $e(r,e,t,i){if(!e){console.error("Failed to apply texture to material: material is null.");return}r==="opacityTexture"&&(e.useAlphaFromAlbedoTexture=!1),r==="metallicTexture"&&(e.useRoughnessFromMetallicTextureAlpha=!1,e.useRoughnessFromMetallicTextureGreen=!0,e.useMetallnessFromMetallicTextureBlue=!0),r==="refractionTexture"&&(e.subSurface.isRefractionEnabled=!0,e.subSurface.refractionIntensity=t.refractionIntensity||1),r==="reflectionTexture"&&(e.environmentIntensity=t.reflectionIntensity||1,i.isCube&&(i.rotationY=t.reflectionRotation?t.reflectionRotation*Math.PI/180:0)),e[r]=i,r==="emissiveTexture"&&(e.emissiveColor=new b.Color3(1,1,1),e.emissiveIntensity=1)}function Ye(r,e){r.clearCoat&&(r.clearCoat===R.RemoveWhenSelected?(e.clearCoat.isEnabled=!1,e.clearCoat.indexOfRefraction=1.5):r.clearCoat===R.ApplyWhenSelected&&(e.clearCoat.isEnabled=!0,e.clearCoat.indexOfRefraction=r.clearCoatIOR||e.clearCoat.indexOfRefraction))}class Ze{constructor(e,t,i){this.materialVariantMap=new Map,this.keysThatRemovedBaseModel=[],this.loadedContainerForKey=new Map,this.loadedMaterialsForKey=new Map,this.scene=e,this.renameClonedAsset=t,this.setBaseModelEnabled=i}async applyMaterial(e,t,i,n){return new Promise(s=>{const o=this.materialVariantMap.get(e);this.materialVariantMap.set(e,{...o,...t});const a=this.renameClonedAsset(e),l=this.scene.materials.filter(c=>c.name===a);if(l.length===0){s();return}const h=new Se.AssetsManager(this.scene);h.useDefaultLoadingScreen=!1,l.forEach(c=>Ke(t,c,h,n)),h.onProgress=(c,g,m)=>{i&&i(c/g*100,100,m.name)},h.onFinish=c=>{c.forEach(g=>{const m=g;i&&i(100,100,g.name),this.scene.materials.filter(v=>v.name===a).forEach(v=>{console.log(`asset manager applying texture ${g.name}`),$e(g.name,v,t,m.texture)})}),s()},h.loadAsync()})}async applyModel(e,t,i,n,s,o,a){var g;if(i&&t&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!i)return this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.length===1&&await this.setBaseModelEnabled(!0),(g=this.loadedContainerForKey.get(e))==null||g.dispose(),this.loadedContainerForKey.delete(e),this.loadedMaterialsForKey.delete(e),this.keysThatRemovedBaseModel=this.keysThatRemovedBaseModel.filter(m=>m!==e),Promise.resolve(void 0);const h=(await S(i,this.scene,n)).instantiateModelsToScene(this.renameClonedAsset,!0);if(this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e).dispose(),this.loadedContainerForKey.delete(e),this.loadedMaterialsForKey.delete(e)),s){const m=o&&o(),f=s.name?this.renameClonedAsset(s.name):void 0;if(Y(h.animationGroups,s.loop,s.to,s.from,f),m!=null){const v=a&&a()||!0;He(h.animationGroups,m+(v?2:0),f)}}t&&await this.setBaseModelEnabled(!1),this.loadedContainerForKey.set(e,h),this.loadedMaterialsForKey.set(e,_(h));const c=[];return this.materialVariantMap.forEach(async(m,f)=>{c.push(this.applyMaterial(f,m))}),await Promise.all(c),h}dispose(){this.loadedContainerForKey.forEach(e=>e==null?void 0:e.dispose()),this.loadedContainerForKey.clear(),this.loadedMaterialsForKey.forEach(e=>e.forEach(t=>t==null?void 0:t.dispose())),this.loadedMaterialsForKey.clear(),this.materialVariantMap.clear(),this.keysThatRemovedBaseModel=[]}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach(t=>{t.forEach(i=>{e.includes(i)||e.push(i)})}),e}getAnimationGroups(){const e=[];return this.loadedContainerForKey.forEach(t=>{e.push(...t.animationGroups)}),e}}function _(r){const e=[];return r.rootNodes.forEach(t=>{t.getChildMeshes().forEach(i=>{i.material&&!e.includes(i.material)&&e.push(i.material),i.subMeshes&&i.subMeshes.forEach(n=>{const s=n.getMaterial(!1);s&&!e.includes(s)&&e.push(s)})})}),e}function X(r,e=""){return r.map(t=>({name:t.name.substring(e.length),loop:t.loopAnimation,to:t.to,from:t.from}))}class _e{constructor(e){this.metadata=new Map,this.materialSelectedObservable=new M.Observable,this.materialDeselectedObservable=new M.Observable,this.materialVariantObservable=new M.Observable,this.modelVariantObservable=new M.Observable,this.materialReadyToLoadCallbacks=new Map,this.modelReadyToLoadCallbacks=new Map,this.dynamicTextures=new Map,this.queuedMaterialChanges=new Map,this.materialChangesInProgress=[],this.queuedModelChanges=new Map,this.modelChangesInProgress=[],this.isExecutingAnimation=!1,this.animations=[],this.initialized=!1,this.materials=[];const{enablePicking:t,modelDetails:i,previewService:n,progressHandler:s,scene:o}=e;this.enablePicking=t,this.contextService=i.contextService,this.id=Ne(),this.previewService=n,this.scene=o,this.variantManager=new Ze(o,this.renameClonedAsset.bind(this),this.setBaseModelEnabled.bind(this)),this.transformRoot=new Oe.TransformNode("root",this.scene);const a=async()=>{if(!i.model)throw new Error("Model container constructed with no URL. This is currently unsupported.");return this.assetContainer=await S(i.model,o,s),await this.instantiate(),this};this.importPromise=a()}async applyMaterialVariant(e,t,i,n){if(!this.initialized){if(this.materialReadyToLoadCallbacks.has(e)){const o=this.materialReadyToLoadCallbacks.get(e);o==null||o.set(t,this.applyMaterialVariant.bind(this,e,t,i,n))}else{this.materialReadyToLoadCallbacks.set(e,new Map);const o=this.materialReadyToLoadCallbacks.get(e);o==null||o.set(t,this.applyMaterialVariant.bind(this,e,t,i,n))}return}const s=async()=>{await this.variantManager.applyMaterial(e,i,(o,a,l)=>{this.materialVariantObservable.notifyObservers({remainingCount:o,totalCount:a,taskName:l})},n)};if(this.materialChangesInProgress.includes(e)){if(this.queuedMaterialChanges.has(e)){const o=this.queuedMaterialChanges.get(e);o==null||o.set(t,s)}else{this.queuedMaterialChanges.set(e,new Map);const o=this.queuedMaterialChanges.get(e);o==null||o.set(t,s)}return}if(this.materialChangesInProgress.push(e),await s(),this.queuedMaterialChanges.has(e)){const o=this.queuedMaterialChanges.get(e);if(!o)throw new Error("Target material is undefined");o.forEach(async a=>{await a()}),this.queuedMaterialChanges.delete(e)}this.materialChangesInProgress.splice(this.materialChangesInProgress.indexOf(e),1),this.configureGlowLayer()}async applyModelVariant(e,t,i){if(!this.initialized){this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,t,i));return}const n=()=>this.variantManager.applyModel(e,i,t==null?void 0:t.model,a=>{this.modelVariantObservable.notifyObservers({...a,key:e})},this.lastPlayedAnimation,this.getCurrentAnimationFrame.bind(this),this.getAnimationIsPlaying.bind(this));if(this.modelChangesInProgress.includes(e)){this.queuedModelChanges.set(e,n);return}const o=await(async()=>{this.modelChangesInProgress.push(e);let a=await n();if(this.queuedModelChanges.has(e)){const l=this.queuedModelChanges.get(e);if(!l)throw new Error("Queued change resolved undefined");a=await l(),this.queuedModelChanges.delete(e)}return this.modelChangesInProgress.splice(this.modelChangesInProgress.indexOf(e),1),a})();this.contextService||(this.contextService=t==null?void 0:t.contextService),o?this.configureModelInstance(o):this.configureGlowLayer()}dispose(){var e;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)}executeAnimation(e){if(!this.initialized)return this.queuedModelAnimation=e,Promise.resolve();let t=()=>{};const i=async()=>{this.lastPlayedAnimation=e,this.isExecutingAnimation=!0,await new Promise(n=>{var o;const s=[...((o=this.modelInstance)==null?void 0:o.animationGroups)||[],...this.variantManager.getAnimationGroups()];Y(s,e.loop,e.to,e.from,e.name?this.renameClonedAsset(e.name):void 0,n)}),this.isExecutingAnimation=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,t()};return this.isExecutingAnimation?(this.queuedAnimationFunction=i,new Promise(n=>{t=n})):i()}getAnimations(e){return[...this.animations,...e?X(this.variantManager.getAnimationGroups(),this.renameClonedAsset("")):[]].map((t,i)=>({...t,name:t.name||`UNNAMED_ANIMATION_${i}`})).filter((t,i,n)=>n.indexOf(n.find(s=>s.name===t.name))==i)}getId(){return this.id}listMaterials(){var t;const e=(t=this.scene)==null?void 0:t.materials.filter(i=>i.name.startsWith(this.id));return e?e.map(i=>({id:i.id,name:this.stripIdFromName(i.name)})):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to requesting position!");return this.transformRoot.position}set position(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting position!");this.transformRoot.position=new p.Vector3(e.x,e.y,e.z)}get rotation(){var e;if(!((e=this.transformRoot)!=null&&e.rotationQuaternion))throw new Error("ModelContainer disposed prior to requesting rotation!");return this.transformRoot.rotationQuaternion.toEulerAngles()}set rotation(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting rotation!");this.transformRoot.rotationQuaternion=p.Quaternion.FromEulerAngles(e.x,e.y,e.z)}get scale(){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to requesting scale!");return this.transformRoot.scaling}set scale(e){if(!this.transformRoot)throw new Error("ModelContainer disposed prior to setting scale!");this.transformRoot.scaling=new p.Vector3(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach(t=>{t.getChildMeshes(!1).forEach(i=>{i.name==="targetcube_t"||i.name==="backgroundShell"||(i.actionManager||(i.actionManager=new F.ActionManager(this.scene)),i.actionManager.registerAction(new N.ExecuteCodeAction(F.ActionManager.OnPointerOverTrigger,n=>{n.meshUnderPointer&&i.material&&this.materialSelectedObservable.notifyObservers({id:i.material.id,name:this.stripIdFromName(i.material.name)})})),i.actionManager.registerAction(new N.ExecuteCodeAction(F.ActionManager.OnPointerOutTrigger,()=>{i.material&&this.materialDeselectedObservable.notifyObservers({id:i.material.id,name:this.stripIdFromName(i.material.name)})})))})})}getInitializationPromise(){return this.importPromise}getIsInitialized(){return this.initialized}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureGlowLayer(){const e=i=>i instanceof O.PBRMaterial&&i.emissiveTexture!==null;this.materials.some(e)||this.variantManager.getAllMaterials().some(e)?this.previewService.getGlowLayerManager().includeMeshes(this.getAllMeshes()):this.previewService.getGlowLayerManager().removeMeshes(this.getAllMeshes())}configureModelInstance(e){var s;if(!this.transformRoot)throw new Error("Transform disposed! This should never happen unless there is a race condition present!");const t=this.transformRoot.position,i=this.transformRoot.rotationQuaternion,n=this.transformRoot.scaling;this.transformRoot.position=p.Vector3.Zero(),this.transformRoot.rotationQuaternion=p.Quaternion.Identity(),this.transformRoot.scaling=p.Vector3.One();for(const o of e.rootNodes){o.parent=this.transformRoot;for(const a of o.getChildMeshes(!1))a.alwaysSelectAsActiveMesh=!0}this.transformRoot.position=t,this.transformRoot.rotationQuaternion=i,this.transformRoot.scaling=n,this.canvasPanels=((s=this.contextService)==null?void 0:s.getAll())||new Map,De(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.enablePicking&&this.attachPickingHandler(e),this.configureGlowLayer()}destroyInstance(){var e;(e=this.modelInstance)==null||e.dispose(),this.modelInstance=void 0}getAllMeshes(){var e;return(e=this.modelInstance)==null?void 0:e.rootNodes.map(t=>t.getChildMeshes(!1).filter(i=>i instanceof Le.Mesh)).flat()}async instantiate(){if(!this.assetContainer)throw new Error("Attempted to instantiate ModelContainer without an AssetContainer");this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=_(this.modelInstance),this.configureModelInstance(this.modelInstance),this.animations=X(this.modelInstance.animationGroups,this.renameClonedAsset("")),this.initialized=!0,await this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}async setBaseModelEnabled(e){e&&!this.modelInstance?await this.instantiate():!e&&this.modelInstance&&this.destroyInstance()}updateDynamicTextures(){var e;(e=this.canvasPanels)==null||e.forEach((t,i)=>{const n=this.dynamicTextures.get(i);n&&t.getStaticContextDirty()&&n.isReady()&&(n.update(!1),t.setStaticContextDirty(!1))})}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}getCurrentAnimationFrame(){var t;const e=[...((t=this.modelInstance)==null?void 0:t.animationGroups)||[],...this.variantManager.getAnimationGroups()];for(const i of e)if(i.animatables.length>0&&i.animatables[0].masterFrame!==void 0&&i.animatables[0].masterFrame!==null)return i.animatables[0].masterFrame;return 0}getAnimationIsPlaying(){var t;const e=[...((t=this.modelInstance)==null?void 0:t.animationGroups)||[],...this.variantManager.getAnimationGroups()];for(const i of e)if(i.isPlaying)return!0;return!1}stripIdFromName(e){return e.substring(this.id.length+1)}async processQueuedEvents(){await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).flatMap(e=>Array.from(e.values()).map(t=>t()))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map(e=>e())),this.modelReadyToLoadCallbacks.clear(),this.scene.onAfterRenderObservable.addOnce(()=>{this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0)})}}class B extends y.ArcRotateCamera{constructor(e,t,i,n,s,o,a,l){super(e,t,i,n,s,o,l),this.lastFocus=new p.Vector3(0,0,0),this._isRunningFramingBehavior=!1,this.panDenominator=1,this.panEnabled=!0,this.minZ=.01,this.updateRadiusBounds(this.radius),this.enableFramingBehavior(),this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,a.camera.autoOrientation&&(this.alpha+=Math.PI),a&&(a.camera.limits.min.beta&&(this.lowerBetaLimit=a.camera.limits.min.beta),a.camera.limits.max.beta&&(this.upperBetaLimit=a.camera.limits.max.beta),a.camera.limits.min.alpha&&(this.lowerAlphaLimit=a.camera.limits.min.alpha),a.camera.limits.max.alpha&&(this.upperAlphaLimit=a.camera.limits.max.alpha),a.camera.limits.min.radius&&(this.lowerRadiusLimit=a.camera.limits.min.radius),a.camera.limits.max.radius&&(this.upperRadiusLimit=a.camera.limits.max.radius),a.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(a.camera.autoRotation.idleTimeMs))}updateConfiguration(e){e&&(this.lowerBetaLimit=e.camera.limits.min.beta??null,this.upperBetaLimit=e.camera.limits.max.beta??null,this.lowerAlphaLimit=e.camera.limits.min.alpha??null,this.upperAlphaLimit=e.camera.limits.max.alpha??null,e.camera.autoRotation.enabled?this.enableAutoRotationBehavior(e.camera.autoRotation.idleTimeMs):this.disableAutoRotationBehavior())}get isRunningFramingBehavior(){return this._isRunningFramingBehavior}set isRunningFramingBehavior(e){this._isRunningFramingBehavior=e,!e&&this.framingBehaviourCallback&&(this.framingBehaviourCallback(),this.framingBehaviourCallback=void 0)}setPanEnabled(e){this.panEnabled=e,this.panningSensibility=1e3/this.panDenominator,this.panningAxis=e?new p.Vector3(1,1,0):new p.Vector3(0,0,0)}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");if(e)return e}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const t=j(this._scene);return e.zoomOnBoundingInfo(t.min,t.max),this.wheelPrecision=100/this.radius,this.lowerRadiusLimit===null&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e,t){this._isRunningFramingBehavior=!0,this.framingBehaviourCallback=e;const i=this.getFramingBehavior();i.framingTime=t||800;const n=()=>{this.isRunningFramingBehavior=!1},s=j(this._scene),o=s.max.subtract(s.min),a=s.min.add(o.scale(.5));this.updateRadiusBounds(o.length()*1.5),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(a),this.panDenominator=o.length(),this.lastFocus.copyFrom(a),i.zoomOnBoundingInfo(s.min,s.max,void 0,n),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}updateRadiusBounds(e){this.maxZ=e*1e3,this.lowerRadiusLimit=e*.01,this.upperRadiusLimit=1.5*e,this.wheelPrecision=100/e,this.pinchPrecision=300/e}static create(e,t,i){var l;const n=j(e),s=n.max.subtract(n.min),o=n.min.add(s.scale(.5)),a=new B("ProductCamera",-(Math.PI/2),Math.PI/2,s.length()*1.5,o,e,t);return a.setPanEnabled(((l=t.options)==null?void 0:l.noPan)!==void 0?!t.options.noPan:!0),a.panningInertia=0,a.panningOriginTarget.copyFrom(o),a.panDenominator=s.length(),a.onAfterCheckInputsObservable.addOnce(()=>{a.setPanEnabled(a.panEnabled)}),i&&(e.activeCamera=a),a}}function j(r){if(r.meshes.length===0)return{min:new p.Vector3(-1,-1,-1),max:new p.Vector3(1,1,1)};const e=r.meshes.filter(t=>t.name.toLowerCase().endsWith("_t")||t.name.toLowerCase().includes("_t_"));return r.getWorldExtends(t=>t.isVisible&&t.isEnabled()&&(e.length===0||e.includes(t)))}class Xe{constructor(e,t=!1,i=void 0){this.renderingPipeline=new Be.DefaultRenderingPipeline("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.isSupported&&(this.renderingPipeline.prepare(),this.setConfiguration(u))}dispose(){this.renderingPipeline.dispose()}getConfiguration(){return this.currentConfiguration}setConfiguration(e){var t,i,n,s,o,a,l,h,c,g,m,f,v,J,ee,te,ie,ne,se,re,ae,oe,le,he,ce,de,ue,ge,me,pe,fe,be,ve;if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=((t=e.antiAliasing)==null?void 0:t.samples)??u.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=((i=e.antiAliasing)==null?void 0:i.fxaaEnabled)??u.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=((n=e.bloom)==null?void 0:n.enabled)??u.bloom.enabled,this.renderingPipeline.bloomKernel=((s=e.bloom)==null?void 0:s.kernel)??u.bloom.kernel,this.renderingPipeline.bloomScale=((o=e.bloom)==null?void 0:o.scale)??u.bloom.scale,this.renderingPipeline.bloomThreshold=((a=e.bloom)==null?void 0:a.threshold)??u.bloom.threshold,this.renderingPipeline.bloomWeight=((l=e.bloom)==null?void 0:l.weight)??u.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=((h=e.chromaticAberration)==null?void 0:h.enabled)??u.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=((c=e.chromaticAberration)==null?void 0:c.aberrationAmount)??u.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=((g=e.chromaticAberration)==null?void 0:g.radialIntensity)??u.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=(m=e.chromaticAberration)!=null&&m.direction?new p.Vector2(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new p.Vector2(u.chromaticAberration.direction.x,u.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=((f=e.colorCurves)==null?void 0:f.enabled)??u.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new G.ColorCurves,this.renderingPipeline.depthOfFieldEnabled=((v=e.depthOfField)==null?void 0:v.enabled)??u.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??u.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=I.DepthOfFieldEffectBlurLevel.High;break}if(this.renderingPipeline.depthOfField.focalLength=((J=e.depthOfField)==null?void 0:J.focalLength)??u.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=((ee=e.depthOfField)==null?void 0:ee.fStop)??u.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=((te=e.depthOfField)==null?void 0:te.focusDistance)??u.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=((ie=e.depthOfField)==null?void 0:ie.lensSize)??u.depthOfField.lensSize,this.renderingPipeline.grainEnabled=((ne=e.grain)==null?void 0:ne.enabled)??u.grain.enabled,this.renderingPipeline.grain.animated=((se=e.grain)==null?void 0:se.animated)??u.grain.animated,this.renderingPipeline.grain.intensity=((re=e.grain)==null?void 0:re.intensity)??u.grain.intensity,this.renderingPipeline.imageProcessing.contrast=((ae=e.misc)==null?void 0:ae.contrast)??u.misc.contrast,this.renderingPipeline.imageProcessing.exposure=((oe=e.misc)==null?void 0:oe.exposure)??u.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=((le=e.misc)==null?void 0:le.toneMappingEnabled)??u.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??u.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=P.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=P.ImageProcessingConfiguration.TONEMAPPING_ACES;break}if(this.renderingPipeline.sharpenEnabled=((he=e.sharpen)==null?void 0:he.enabled)??u.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=((ce=e.sharpen)==null?void 0:ce.colorAmount)??u.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=((de=e.sharpen)==null?void 0:de.edgeAmount)??u.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=((ue=e.vignette)==null?void 0:ue.enabled)??u.vignette.enabled,(ge=e.vignette)!=null&&ge.center?(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y):(this.renderingPipeline.imageProcessing.vignetteCenterX=u.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=u.vignette.center.y),e.vignette)switch(((me=e.vignette)==null?void 0:me.blendMode)??u.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=P.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=P.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE;break}(pe=e.vignette)!=null&&pe.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new b.Color4(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):(fe=e.vignette)!=null&&fe.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=b.Color4.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new b.Color4(u.vignette.colorRgba.r,u.vignette.colorRgba.g,u.vignette.colorRgba.b,u.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=((be=e.vignette)==null?void 0:be.stretch)??u.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=((ve=e.vignette)==null?void 0:ve.weight)??u.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const t=new G.ColorCurves;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}}Ae.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",function(r){return new je(r)}),L.SceneLoader.OnPluginActivatedObservable.add(r=>{if(r.name==="gltf"){const e=r;e.transparencyAsCoverage=!0}});function q(r){return new p.Vector3(r.x,r.y,r.z)}function D(r){return{x:r.x,y:r.y,z:r.z}}class Je{constructor(e){var l;this.focusLostNotified=!1,this.focusLostObservable=new M.Observable,this.modelLoadEventCallbacks=[],this.modelContainers=new Map,this.plugins=[],this.initComplete=!1,this.isAnimatingCamera=!1,this.renderLoop=()=>{if(!this.engine.views)return;this.modelContainers.forEach(g=>{g.updateDynamicTextures()}),this.scene.autoClear=!0,this.scene.autoClearDepthAndStencil=!0;const h=this.engine.getRenderingCanvas();if(h)if(h.getContext("webgl2")??h.getContext("webgl")){const g=this.configuration.scene.clearColor,m=h.getContext("webgl2")??h.getContext("webgl");m.clearDepth(1),m.depthFunc(m.LEQUAL),m.clearStencil(0),m.clearColor(g.r,g.g,g.b,g.a),m.clear(m.COLOR_BUFFER_BIT|m.DEPTH_BUFFER_BIT|m.STENCIL_BUFFER_BIT)}else h.getContext("2d")?h.getContext("2d").clearRect(0,0,h.width,h.height):console.error("SpiffCommerce: Failed to get any context on the rendering canvas.");this.scene.render(),this.camera.isRunningFramingBehavior&&this.camera.getFramingBehavior().isUserIsMoving&&(this.camera.isRunningFramingBehavior=!1);const c=Math.max((this.camera.lowerRadiusLimit??1)*.01,.001);!this.camera.isRunningFramingBehavior&&!this.camera.target.equalsWithEpsilon(this.camera.lastFocus,c)&&!this.focusLostNotified&&(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0),this.screenshotPrepareResolve&&(this.screenshotPrepareResolve(),this.screenshotPrepareResolve=void 0)},this.configuration=new U(e);const i=(()=>{if(!(e!=null&&e.noRender))return this.configuration.createCanvas()})(),n="1.5.6";we.DracoCompression.Configuration={decoder:{wasmUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_wasm_wrapper_gltf.js`,wasmBinaryUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_decoder_gltf.wasm`,fallbackUrl:`https://www.gstatic.com/draco/versioned/decoders/${n}/draco_decoder_gltf.js`}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const s=console.log;console.log=()=>{};const o=i?new V.Engine(i,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!(e!=null&&e.backgroundImage),audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new ye.NullEngine;console.log=s,o.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=o,this.scene=new xe.Scene(o),this.camera=B.create(this.scene,this.configuration),this.scene.activeCamera=this.camera,this.renderingPipeline=new Xe(this.scene,!1,this.camera),this.scene.clearColor=this.configuration.scene.clearColor;const a=k.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environment.file,this.scene);a.name="initial-environment-cube",a.rotationY=this.configuration.scene.environment.rotationY,this.scene.environmentTexture=a,this.scene.environmentIntensity=this.configuration.scene.environment.intensity,(l=this.configuration.options)!=null&&l.renderingPipelineConfiguration?this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration):(this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast),this.glowLayerManager=new qe(this.scene,this.configuration.emissiveGlowIntensity),this.initPromise=new Promise(h=>{this.scene.onReadyObservable.addOnce(()=>{this.initComplete=!0,h()})}),this.engine.runRenderLoop(this.renderLoop)}getInitializationPromise(){return this.initPromise}getInitializationComplete(){return this.initComplete}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerModelLoadEventListener(e){this.modelLoadEventCallbacks.push(e)}unregisterModelLoadEventListener(e){const t=this.modelLoadEventCallbacks.indexOf(e);t>-1&&this.modelLoadEventCallbacks.splice(t,1)}registerView(e){const t=e.height,i=e.width;this.engine.registerView(e,void 0,!0),e.setAttribute("height",t.toString()),e.setAttribute("width",i.toString()),this.orbitEnabled()||this.setCameraState(T.Pan),this.reattachControls(e)}getNumViewports(){var e;return((e=this.engine.views)==null?void 0:e.length)||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.plugins.forEach(e=>e.dispose(!0)),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}executeCameraAnimation(e){if(!this.camera||this.scene.activeCamera!==this.camera||this.getAllModels().length===0||!this.getAllModels().some(n=>n.getIsInitialized()))return this.queuedCameraAnimation=e,Promise.resolve();let t=()=>{};const i=async()=>{this.isAnimatingCamera=!0,await ze(this.scene,this.scene.activeCamera,e),this.isAnimatingCamera=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,t()};return this.isAnimatingCamera?(this.queuedAnimationFunction=i,new Promise(n=>{t=n})):i()}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(this.camera.alpha*180/Math.PI),latDeg:Math.round(this.camera.beta*180/Math.PI),radius:Math.round((this.camera.radius+Number.EPSILON)*1e4)/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new p.Vector3(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}setCameraState(e){var t,i;if(!((t=this.engine)!=null&&t.views)||!((i=this.engine)!=null&&i.views[0]))throw new Error("No views attached, camera state requires a view to attach controls onto.");e===T.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){let e=()=>{};const t=async()=>{this.isAnimatingCamera=!0,await new Promise(i=>{this.focusLostNotified=!1;const n=()=>{const s=this.configuration;this.camera.rerunFramingBehavior(()=>{s.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.camera.upperRadiusLimit=s.camera.limits.max.radius),i()})};this.scene.onAfterRenderObservable.addOnce(n)}),this.isAnimatingCamera=!1,this.queuedAnimationFunction&&this.queuedAnimationFunction(),this.queuedAnimationFunction=void 0,e()};return this.isAnimatingCamera?(this.queuedAnimationFunction=t,new Promise(i=>{e=i})):t()}forceStopCameraAnimations(){var e;this.queuedAnimationFunction=void 0,this.queuedCameraAnimation=void 0,this.isAnimatingCamera=!1,(e=this.camera.framingBehavior)==null||e.stopAllAnimations(),this.scene.stopAnimation(this.camera)}setAutoRotation(e){!this.configuration.camera.autoRotation.enabled||!this.camera||(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");const i=new y.ArcRotateCamera("screenshotCamera",0,0,0,p.Vector3.Zero(),this.scene);try{const n=t.latDeg*Math.PI/180,s=t.lonDeg*Math.PI/180;i.target=t.target?new p.Vector3(t.target.x,t.target.y,t.target.z):p.Vector3.Zero(),i.alpha=s,i.beta=n,i.radius=t.radius||this.camera.radius,i.minZ=.01,this.scene.render();const o=await Me.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,i,e,"image/png",2,!0);return i.dispose(),o}catch{throw i.isDisposed()||i.dispose(),new Error("Failed to render screenshot")}}orbitEnabled(){const e=this.configuration;if(!e)return!0;const t=e.camera.limits.min.alpha,i=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,s=e.camera.limits.max.beta;if(t===void 0||i===void 0||n===void 0||s===void 0)return!0;const o=[t,i],a=[n,s],l=o.every(c=>c===t),h=a.every(c=>c===n);return!l&&!h}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}setHighlights(e,t){var n;e.length===0&&((n=this.highlightLayer)==null||n.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new Ce.HighlightLayer("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const i=t?new b.Color3(t[0],t[1],t[2]).toLinearSpace():void 0;e.forEach(s=>{const o=this.scene.materials.find(a=>a.name===s.name&&a.id===s.id);o&&o.getBindedMeshes().forEach(a=>{var l;return(l=this.highlightLayer)==null?void 0:l.addMesh(a,i||b.Color3.FromHexString("#fcba03"))})})}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}loadModel(e,t){const{refocusCamera:i=!0,progressHandler:n}=t??{},s=new _e({enablePicking:this.configuration.highlights.enabled,modelDetails:e,scene:this.scene,previewService:this,progressHandler:n});return s.getInitializationPromise().then(()=>{if(this.modelContainers.size<=1&&i){const o=this.queuedCameraAnimation;this.forceStopCameraAnimations(),this.camera.rerunFramingBehavior(()=>{this.scene.onAfterRenderObservable.addOnce(()=>{o&&(this.executeCameraAnimation(o),this.queuedCameraAnimation=void 0)})},1)}}),this.configuration.highlights.enabled&&(s.registerMaterialSelectedCallback(o=>{this.setHighlights([o])}),s.registerMaterialDeselectedCallback(()=>{this.setHighlights([])})),this.modelContainers.set(s.getId(),s),this.triggerModelLoadEvent({eventType:"load",modelContainer:s}),s}async preloadModel(e){await S(e,this.scene)}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const t=this.plugins.indexOf(e);t>-1&&this.plugins.splice(t,1).forEach(n=>n.dispose(!1))}getGlowLayerManager(){return this.glowLayerManager}modelUnloaded(e){this.modelContainers.delete(e.getId()),this.triggerModelLoadEvent({eventType:"unload",modelContainer:e})}triggerModelLoadEvent(e){this.modelLoadEventCallbacks.forEach(t=>t(e))}flipTransform(e,t,i){const n=p.Matrix.Compose(q(i||{x:1,y:1,z:1}),p.Quaternion.FromEulerVector(q(t||{x:0,y:0,z:0})),q(e||{x:0,y:0,z:0})),s=p.Matrix.RotationAxis(p.Vector3.Up(),Math.PI),o=n.multiply(s),a=p.Vector3.Zero(),l=p.Quaternion.Identity(),h=p.Vector3.Zero();return o.decompose(h,l,a),l.multiplyInPlace(p.Quaternion.FromEulerAngles(0,Math.PI,0)),{position:D(a),rotation:D(l.toEulerAngles()),scale:D(h)}}updatePreviewOptions(e){var n,s;const t=new U(e);this.configuration.highlights.enabled!==t.highlights.enabled&&this.engine.setStencilBuffer(t.highlights.enabled),this.scene.clearColor=t.scene.clearColor;let i=this.scene.environmentTexture;this.configuration.scene.environment.file!==t.scene.environment.file&&(i=k.CubeTexture.CreateFromPrefilteredData(t.scene.environment.file,this.scene),i.name="updated-environment-cube",i.rotationY=this.configuration.scene.environment.rotationY,this.scene.environmentTexture=i),i.rotationY=t.scene.environment.rotationY,this.scene.environmentIntensity=t.scene.environment.intensity,(n=t.options)!=null&&n.renderingPipelineConfiguration?this.renderingPipeline.setConfiguration(t.options.renderingPipelineConfiguration):(this.scene.imageProcessingConfiguration.exposure=t.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=t.lighting.contrast),this.glowLayerManager.setIntensity(t.emissiveGlowIntensity),this.camera.updateConfiguration(t),this.camera.setPanEnabled(((s=t.options)==null?void 0:s.noPan)!==void 0?!t.options.noPan:!0),this.configuration=t}reattachControls(e,t=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,t);const i=this.camera.inputs.attached.pointers;i.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}}d.MaterialEffectMode=R,d.ProductCameraRig=T,d.REFLECTION_PROBE_RESOLUTION=K,d.RenderingConfiguration=w,d.SpiffCommerce3DPreviewService=Je,d.renderingPipelineDefaults=u,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/preview",
3
- "version": "5.7.9-4",
3
+ "version": "5.7.9-5",
4
4
  "description": "An internal implementation of the ThreeDPreviewService interface used by Spiff Commerce",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.umd.js",