@spiffcommerce/preview 5.5.8-alpha.2 → 5.5.8-alpha.3

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