@spiffcommerce/preview 3.6.2-rc.3 → 3.6.2-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/assetCache.esm.js +21 -0
- package/dist/lib/configuration.esm.js +98 -0
- package/dist/lib/core.esm.js +417 -0
- package/dist/lib/dynamicTexture.esm.js +51 -0
- package/dist/lib/glbLoaderExtensions.esm.js +137 -0
- package/dist/lib/glowLayerManager.esm.js +19 -0
- package/dist/lib/guid.esm.js +7 -0
- package/dist/lib/material.esm.js +50 -0
- package/dist/lib/modelContainer.esm.js +351 -0
- package/dist/lib/productAnimations.esm.js +123 -0
- package/dist/lib/productCamera.esm.js +113 -0
- package/dist/lib/renderConstants.esm.js +103 -0
- package/dist/lib/renderingPipeline.esm.js +99 -0
- package/dist/lib/types.esm.js +5 -0
- package/dist/lib/variants.esm.js +112 -0
- package/package.json +4 -3
- /package/dist/{src/index.esm.js → index.esm.js} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { PBRMaterial as d } from "../node_modules/@babylonjs/core/Materials/PBR/pbrMaterial.esm.js";
|
|
2
|
+
import { MirrorTexture as p } from "../node_modules/@babylonjs/core/Materials/Textures/mirrorTexture.esm.js";
|
|
3
|
+
import "../node_modules/@babylonjs/core/Maths/math.axis.esm.js";
|
|
4
|
+
import { Color3 as m } from "../node_modules/@babylonjs/core/Maths/math.color.esm.js";
|
|
5
|
+
import { Plane as P } from "../node_modules/@babylonjs/core/Maths/math.plane.esm.js";
|
|
6
|
+
import "../node_modules/@babylonjs/core/Maths/math.path.esm.js";
|
|
7
|
+
import { Vector3 as u } from "../node_modules/@babylonjs/core/Maths/math.vector.esm.js";
|
|
8
|
+
import { ReflectionProbe as R } from "../node_modules/@babylonjs/core/Probes/reflectionProbe.esm.js";
|
|
9
|
+
import { RenderingConfiguration as h, REFLECTION_PROBE_RESOLUTION as E } from "./renderConstants.esm.js";
|
|
10
|
+
class B {
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.name = "glbPostProcessor", this.enabled = !0, this.loader = e;
|
|
13
|
+
}
|
|
14
|
+
onReady() {
|
|
15
|
+
this.applyReflections(this.loader.babylonScene);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Any custom properties set in blender on transform nodes will appear here. We can
|
|
19
|
+
* write the properties into the object metadata for retrieval at runtime.
|
|
20
|
+
*/
|
|
21
|
+
loadNodeAsync(e, s, r) {
|
|
22
|
+
return this.loader.loadNodeAsync(
|
|
23
|
+
e,
|
|
24
|
+
s,
|
|
25
|
+
function(a) {
|
|
26
|
+
s.extras && Object.keys(s.extras).forEach((t) => {
|
|
27
|
+
const o = s.extras[t];
|
|
28
|
+
a.metadata[t] = o;
|
|
29
|
+
}), r(a);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Material properties can be set at load time as we don't depend
|
|
35
|
+
* on the entire scene graph being loaded (for reflection render lists).
|
|
36
|
+
* The need for these properties may go over time as the relevant exporters/importers are updated.
|
|
37
|
+
*/
|
|
38
|
+
async loadMaterialPropertiesAsync(e, s, r) {
|
|
39
|
+
await this.loader.loadMaterialPropertiesAsync(
|
|
40
|
+
e,
|
|
41
|
+
s,
|
|
42
|
+
r
|
|
43
|
+
), this.enableMaterialExtrasIfRequired(s, r), r.needDepthPrePass = !0;
|
|
44
|
+
}
|
|
45
|
+
dispose() {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* With a given material descriptor and babylon material instance, looks for any
|
|
49
|
+
* metadata defined on the descriptor and applies to the babylon material.
|
|
50
|
+
* @param material A material descriptor
|
|
51
|
+
* @param babylonMaterial An instance of a material representation in babylon.
|
|
52
|
+
*/
|
|
53
|
+
enableMaterialExtrasIfRequired(e, s) {
|
|
54
|
+
if (!(!e.extras || !(s instanceof d))) {
|
|
55
|
+
if (e.extras.sheen) {
|
|
56
|
+
const r = s;
|
|
57
|
+
r.sheen.isEnabled = !0, r.sheen.intensity = e.extras.sheen;
|
|
58
|
+
}
|
|
59
|
+
if (e.extras.translucency) {
|
|
60
|
+
const r = s;
|
|
61
|
+
r.subSurface.isTranslucencyEnabled = !0, r.subSurface.translucencyIntensity = e.extras.translucency, e.extras.translucencyR && e.extras.translucencyG && e.extras.translucencyB && (r.subSurface.tintColor = new m(
|
|
62
|
+
e.extras.translucencyR,
|
|
63
|
+
e.extras.translucencyG,
|
|
64
|
+
e.extras.translucencyB
|
|
65
|
+
));
|
|
66
|
+
}
|
|
67
|
+
if (e.extras.refractionIOR) {
|
|
68
|
+
const r = s;
|
|
69
|
+
r.subSurface.isRefractionEnabled = !0, r.subSurface.volumeIndexOfRefraction = e.extras.refractionIOR;
|
|
70
|
+
}
|
|
71
|
+
if (e.extras.useDepthPrePass) {
|
|
72
|
+
const r = s;
|
|
73
|
+
r.needDepthPrePass = !0, r.forceIrradianceInFragment = !0;
|
|
74
|
+
}
|
|
75
|
+
if (e.extras.useParallax) {
|
|
76
|
+
const r = s;
|
|
77
|
+
r.useParallax = !0, r.useParallaxOcclusion = !0, r.parallaxScaleBias = e.extras.useParallax;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Called with a loaded scene. Will finish initialization
|
|
83
|
+
* of any reflective properties within the scene.
|
|
84
|
+
* @param scene The scene to parse.
|
|
85
|
+
*/
|
|
86
|
+
applyReflections(e) {
|
|
87
|
+
function s(t) {
|
|
88
|
+
const o = [];
|
|
89
|
+
return t.transformNodes.forEach((n) => {
|
|
90
|
+
n.metadata && n.metadata.reflective && o.push(...n.getChildMeshes());
|
|
91
|
+
}), t.meshes.forEach((n) => {
|
|
92
|
+
n.metadata && n.metadata.reflective && !o.includes(n) && o.push(n);
|
|
93
|
+
}), o;
|
|
94
|
+
}
|
|
95
|
+
function r(t, o = 1) {
|
|
96
|
+
const n = t.material;
|
|
97
|
+
if (!n)
|
|
98
|
+
return;
|
|
99
|
+
const i = new p(
|
|
100
|
+
"mirror",
|
|
101
|
+
h.getMirrorTextureResolution(),
|
|
102
|
+
e,
|
|
103
|
+
!0
|
|
104
|
+
);
|
|
105
|
+
i.renderList = s(e);
|
|
106
|
+
const c = t.getVerticesData("normal");
|
|
107
|
+
if (!c)
|
|
108
|
+
throw new Error(
|
|
109
|
+
"Mirror attribute specified on: " + t.name + "But no normals exist to generate a mirror from!"
|
|
110
|
+
);
|
|
111
|
+
t.computeWorldMatrix(!0);
|
|
112
|
+
const f = t.getWorldMatrix(), l = u.TransformNormal(
|
|
113
|
+
new u(c[0], c[1], c[2]),
|
|
114
|
+
f
|
|
115
|
+
).normalize(), x = P.FromPositionAndNormal(
|
|
116
|
+
t.position,
|
|
117
|
+
l.scale(-1)
|
|
118
|
+
);
|
|
119
|
+
i.mirrorPlane = x, i.level = o, n.reflectionTexture = i;
|
|
120
|
+
}
|
|
121
|
+
function a(t) {
|
|
122
|
+
const o = t.material, n = new R(
|
|
123
|
+
"probe-" + o.name,
|
|
124
|
+
E,
|
|
125
|
+
e
|
|
126
|
+
);
|
|
127
|
+
n.attachToMesh(t), n.renderList && n.renderList.push(...s(e)), o.reflectionTexture = n.cubeTexture;
|
|
128
|
+
}
|
|
129
|
+
e.meshes.forEach((t) => {
|
|
130
|
+
const o = t.metadata;
|
|
131
|
+
o && (o.mirrorTexture && r(t, o.mirrorTexture), o.reflectionProbe && a(t));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
B as GLBLoaderExtension
|
|
137
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { GlowLayer as t } from "../node_modules/@babylonjs/core/Layers/glowLayer.esm.js";
|
|
2
|
+
class o {
|
|
3
|
+
constructor(s, e) {
|
|
4
|
+
this.scene = s, this.intensity = e, this.meshCount = 0;
|
|
5
|
+
}
|
|
6
|
+
includeMeshes(s) {
|
|
7
|
+
this.glowLayer || (this.glowLayer = new t("glow", this.scene), this.glowLayer.intensity = this.intensity), s.forEach((e) => {
|
|
8
|
+
this.glowLayer.hasMesh(e) || (this.glowLayer.addIncludedOnlyMesh(e), this.meshCount++);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
removeMeshes(s) {
|
|
12
|
+
this.glowLayer && (s.forEach((e) => {
|
|
13
|
+
this.glowLayer.hasMesh(e) && (this.glowLayer.removeIncludedOnlyMesh(e), this.meshCount--);
|
|
14
|
+
}), this.meshCount === 0 && (this.glowLayer.dispose(), this.glowLayer = void 0));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
o as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Color3 as f } from "../node_modules/@babylonjs/core/Maths/math.color.esm.js";
|
|
2
|
+
import { MaterialEffectMode as r } from "./types.esm.js";
|
|
3
|
+
const p = {
|
|
4
|
+
albedoTexture: "albedoMap",
|
|
5
|
+
bumpTexture: "normalMap",
|
|
6
|
+
ambientTexture: "ambientMap",
|
|
7
|
+
emissiveTexture: "emissionMap",
|
|
8
|
+
opacityTexture: "alphaMap",
|
|
9
|
+
metallicTexture: "metallicMap",
|
|
10
|
+
refractionTexture: "refractionMap"
|
|
11
|
+
};
|
|
12
|
+
function m(o, e, s, i) {
|
|
13
|
+
[
|
|
14
|
+
"albedoTexture",
|
|
15
|
+
"bumpTexture",
|
|
16
|
+
"ambientTexture",
|
|
17
|
+
"emissiveTexture",
|
|
18
|
+
"opacityTexture",
|
|
19
|
+
"metallicTexture",
|
|
20
|
+
"refractionTexture"
|
|
21
|
+
].forEach((l) => {
|
|
22
|
+
T(
|
|
23
|
+
l,
|
|
24
|
+
o,
|
|
25
|
+
e,
|
|
26
|
+
s,
|
|
27
|
+
i
|
|
28
|
+
);
|
|
29
|
+
}), d(o, e);
|
|
30
|
+
}
|
|
31
|
+
function T(o, e, s, i, u) {
|
|
32
|
+
const l = p[o];
|
|
33
|
+
if (!l)
|
|
34
|
+
throw new Error("Unexpected texture name encountered.");
|
|
35
|
+
const n = e[l], c = n == null ? void 0 : n.fileLink;
|
|
36
|
+
c ? i.addTextureTask(o, c, !1, !1) : u && s[o] && (s[o] && s[o].dispose(), s[o] = null, x(o, s));
|
|
37
|
+
}
|
|
38
|
+
function x(o, e) {
|
|
39
|
+
o === "opacityTexture" && (e.useAlphaFromAlbedoTexture = !0), o === "metallicTexture" && (e.useRoughnessFromMetallicTextureAlpha = !1, e.useRoughnessFromMetallicTextureGreen = !1, e.useMetallnessFromMetallicTextureBlue = !1), o === "refractionTexture" && (e.subSurface.isRefractionEnabled = !1, e.subSurface.refractionIntensity = 1), o === "emissiveTexture" && (e.emissiveIntensity = 0, e.emissiveColor = new f(0, 0, 0));
|
|
40
|
+
}
|
|
41
|
+
function b(o, e, s, i) {
|
|
42
|
+
o === "opacityTexture" && (e.useAlphaFromAlbedoTexture = !1), o === "metallicTexture" && (e.useRoughnessFromMetallicTextureAlpha = !1, e.useRoughnessFromMetallicTextureGreen = !0, e.useMetallnessFromMetallicTextureBlue = !0), o === "refractionTexture" && (e.subSurface.isRefractionEnabled = !0, e.subSurface.refractionIntensity = s.refractionIntensity || 1), e[o] = i, o === "emissiveTexture" && (e.emissiveColor = new f(1, 1, 1), e.emissiveIntensity = 1);
|
|
43
|
+
}
|
|
44
|
+
function d(o, e) {
|
|
45
|
+
o.clearCoat && (o.clearCoat === r.RemoveWhenSelected ? (e.clearCoat.isEnabled = !1, e.clearCoat.indexOfRefraction = 1.5) : o.clearCoat === r.ApplyWhenSelected && (e.clearCoat.isEnabled = !0, e.clearCoat.indexOfRefraction = o.clearCoatIOR || e.clearCoat.indexOfRefraction));
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
b as applyDownloadedTexture,
|
|
49
|
+
m as calculateMaterialProperties
|
|
50
|
+
};
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { ActionManager as h } from "../node_modules/@babylonjs/core/Actions/actionManager.esm.js";
|
|
2
|
+
import { ExecuteCodeAction as m } from "../node_modules/@babylonjs/core/Actions/directActions.esm.js";
|
|
3
|
+
import { PBRMaterial as g } from "../node_modules/@babylonjs/core/Materials/PBR/pbrMaterial.esm.js";
|
|
4
|
+
import { Vector3 as o } from "../node_modules/@babylonjs/core/Maths/math.vector.esm.js";
|
|
5
|
+
import { Mesh as p } from "../node_modules/@babylonjs/core/Meshes/mesh.esm.js";
|
|
6
|
+
import { TransformNode as f } from "../node_modules/@babylonjs/core/Meshes/transformNode.esm.js";
|
|
7
|
+
import { Observable as l } from "../node_modules/@babylonjs/core/Misc/observable.esm.js";
|
|
8
|
+
import { getAssetContainer as b } from "./assetCache.esm.js";
|
|
9
|
+
import { attachDynamicTextures as v } from "./dynamicTexture.esm.js";
|
|
10
|
+
import { generateGuid as C } from "./guid.esm.js";
|
|
11
|
+
import { resetAnimationGroups as M, executeAnimationGroups as I } from "./productAnimations.esm.js";
|
|
12
|
+
import w, { getAllMaterialsForInstance as y } from "./variants.esm.js";
|
|
13
|
+
function u(d, e = "") {
|
|
14
|
+
return d.map((t) => ({
|
|
15
|
+
name: t.name.substring(e.length),
|
|
16
|
+
loop: t.loopAnimation,
|
|
17
|
+
to: t.to,
|
|
18
|
+
from: t.from
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
class E {
|
|
22
|
+
constructor(e) {
|
|
23
|
+
this.metadata = /* @__PURE__ */ new Map(), this.materialSelectedObservable = new l(), this.materialDeselectedObservable = new l(), this.materialVariantObservable = new l(), this.modelVariantObservable = new l(), this.materialReadyToLoadCallbacks = /* @__PURE__ */ new Map(), this.modelReadyToLoadCallbacks = /* @__PURE__ */ new Map(), this.dynamicTextures = /* @__PURE__ */ new Map(), this.queuedMaterialChanges = /* @__PURE__ */ new Map(), this.materialChangesInProgress = [], this.queuedModelChanges = /* @__PURE__ */ new Map(), this.modelChangesInProgress = [], this.animations = [], this.initialized = !1, this.materials = [];
|
|
24
|
+
const {
|
|
25
|
+
enablePicking: t,
|
|
26
|
+
modelDetails: i,
|
|
27
|
+
previewService: a,
|
|
28
|
+
progressHandler: r,
|
|
29
|
+
scene: s
|
|
30
|
+
} = e;
|
|
31
|
+
this.enablePicking = t, this.contextService = i.contextService, this.id = C(), this.previewService = a, this.scene = s, this.variantManager = new w(
|
|
32
|
+
s,
|
|
33
|
+
this.renameClonedAsset.bind(this),
|
|
34
|
+
this.setEnabled.bind(this)
|
|
35
|
+
), this.previewService.registerInitializedListener(
|
|
36
|
+
async () => await this.processQueuedEvents()
|
|
37
|
+
), this.transformRoot = new f("root", this.scene);
|
|
38
|
+
const n = async () => (this.assetContainer = await b(
|
|
39
|
+
i.model,
|
|
40
|
+
s,
|
|
41
|
+
r
|
|
42
|
+
), this.initialized = !0, this.instantiate(), this);
|
|
43
|
+
this.importPromise = n();
|
|
44
|
+
}
|
|
45
|
+
//#region Interface implementation
|
|
46
|
+
async applyMaterialVariant(e, t, i, a) {
|
|
47
|
+
if (this.previewService.getSceneInitializationProgress() !== 100 || !this.initialized) {
|
|
48
|
+
if (this.materialReadyToLoadCallbacks.has(e)) {
|
|
49
|
+
const s = this.materialReadyToLoadCallbacks.get(e);
|
|
50
|
+
s == null || s.set(
|
|
51
|
+
t,
|
|
52
|
+
this.applyMaterialVariant.bind(
|
|
53
|
+
this,
|
|
54
|
+
e,
|
|
55
|
+
t,
|
|
56
|
+
i,
|
|
57
|
+
a
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
this.materialReadyToLoadCallbacks.set(
|
|
62
|
+
e,
|
|
63
|
+
/* @__PURE__ */ new Map()
|
|
64
|
+
);
|
|
65
|
+
const s = this.materialReadyToLoadCallbacks.get(e);
|
|
66
|
+
s == null || s.set(
|
|
67
|
+
t,
|
|
68
|
+
this.applyMaterialVariant.bind(
|
|
69
|
+
this,
|
|
70
|
+
e,
|
|
71
|
+
t,
|
|
72
|
+
i,
|
|
73
|
+
a
|
|
74
|
+
)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const r = async () => {
|
|
80
|
+
await this.variantManager.applyMaterial(
|
|
81
|
+
e,
|
|
82
|
+
i,
|
|
83
|
+
(s, n, c) => {
|
|
84
|
+
this.materialVariantObservable.notifyObservers({
|
|
85
|
+
remainingCount: s,
|
|
86
|
+
totalCount: n,
|
|
87
|
+
taskName: c
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
a
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
if (this.materialChangesInProgress.includes(e)) {
|
|
94
|
+
if (this.queuedMaterialChanges.has(e)) {
|
|
95
|
+
const s = this.queuedMaterialChanges.get(e);
|
|
96
|
+
s == null || s.set(t, r);
|
|
97
|
+
} else {
|
|
98
|
+
this.queuedMaterialChanges.set(
|
|
99
|
+
e,
|
|
100
|
+
/* @__PURE__ */ new Map()
|
|
101
|
+
);
|
|
102
|
+
const s = this.queuedMaterialChanges.get(e);
|
|
103
|
+
s == null || s.set(t, r);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.materialChangesInProgress.push(e), await r(), this.queuedMaterialChanges.has(e) && (this.queuedMaterialChanges.get(e).forEach(async (n) => {
|
|
108
|
+
await n();
|
|
109
|
+
}), this.queuedMaterialChanges.delete(e)), this.materialChangesInProgress.splice(
|
|
110
|
+
this.materialChangesInProgress.indexOf(e),
|
|
111
|
+
1
|
|
112
|
+
), this.configureGlowLayer();
|
|
113
|
+
}
|
|
114
|
+
async applyModelVariant(e, t, i) {
|
|
115
|
+
if (!this.previewService.getIsInitialized() || !this.initialized) {
|
|
116
|
+
this.modelReadyToLoadCallbacks.set(
|
|
117
|
+
e,
|
|
118
|
+
this.applyModelVariant.bind(
|
|
119
|
+
this,
|
|
120
|
+
e,
|
|
121
|
+
t,
|
|
122
|
+
i
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const a = () => this.variantManager.applyModel(
|
|
128
|
+
e,
|
|
129
|
+
i,
|
|
130
|
+
t == null ? void 0 : t.model,
|
|
131
|
+
(n) => {
|
|
132
|
+
this.modelVariantObservable.notifyObservers({
|
|
133
|
+
...n,
|
|
134
|
+
key: e
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
if (this.modelChangesInProgress.includes(e)) {
|
|
139
|
+
this.queuedModelChanges.set(e, a);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const s = await (async () => {
|
|
143
|
+
this.modelChangesInProgress.push(e);
|
|
144
|
+
let n = await a();
|
|
145
|
+
return this.queuedModelChanges.has(e) && (n = await this.queuedModelChanges.get(e)(), this.queuedModelChanges.delete(e)), this.modelChangesInProgress.splice(
|
|
146
|
+
this.modelChangesInProgress.indexOf(e),
|
|
147
|
+
1
|
|
148
|
+
), n;
|
|
149
|
+
})();
|
|
150
|
+
this.modelInstance && M(this.modelInstance.animationGroups), this.contextService || (this.contextService = t == null ? void 0 : t.contextService), s ? this.configureModelInstance(s) : this.configureGlowLayer();
|
|
151
|
+
}
|
|
152
|
+
dispose() {
|
|
153
|
+
var e;
|
|
154
|
+
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);
|
|
155
|
+
}
|
|
156
|
+
executeAnimation(e) {
|
|
157
|
+
if (!this.previewService.getIsInitialized()) {
|
|
158
|
+
this.queuedModelAnimation = e;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.modelInstance && I(
|
|
162
|
+
[
|
|
163
|
+
...this.modelInstance.animationGroups,
|
|
164
|
+
...this.variantManager.getAnimationGroups()
|
|
165
|
+
],
|
|
166
|
+
e.loop,
|
|
167
|
+
e.to,
|
|
168
|
+
e.from,
|
|
169
|
+
e.name ? this.renameClonedAsset(e.name) : void 0
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
getAnimations(e) {
|
|
173
|
+
return [
|
|
174
|
+
...this.animations,
|
|
175
|
+
...e ? u(
|
|
176
|
+
this.variantManager.getAnimationGroups(),
|
|
177
|
+
this.renameClonedAsset("")
|
|
178
|
+
) : []
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
getId() {
|
|
182
|
+
return this.id;
|
|
183
|
+
}
|
|
184
|
+
listMaterials() {
|
|
185
|
+
var t;
|
|
186
|
+
const e = (t = this.scene) == null ? void 0 : t.materials.filter(
|
|
187
|
+
(i) => i.name.startsWith(this.id)
|
|
188
|
+
);
|
|
189
|
+
return e ? e.map((i) => ({
|
|
190
|
+
id: i.id,
|
|
191
|
+
name: this.stripIdFromName(i.name)
|
|
192
|
+
})) : [];
|
|
193
|
+
}
|
|
194
|
+
registerMaterialSelectedCallback(e) {
|
|
195
|
+
this.materialSelectedObservable.add(e);
|
|
196
|
+
}
|
|
197
|
+
unregisterMaterialSelectedCallback(e) {
|
|
198
|
+
this.materialSelectedObservable.removeCallback(e);
|
|
199
|
+
}
|
|
200
|
+
registerMaterialDeselectedCallback(e) {
|
|
201
|
+
this.materialDeselectedObservable.add(e);
|
|
202
|
+
}
|
|
203
|
+
unregisterMaterialDeselectedCallback(e) {
|
|
204
|
+
this.materialDeselectedObservable.removeCallback(e);
|
|
205
|
+
}
|
|
206
|
+
get position() {
|
|
207
|
+
return this.transformRoot.position;
|
|
208
|
+
}
|
|
209
|
+
set position(e) {
|
|
210
|
+
this.transformRoot.position = new o(e.x, e.y, e.z);
|
|
211
|
+
}
|
|
212
|
+
get rotation() {
|
|
213
|
+
return this.transformRoot.rotation;
|
|
214
|
+
}
|
|
215
|
+
set rotation(e) {
|
|
216
|
+
this.transformRoot.rotation = new o(e.x, e.y, e.z);
|
|
217
|
+
}
|
|
218
|
+
get scale() {
|
|
219
|
+
return this.transformRoot.scaling;
|
|
220
|
+
}
|
|
221
|
+
set scale(e) {
|
|
222
|
+
this.transformRoot.scaling = new o(e.x, e.y, e.z);
|
|
223
|
+
}
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region Custom implementation functions
|
|
226
|
+
attachPickingHandler(e) {
|
|
227
|
+
e.rootNodes.forEach((t) => {
|
|
228
|
+
t.getChildMeshes(!1).forEach((i) => {
|
|
229
|
+
i.name === "targetcube_t" || i.name === "backgroundShell" || (i.actionManager || (i.actionManager = new h(this.scene)), i.actionManager.registerAction(
|
|
230
|
+
new m(h.OnPointerOverTrigger, (a) => {
|
|
231
|
+
a.meshUnderPointer && i.material && this.materialSelectedObservable.notifyObservers({
|
|
232
|
+
id: i.material.id,
|
|
233
|
+
name: this.stripIdFromName(i.material.name)
|
|
234
|
+
});
|
|
235
|
+
})
|
|
236
|
+
), i.actionManager.registerAction(
|
|
237
|
+
new m(h.OnPointerOutTrigger, () => {
|
|
238
|
+
i.material && this.materialDeselectedObservable.notifyObservers({
|
|
239
|
+
id: i.material.id,
|
|
240
|
+
name: this.stripIdFromName(i.material.name)
|
|
241
|
+
});
|
|
242
|
+
})
|
|
243
|
+
));
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns a promise which resolves when the model has been initialized.
|
|
249
|
+
*/
|
|
250
|
+
getInitializationPromise() {
|
|
251
|
+
return this.importPromise;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns true if the model has been initialized.
|
|
255
|
+
*/
|
|
256
|
+
getIsInitialized() {
|
|
257
|
+
return this.initialized;
|
|
258
|
+
}
|
|
259
|
+
getQueuedMaterialVariantCount() {
|
|
260
|
+
return this.materialReadyToLoadCallbacks.size;
|
|
261
|
+
}
|
|
262
|
+
getQueuedModelVariantCount() {
|
|
263
|
+
return this.modelReadyToLoadCallbacks.size;
|
|
264
|
+
}
|
|
265
|
+
configureGlowLayer() {
|
|
266
|
+
const e = (i) => i instanceof g && i.emissiveTexture !== null;
|
|
267
|
+
this.materials.some(e) || this.variantManager.getAllMaterials().some(e) ? this.previewService.getGlowLayerManager().includeMeshes(this.getAllMeshes()) : this.previewService.getGlowLayerManager().removeMeshes(this.getAllMeshes());
|
|
268
|
+
}
|
|
269
|
+
configureModelInstance(e) {
|
|
270
|
+
var r;
|
|
271
|
+
const t = this.transformRoot.position, i = this.transformRoot.rotation, a = this.transformRoot.scaling;
|
|
272
|
+
this.transformRoot.position = o.Zero(), this.transformRoot.rotation = o.Zero(), this.transformRoot.scaling = o.One(), e.rootNodes.forEach((s) => {
|
|
273
|
+
s.parent = this.transformRoot;
|
|
274
|
+
}), this.transformRoot.position = t, this.transformRoot.rotation = i, this.transformRoot.scaling = a, this.canvasPanels = ((r = this.contextService) == null ? void 0 : r.getAll()) || /* @__PURE__ */ new Map(), v(
|
|
275
|
+
this.materials.concat(this.variantManager.getAllMaterials()),
|
|
276
|
+
this.scene,
|
|
277
|
+
this.canvasPanels,
|
|
278
|
+
this.dynamicTextures,
|
|
279
|
+
`${this.id}_`
|
|
280
|
+
), this.enablePicking && this.attachPickingHandler(e), this.configureGlowLayer();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Destroys the model instance.
|
|
284
|
+
*/
|
|
285
|
+
destroyInstance() {
|
|
286
|
+
var e;
|
|
287
|
+
(e = this.modelInstance) == null || e.dispose(), this.modelInstance = void 0;
|
|
288
|
+
}
|
|
289
|
+
getAllMeshes() {
|
|
290
|
+
var e;
|
|
291
|
+
return (e = this.modelInstance) == null ? void 0 : e.rootNodes.map(
|
|
292
|
+
(t) => t.getChildMeshes(!1).filter((i) => i instanceof p)
|
|
293
|
+
).flat();
|
|
294
|
+
}
|
|
295
|
+
instantiate() {
|
|
296
|
+
this.modelInstance = this.assetContainer.instantiateModelsToScene(
|
|
297
|
+
this.renameClonedAsset.bind(this),
|
|
298
|
+
!0
|
|
299
|
+
), this.materials = y(this.modelInstance), this.configureModelInstance(this.modelInstance), this.animations = u(
|
|
300
|
+
this.modelInstance.animationGroups,
|
|
301
|
+
this.renameClonedAsset("")
|
|
302
|
+
), this.processQueuedEvents();
|
|
303
|
+
}
|
|
304
|
+
renameClonedAsset(e) {
|
|
305
|
+
return `${this.id}_${e}`;
|
|
306
|
+
}
|
|
307
|
+
setEnabled(e) {
|
|
308
|
+
e && !this.modelInstance ? this.instantiate() : !e && this.modelInstance && this.destroyInstance();
|
|
309
|
+
}
|
|
310
|
+
updateDynamicTextures() {
|
|
311
|
+
var e;
|
|
312
|
+
(e = this.canvasPanels) == null || e.forEach(
|
|
313
|
+
(t, i) => {
|
|
314
|
+
const a = this.dynamicTextures.get(i);
|
|
315
|
+
a && t.getStaticContextDirty() && a.isReady() && (a.update(!1), t.setStaticContextDirty(!1));
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
//#region Listeners
|
|
320
|
+
registerMaterialVariantListener(e) {
|
|
321
|
+
this.materialVariantObservable.add(e);
|
|
322
|
+
}
|
|
323
|
+
unregisterMaterialVariantListener(e) {
|
|
324
|
+
this.materialVariantObservable.removeCallback(e);
|
|
325
|
+
}
|
|
326
|
+
registerModelVariantListener(e) {
|
|
327
|
+
this.modelVariantObservable.add(e);
|
|
328
|
+
}
|
|
329
|
+
unregisterModelVariantListener(e) {
|
|
330
|
+
this.modelVariantObservable.removeCallback(e);
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
stripIdFromName(e) {
|
|
334
|
+
return e.substring(this.id.length + 1);
|
|
335
|
+
}
|
|
336
|
+
async processQueuedEvents() {
|
|
337
|
+
this.previewService.getIsInitialized() && (await Promise.all(
|
|
338
|
+
Array.from(this.materialReadyToLoadCallbacks.values()).map(
|
|
339
|
+
(e) => Array.from(e.values()).map((t) => t())
|
|
340
|
+
)
|
|
341
|
+
), this.materialReadyToLoadCallbacks.clear(), await Promise.all(
|
|
342
|
+
Array.from(this.modelReadyToLoadCallbacks.values()).map(
|
|
343
|
+
(e) => e()
|
|
344
|
+
)
|
|
345
|
+
), this.modelReadyToLoadCallbacks.clear(), this.queuedModelAnimation && (this.executeAnimation(this.queuedModelAnimation), this.queuedModelAnimation = void 0));
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
}
|
|
349
|
+
export {
|
|
350
|
+
E as ModelContainerImpl
|
|
351
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Animation as p } from "../node_modules/@babylonjs/core/Animations/animation.esm.js";
|
|
2
|
+
import { EasingFunction as T, QuadraticEase as I } from "../node_modules/@babylonjs/core/Animations/easing.esm.js";
|
|
3
|
+
import { Vector3 as c } from "../node_modules/@babylonjs/core/Maths/math.vector.esm.js";
|
|
4
|
+
const A = 60, f = 1;
|
|
5
|
+
function d(n) {
|
|
6
|
+
return n.targetedAnimations.map((e) => e.animation.framePerSecond).reduce((e, o) => e + o, 0) / n.targetedAnimations.length || 0;
|
|
7
|
+
}
|
|
8
|
+
function F(n, t, e, o, r) {
|
|
9
|
+
const i = r ? n.filter((s) => s.name === r) : n;
|
|
10
|
+
if (i.length === 0) {
|
|
11
|
+
console.warn(`No animations found for name: ${r}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (o !== void 0 && e !== void 0 && o === e) {
|
|
15
|
+
i.forEach((s) => {
|
|
16
|
+
s.stop();
|
|
17
|
+
const u = d(s), a = o * u;
|
|
18
|
+
s.start(t, f, a, a);
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
i.forEach((s) => {
|
|
23
|
+
s.stop();
|
|
24
|
+
const u = d(s), a = o !== void 0 ? o * u : void 0, g = e !== void 0 ? e * u : void 0;
|
|
25
|
+
s.start(t, f, a, g);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function O(n) {
|
|
29
|
+
n.forEach((t) => {
|
|
30
|
+
t.stop();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function v(n) {
|
|
34
|
+
const t = n.animationGroups;
|
|
35
|
+
O(t);
|
|
36
|
+
}
|
|
37
|
+
function P(n, t, e) {
|
|
38
|
+
n.stopAnimation(t), t.animations = [], Math.abs(t.alpha) > 2 * Math.PI && (t.alpha = M(t.alpha, 0, 2 * Math.PI));
|
|
39
|
+
const o = [], r = e.target, i = 0, s = r ? 1 : 0;
|
|
40
|
+
if (e.target && Object.keys(e.target).length > 0 && o.push(
|
|
41
|
+
h(
|
|
42
|
+
"cameraTargetLerp",
|
|
43
|
+
"target",
|
|
44
|
+
new c().copyFrom(t.target),
|
|
45
|
+
new c(
|
|
46
|
+
e.target.x,
|
|
47
|
+
e.target.y,
|
|
48
|
+
e.target.z
|
|
49
|
+
),
|
|
50
|
+
p.ANIMATIONTYPE_VECTOR3,
|
|
51
|
+
i
|
|
52
|
+
)
|
|
53
|
+
), o.push(
|
|
54
|
+
h(
|
|
55
|
+
"cameraAlphaLerp",
|
|
56
|
+
"alpha",
|
|
57
|
+
t.alpha,
|
|
58
|
+
E(e.lonDeg),
|
|
59
|
+
p.ANIMATIONTYPE_FLOAT,
|
|
60
|
+
s
|
|
61
|
+
)
|
|
62
|
+
), o.push(
|
|
63
|
+
h(
|
|
64
|
+
"cameraBetaLerp",
|
|
65
|
+
"beta",
|
|
66
|
+
t.beta,
|
|
67
|
+
E(e.latDeg),
|
|
68
|
+
p.ANIMATIONTYPE_FLOAT,
|
|
69
|
+
s
|
|
70
|
+
)
|
|
71
|
+
), e.radius !== void 0) {
|
|
72
|
+
const g = Math.max(0.01, e.radius);
|
|
73
|
+
o.push(
|
|
74
|
+
h(
|
|
75
|
+
"cameraRadiusLerp",
|
|
76
|
+
"radius",
|
|
77
|
+
t.radius,
|
|
78
|
+
g,
|
|
79
|
+
p.ANIMATIONTYPE_FLOAT,
|
|
80
|
+
s
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
t.animations.push(...o);
|
|
85
|
+
const a = t.useAutoRotationBehavior;
|
|
86
|
+
t.disableAutoRotationBehavior(), n.beginAnimation(
|
|
87
|
+
t,
|
|
88
|
+
0,
|
|
89
|
+
r ? A * 2 : A,
|
|
90
|
+
!1,
|
|
91
|
+
1,
|
|
92
|
+
() => {
|
|
93
|
+
t.animations = [], a && t.enableAutoRotationBehavior();
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
function E(n) {
|
|
98
|
+
return n * Math.PI / 180;
|
|
99
|
+
}
|
|
100
|
+
function h(n, t, e, o, r, i = 0, s = p.ANIMATIONLOOPMODE_CONSTANT) {
|
|
101
|
+
const u = new I();
|
|
102
|
+
u.setEasingMode(T.EASINGMODE_EASEINOUT);
|
|
103
|
+
const a = new p(
|
|
104
|
+
n,
|
|
105
|
+
t,
|
|
106
|
+
A,
|
|
107
|
+
r,
|
|
108
|
+
s
|
|
109
|
+
), g = [];
|
|
110
|
+
return i > 0 && g.push({ frame: 0, value: e }), g.push({ frame: A * i, value: e }), g.push({
|
|
111
|
+
frame: A * (i + 1),
|
|
112
|
+
value: o
|
|
113
|
+
}), a.setKeys(g), a.setEasingFunction(u), a;
|
|
114
|
+
}
|
|
115
|
+
function M(n, t, e) {
|
|
116
|
+
return n < t ? n = e - (t - n) % (e - t) : n = t + (n - t) % (e - t);
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
P as animateCameraInScene,
|
|
120
|
+
F as executeAnimationGroups,
|
|
121
|
+
O as resetAnimationGroups,
|
|
122
|
+
v as resetSceneModelAnimations
|
|
123
|
+
};
|