@spiffcommerce/preview 3.6.2-rc.4 → 3.6.2-rc.6

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@spiffcommerce/preview",
3
- "version": "3.6.2-rc.4",
3
+ "version": "3.6.2-rc.6",
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",
7
7
  "module": "dist/index.esm.js",
8
8
  "types": "dist/index.d.mts",
9
9
  "license": "UNLICENSED",
10
+ "sideEffects": false,
10
11
  "scripts": {
11
12
  "build": "vite build",
12
13
  "test": "eslint src --ext .ts && vitest",
@@ -43,11 +44,10 @@
43
44
  "size-limit": [
44
45
  {
45
46
  "limit": "485 KB",
46
- "path": "dist/src/index.esm.js"
47
+ "path": "dist/index.esm.js"
47
48
  }
48
49
  ],
49
50
  "files": [
50
- "dist/lib/*.js",
51
51
  "dist/index.esm.js",
52
52
  "dist/index.umd.js",
53
53
  "dist/index.d.mts"
@@ -1,21 +0,0 @@
1
- import { SceneLoader as c } from "../node_modules/@babylonjs/core/Loading/sceneLoader.esm.js";
2
- const s = /* @__PURE__ */ new Map();
3
- async function u(e, n, a) {
4
- return new Promise((i, r) => {
5
- const t = s.get(e);
6
- if (t && t.scene.uid === n.uid)
7
- return i(t);
8
- c.LoadAssetContainerAsync(
9
- e,
10
- void 0,
11
- n,
12
- a
13
- ).then((o) => {
14
- s.set(e, o), i(o);
15
- }).catch(r);
16
- });
17
- }
18
- export {
19
- s as assetCache,
20
- u as getAssetContainer
21
- };
@@ -1,98 +0,0 @@
1
- import { Color4 as a, Color3 as g } from "../node_modules/@babylonjs/core/Maths/math.color.esm.js";
2
- class C {
3
- constructor(t) {
4
- this.getSceneClearColor = () => {
5
- var i, s, n, r;
6
- const o = (i = this.customOptions) != null && i.transparentBackground || (s = this.customOptions) != null && s.backgroundImage ? 0 : 1;
7
- if (this.customOptions && ((n = this.customOptions) != null && n.transparentBackground) || (r = this.customOptions) != null && r.backgroundImage)
8
- return new a(0, 0, 0, o).toLinearSpace();
9
- if (this.customOptions && this.customOptions.backgroundColor) {
10
- const e = g.FromHexString(
11
- this.customOptions.backgroundColor
12
- );
13
- return new a(
14
- e.r,
15
- e.g,
16
- e.b,
17
- o
18
- ).toLinearSpace();
19
- }
20
- return new a(0.98, 0.98, 0.98, o).toLinearSpace();
21
- }, this.highlightColorFromConfig = () => this.customOptions && this.customOptions.highlightColor ? this.hexToColor4(this.customOptions.highlightColor) : new a(0.98, 0.98, 0.98, 1).toLinearSpace(), this.hexToColor4 = (o, i = 1) => {
22
- const s = g.FromHexString(o);
23
- return new a(
24
- s.r,
25
- s.g,
26
- s.b,
27
- i
28
- ).toLinearSpace();
29
- }, this.customOptions = t;
30
- }
31
- createCanvas() {
32
- return this.customOptions.createCanvas ? this.customOptions.createCanvas() : document.createElement("canvas");
33
- }
34
- get options() {
35
- return this.customOptions;
36
- }
37
- /**
38
- * Configuration related to the scene
39
- */
40
- get scene() {
41
- var t, o, i;
42
- return {
43
- clearColor: this.getSceneClearColor(),
44
- transparentBackground: ((t = this.customOptions) == null ? void 0 : t.transparentBackground) || ((o = this.customOptions) == null ? void 0 : o.backgroundImage),
45
- environmentFile: ((i = this.customOptions) == null ? void 0 : i.environmentFile) ?? "assets/model-viewer/default.env"
46
- };
47
- }
48
- /**
49
- * Configuration related to the camera used to view and interact with the scene.
50
- */
51
- get camera() {
52
- var t, o, i, s, n, r, e, h, u, c, m, p, l;
53
- return {
54
- autoOrientation: ((t = this.customOptions) == null ? void 0 : t.disableAutomaticOrientation) ?? !0,
55
- autoRotation: {
56
- enabled: ((o = this.customOptions) == null ? void 0 : o.autoRotation) ?? !1,
57
- idleTimeMs: ((i = this.customOptions) == null ? void 0 : i.idleTimeBeforeRotation) ?? 5e3
58
- },
59
- limits: {
60
- min: {
61
- alpha: (s = this.customOptions) != null && s.lowerAlphaLimitDeg ? ((n = this.customOptions) == null ? void 0 : n.lowerAlphaLimitDeg) * Math.PI / 180 : void 0,
62
- beta: (r = this.customOptions) != null && r.lowerBetaLimitDeg ? ((e = this.customOptions) == null ? void 0 : e.lowerBetaLimitDeg) * Math.PI / 180 : void 0,
63
- radius: (h = this.customOptions) == null ? void 0 : h.minZoomOverride
64
- },
65
- max: {
66
- alpha: (u = this.customOptions) != null && u.upperAlphaLimitDeg ? ((c = this.customOptions) == null ? void 0 : c.upperAlphaLimitDeg) * Math.PI / 180 : void 0,
67
- beta: (m = this.customOptions) != null && m.upperBetaLimitDeg ? ((p = this.customOptions) == null ? void 0 : p.upperBetaLimitDeg) * Math.PI / 180 : void 0,
68
- radius: (l = this.customOptions) == null ? void 0 : l.maxZoomOverride
69
- }
70
- }
71
- };
72
- }
73
- /**
74
- * Configuration related to the highlighting system. Highlights are used to add
75
- * a visual cue to the user that something is moused over in the preview.
76
- */
77
- get highlights() {
78
- var t;
79
- return {
80
- enabled: ((t = this.customOptions) == null ? void 0 : t.highlightOnMaterialHover) ?? !1,
81
- color: this.highlightColorFromConfig()
82
- };
83
- }
84
- get lighting() {
85
- var t, o, i, s;
86
- return {
87
- exposure: ((o = (t = this.customOptions) == null ? void 0 : t.lighting) == null ? void 0 : o.exposure) ?? 0.9,
88
- contrast: ((s = (i = this.customOptions) == null ? void 0 : i.lighting) == null ? void 0 : s.contrast) ?? 1.6
89
- };
90
- }
91
- get emissiveGlowIntensity() {
92
- var t;
93
- return ((t = this.customOptions) == null ? void 0 : t.emissiveGlowIntensity) ?? 0.5;
94
- }
95
- }
96
- export {
97
- C as Configuration
98
- };
@@ -1,417 +0,0 @@
1
- import { ArcRotateCamera as p } from "../node_modules/@babylonjs/core/Cameras/arcRotateCamera.esm.js";
2
- import { Engine as v } from "../node_modules/@babylonjs/core/Engines/engine.esm.js";
3
- import { NullEngine as C } from "../node_modules/@babylonjs/core/Engines/nullEngine.esm.js";
4
- import { HighlightLayer as w } from "../node_modules/@babylonjs/core/Layers/highlightLayer.esm.js";
5
- import { SceneLoader as L } from "../node_modules/@babylonjs/core/Loading/sceneLoader.esm.js";
6
- import { CubeTexture as b } from "../node_modules/@babylonjs/core/Materials/Textures/cubeTexture.esm.js";
7
- import { Color3 as d } from "../node_modules/@babylonjs/core/Maths/math.color.esm.js";
8
- import { Vector3 as l } from "../node_modules/@babylonjs/core/Maths/math.vector.esm.js";
9
- import { DracoCompression as P } from "../node_modules/@babylonjs/core/Meshes/Compression/dracoCompression.esm.js";
10
- import { Observable as m } from "../node_modules/@babylonjs/core/Misc/observable.esm.js";
11
- import { Tools as y } from "../node_modules/@babylonjs/core/Misc/tools.esm.js";
12
- import { Scene as E } from "../node_modules/@babylonjs/core/scene.esm.js";
13
- import "../node_modules/@babylonjs/loaders/glTF/glTFFileLoader.esm.js";
14
- import "../node_modules/@babylonjs/loaders/glTF/glTFValidation.esm.js";
15
- import "../node_modules/@babylonjs/loaders/glTF/1.0/glTFBinaryExtension.esm.js";
16
- import "../node_modules/@babylonjs/loaders/glTF/1.0/glTFLoader.esm.js";
17
- import "../node_modules/@babylonjs/loaders/glTF/1.0/glTFLoaderInterfaces.esm.js";
18
- import "../node_modules/@babylonjs/loaders/glTF/1.0/glTFLoaderUtils.esm.js";
19
- import "../node_modules/@babylonjs/loaders/glTF/1.0/glTFMaterialsCommonExtension.esm.js";
20
- import { GLTFLoader as M } from "../node_modules/@babylonjs/loaders/glTF/2.0/glTFLoader.esm.js";
21
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/EXT_lights_image_based.esm.js";
22
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.esm.js";
23
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/EXT_meshopt_compression.esm.js";
24
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/EXT_texture_webp.esm.js";
25
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression.esm.js";
26
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual.esm.js";
27
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.esm.js";
28
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit.esm.js";
29
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat.esm.js";
30
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_iridescence.esm.js";
31
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_anisotropy.esm.js";
32
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_emissive_strength.esm.js";
33
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen.esm.js";
34
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_specular.esm.js";
35
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_ior.esm.js";
36
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants.esm.js";
37
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_transmission.esm.js";
38
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_translucency.esm.js";
39
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_volume.esm.js";
40
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_mesh_quantization.esm.js";
41
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu.esm.js";
42
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform.esm.js";
43
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_xmp_json_ld.esm.js";
44
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/KHR_animation_pointer.esm.js";
45
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/MSFT_audio_emitter.esm.js";
46
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/MSFT_lod.esm.js";
47
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/MSFT_minecraftMesh.esm.js";
48
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/MSFT_sRGBFactors.esm.js";
49
- import "../node_modules/@babylonjs/loaders/glTF/2.0/Extensions/ExtrasAsMetadata.esm.js";
50
- import { Configuration as z } from "./configuration.esm.js";
51
- import { GLBLoaderExtension as x } from "./glbLoaderExtensions.esm.js";
52
- import R from "./glowLayerManager.esm.js";
53
- import { ModelContainerImpl as I } from "./modelContainer.esm.js";
54
- import { resetSceneModelAnimations as S, animateCameraInScene as k } from "./productAnimations.esm.js";
55
- import { ProductCamera as O } from "./productCamera.esm.js";
56
- import { RenderingPipeline as A } from "./renderingPipeline.esm.js";
57
- import { ProductCameraRig as u } from "./types.esm.js";
58
- import "../node_modules/@babylonjs/core/Engines/Extensions/engine.views.esm.js";
59
- import "../node_modules/@babylonjs/core/Meshes/instancedMesh.esm.js";
60
- import "../node_modules/@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader.esm.js";
61
- import "../node_modules/@babylonjs/core/Materials/Textures/Loaders/envTextureLoader.esm.js";
62
- import "../node_modules/@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader.esm.js";
63
- import "../node_modules/@babylonjs/core/Animations/animatable.esm.js";
64
- import "../node_modules/@babylonjs/core/Misc/screenshotTools.esm.js";
65
- import "../node_modules/@babylonjs/core/Rendering/boundingBoxRenderer.esm.js";
66
- M.RegisterExtension("glbPostProcessor", function(o) {
67
- return new x(o);
68
- });
69
- L.OnPluginActivatedObservable.add((o) => {
70
- if (o.name === "gltf") {
71
- const e = o;
72
- e.transparencyAsCoverage = !0;
73
- }
74
- });
75
- const c = "initialScene";
76
- class $e {
77
- constructor(e) {
78
- this.loadProgress = /* @__PURE__ */ new Map([
79
- [c, 0]
80
- ]), this.focusLostNotified = !1, this.loadObservable = new m(), this.focusLostObservable = new m(), this.initializedCallbacks = [], this.isInitialized = !1, this.modelLoadEventCallbacks = [], this.modelContainers = /* @__PURE__ */ new Map(), this.plugins = [], this.configuration = new z(e);
81
- const t = (() => {
82
- if (!(e != null && e.noRender))
83
- return this.configuration.createCanvas();
84
- })(), r = "1.5.6";
85
- P.Configuration = {
86
- decoder: {
87
- wasmUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_wasm_wrapper_gltf.js`,
88
- wasmBinaryUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_decoder_gltf.wasm`,
89
- fallbackUrl: `https://www.gstatic.com/draco/versioned/decoders/${r}/draco_decoder_gltf.js`
90
- }
91
- }, t && (t.getContext("webgl2") || t.getContext("webgl"));
92
- const s = console.log;
93
- console.log = () => {
94
- };
95
- const a = t ? new v(t, !0, {
96
- adaptToDeviceRatio: !0,
97
- limitDeviceRatio: 2,
98
- premultipliedAlpha: !1,
99
- preserveDrawingBuffer: !!(e != null && e.backgroundImage),
100
- audioEngine: !1,
101
- stencil: this.configuration.highlights.enabled,
102
- forceSRGBBufferSupportState: !0
103
- }) : new C();
104
- console.log = s, a.hideLoadingUI(), window.addEventListener("resize", this.fireResizeEvent.bind(this)), this.engine = a, this.scene = new E(a), this.camera = O.create(this.scene, this.configuration), this.renderingPipeline = new A(
105
- this.scene,
106
- !1,
107
- this.camera
108
- ), this.scene.imageProcessingConfiguration.exposure = this.configuration.lighting.exposure, this.scene.imageProcessingConfiguration.contrast = this.configuration.lighting.contrast, this.glowLayerManager = new R(
109
- this.scene,
110
- this.configuration.emissiveGlowIntensity
111
- );
112
- }
113
- getEngineContext() {
114
- return {
115
- engine: this.engine,
116
- scene: this.scene,
117
- camera: this.camera
118
- };
119
- }
120
- registerFocusLostListener(e) {
121
- this.focusLostObservable.add(e);
122
- }
123
- unregisterFocusLostListener(e) {
124
- this.focusLostObservable.removeCallback(e);
125
- }
126
- registerLoadProgressListener(e) {
127
- this.loadObservable.add(e), e(this.getLoadListenerEvent());
128
- }
129
- unregisterLoadProgressListener(e) {
130
- this.loadObservable.removeCallback(e);
131
- }
132
- registerInitializedListener(e) {
133
- this.isInitialized || !this.isInitialized && this.initializedCallbacks.push(e);
134
- }
135
- unregisterInitializedListener(e) {
136
- if (this.isInitialized)
137
- return;
138
- const i = this.initializedCallbacks.indexOf(e);
139
- i > -1 && this.initializedCallbacks.splice(i, 1);
140
- }
141
- getIsInitialized() {
142
- return this.isInitialized;
143
- }
144
- registerModelLoadEventListener(e) {
145
- this.modelLoadEventCallbacks.push(e);
146
- }
147
- unregisterModelLoadEventListener(e) {
148
- const i = this.modelLoadEventCallbacks.indexOf(e);
149
- i > -1 && this.modelLoadEventCallbacks.splice(i, 1);
150
- }
151
- registerView(e) {
152
- const i = e.height, t = e.width;
153
- this.engine.registerView(e), e.setAttribute("height", i.toString()), e.setAttribute("width", t.toString()), this.orbitEnabled() || this.setCameraState(u.Pan), this.reattachControls(e);
154
- }
155
- getNumViewports() {
156
- var e;
157
- return ((e = this.engine.views) == null ? void 0 : e.length) || 0;
158
- }
159
- unregisterView(e) {
160
- this.engine.unRegisterView(e);
161
- }
162
- shutdown() {
163
- this.plugins.forEach((e) => e.dispose(!0)), this.renderingPipeline.dispose(), this.engine && this.engine.dispose(), window.removeEventListener("resize", this.fireResizeEvent);
164
- }
165
- getSceneInitializationProgress() {
166
- return this.loadProgress.get(c);
167
- }
168
- async initialize(e) {
169
- var t, r;
170
- this.scene.clearColor = this.configuration.scene.clearColor, this.scene.environmentTexture = b.CreateFromPrefilteredData(
171
- this.configuration.scene.environmentFile,
172
- this.scene
173
- );
174
- let i;
175
- return e && (i = await this.loadModel(
176
- e,
177
- (a) => {
178
- this.loadProgress.set(
179
- c,
180
- a.loaded * 100 / a.total
181
- ), this.notifyLoadHandlers();
182
- }
183
- ).getInitializationPromise()), this.loadProgress.set(c, 100), this.notifyLoadHandlers(), this.scene.activeCamera = this.camera, this.camera.rerunFramingBehavior(void 0, 1), S(this.scene), ((t = this.engine.views) == null ? void 0 : t.length) >= 1 && this.reattachControls(
184
- this.engine.views[this.engine.views.length - 1].target
185
- ), this.queuedCameraAnimation && (this.executeCameraAnimation(this.queuedCameraAnimation), this.queuedCameraAnimation = void 0), this.isInitialized = !0, await Promise.all(this.initializedCallbacks.map((s) => s())), this.initializedCallbacks = [], (r = this.configuration.options) != null && r.renderingPipelineConfiguration && this.renderingPipeline.setConfiguration(
186
- this.configuration.options.renderingPipelineConfiguration
187
- ), this.engine.runRenderLoop(() => {
188
- this.engine.views && (this.modelContainers.forEach((s) => {
189
- s.updateDynamicTextures();
190
- }), this.configuration.scene.transparentBackground && this.engine.views.forEach((s) => {
191
- const a = this.engine.getRenderingCanvas();
192
- s.target.getContext("2d").clearRect(
193
- 0,
194
- 0,
195
- a.width,
196
- a.height
197
- );
198
- }), this.scene.render(), !this.camera.target.equalsWithEpsilon(this.camera.lastFocus, 0.1) && !this.focusLostNotified && (this.focusLostObservable.notifyObservers(void 0), this.focusLostNotified = !0), this.screenshotPrepareResolve && (this.screenshotPrepareResolve(), this.screenshotPrepareResolve = void 0));
199
- }), i;
200
- }
201
- executeCameraAnimation(e) {
202
- if (this.getSceneInitializationProgress() !== 100 || !this.camera || this.scene.activeCamera !== this.camera) {
203
- this.queuedCameraAnimation = e;
204
- return;
205
- }
206
- k(
207
- this.scene,
208
- this.scene.activeCamera,
209
- e
210
- );
211
- }
212
- getCameraPose() {
213
- if (this.scene && this.camera)
214
- return {
215
- lonDeg: Math.round(this.camera.alpha * 180 / Math.PI),
216
- latDeg: Math.round(this.camera.beta * 180 / Math.PI),
217
- radius: Math.round((this.camera.radius + Number.EPSILON) * 1e4) / 1e4,
218
- target: {
219
- x: this.camera.target.x,
220
- y: this.camera.target.y,
221
- z: this.camera.target.z
222
- }
223
- };
224
- }
225
- setCameraPose(e) {
226
- this.scene && this.camera && (this.camera.target = new l(
227
- e.target.x,
228
- e.target.y,
229
- e.target.z
230
- ), this.camera.radius = e.radius, this.camera.alpha = e.latDeg, this.camera.beta = e.lonDeg);
231
- }
232
- setCameraState(e) {
233
- var i, t;
234
- if (!((i = this.engine) != null && i.views) || !((t = this.engine) != null && t.views[0]))
235
- throw new Error(
236
- "No views attached, camera state requires a view to attach controls onto."
237
- );
238
- e === u.Orbit ? this.reattachControls(this.engine.views[0].target, 2) : this.reattachControls(this.engine.views[0].target, 0);
239
- }
240
- animateToLastCameraFocus() {
241
- return new Promise((e) => {
242
- const i = this.configuration;
243
- this.camera.rerunFramingBehavior(() => {
244
- this.focusLostNotified = !1, i.camera.limits.min.radius && (this.camera.lowerRadiusLimit = i.camera.limits.min.radius), i.camera.limits.max.radius && (this.camera.upperRadiusLimit = i.camera.limits.max.radius), e();
245
- });
246
- });
247
- }
248
- setAutoRotation(e) {
249
- !this.configuration.camera.autoRotation.enabled || !this.camera || (e ? this.camera.enableAutoRotationBehavior(
250
- this.configuration.camera.autoRotation.idleTimeMs
251
- ) : this.camera.disableAutoRotationBehavior());
252
- }
253
- getCurrentConfiguration() {
254
- return this.configuration.options;
255
- }
256
- async renderSceneScreenshot(e, i) {
257
- if (!this.camera)
258
- throw new Error("Missing product camera, cannot render screenshot!");
259
- const t = new p(
260
- "screenshotCamera",
261
- 0,
262
- 0,
263
- 0,
264
- l.Zero(),
265
- this.scene
266
- );
267
- try {
268
- const r = i.latDeg * Math.PI / 180, s = i.lonDeg * Math.PI / 180;
269
- t.target = i.target ? new l(i.target.x, i.target.y, i.target.z) : l.Zero(), t.alpha = s, t.beta = r, t.radius = i.radius || this.camera.radius, t.minZ = 0.01, this.scene.render();
270
- const a = await y.CreateScreenshotUsingRenderTargetAsync(
271
- this.engine,
272
- t,
273
- e,
274
- "image/png",
275
- 2,
276
- !0
277
- );
278
- return t.dispose(), a;
279
- } catch {
280
- throw t.isDisposed() || t.dispose(), new Error("Failed to render screenshot");
281
- }
282
- }
283
- orbitEnabled() {
284
- const e = this.configuration;
285
- if (!e)
286
- return !0;
287
- const i = e.camera.limits.min.alpha, t = e.camera.limits.max.alpha, r = e.camera.limits.min.beta, s = e.camera.limits.max.beta;
288
- if (i === void 0 || t === void 0 || r === void 0 || s === void 0)
289
- return !0;
290
- const a = [i, t], n = [r, s], h = a.every((g) => g === i), f = n.every((g) => g === r);
291
- return !h && !f;
292
- }
293
- fireResizeEvent() {
294
- this.getNumViewports() > 0 && this.engine.resize();
295
- }
296
- setHighlights(e, i) {
297
- var r;
298
- e.length === 0 && ((r = this.highlightLayer) == null || r.dispose(), this.highlightLayer = void 0), this.highlightLayer || (this.highlightLayer = new w("highlights", this.scene, {
299
- isStroke: !0,
300
- blurVerticalSize: 0.85,
301
- blurHorizontalSize: 0.85
302
- }), this.highlightLayer.innerGlow = !0, this.highlightLayer.outerGlow = !1), this.highlightLayer.removeAllMeshes();
303
- const t = i ? new d(i[0], i[1], i[2]).toLinearSpace() : void 0;
304
- e.forEach((s) => {
305
- const a = this.scene.materials.find(
306
- (n) => n.name === s.name && n.id === s.id
307
- );
308
- a && a.getBindedMeshes().forEach(
309
- (n) => {
310
- var h;
311
- return (h = this.highlightLayer) == null ? void 0 : h.addMesh(
312
- n,
313
- t || d.FromHexString("#fcba03")
314
- );
315
- }
316
- );
317
- });
318
- }
319
- setRenderingPipelineConfiguration(e) {
320
- this.renderingPipeline && this.renderingPipeline.setConfiguration(e);
321
- }
322
- loadModel(e, i) {
323
- const t = new I({
324
- enablePicking: this.configuration.highlights.enabled,
325
- modelDetails: e,
326
- scene: this.scene,
327
- previewService: this,
328
- progressHandler: i
329
- });
330
- return t.registerMaterialVariantListener(
331
- (r) => this.handleMaterialProgressCallback(
332
- r.remainingCount,
333
- r.totalCount,
334
- r.taskName
335
- )
336
- ), t.registerModelVariantListener(
337
- (r) => this.handleModelProgressCallback(r, r.key)
338
- ), this.configuration.highlights.enabled && (t.registerMaterialSelectedCallback((r) => {
339
- this.setHighlights([r]);
340
- }), t.registerMaterialDeselectedCallback(() => {
341
- this.setHighlights([]);
342
- })), this.modelContainers.set(t.getId(), t), this.triggerModelLoadEvent({
343
- eventType: "load",
344
- modelContainer: t
345
- }), t;
346
- }
347
- getAllModels() {
348
- return Array.from(this.modelContainers.values());
349
- }
350
- getModelById(e) {
351
- return this.modelContainers.get(e);
352
- }
353
- registerPlugin(e) {
354
- this.plugins.push(e), e.initialize(this, {
355
- camera: this.camera,
356
- engine: this.engine,
357
- scene: this.scene
358
- });
359
- }
360
- unregisterPlugin(e) {
361
- const i = this.plugins.indexOf(e);
362
- i > -1 && this.plugins.splice(i, 1).forEach((r) => r.dispose(!1));
363
- }
364
- getGlowLayerManager() {
365
- return this.glowLayerManager;
366
- }
367
- modelUnloaded(e) {
368
- this.modelContainers.delete(e.getId()), this.triggerModelLoadEvent({
369
- eventType: "unload",
370
- modelContainer: e
371
- });
372
- }
373
- triggerModelLoadEvent(e) {
374
- this.modelLoadEventCallbacks.forEach((i) => i(e));
375
- }
376
- handleMaterialProgressCallback(e, i, t) {
377
- this.loadProgress.set(`key_${t}`, e / i * 100), this.notifyLoadHandlers();
378
- }
379
- handleModelProgressCallback(e, i) {
380
- this.loadProgress.set(i, e.loaded * 100 / e.total), this.notifyLoadHandlers();
381
- }
382
- /**
383
- * Given a valid canvas element, will remove any existing input controls
384
- * and re-attach them to the given canvas. The pan mouse button can be set
385
- * to either 0 (left mouse) or 2 (right mouse).
386
- */
387
- reattachControls(e, i = 2) {
388
- if (this.scene.detachControl(), this.engine.inputElement = e, this.camera) {
389
- this.camera.attachControl(!0, !1, i);
390
- const t = this.camera.inputs.attached.pointers;
391
- t.multiTouchPanning = !1;
392
- }
393
- this.scene.attachControl(!0, !0, !0);
394
- }
395
- /**
396
- * Computes a load listener event based on current state of scene.
397
- */
398
- getLoadListenerEvent() {
399
- const e = Array.from(this.loadProgress.values()).filter(
400
- (r) => r < 100
401
- ), t = e.reduce((r, s) => r + s, 0) / e.length || 0;
402
- return {
403
- loadValue: e.length === 0 ? 100 : t,
404
- sceneInitialized: this.getSceneInitializationProgress() === 100
405
- };
406
- }
407
- /**
408
- * Computes the average loading time across all loading events and notifies
409
- * listeners of the current load progress.
410
- */
411
- notifyLoadHandlers() {
412
- this.loadObservable.notifyObservers(this.getLoadListenerEvent());
413
- }
414
- }
415
- export {
416
- $e as SpiffCommerce3DPreviewService
417
- };
@@ -1,51 +0,0 @@
1
- import { Engine as d } from "../node_modules/@babylonjs/core/Engines/engine.esm.js";
2
- import { PBRMaterial as m } from "../node_modules/@babylonjs/core/Materials/PBR/pbrMaterial.esm.js";
3
- import { DynamicTexture as T } from "../node_modules/@babylonjs/core/Materials/Textures/dynamicTexture.esm.js";
4
- import { Texture as g } from "../node_modules/@babylonjs/core/Materials/Textures/texture.esm.js";
5
- import { RenderingConfiguration as x } from "./renderConstants.esm.js";
6
- function I(o, t, r, e, n = "") {
7
- r.forEach((a) => {
8
- const c = a.getID(), p = a.getName(), u = x.getDynamicTextureResolution();
9
- o.filter((f) => f.name === n + p).forEach((f) => {
10
- const s = e.get(c), l = !1;
11
- if (s)
12
- w(f, s), s.update(l);
13
- else {
14
- const i = D(
15
- p,
16
- t,
17
- u.width,
18
- u.height
19
- );
20
- e.set(c, i), a.setStaticContext(
21
- i.getContext()
22
- ), w(f, i), i.onLoadObservable.addOnce(() => {
23
- i.update(l);
24
- });
25
- }
26
- });
27
- });
28
- }
29
- function D(o, t, r, e) {
30
- const n = new T(
31
- o,
32
- { width: r, height: e },
33
- t,
34
- x.shouldMipMap(),
35
- g.TRILINEAR_SAMPLINGMODE,
36
- d.TEXTUREFORMAT_RGBA
37
- ), a = n.getContext();
38
- return a && (a.fillStyle = "#f5f5f5", a.fillRect(0, 0, r, e), n.update()), n;
39
- }
40
- function w(o, t) {
41
- if (o instanceof m) {
42
- const r = o, e = r.albedoTexture;
43
- e ? (t.wrapU = e.wrapU, t.wrapV = e.wrapV) : (t.wrapU = 1, t.wrapV = 1), r.albedoTexture = t;
44
- } else {
45
- const r = o, e = r.diffuseTexture;
46
- e && (t.wrapU = e.wrapU, t.wrapV = e.wrapV), r.diffuseTexture = t;
47
- }
48
- }
49
- export {
50
- I as attachDynamicTextures
51
- };