@mymosdk/avatar 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Avatar-DEkBZdcp.js +2583 -0
- package/dist/Avatar-DEkBZdcp.js.map +1 -0
- package/dist/Avatar-Ok6vAXs6.cjs +10 -0
- package/dist/Avatar-Ok6vAXs6.cjs.map +1 -0
- package/dist/Avatar.d.ts +77 -0
- package/dist/Avatar.d.ts.map +1 -0
- package/dist/animation/AnimationEngine.d.ts +58 -0
- package/dist/animation/AnimationEngine.d.ts.map +1 -0
- package/dist/audio/AudioEngine.d.ts +19 -0
- package/dist/audio/AudioEngine.d.ts.map +1 -0
- package/dist/audio/LipSync.d.ts +14 -0
- package/dist/audio/LipSync.d.ts.map +1 -0
- package/dist/events/EventEmitter.d.ts +9 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/loader/AssetLoader.d.ts +18 -0
- package/dist/loader/AssetLoader.d.ts.map +1 -0
- package/dist/mymo-avatar.cjs +2 -0
- package/dist/mymo-avatar.cjs.map +1 -0
- package/dist/mymo-avatar.js +5 -0
- package/dist/mymo-avatar.js.map +1 -0
- package/dist/mymo-avatar.umd.js +992 -0
- package/dist/mymo-avatar.umd.js.map +1 -0
- package/dist/plugins/PluginSystem.d.ts +7 -0
- package/dist/plugins/PluginSystem.d.ts.map +1 -0
- package/dist/react/AvatarWidget.d.ts +4 -0
- package/dist/react/AvatarWidget.d.ts.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/useAvatar.d.ts +3 -0
- package/dist/react/useAvatar.d.ts.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.js +19 -0
- package/dist/react.js.map +1 -0
- package/dist/renderer/Renderer.d.ts +46 -0
- package/dist/renderer/Renderer.d.ts.map +1 -0
- package/dist/types/index.d.ts +69 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/vue/AvatarWidget.d.ts +4 -0
- package/dist/vue/AvatarWidget.d.ts.map +1 -0
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/useAvatar.d.ts +4 -0
- package/dist/vue/useAvatar.d.ts.map +1 -0
- package/dist/vue.cjs +2 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.js +41 -0
- package/dist/vue.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,2583 @@
|
|
|
1
|
+
import * as M from "three";
|
|
2
|
+
import { TrianglesDrawMode as Be, TriangleFanDrawMode as se, TriangleStripDrawMode as Re, Loader as ve, LoaderUtils as j, FileLoader as Me, MeshPhysicalMaterial as C, Vector2 as Ne, Color as z, LinearSRGBColorSpace as v, SRGBColorSpace as K, SpotLight as Pe, PointLight as Fe, DirectionalLight as De, Matrix4 as W, Vector3 as H, Quaternion as Ee, InstancedMesh as Oe, InstancedBufferAttribute as ze, Object3D as we, TextureLoader as He, ImageBitmapLoader as Ge, BufferAttribute as Q, InterleavedBuffer as Ue, InterleavedBufferAttribute as Ve, LinearMipmapLinearFilter as Le, NearestMipmapLinearFilter as je, LinearMipmapNearestFilter as Ke, NearestMipmapNearestFilter as Xe, LinearFilter as Se, NearestFilter as We, RepeatWrapping as ie, MirroredRepeatWrapping as Ye, ClampToEdgeWrapping as Qe, PointsMaterial as qe, Material as q, LineBasicMaterial as Ze, MeshStandardMaterial as be, DoubleSide as $e, MeshBasicMaterial as V, PropertyBinding as Je, BufferGeometry as et, SkinnedMesh as tt, Mesh as nt, LineSegments as st, Line as it, LineLoop as ot, Points as rt, Group as Z, PerspectiveCamera as at, MathUtils as ct, OrthographicCamera as lt, Skeleton as ht, AnimationClip as ut, Bone as dt, InterpolateDiscrete as ft, InterpolateLinear as Ie, Texture as ce, VectorKeyframeTrack as le, NumberKeyframeTrack as he, QuaternionKeyframeTrack as ue, ColorManagement as de, FrontSide as pt, Interpolant as mt, Box3 as gt, Sphere as At } from "three";
|
|
3
|
+
import { VRMHumanBoneName as f, VRMLoaderPlugin as Tt } from "@pixiv/three-vrm";
|
|
4
|
+
class xt {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
on(t, e) {
|
|
9
|
+
return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(e), this;
|
|
10
|
+
}
|
|
11
|
+
off(t, e) {
|
|
12
|
+
return this.listeners.get(t)?.delete(e), this;
|
|
13
|
+
}
|
|
14
|
+
emit(t, e) {
|
|
15
|
+
this.listeners.get(t)?.forEach((s) => s(t, e));
|
|
16
|
+
}
|
|
17
|
+
removeAllListeners(t) {
|
|
18
|
+
t ? this.listeners.delete(t) : this.listeners.clear();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const _t = {
|
|
22
|
+
full: [0, 1, 0.5],
|
|
23
|
+
half: [0.48, 1, 0.5],
|
|
24
|
+
bust: [0.68, 1, 0.46],
|
|
25
|
+
face: [0.8, 1, 0.36]
|
|
26
|
+
// look well below center → full head/ears visible at top
|
|
27
|
+
}, yt = {
|
|
28
|
+
full: { camY: 0, camZ: 2.8, lookY: 0 },
|
|
29
|
+
half: { camY: 0.5, camZ: 2, lookY: 0.4 },
|
|
30
|
+
bust: { camY: 0.8, camZ: 1, lookY: 0.55 },
|
|
31
|
+
face: { camY: 0.8, camZ: 0.7, lookY: 0.7 }
|
|
32
|
+
}, Rt = {
|
|
33
|
+
"bottom-right": { bottom: "20px", right: "20px" },
|
|
34
|
+
"bottom-left": { bottom: "20px", left: "20px" },
|
|
35
|
+
"top-right": { top: "20px", right: "20px" },
|
|
36
|
+
"top-left": { top: "20px", left: "20px" }
|
|
37
|
+
};
|
|
38
|
+
class Mt {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.clock = new M.Clock(), this.rafId = 0, this.tickCallbacks = [], this.currentModel = null, this.currentFraming = "full", this.currentTheme = "light", this.modelFraming = null, this.userSliceConfig = {}, this.userThemeConfig = {}, this._skeletonHelper = null, this.scene = new M.Scene(), this.camera = new M.PerspectiveCamera(45, 1, 0.1, 100);
|
|
41
|
+
}
|
|
42
|
+
setup(t) {
|
|
43
|
+
this.webgl = new M.WebGLRenderer({ antialias: !0, alpha: !0 }), this.webgl.setPixelRatio(Math.min(window.devicePixelRatio, 2)), this.webgl.setSize(t.size, t.size), this.webgl.shadowMap.enabled = t.shadows, this.webgl.shadowMap.type = M.PCFSoftShadowMap, this.webgl.outputColorSpace = M.SRGBColorSpace, this.webgl.toneMapping = M.ACESFilmicToneMapping, this._setupLights(), t.themeConfig && (this.userThemeConfig = t.themeConfig), this._createContainer(t), this.currentFraming = t.framing, t.framingConfig && (this.userSliceConfig = t.framingConfig), this._applyFraming(t.framing), this._startLoop();
|
|
44
|
+
}
|
|
45
|
+
_setupLights() {
|
|
46
|
+
const t = new M.AmbientLight(16777215, 0.8), e = new M.DirectionalLight(16777215, 1.5);
|
|
47
|
+
e.position.set(1.5, 3, 2.5);
|
|
48
|
+
const s = new M.DirectionalLight(8947967, 0.5);
|
|
49
|
+
s.position.set(-2, 0, 1), this.scene.add(t, e, s);
|
|
50
|
+
}
|
|
51
|
+
_createContainer(t) {
|
|
52
|
+
this.container = document.createElement("div");
|
|
53
|
+
const e = this.container.style;
|
|
54
|
+
e.position = "fixed", e.width = `${t.size}px`, e.height = `${t.size}px`, e.zIndex = String(t.zIndex), e.overflow = "hidden", e.borderRadius = "50%", e.cursor = "pointer", e.userSelect = "none", e.boxSizing = "border-box", this.currentTheme = t.theme, this._applyTheme(t.theme, t.size), this._applyPosition(t.position), this.container.appendChild(this.webgl.domElement), document.body.appendChild(this.container), t.draggable && this._makeDraggable();
|
|
55
|
+
}
|
|
56
|
+
setTheme(t) {
|
|
57
|
+
this.currentTheme = t, this._applyTheme(t, 0);
|
|
58
|
+
}
|
|
59
|
+
setThemeConfig(t) {
|
|
60
|
+
this.userThemeConfig = { ...this.userThemeConfig, ...t }, this._applyTheme(this.currentTheme, 0);
|
|
61
|
+
}
|
|
62
|
+
_applyTheme(t, e) {
|
|
63
|
+
const s = this.container.style;
|
|
64
|
+
if (t === "dark" ? (s.background = this.userThemeConfig.dark?.background ?? "radial-gradient(circle at 40% 35%, #2a2a4a 0%, #0d0d1a 100%)", s.boxShadow = this.userThemeConfig.dark?.boxShadow ?? "0 8px 32px rgba(0,0,0,0.5), 0 0 0 2px rgba(255,255,255,0.08)") : t === "light" ? (s.background = this.userThemeConfig.light?.background ?? "radial-gradient(circle at 40% 35%, #f8f8ff 0%, #e0e0f0 100%)", s.boxShadow = this.userThemeConfig.light?.boxShadow ?? "0 8px 32px rgba(0,0,0,0.15), 0 0 0 2px rgba(0,0,0,0.06)") : (s.background = "transparent", s.boxShadow = "none"), s.transition = "box-shadow 0.3s ease", s.setProperty("--ring-color", "transparent"), !document.getElementById("__mymo_styles__")) {
|
|
65
|
+
const n = document.createElement("style");
|
|
66
|
+
n.id = "__mymo_styles__", n.textContent = `
|
|
67
|
+
@keyframes mymo-ring {
|
|
68
|
+
0% { box-shadow: 0 0 0 0px var(--ring-color); }
|
|
69
|
+
70% { box-shadow: 0 0 0 10px transparent; }
|
|
70
|
+
100% { box-shadow: 0 0 0 0px transparent; }
|
|
71
|
+
}
|
|
72
|
+
[data-state] { animation: mymo-ring 1.2s ease-out infinite; }
|
|
73
|
+
[data-state=""] { animation: none; }
|
|
74
|
+
`, document.head.appendChild(n);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_applyPosition(t) {
|
|
78
|
+
const e = this.container.style;
|
|
79
|
+
e.top = e.bottom = e.left = e.right = "";
|
|
80
|
+
const s = Rt[t];
|
|
81
|
+
for (const [n, i] of Object.entries(s))
|
|
82
|
+
i !== void 0 && (e[n] = i);
|
|
83
|
+
}
|
|
84
|
+
_startLoop() {
|
|
85
|
+
const t = () => {
|
|
86
|
+
this.rafId = requestAnimationFrame(t);
|
|
87
|
+
const e = this.clock.getDelta();
|
|
88
|
+
for (const s of this.tickCallbacks) s(e);
|
|
89
|
+
this.webgl.render(this.scene, this.camera);
|
|
90
|
+
};
|
|
91
|
+
t();
|
|
92
|
+
}
|
|
93
|
+
_makeDraggable() {
|
|
94
|
+
let t = !1, e = 0, s = 0;
|
|
95
|
+
this.container.addEventListener("pointerdown", (n) => {
|
|
96
|
+
t = !0;
|
|
97
|
+
const i = this.container.getBoundingClientRect();
|
|
98
|
+
e = n.clientX - i.left, s = n.clientY - i.top, this.container.style.transition = "none", n.preventDefault();
|
|
99
|
+
}), window.addEventListener("pointermove", (n) => {
|
|
100
|
+
if (!t) return;
|
|
101
|
+
const i = this.container.style;
|
|
102
|
+
i.top = i.bottom = i.left = i.right = "", i.left = `${n.clientX - e}px`, i.top = `${n.clientY - s}px`;
|
|
103
|
+
}), window.addEventListener("pointerup", () => {
|
|
104
|
+
t = !1;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
addTickCallback(t) {
|
|
108
|
+
this.tickCallbacks.push(t);
|
|
109
|
+
}
|
|
110
|
+
setModel(t) {
|
|
111
|
+
this.currentModel && this.scene.remove(this.currentModel), this._skeletonHelper && (this.scene.remove(this._skeletonHelper), this._skeletonHelper = null), this.currentModel = t, this._autoFit(t), this.scene.add(t), this.modelFraming = this._computeFraming(t), this._applyFraming(this.currentFraming);
|
|
112
|
+
}
|
|
113
|
+
// Toggle bone visualization for debugging — call avatar.renderer.debugBones()
|
|
114
|
+
debugBones(t) {
|
|
115
|
+
if (this.currentModel) {
|
|
116
|
+
if (t === !1) {
|
|
117
|
+
this._skeletonHelper && (this.scene.remove(this._skeletonHelper), this._skeletonHelper = null);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this._skeletonHelper ? (this.scene.remove(this._skeletonHelper), this._skeletonHelper = null) : (this._skeletonHelper = new M.SkeletonHelper(this.currentModel), this.scene.add(this._skeletonHelper));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_computeFraming(t) {
|
|
124
|
+
const e = new M.Box3().setFromObject(t), s = e.max.y - e.min.y, n = Math.tan(this.camera.fov * Math.PI / 180 / 2), i = {};
|
|
125
|
+
for (const [o, a] of Object.entries(_t)) {
|
|
126
|
+
const r = this.userSliceConfig[o] ?? {}, c = r.from ?? a[0], u = r.to ?? a[1], h = r.lookBias ?? a[2], d = e.min.y + s * c, m = e.min.y + s * u - d, A = d + m * h, g = m / 2 / n * 1.15;
|
|
127
|
+
i[o] = { camY: A, camZ: g, lookY: A };
|
|
128
|
+
}
|
|
129
|
+
return i;
|
|
130
|
+
}
|
|
131
|
+
_autoFit(t) {
|
|
132
|
+
const e = new M.Box3().setFromObject(t), s = e.getCenter(new M.Vector3()), n = e.getSize(new M.Vector3()), o = 1.8 / Math.max(n.x, n.y, n.z);
|
|
133
|
+
t.scale.setScalar(o), t.position.set(-s.x * o, -s.y * o, -s.z * o);
|
|
134
|
+
}
|
|
135
|
+
_applyFraming(t) {
|
|
136
|
+
const { camY: e, camZ: s, lookY: n } = (this.modelFraming ?? yt)[t];
|
|
137
|
+
this.camera.position.set(0, e, s), this.camera.lookAt(0, n, 0);
|
|
138
|
+
}
|
|
139
|
+
// ── Public controls ──────────────────────────────────────────────────────
|
|
140
|
+
show() {
|
|
141
|
+
this.container.style.display = "";
|
|
142
|
+
}
|
|
143
|
+
hide() {
|
|
144
|
+
this.container.style.display = "none";
|
|
145
|
+
}
|
|
146
|
+
setFraming(t) {
|
|
147
|
+
this.currentFraming = t, this._applyFraming(t);
|
|
148
|
+
}
|
|
149
|
+
setFramingConfig(t) {
|
|
150
|
+
this.userSliceConfig = { ...this.userSliceConfig, ...t }, this.currentModel && (this.modelFraming = this._computeFraming(this.currentModel), this._applyFraming(this.currentFraming));
|
|
151
|
+
}
|
|
152
|
+
setPosition(t) {
|
|
153
|
+
this._applyPosition(t);
|
|
154
|
+
}
|
|
155
|
+
setSize(t) {
|
|
156
|
+
this.container.style.width = `${t}px`, this.container.style.height = `${t}px`, this.webgl.setSize(t, t);
|
|
157
|
+
}
|
|
158
|
+
moveTo(t, e) {
|
|
159
|
+
const s = this.container.style;
|
|
160
|
+
s.top = s.bottom = s.left = s.right = "", s.left = `${t}px`, s.top = `${e}px`;
|
|
161
|
+
}
|
|
162
|
+
getContainer() {
|
|
163
|
+
return this.container;
|
|
164
|
+
}
|
|
165
|
+
dispose() {
|
|
166
|
+
cancelAnimationFrame(this.rafId), this.tickCallbacks = [], this.webgl.dispose(), this.container.remove();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function y(l, t, e) {
|
|
170
|
+
return l + (t - l) * e;
|
|
171
|
+
}
|
|
172
|
+
function b(l) {
|
|
173
|
+
return l * l * (3 - 2 * l);
|
|
174
|
+
}
|
|
175
|
+
function fe(l) {
|
|
176
|
+
return Math.max(0, Math.min(1, l));
|
|
177
|
+
}
|
|
178
|
+
const w = Math.PI / 3.2, $ = -0.1, Nt = 0.1, X = -0.15, Et = {
|
|
179
|
+
wave: {
|
|
180
|
+
duration: 3,
|
|
181
|
+
fn(l, t) {
|
|
182
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.RightShoulder), n = e.getNormalizedBoneNode(f.RightUpperArm), i = e.getNormalizedBoneNode(f.RightLowerArm), o = e.getNormalizedBoneNode(f.RightHand), a = e.getNormalizedBoneNode(f.LeftUpperArm), r = b(fe(l / 0.25)), c = l > 0.8 ? b((l - 0.8) / 0.2) : 0, u = r * (1 - c);
|
|
183
|
+
s && (s.rotation.z = y(0, -0.2, u), s.rotation.x = 0, s.rotation.y = 0), n && (n.rotation.z = y(w, 0, u), n.rotation.x = 0, n.rotation.y = 0), i && (i.rotation.order = "XYZ", i.rotation.z = y($, -Math.PI / 2, u), i.rotation.x = 0, i.rotation.y = 0);
|
|
184
|
+
const h = l >= 0.25 && l <= 0.8 ? Math.sin((l - 0.25) / 0.55 * Math.PI * 4) : 0;
|
|
185
|
+
o && (o.rotation.x = y(X, -Math.PI / 2, u), o.rotation.y = h * 0.4 * u, o.rotation.z = 0), a && (a.rotation.z = -w);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
nod: {
|
|
189
|
+
duration: 1.8,
|
|
190
|
+
fn(l, t) {
|
|
191
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Neck), n = e.getNormalizedBoneNode(f.RightUpperArm), i = e.getNormalizedBoneNode(f.LeftUpperArm), o = l > 0.85 ? (1 - l) / 0.15 : 1;
|
|
192
|
+
s && (s.rotation.x = 0.32 * Math.max(0, Math.sin(l * Math.PI * 2)) * o), n && (n.rotation.z = w), i && (i.rotation.z = -w);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
shakeHead: {
|
|
196
|
+
duration: 1.8,
|
|
197
|
+
fn(l, t) {
|
|
198
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Neck), n = e.getNormalizedBoneNode(f.RightUpperArm), i = e.getNormalizedBoneNode(f.LeftUpperArm), o = l > 0.85 ? (1 - l) / 0.15 : 1;
|
|
199
|
+
s && (s.rotation.y = 0.35 * Math.sin(l * Math.PI * 2.5) * o), n && (n.rotation.z = w), i && (i.rotation.z = -w);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
clap: {
|
|
203
|
+
duration: 2.2,
|
|
204
|
+
fn(l, t) {
|
|
205
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.RightUpperArm), n = e.getNormalizedBoneNode(f.LeftUpperArm), i = e.getNormalizedBoneNode(f.RightLowerArm), o = e.getNormalizedBoneNode(f.LeftLowerArm), a = b(fe(l / 0.2)), r = l > 0.8 ? b((l - 0.8) / 0.2) : 0, c = a * (1 - r), u = l >= 0.2 && l <= 0.8 ? Math.max(0, Math.sin((l - 0.2) / 0.6 * Math.PI * 10)) : 0, h = Math.PI / 2 - 0.08, d = Math.PI / 2 + 0.05, p = y(h, d, u);
|
|
206
|
+
s && (s.rotation.z = y(w, Math.PI / 3, c), s.rotation.y = y(0, p, c), s.rotation.x = 0), n && (n.rotation.z = y(-w, -Math.PI / 3, c), n.rotation.y = y(0, -p, c), n.rotation.x = 0);
|
|
207
|
+
const m = e.getNormalizedBoneNode(f.RightHand), A = e.getNormalizedBoneNode(f.LeftHand);
|
|
208
|
+
i && (i.rotation.z = y($, -Math.PI / 2.5, c), i.rotation.y = y(0, Math.PI / 2, c), i.rotation.x = 0), o && (o.rotation.z = y(Nt, Math.PI / 2.5, c), o.rotation.y = y(0, -Math.PI / 2, c), o.rotation.x = 0), m && (m.rotation.z = y(0, -Math.PI / 11.25, c), m.rotation.y = 0, m.rotation.x = y(X, 0, c)), A && (A.rotation.z = y(0, Math.PI / 11.25, c), A.rotation.y = 0, A.rotation.x = y(X, 0, c));
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
jump: {
|
|
212
|
+
duration: 1.5,
|
|
213
|
+
fn(l, t) {
|
|
214
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Hips), n = e.getNormalizedBoneNode(f.Spine), i = e.getNormalizedBoneNode(f.Chest), o = e.getNormalizedBoneNode(f.RightUpperArm), a = e.getNormalizedBoneNode(f.LeftUpperArm), r = e.getNormalizedBoneNode(f.RightUpperLeg), c = e.getNormalizedBoneNode(f.LeftUpperLeg), u = e.getNormalizedBoneNode(f.RightLowerLeg), h = e.getNormalizedBoneNode(f.LeftLowerLeg), d = e.getNormalizedBoneNode(f.RightFoot), p = e.getNormalizedBoneNode(f.LeftFoot);
|
|
215
|
+
let m = 0, A = 0, g = 0, x = 0, _ = 0;
|
|
216
|
+
if (l < 0.22) {
|
|
217
|
+
const T = b(l / 0.22);
|
|
218
|
+
m = -0.12 * T, A = T, g = -T * 0.85, _ = T * 0.06;
|
|
219
|
+
} else if (l < 0.55) {
|
|
220
|
+
const T = b((l - 0.22) / 0.33);
|
|
221
|
+
m = y(-0.12, 0.22, T), A = y(1, 0, T), g = y(-0.85, 0.6, T), x = T * 0.5, _ = y(0.06, -0.05, T);
|
|
222
|
+
} else if (l < 0.72) {
|
|
223
|
+
const T = b((l - 0.55) / 0.17);
|
|
224
|
+
m = y(0.22, -0.07, T), A = T * 0.75, g = y(0.6, -0.6, T), x = y(0.5, 0, T), _ = y(-0.05, 0.07, T);
|
|
225
|
+
} else {
|
|
226
|
+
const T = b((l - 0.72) / 0.28);
|
|
227
|
+
m = y(-0.07, 0, T), A = y(0.75, 0, T), g = y(-0.6, 0, T), _ = y(0.07, 0, T);
|
|
228
|
+
}
|
|
229
|
+
const N = t.scene.userData.hipsRestY ?? 0;
|
|
230
|
+
s && (s.position.y = N + m), r && (r.rotation.x = -A * 0.35, r.rotation.z = 0, r.rotation.y = 0), c && (c.rotation.x = -A * 0.35, c.rotation.z = 0, c.rotation.y = 0), u && (u.rotation.x = A * 1.2, u.rotation.z = 0, u.rotation.y = 0), h && (h.rotation.x = A * 1.2, h.rotation.z = 0, h.rotation.y = 0), d && (d.rotation.x = g, d.rotation.z = 0, d.rotation.y = 0), p && (p.rotation.x = g, p.rotation.z = 0, p.rotation.y = 0), n && (n.rotation.x = _), i && (i.rotation.x = _ * 0.4), o && (o.rotation.z = w - x), a && (a.rotation.z = -w + x);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
no: {
|
|
234
|
+
duration: 1.8,
|
|
235
|
+
fn(l, t) {
|
|
236
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Neck), n = e.getNormalizedBoneNode(f.Head), i = e.getNormalizedBoneNode(f.RightUpperArm), o = e.getNormalizedBoneNode(f.LeftUpperArm), a = l < 0.12 ? b(l / 0.12) : l > 0.85 ? b((1 - l) / 0.15) : 1, r = Math.sin(l * Math.PI * 6) * a;
|
|
237
|
+
s && (s.rotation.y = r * 0.38), n && (n.rotation.y = r * 0.12), i && (i.rotation.z = w), o && (o.rotation.z = -w);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
yes: {
|
|
241
|
+
duration: 2,
|
|
242
|
+
fn(l, t) {
|
|
243
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Neck), n = e.getNormalizedBoneNode(f.Head), i = e.getNormalizedBoneNode(f.RightUpperArm), o = e.getNormalizedBoneNode(f.LeftUpperArm), a = l < 0.12 ? b(l / 0.12) : l > 0.85 ? b((1 - l) / 0.15) : 1, r = Math.max(0, Math.sin(l * Math.PI * 6)) * a;
|
|
244
|
+
s && (s.rotation.x = r * 0.3), n && (n.rotation.x = r * 0.12), i && (i.rotation.z = w), o && (o.rotation.z = -w);
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
thumbsUp: {
|
|
248
|
+
duration: 2.5,
|
|
249
|
+
fn(l, t) {
|
|
250
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.RightUpperArm), n = e.getNormalizedBoneNode(f.RightLowerArm), i = e.getNormalizedBoneNode(f.RightHand), o = e.getNormalizedBoneNode(f.LeftUpperArm), a = l < 0.2 ? b(l / 0.2) : l > 0.8 ? b(1 - (l - 0.8) / 0.2) : 1;
|
|
251
|
+
s && (s.rotation.y = y(0, 0.9, a), s.rotation.z = w, s.rotation.x = 0), n && (n.rotation.order = "XYZ", n.rotation.y = y(0, 1.8, a), n.rotation.z = y($, 0, a), n.rotation.x = 0), i && (i.rotation.x = y(X, -0.9, a), i.rotation.y = y(0, 0.05, a), i.rotation.z = y(0, 0.6, a));
|
|
252
|
+
const r = [
|
|
253
|
+
[f.RightIndexProximal, f.RightIndexIntermediate, f.RightIndexDistal],
|
|
254
|
+
[f.RightMiddleProximal, f.RightMiddleIntermediate, f.RightMiddleDistal],
|
|
255
|
+
[f.RightRingProximal, f.RightRingIntermediate, f.RightRingDistal],
|
|
256
|
+
[f.RightLittleProximal, f.RightLittleIntermediate, f.RightLittleDistal]
|
|
257
|
+
];
|
|
258
|
+
for (const [d, p, m] of r) {
|
|
259
|
+
const A = y(0.28, 1.45, a), g = e.getNormalizedBoneNode(d), x = e.getNormalizedBoneNode(p), _ = e.getNormalizedBoneNode(m);
|
|
260
|
+
g && (g.rotation.z = A, g.rotation.x = 0), x && (x.rotation.z = A * 0.9, x.rotation.x = 0), _ && (_.rotation.z = A * 0.7, _.rotation.x = 0);
|
|
261
|
+
}
|
|
262
|
+
const c = e.getNormalizedBoneNode(f.RightThumbMetacarpal), u = e.getNormalizedBoneNode(f.RightThumbProximal), h = e.getNormalizedBoneNode(f.RightThumbDistal);
|
|
263
|
+
c && (c.rotation.x = y(0.2, 0.2, a), c.rotation.z = y(-0.3, -0.3, a), c.rotation.y = 0), u && (u.rotation.x = 0, u.rotation.z = 0, u.rotation.y = 0), h && (h.rotation.x = 0, h.rotation.z = 0, h.rotation.y = 0), o && (o.rotation.z = -w);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
dance: {
|
|
267
|
+
duration: 3,
|
|
268
|
+
fn(l, t) {
|
|
269
|
+
const e = t.humanoid, s = e.getNormalizedBoneNode(f.Hips), n = e.getNormalizedBoneNode(f.Spine), i = e.getNormalizedBoneNode(f.Chest), o = e.getNormalizedBoneNode(f.Neck), a = e.getNormalizedBoneNode(f.RightUpperArm), r = e.getNormalizedBoneNode(f.LeftUpperArm), c = l < 0.1 ? l / 0.1 : l > 0.9 ? (1 - l) / 0.1 : 1, u = Math.sin(l * Math.PI * 4) * c, h = Math.sin(l * Math.PI * 4 + Math.PI) * c, d = t.scene.userData.hipsRestY ?? 0, p = e.getNormalizedBoneNode(f.RightUpperLeg), m = e.getNormalizedBoneNode(f.LeftUpperLeg), A = e.getNormalizedBoneNode(f.RightFoot), g = e.getNormalizedBoneNode(f.LeftFoot);
|
|
270
|
+
s && (s.position.y = d, s.rotation.z = h * 0.18, s.rotation.y = h * 0.06), p && (p.rotation.z = -h * 0.18, p.rotation.x = 0, p.rotation.y = 0), m && (m.rotation.z = -h * 0.18, m.rotation.x = 0, m.rotation.y = 0), A && (A.rotation.x = 0, A.rotation.z = 0, A.rotation.y = 0), g && (g.rotation.x = 0, g.rotation.z = 0, g.rotation.y = 0), n && (n.rotation.z = u * 0.1), i && (i.rotation.z = -u * 0.07), o && (o.rotation.z = Math.sin(l * Math.PI * 4 + Math.PI / 4) * 0.07 * c), a && (a.rotation.z = w - u * 0.5, a.rotation.x = Math.abs(u) * 0.1), r && (r.rotation.z = -w + u * 0.5, r.rotation.x = Math.abs(u) * 0.1);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, J = {
|
|
274
|
+
idle: [],
|
|
275
|
+
smile: ["Smile", "smile", "Happy", "happy", "mouthSmile", "Joy"],
|
|
276
|
+
sad: ["Sad", "sad", "Frown", "frown", "mouthFrown"],
|
|
277
|
+
happy: ["Smile", "smile", "Happy", "happy", "Joy", "joy"],
|
|
278
|
+
angry: ["Angry", "angry", "Frown", "frown", "Mad"],
|
|
279
|
+
surprised: ["Surprised", "surprised", "Awe", "awe", "Oh", "Shock"],
|
|
280
|
+
thinking: ["Thinking", "thinking", "Sad", "Awe"],
|
|
281
|
+
confused: ["Confused", "confused", "Awe", "Surprised"],
|
|
282
|
+
sleep: ["Sleep", "sleep", "Blink", "eyesClosed"]
|
|
283
|
+
}, pe = {
|
|
284
|
+
idle: null,
|
|
285
|
+
smile: "happy",
|
|
286
|
+
happy: "happy",
|
|
287
|
+
sad: "sad",
|
|
288
|
+
angry: "angry",
|
|
289
|
+
surprised: "surprised",
|
|
290
|
+
thinking: "relaxed",
|
|
291
|
+
confused: "surprised",
|
|
292
|
+
sleep: "blink"
|
|
293
|
+
}, me = ["Blink", "blink", "EyesClosed", "eyesClosed", "eyeBlink_L", "eyeBlink"], wt = [
|
|
294
|
+
"mouthOpen",
|
|
295
|
+
"MouthOpen",
|
|
296
|
+
"jawOpen",
|
|
297
|
+
"JawOpen",
|
|
298
|
+
"jaw_open",
|
|
299
|
+
"mouth_open",
|
|
300
|
+
"viseme_O",
|
|
301
|
+
"viseme_aa",
|
|
302
|
+
"A",
|
|
303
|
+
"open"
|
|
304
|
+
], Lt = [
|
|
305
|
+
"Head",
|
|
306
|
+
"head",
|
|
307
|
+
"mixamorigHead",
|
|
308
|
+
"Bip01_Head",
|
|
309
|
+
"Bip001 Head",
|
|
310
|
+
"head_joint",
|
|
311
|
+
"HeadBone"
|
|
312
|
+
], St = [/^bip_head/i, /^head$/i, /head_0/i], O = class O {
|
|
313
|
+
constructor() {
|
|
314
|
+
this.mixer = null, this.clips = [], this.currentAction = null, this.idleAction = null, this.vrm = null, this.morphMeshes = [], this.headBone = null, this.headBoneRestWorldQ = new M.Quaternion(), this.lookCurrentDelta = new M.Quaternion(), this.lookTargetDelta = new M.Quaternion(), this.lookSettled = !0, this._tmpParentWorldQInv = new M.Quaternion(), this._tmpDesiredWorldQ = new M.Quaternion(), this.blinkTimer = null, this.idleTimer = null, this.randomLookTimeout = null, this._vrmIdleTime = 0, this._gestureActive = !1, this._gestureElapsed = 0, this._gestureDuration = 0, this._gestureUpdateFn = null, this._pendingGesture = null;
|
|
315
|
+
}
|
|
316
|
+
init(t) {
|
|
317
|
+
if (this.dispose(), this.vrm = t.vrm ?? null, this.mixer = new M.AnimationMixer(t.scene), this.clips = t.animations, this.morphMeshes = [], this.headBone = null, this.vrm) {
|
|
318
|
+
const e = this.vrm.humanoid.getNormalizedBoneNode(f.Head);
|
|
319
|
+
e && (this.headBone = e, t.scene.updateWorldMatrix(!0, !0), this.headBone.getWorldQuaternion(this.headBoneRestWorldQ)), this._initVRMRestPose();
|
|
320
|
+
} else
|
|
321
|
+
t.scene.traverse((e) => {
|
|
322
|
+
if (e instanceof M.Bone && !this.headBone) {
|
|
323
|
+
const s = Lt.includes(e.name), n = !s && St.some((i) => i.test(e.name));
|
|
324
|
+
(s || n) && (this.headBone = e, t.scene.updateWorldMatrix(!0, !0), e.getWorldQuaternion(this.headBoneRestWorldQ));
|
|
325
|
+
}
|
|
326
|
+
(e instanceof M.Mesh || e instanceof M.SkinnedMesh) && e.morphTargetDictionary && Object.keys(e.morphTargetDictionary).length > 0 && this.morphMeshes.push(e);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
update(t) {
|
|
330
|
+
if (this.mixer?.update(t), this._vrmIdleTime += t, this._gestureActive ? this._tickProceduralGesture(t) : this._updateVRMProceduralIdle(this._vrmIdleTime), this.vrm?.update(t), this.headBone) {
|
|
331
|
+
if (!this.lookSettled) {
|
|
332
|
+
const s = 1 - Math.pow(1e-4, t);
|
|
333
|
+
this.lookCurrentDelta.slerp(this.lookTargetDelta, s), this.lookCurrentDelta.angleTo(this.lookTargetDelta) < 0.01 && (this.lookCurrentDelta.copy(this.lookTargetDelta), this.lookSettled = !0);
|
|
334
|
+
}
|
|
335
|
+
this._tmpDesiredWorldQ.multiplyQuaternions(this.headBoneRestWorldQ, this.lookCurrentDelta);
|
|
336
|
+
const e = this.headBone.parent;
|
|
337
|
+
e ? (e.getWorldQuaternion(this._tmpParentWorldQInv), this._tmpParentWorldQInv.invert(), this.headBone.quaternion.multiplyQuaternions(this._tmpParentWorldQInv, this._tmpDesiredWorldQ)) : this.headBone.quaternion.copy(this._tmpDesiredWorldQ);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// ── Animation clips ───────────────────────────────────────────────────────────
|
|
341
|
+
play(t) {
|
|
342
|
+
const e = M.AnimationClip.findByName(this.clips, t);
|
|
343
|
+
!e || !this.mixer || this._transitionTo(this.mixer.clipAction(e));
|
|
344
|
+
}
|
|
345
|
+
stop() {
|
|
346
|
+
this.currentAction && (this.currentAction.fadeOut(0.3), this.currentAction = null, this.idleAction && this.idleAction.fadeIn(0.3).play());
|
|
347
|
+
}
|
|
348
|
+
_transitionTo(t, e = 0.3) {
|
|
349
|
+
this.currentAction !== t && (this.currentAction?.fadeOut(e), t.reset().fadeIn(e).play(), this.currentAction = t);
|
|
350
|
+
}
|
|
351
|
+
// ── Idle ──────────────────────────────────────────────────────────────────────
|
|
352
|
+
startIdle(t = 8e3) {
|
|
353
|
+
const e = this._findClip(/idle|breathing|float/i) ?? this.clips[0];
|
|
354
|
+
e && this.mixer && (this.idleAction = this.mixer.clipAction(e), this.idleAction.setLoop(M.LoopRepeat, 1 / 0), this.idleAction.play()), this.idleTimer = setInterval(() => {
|
|
355
|
+
this._randomIdleExpression();
|
|
356
|
+
}, t);
|
|
357
|
+
}
|
|
358
|
+
stopIdle() {
|
|
359
|
+
this.idleAction?.stop(), this.idleAction = null, this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
360
|
+
}
|
|
361
|
+
_randomIdleExpression() {
|
|
362
|
+
const t = ["idle", "smile", "thinking"], e = t[Math.floor(Math.random() * t.length)];
|
|
363
|
+
e !== "idle" && (this.setExpression(e, 0.3), setTimeout(() => this.setExpression("idle", 0), 1200));
|
|
364
|
+
}
|
|
365
|
+
// ── Blink ─────────────────────────────────────────────────────────────────────
|
|
366
|
+
startBlink(t = 3500) {
|
|
367
|
+
this.blinkTimer = setInterval(() => {
|
|
368
|
+
this._doBlink();
|
|
369
|
+
}, t + Math.random() * 1e3 - 500);
|
|
370
|
+
}
|
|
371
|
+
stopBlink() {
|
|
372
|
+
this.blinkTimer && (clearInterval(this.blinkTimer), this.blinkTimer = null);
|
|
373
|
+
}
|
|
374
|
+
async _doBlink() {
|
|
375
|
+
this.vrm?.expressionManager ? (this.vrm.expressionManager.setValue("blink", 1), await this._delay(120), this.vrm.expressionManager.setValue("blink", 0)) : (this._setMorphTarget(me, 1), await this._delay(120), this._setMorphTarget(me, 0));
|
|
376
|
+
}
|
|
377
|
+
// ── Expressions ───────────────────────────────────────────────────────────────
|
|
378
|
+
setExpression(t, e = 1) {
|
|
379
|
+
if (this.vrm?.expressionManager) {
|
|
380
|
+
const n = this.vrm.expressionManager;
|
|
381
|
+
for (const o of Object.values(pe))
|
|
382
|
+
o && n.setValue(o, 0);
|
|
383
|
+
const i = pe[t];
|
|
384
|
+
i && n.setValue(i, e);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (t === "idle") {
|
|
388
|
+
for (const n of Object.values(J))
|
|
389
|
+
this._setMorphTarget(n, 0);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const s = J[t];
|
|
393
|
+
if (s.length) {
|
|
394
|
+
for (const [n, i] of Object.entries(J))
|
|
395
|
+
n !== t && n !== "idle" && this._setMorphTarget(i, 0);
|
|
396
|
+
this._setMorphTarget(s, e);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
setMouthMorph(t) {
|
|
400
|
+
const e = Math.max(0, Math.min(1, t));
|
|
401
|
+
if (this.vrm?.expressionManager) {
|
|
402
|
+
const s = this.vrm.expressionManager;
|
|
403
|
+
for (const n of O._VRM_VISEMES) s.setValue(n, 0);
|
|
404
|
+
if (e > 0.01) {
|
|
405
|
+
const n = Math.floor(performance.now() / 250) % O._VRM_VISEME_CYCLE.length, i = O._VRM_VISEME_CYCLE[n] ?? "aa";
|
|
406
|
+
s.setValue(i, e);
|
|
407
|
+
}
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
this._setMorphTarget(wt, e);
|
|
411
|
+
}
|
|
412
|
+
// ── Gestures ──────────────────────────────────────────────────────────────────
|
|
413
|
+
playGesture(t) {
|
|
414
|
+
if (this.vrm) {
|
|
415
|
+
this._playVRMProceduralGesture(t);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const e = this._findClip(new RegExp(t, "i"));
|
|
419
|
+
if (e && this.mixer) {
|
|
420
|
+
const s = this.mixer.clipAction(e);
|
|
421
|
+
s.setLoop(M.LoopOnce, 1), s.clampWhenFinished = !0, this._transitionTo(s), this.mixer.addEventListener("finished", (n) => {
|
|
422
|
+
n.action === s && (this.stop(), this.mixer?.removeEventListener("finished", () => {
|
|
423
|
+
}));
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
_playVRMProceduralGesture(t) {
|
|
428
|
+
if (this.vrm) {
|
|
429
|
+
if (this._gestureActive) {
|
|
430
|
+
const e = this._gestureDuration * 0.82;
|
|
431
|
+
this._gestureElapsed < e && (this._gestureElapsed = e), this._pendingGesture = t;
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
this._startGesture(t);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
_startGesture(t) {
|
|
438
|
+
const e = Et[t];
|
|
439
|
+
if (!e || !this.vrm) return;
|
|
440
|
+
const s = this.vrm;
|
|
441
|
+
this._gestureActive = !0, this._gestureElapsed = 0, this._gestureDuration = e.duration, this._gestureUpdateFn = (n) => e.fn(n, s), this._pendingGesture = null;
|
|
442
|
+
}
|
|
443
|
+
_tickProceduralGesture(t) {
|
|
444
|
+
if (!this._gestureUpdateFn) return;
|
|
445
|
+
this._gestureElapsed += t;
|
|
446
|
+
const e = Math.min(this._gestureElapsed / this._gestureDuration, 1);
|
|
447
|
+
this._gestureUpdateFn(e), e >= 1 && (this._gestureActive = !1, this._gestureUpdateFn = null, this._gestureElapsed = 0, this._pendingGesture && this._startGesture(this._pendingGesture));
|
|
448
|
+
}
|
|
449
|
+
// ── Look ──────────────────────────────────────────────────────────────────────
|
|
450
|
+
lookAt(t, e) {
|
|
451
|
+
const s = new M.Euler(e * 0.6, t * 0.75, 0, "YXZ");
|
|
452
|
+
this.lookTargetDelta.setFromEuler(s), this.lookSettled = !1;
|
|
453
|
+
}
|
|
454
|
+
lookForward() {
|
|
455
|
+
this.stopRandomLook(), this.lookTargetDelta.identity(), this.lookSettled = !1;
|
|
456
|
+
}
|
|
457
|
+
startRandomLook() {
|
|
458
|
+
this.stopRandomLook();
|
|
459
|
+
const t = () => {
|
|
460
|
+
const e = (Math.random() - 0.5) * 1.4, s = (Math.random() - 0.5) * 0.8;
|
|
461
|
+
this.lookAt(e, s), this.randomLookTimeout = setTimeout(t, 1500 + Math.random() * 2e3);
|
|
462
|
+
};
|
|
463
|
+
t();
|
|
464
|
+
}
|
|
465
|
+
stopRandomLook() {
|
|
466
|
+
this.randomLookTimeout && (clearTimeout(this.randomLookTimeout), this.randomLookTimeout = null);
|
|
467
|
+
}
|
|
468
|
+
stopLook() {
|
|
469
|
+
this.stopRandomLook(), this.lookTargetDelta.identity(), this.lookCurrentDelta.identity();
|
|
470
|
+
}
|
|
471
|
+
hasHeadBone() {
|
|
472
|
+
return this.headBone !== null;
|
|
473
|
+
}
|
|
474
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
475
|
+
_setMorphTarget(t, e) {
|
|
476
|
+
for (const s of this.morphMeshes) {
|
|
477
|
+
const n = s.morphTargetDictionary;
|
|
478
|
+
if (!(!n || !s.morphTargetInfluences))
|
|
479
|
+
for (const i of t) {
|
|
480
|
+
const o = n[i];
|
|
481
|
+
if (o !== void 0) {
|
|
482
|
+
s.morphTargetInfluences[o] = e;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
_initVRMRestPose() {
|
|
489
|
+
if (!this.vrm) return;
|
|
490
|
+
const t = this.vrm.humanoid, e = t.getNormalizedBoneNode(f.RightUpperArm), s = t.getNormalizedBoneNode(f.LeftUpperArm);
|
|
491
|
+
e && (e.rotation.z = Math.PI / 6), s && (s.rotation.z = -Math.PI / 6);
|
|
492
|
+
const n = t.getNormalizedBoneNode(f.Hips);
|
|
493
|
+
n && (this.vrm.scene.userData.hipsRestY = n.position.y);
|
|
494
|
+
}
|
|
495
|
+
_updateVRMProceduralIdle(t) {
|
|
496
|
+
if (!this.vrm) return;
|
|
497
|
+
const e = this.vrm.humanoid, s = e.getNormalizedBoneNode(f.Hips);
|
|
498
|
+
s && (s.position.y = this.vrm.scene.userData.hipsRestY ?? 0);
|
|
499
|
+
const n = Math.sin(t * 1.8), i = Math.sin(t * 0.7), o = e.getNormalizedBoneNode(f.Spine), a = e.getNormalizedBoneNode(f.Chest);
|
|
500
|
+
o && (o.rotation.z = i * 8e-3), a && (a.rotation.x = n * 0.015);
|
|
501
|
+
const r = e.getNormalizedBoneNode(f.RightUpperArm), c = e.getNormalizedBoneNode(f.LeftUpperArm);
|
|
502
|
+
r && (r.rotation.z = Math.PI / 3.2 + n * 0.018, r.rotation.y = 0, r.rotation.x = 0), c && (c.rotation.z = -(Math.PI / 3.2 + n * 0.018), c.rotation.y = 0, c.rotation.x = 0);
|
|
503
|
+
const u = e.getNormalizedBoneNode(f.RightLowerArm), h = e.getNormalizedBoneNode(f.LeftLowerArm);
|
|
504
|
+
u && (u.rotation.order = "XYZ", u.rotation.z = -0.1, u.rotation.y = 0, u.rotation.x = 0), h && (h.rotation.z = 0.1, h.rotation.y = 0, h.rotation.x = 0);
|
|
505
|
+
const d = e.getNormalizedBoneNode(f.RightHand), p = e.getNormalizedBoneNode(f.LeftHand);
|
|
506
|
+
d && (d.rotation.x = -0.15, d.rotation.y = 0, d.rotation.z = 0), p && (p.rotation.x = -0.15, p.rotation.y = 0, p.rotation.z = 0);
|
|
507
|
+
const m = 0.28 + n * 0.06, A = [
|
|
508
|
+
[f.RightIndexProximal, f.RightIndexIntermediate, f.RightIndexDistal],
|
|
509
|
+
[f.RightMiddleProximal, f.RightMiddleIntermediate, f.RightMiddleDistal],
|
|
510
|
+
[f.RightRingProximal, f.RightRingIntermediate, f.RightRingDistal],
|
|
511
|
+
[f.RightLittleProximal, f.RightLittleIntermediate, f.RightLittleDistal]
|
|
512
|
+
];
|
|
513
|
+
for (const [N, T, S] of A) {
|
|
514
|
+
const L = e.getNormalizedBoneNode(N), E = e.getNormalizedBoneNode(T), I = e.getNormalizedBoneNode(S);
|
|
515
|
+
L && (L.rotation.z = m, L.rotation.x = 0), E && (E.rotation.z = m * 0.8, E.rotation.x = 0), I && (I.rotation.z = m * 0.5, I.rotation.x = 0);
|
|
516
|
+
}
|
|
517
|
+
const g = [
|
|
518
|
+
[f.LeftIndexProximal, f.LeftIndexIntermediate, f.LeftIndexDistal],
|
|
519
|
+
[f.LeftMiddleProximal, f.LeftMiddleIntermediate, f.LeftMiddleDistal],
|
|
520
|
+
[f.LeftRingProximal, f.LeftRingIntermediate, f.LeftRingDistal],
|
|
521
|
+
[f.LeftLittleProximal, f.LeftLittleIntermediate, f.LeftLittleDistal]
|
|
522
|
+
];
|
|
523
|
+
for (const [N, T, S] of g) {
|
|
524
|
+
const L = e.getNormalizedBoneNode(N), E = e.getNormalizedBoneNode(T), I = e.getNormalizedBoneNode(S);
|
|
525
|
+
L && (L.rotation.z = -m, L.rotation.x = 0), E && (E.rotation.z = -m * 0.8, E.rotation.x = 0), I && (I.rotation.z = -m * 0.5, I.rotation.x = 0);
|
|
526
|
+
}
|
|
527
|
+
const x = e.getNormalizedBoneNode(f.RightThumbProximal), _ = e.getNormalizedBoneNode(f.LeftThumbProximal);
|
|
528
|
+
x && (x.rotation.z = -0.3, x.rotation.x = 0.2), _ && (_.rotation.z = 0.3, _.rotation.x = 0.2);
|
|
529
|
+
}
|
|
530
|
+
_findClip(t) {
|
|
531
|
+
return this.clips.find((e) => t.test(e.name));
|
|
532
|
+
}
|
|
533
|
+
_delay(t) {
|
|
534
|
+
return new Promise((e) => setTimeout(e, t));
|
|
535
|
+
}
|
|
536
|
+
dispose() {
|
|
537
|
+
this.stopBlink(), this.stopIdle(), this.stopRandomLook(), this.stopLook(), this.mixer?.stopAllAction(), this.mixer = null, this.vrm = null, this.clips = [], this.morphMeshes = [], this.headBone = null, this.lookCurrentDelta.identity(), this.lookTargetDelta.identity(), this.lookSettled = !0, this.currentAction = null, this.idleAction = null, this._gestureActive = !1, this._gestureUpdateFn = null, this._gestureElapsed = 0, this._pendingGesture = null;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
O._VRM_VISEME_CYCLE = ["aa", "aa", "oh", "aa", "ih", "aa", "ee", "ou"], O._VRM_VISEMES = ["aa", "ih", "ou", "ee", "oh"];
|
|
541
|
+
let oe = O;
|
|
542
|
+
class bt {
|
|
543
|
+
constructor() {
|
|
544
|
+
this.context = null, this.source = null, this.analyser = null, this.gainNode = null, this.dataArray = new Float32Array(0), this._endedCallback = null;
|
|
545
|
+
}
|
|
546
|
+
_ctx() {
|
|
547
|
+
return (!this.context || this.context.state === "closed") && (this.context = new AudioContext()), this.context;
|
|
548
|
+
}
|
|
549
|
+
async play(t) {
|
|
550
|
+
const e = this._ctx();
|
|
551
|
+
e.state === "suspended" && await e.resume(), this._stopSource();
|
|
552
|
+
const s = await this._toBuffer(e, t);
|
|
553
|
+
return this.analyser = e.createAnalyser(), this.analyser.fftSize = 512, this.analyser.smoothingTimeConstant = 0.6, this.dataArray = new Float32Array(this.analyser.frequencyBinCount), this.gainNode = e.createGain(), this.source = e.createBufferSource(), this.source.buffer = s, this.source.connect(this.analyser), this.analyser.connect(this.gainNode), this.gainNode.connect(e.destination), new Promise((n) => {
|
|
554
|
+
this.source.onended = () => {
|
|
555
|
+
this._endedCallback?.(), n();
|
|
556
|
+
}, this.source.start(0);
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
pause() {
|
|
560
|
+
this.context?.suspend();
|
|
561
|
+
}
|
|
562
|
+
async resume() {
|
|
563
|
+
await this.context?.resume();
|
|
564
|
+
}
|
|
565
|
+
stop() {
|
|
566
|
+
this._stopSource();
|
|
567
|
+
}
|
|
568
|
+
// RMS amplitude in 0–1 range — used by LipSync each frame
|
|
569
|
+
getAmplitude() {
|
|
570
|
+
if (!this.analyser || this.dataArray.length === 0) return 0;
|
|
571
|
+
this.analyser.getFloatTimeDomainData(this.dataArray);
|
|
572
|
+
let t = 0;
|
|
573
|
+
for (const e of this.dataArray) t += e * e;
|
|
574
|
+
return Math.sqrt(t / this.dataArray.length);
|
|
575
|
+
}
|
|
576
|
+
set onEnded(t) {
|
|
577
|
+
this._endedCallback = t;
|
|
578
|
+
}
|
|
579
|
+
async _toBuffer(t, e) {
|
|
580
|
+
if (e instanceof AudioBuffer) return e;
|
|
581
|
+
if (typeof e == "string") {
|
|
582
|
+
const n = await (await fetch(e)).arrayBuffer();
|
|
583
|
+
return t.decodeAudioData(n);
|
|
584
|
+
}
|
|
585
|
+
return t.decodeAudioData(e.slice(0));
|
|
586
|
+
}
|
|
587
|
+
_stopSource() {
|
|
588
|
+
try {
|
|
589
|
+
this.source?.stop();
|
|
590
|
+
} catch {
|
|
591
|
+
}
|
|
592
|
+
this.source?.disconnect(), this.source = null;
|
|
593
|
+
}
|
|
594
|
+
dispose() {
|
|
595
|
+
this._stopSource(), this.context?.close(), this.context = null, this.analyser = null, this.gainNode = null;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const It = {
|
|
599
|
+
sil: 0,
|
|
600
|
+
// silence
|
|
601
|
+
PP: 0.05,
|
|
602
|
+
// p, b, m
|
|
603
|
+
FF: 0.2,
|
|
604
|
+
// f, v
|
|
605
|
+
TH: 0.25,
|
|
606
|
+
// th
|
|
607
|
+
DD: 0.3,
|
|
608
|
+
// d, t
|
|
609
|
+
kk: 0.35,
|
|
610
|
+
// k, g
|
|
611
|
+
CH: 0.5,
|
|
612
|
+
// ch, j
|
|
613
|
+
SS: 0.2,
|
|
614
|
+
// s, z
|
|
615
|
+
nn: 0.15,
|
|
616
|
+
// n, l
|
|
617
|
+
RR: 0.4,
|
|
618
|
+
// r
|
|
619
|
+
aa: 1,
|
|
620
|
+
// a (open)
|
|
621
|
+
E: 0.7,
|
|
622
|
+
// e
|
|
623
|
+
ih: 0.5,
|
|
624
|
+
// i
|
|
625
|
+
oh: 0.85,
|
|
626
|
+
// o
|
|
627
|
+
ou: 0.6
|
|
628
|
+
// u
|
|
629
|
+
};
|
|
630
|
+
class kt {
|
|
631
|
+
constructor(t, e) {
|
|
632
|
+
this.audioEngine = t, this.onMouth = e, this.rafId = 0;
|
|
633
|
+
}
|
|
634
|
+
// Manual viseme — maps phoneme to mouth openness
|
|
635
|
+
setViseme(t) {
|
|
636
|
+
this.onMouth(It[t] ?? 0);
|
|
637
|
+
}
|
|
638
|
+
// Direct mouth shape override (0–1)
|
|
639
|
+
setMouth(t) {
|
|
640
|
+
this.onMouth(Math.max(0, Math.min(1, t)));
|
|
641
|
+
}
|
|
642
|
+
// Drive mouth from a volume value (0–1), e.g. from external TTS
|
|
643
|
+
setVolume(t) {
|
|
644
|
+
this.onMouth(Math.max(0, Math.min(1, t)));
|
|
645
|
+
}
|
|
646
|
+
// Auto lip sync: reads amplitude from AudioEngine every frame via RAF
|
|
647
|
+
startAutoSync() {
|
|
648
|
+
this.stopAutoSync();
|
|
649
|
+
const t = () => {
|
|
650
|
+
const e = this.audioEngine.getAmplitude();
|
|
651
|
+
this.onMouth(Math.min(1, e * 10)), this.rafId = requestAnimationFrame(t);
|
|
652
|
+
};
|
|
653
|
+
this.rafId = requestAnimationFrame(t);
|
|
654
|
+
}
|
|
655
|
+
stopAutoSync() {
|
|
656
|
+
cancelAnimationFrame(this.rafId), this.rafId = 0, this.onMouth(0);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function ge(l, t) {
|
|
660
|
+
if (t === Be)
|
|
661
|
+
return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), l;
|
|
662
|
+
if (t === se || t === Re) {
|
|
663
|
+
let e = l.getIndex();
|
|
664
|
+
if (e === null) {
|
|
665
|
+
const o = [], a = l.getAttribute("position");
|
|
666
|
+
if (a !== void 0) {
|
|
667
|
+
for (let r = 0; r < a.count; r++)
|
|
668
|
+
o.push(r);
|
|
669
|
+
l.setIndex(o), e = l.getIndex();
|
|
670
|
+
} else
|
|
671
|
+
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), l;
|
|
672
|
+
}
|
|
673
|
+
const s = e.count - 2, n = [];
|
|
674
|
+
if (t === se)
|
|
675
|
+
for (let o = 1; o <= s; o++)
|
|
676
|
+
n.push(e.getX(0)), n.push(e.getX(o)), n.push(e.getX(o + 1));
|
|
677
|
+
else
|
|
678
|
+
for (let o = 0; o < s; o++)
|
|
679
|
+
o % 2 === 0 ? (n.push(e.getX(o)), n.push(e.getX(o + 1)), n.push(e.getX(o + 2))) : (n.push(e.getX(o + 2)), n.push(e.getX(o + 1)), n.push(e.getX(o)));
|
|
680
|
+
n.length / 3 !== s && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
|
|
681
|
+
const i = l.clone();
|
|
682
|
+
return i.setIndex(n), i.clearGroups(), i;
|
|
683
|
+
} else
|
|
684
|
+
return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", t), l;
|
|
685
|
+
}
|
|
686
|
+
class Ae extends ve {
|
|
687
|
+
constructor(t) {
|
|
688
|
+
super(t), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(e) {
|
|
689
|
+
return new Ft(e);
|
|
690
|
+
}), this.register(function(e) {
|
|
691
|
+
return new Dt(e);
|
|
692
|
+
}), this.register(function(e) {
|
|
693
|
+
return new Xt(e);
|
|
694
|
+
}), this.register(function(e) {
|
|
695
|
+
return new Wt(e);
|
|
696
|
+
}), this.register(function(e) {
|
|
697
|
+
return new Yt(e);
|
|
698
|
+
}), this.register(function(e) {
|
|
699
|
+
return new zt(e);
|
|
700
|
+
}), this.register(function(e) {
|
|
701
|
+
return new Ht(e);
|
|
702
|
+
}), this.register(function(e) {
|
|
703
|
+
return new Gt(e);
|
|
704
|
+
}), this.register(function(e) {
|
|
705
|
+
return new Ut(e);
|
|
706
|
+
}), this.register(function(e) {
|
|
707
|
+
return new Pt(e);
|
|
708
|
+
}), this.register(function(e) {
|
|
709
|
+
return new Vt(e);
|
|
710
|
+
}), this.register(function(e) {
|
|
711
|
+
return new Ot(e);
|
|
712
|
+
}), this.register(function(e) {
|
|
713
|
+
return new Kt(e);
|
|
714
|
+
}), this.register(function(e) {
|
|
715
|
+
return new jt(e);
|
|
716
|
+
}), this.register(function(e) {
|
|
717
|
+
return new Bt(e);
|
|
718
|
+
}), this.register(function(e) {
|
|
719
|
+
return new Qt(e);
|
|
720
|
+
}), this.register(function(e) {
|
|
721
|
+
return new qt(e);
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
load(t, e, s, n) {
|
|
725
|
+
const i = this;
|
|
726
|
+
let o;
|
|
727
|
+
if (this.resourcePath !== "")
|
|
728
|
+
o = this.resourcePath;
|
|
729
|
+
else if (this.path !== "") {
|
|
730
|
+
const c = j.extractUrlBase(t);
|
|
731
|
+
o = j.resolveURL(c, this.path);
|
|
732
|
+
} else
|
|
733
|
+
o = j.extractUrlBase(t);
|
|
734
|
+
this.manager.itemStart(t);
|
|
735
|
+
const a = function(c) {
|
|
736
|
+
n ? n(c) : console.error(c), i.manager.itemError(t), i.manager.itemEnd(t);
|
|
737
|
+
}, r = new Me(this.manager);
|
|
738
|
+
r.setPath(this.path), r.setResponseType("arraybuffer"), r.setRequestHeader(this.requestHeader), r.setWithCredentials(this.withCredentials), r.load(t, function(c) {
|
|
739
|
+
try {
|
|
740
|
+
i.parse(c, o, function(u) {
|
|
741
|
+
e(u), i.manager.itemEnd(t);
|
|
742
|
+
}, a);
|
|
743
|
+
} catch (u) {
|
|
744
|
+
a(u);
|
|
745
|
+
}
|
|
746
|
+
}, s, a);
|
|
747
|
+
}
|
|
748
|
+
setDRACOLoader(t) {
|
|
749
|
+
return this.dracoLoader = t, this;
|
|
750
|
+
}
|
|
751
|
+
setDDSLoader() {
|
|
752
|
+
throw new Error(
|
|
753
|
+
'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
setKTX2Loader(t) {
|
|
757
|
+
return this.ktx2Loader = t, this;
|
|
758
|
+
}
|
|
759
|
+
setMeshoptDecoder(t) {
|
|
760
|
+
return this.meshoptDecoder = t, this;
|
|
761
|
+
}
|
|
762
|
+
register(t) {
|
|
763
|
+
return this.pluginCallbacks.indexOf(t) === -1 && this.pluginCallbacks.push(t), this;
|
|
764
|
+
}
|
|
765
|
+
unregister(t) {
|
|
766
|
+
return this.pluginCallbacks.indexOf(t) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t), 1), this;
|
|
767
|
+
}
|
|
768
|
+
parse(t, e, s, n) {
|
|
769
|
+
let i;
|
|
770
|
+
const o = {}, a = {}, r = new TextDecoder();
|
|
771
|
+
if (typeof t == "string")
|
|
772
|
+
i = JSON.parse(t);
|
|
773
|
+
else if (t instanceof ArrayBuffer)
|
|
774
|
+
if (r.decode(new Uint8Array(t, 0, 4)) === ke) {
|
|
775
|
+
try {
|
|
776
|
+
o[R.KHR_BINARY_GLTF] = new Zt(t);
|
|
777
|
+
} catch (h) {
|
|
778
|
+
n && n(h);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
i = JSON.parse(o[R.KHR_BINARY_GLTF].content);
|
|
782
|
+
} else
|
|
783
|
+
i = JSON.parse(r.decode(t));
|
|
784
|
+
else
|
|
785
|
+
i = t;
|
|
786
|
+
if (i.asset === void 0 || i.asset.version[0] < 2) {
|
|
787
|
+
n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const c = new un(i, {
|
|
791
|
+
path: e || this.resourcePath || "",
|
|
792
|
+
crossOrigin: this.crossOrigin,
|
|
793
|
+
requestHeader: this.requestHeader,
|
|
794
|
+
manager: this.manager,
|
|
795
|
+
ktx2Loader: this.ktx2Loader,
|
|
796
|
+
meshoptDecoder: this.meshoptDecoder
|
|
797
|
+
});
|
|
798
|
+
c.fileLoader.setRequestHeader(this.requestHeader);
|
|
799
|
+
for (let u = 0; u < this.pluginCallbacks.length; u++) {
|
|
800
|
+
const h = this.pluginCallbacks[u](c);
|
|
801
|
+
h.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[h.name] = h, o[h.name] = !0;
|
|
802
|
+
}
|
|
803
|
+
if (i.extensionsUsed)
|
|
804
|
+
for (let u = 0; u < i.extensionsUsed.length; ++u) {
|
|
805
|
+
const h = i.extensionsUsed[u], d = i.extensionsRequired || [];
|
|
806
|
+
switch (h) {
|
|
807
|
+
case R.KHR_MATERIALS_UNLIT:
|
|
808
|
+
o[h] = new vt();
|
|
809
|
+
break;
|
|
810
|
+
case R.KHR_DRACO_MESH_COMPRESSION:
|
|
811
|
+
o[h] = new $t(i, this.dracoLoader);
|
|
812
|
+
break;
|
|
813
|
+
case R.KHR_TEXTURE_TRANSFORM:
|
|
814
|
+
o[h] = new Jt();
|
|
815
|
+
break;
|
|
816
|
+
case R.KHR_MESH_QUANTIZATION:
|
|
817
|
+
o[h] = new en();
|
|
818
|
+
break;
|
|
819
|
+
default:
|
|
820
|
+
d.indexOf(h) >= 0 && a[h] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + h + '".');
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
c.setExtensions(o), c.setPlugins(a), c.parse(s, n);
|
|
824
|
+
}
|
|
825
|
+
parseAsync(t, e) {
|
|
826
|
+
const s = this;
|
|
827
|
+
return new Promise(function(n, i) {
|
|
828
|
+
s.parse(t, e, n, i);
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function Ct() {
|
|
833
|
+
let l = {};
|
|
834
|
+
return {
|
|
835
|
+
get: function(t) {
|
|
836
|
+
return l[t];
|
|
837
|
+
},
|
|
838
|
+
add: function(t, e) {
|
|
839
|
+
l[t] = e;
|
|
840
|
+
},
|
|
841
|
+
remove: function(t) {
|
|
842
|
+
delete l[t];
|
|
843
|
+
},
|
|
844
|
+
removeAll: function() {
|
|
845
|
+
l = {};
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
const R = {
|
|
850
|
+
KHR_BINARY_GLTF: "KHR_binary_glTF",
|
|
851
|
+
KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
|
|
852
|
+
KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
|
|
853
|
+
KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
|
|
854
|
+
KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
|
|
855
|
+
KHR_MATERIALS_IOR: "KHR_materials_ior",
|
|
856
|
+
KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
|
|
857
|
+
KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
|
|
858
|
+
KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
|
|
859
|
+
KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
|
|
860
|
+
KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
|
|
861
|
+
KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
|
|
862
|
+
KHR_MATERIALS_VOLUME: "KHR_materials_volume",
|
|
863
|
+
KHR_TEXTURE_BASISU: "KHR_texture_basisu",
|
|
864
|
+
KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
|
|
865
|
+
KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
|
|
866
|
+
KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
|
|
867
|
+
EXT_MATERIALS_BUMP: "EXT_materials_bump",
|
|
868
|
+
EXT_TEXTURE_WEBP: "EXT_texture_webp",
|
|
869
|
+
EXT_TEXTURE_AVIF: "EXT_texture_avif",
|
|
870
|
+
EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
|
|
871
|
+
EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
|
|
872
|
+
};
|
|
873
|
+
class Bt {
|
|
874
|
+
constructor(t) {
|
|
875
|
+
this.parser = t, this.name = R.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
|
|
876
|
+
}
|
|
877
|
+
_markDefs() {
|
|
878
|
+
const t = this.parser, e = this.parser.json.nodes || [];
|
|
879
|
+
for (let s = 0, n = e.length; s < n; s++) {
|
|
880
|
+
const i = e[s];
|
|
881
|
+
i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && t._addNodeRef(this.cache, i.extensions[this.name].light);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
_loadLight(t) {
|
|
885
|
+
const e = this.parser, s = "light:" + t;
|
|
886
|
+
let n = e.cache.get(s);
|
|
887
|
+
if (n) return n;
|
|
888
|
+
const i = e.json, r = ((i.extensions && i.extensions[this.name] || {}).lights || [])[t];
|
|
889
|
+
let c;
|
|
890
|
+
const u = new z(16777215);
|
|
891
|
+
r.color !== void 0 && u.setRGB(r.color[0], r.color[1], r.color[2], v);
|
|
892
|
+
const h = r.range !== void 0 ? r.range : 0;
|
|
893
|
+
switch (r.type) {
|
|
894
|
+
case "directional":
|
|
895
|
+
c = new De(u), c.target.position.set(0, 0, -1), c.add(c.target);
|
|
896
|
+
break;
|
|
897
|
+
case "point":
|
|
898
|
+
c = new Fe(u), c.distance = h;
|
|
899
|
+
break;
|
|
900
|
+
case "spot":
|
|
901
|
+
c = new Pe(u), c.distance = h, r.spot = r.spot || {}, r.spot.innerConeAngle = r.spot.innerConeAngle !== void 0 ? r.spot.innerConeAngle : 0, r.spot.outerConeAngle = r.spot.outerConeAngle !== void 0 ? r.spot.outerConeAngle : Math.PI / 4, c.angle = r.spot.outerConeAngle, c.penumbra = 1 - r.spot.innerConeAngle / r.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
|
|
902
|
+
break;
|
|
903
|
+
default:
|
|
904
|
+
throw new Error("THREE.GLTFLoader: Unexpected light type: " + r.type);
|
|
905
|
+
}
|
|
906
|
+
return c.position.set(0, 0, 0), c.decay = 2, B(c, r), r.intensity !== void 0 && (c.intensity = r.intensity), c.name = e.createUniqueName(r.name || "light_" + t), n = Promise.resolve(c), e.cache.add(s, n), n;
|
|
907
|
+
}
|
|
908
|
+
getDependency(t, e) {
|
|
909
|
+
if (t === "light")
|
|
910
|
+
return this._loadLight(e);
|
|
911
|
+
}
|
|
912
|
+
createNodeAttachment(t) {
|
|
913
|
+
const e = this, s = this.parser, i = s.json.nodes[t], a = (i.extensions && i.extensions[this.name] || {}).light;
|
|
914
|
+
return a === void 0 ? null : this._loadLight(a).then(function(r) {
|
|
915
|
+
return s._getNodeRef(e.cache, a, r);
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
class vt {
|
|
920
|
+
constructor() {
|
|
921
|
+
this.name = R.KHR_MATERIALS_UNLIT;
|
|
922
|
+
}
|
|
923
|
+
getMaterialType() {
|
|
924
|
+
return V;
|
|
925
|
+
}
|
|
926
|
+
extendParams(t, e, s) {
|
|
927
|
+
const n = [];
|
|
928
|
+
t.color = new z(1, 1, 1), t.opacity = 1;
|
|
929
|
+
const i = e.pbrMetallicRoughness;
|
|
930
|
+
if (i) {
|
|
931
|
+
if (Array.isArray(i.baseColorFactor)) {
|
|
932
|
+
const o = i.baseColorFactor;
|
|
933
|
+
t.color.setRGB(o[0], o[1], o[2], v), t.opacity = o[3];
|
|
934
|
+
}
|
|
935
|
+
i.baseColorTexture !== void 0 && n.push(s.assignTexture(t, "map", i.baseColorTexture, K));
|
|
936
|
+
}
|
|
937
|
+
return Promise.all(n);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
class Pt {
|
|
941
|
+
constructor(t) {
|
|
942
|
+
this.parser = t, this.name = R.KHR_MATERIALS_EMISSIVE_STRENGTH;
|
|
943
|
+
}
|
|
944
|
+
extendMaterialParams(t, e) {
|
|
945
|
+
const n = this.parser.json.materials[t];
|
|
946
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
947
|
+
return Promise.resolve();
|
|
948
|
+
const i = n.extensions[this.name].emissiveStrength;
|
|
949
|
+
return i !== void 0 && (e.emissiveIntensity = i), Promise.resolve();
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
class Ft {
|
|
953
|
+
constructor(t) {
|
|
954
|
+
this.parser = t, this.name = R.KHR_MATERIALS_CLEARCOAT;
|
|
955
|
+
}
|
|
956
|
+
getMaterialType(t) {
|
|
957
|
+
const s = this.parser.json.materials[t];
|
|
958
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
959
|
+
}
|
|
960
|
+
extendMaterialParams(t, e) {
|
|
961
|
+
const s = this.parser, n = s.json.materials[t];
|
|
962
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
963
|
+
return Promise.resolve();
|
|
964
|
+
const i = [], o = n.extensions[this.name];
|
|
965
|
+
if (o.clearcoatFactor !== void 0 && (e.clearcoat = o.clearcoatFactor), o.clearcoatTexture !== void 0 && i.push(s.assignTexture(e, "clearcoatMap", o.clearcoatTexture)), o.clearcoatRoughnessFactor !== void 0 && (e.clearcoatRoughness = o.clearcoatRoughnessFactor), o.clearcoatRoughnessTexture !== void 0 && i.push(s.assignTexture(e, "clearcoatRoughnessMap", o.clearcoatRoughnessTexture)), o.clearcoatNormalTexture !== void 0 && (i.push(s.assignTexture(e, "clearcoatNormalMap", o.clearcoatNormalTexture)), o.clearcoatNormalTexture.scale !== void 0)) {
|
|
966
|
+
const a = o.clearcoatNormalTexture.scale;
|
|
967
|
+
e.clearcoatNormalScale = new Ne(a, a);
|
|
968
|
+
}
|
|
969
|
+
return Promise.all(i);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
class Dt {
|
|
973
|
+
constructor(t) {
|
|
974
|
+
this.parser = t, this.name = R.KHR_MATERIALS_DISPERSION;
|
|
975
|
+
}
|
|
976
|
+
getMaterialType(t) {
|
|
977
|
+
const s = this.parser.json.materials[t];
|
|
978
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
979
|
+
}
|
|
980
|
+
extendMaterialParams(t, e) {
|
|
981
|
+
const n = this.parser.json.materials[t];
|
|
982
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
983
|
+
return Promise.resolve();
|
|
984
|
+
const i = n.extensions[this.name];
|
|
985
|
+
return e.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
class Ot {
|
|
989
|
+
constructor(t) {
|
|
990
|
+
this.parser = t, this.name = R.KHR_MATERIALS_IRIDESCENCE;
|
|
991
|
+
}
|
|
992
|
+
getMaterialType(t) {
|
|
993
|
+
const s = this.parser.json.materials[t];
|
|
994
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
995
|
+
}
|
|
996
|
+
extendMaterialParams(t, e) {
|
|
997
|
+
const s = this.parser, n = s.json.materials[t];
|
|
998
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
999
|
+
return Promise.resolve();
|
|
1000
|
+
const i = [], o = n.extensions[this.name];
|
|
1001
|
+
return o.iridescenceFactor !== void 0 && (e.iridescence = o.iridescenceFactor), o.iridescenceTexture !== void 0 && i.push(s.assignTexture(e, "iridescenceMap", o.iridescenceTexture)), o.iridescenceIor !== void 0 && (e.iridescenceIOR = o.iridescenceIor), e.iridescenceThicknessRange === void 0 && (e.iridescenceThicknessRange = [100, 400]), o.iridescenceThicknessMinimum !== void 0 && (e.iridescenceThicknessRange[0] = o.iridescenceThicknessMinimum), o.iridescenceThicknessMaximum !== void 0 && (e.iridescenceThicknessRange[1] = o.iridescenceThicknessMaximum), o.iridescenceThicknessTexture !== void 0 && i.push(s.assignTexture(e, "iridescenceThicknessMap", o.iridescenceThicknessTexture)), Promise.all(i);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
class zt {
|
|
1005
|
+
constructor(t) {
|
|
1006
|
+
this.parser = t, this.name = R.KHR_MATERIALS_SHEEN;
|
|
1007
|
+
}
|
|
1008
|
+
getMaterialType(t) {
|
|
1009
|
+
const s = this.parser.json.materials[t];
|
|
1010
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1011
|
+
}
|
|
1012
|
+
extendMaterialParams(t, e) {
|
|
1013
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1014
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1015
|
+
return Promise.resolve();
|
|
1016
|
+
const i = [];
|
|
1017
|
+
e.sheenColor = new z(0, 0, 0), e.sheenRoughness = 0, e.sheen = 1;
|
|
1018
|
+
const o = n.extensions[this.name];
|
|
1019
|
+
if (o.sheenColorFactor !== void 0) {
|
|
1020
|
+
const a = o.sheenColorFactor;
|
|
1021
|
+
e.sheenColor.setRGB(a[0], a[1], a[2], v);
|
|
1022
|
+
}
|
|
1023
|
+
return o.sheenRoughnessFactor !== void 0 && (e.sheenRoughness = o.sheenRoughnessFactor), o.sheenColorTexture !== void 0 && i.push(s.assignTexture(e, "sheenColorMap", o.sheenColorTexture, K)), o.sheenRoughnessTexture !== void 0 && i.push(s.assignTexture(e, "sheenRoughnessMap", o.sheenRoughnessTexture)), Promise.all(i);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
class Ht {
|
|
1027
|
+
constructor(t) {
|
|
1028
|
+
this.parser = t, this.name = R.KHR_MATERIALS_TRANSMISSION;
|
|
1029
|
+
}
|
|
1030
|
+
getMaterialType(t) {
|
|
1031
|
+
const s = this.parser.json.materials[t];
|
|
1032
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1033
|
+
}
|
|
1034
|
+
extendMaterialParams(t, e) {
|
|
1035
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1036
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1037
|
+
return Promise.resolve();
|
|
1038
|
+
const i = [], o = n.extensions[this.name];
|
|
1039
|
+
return o.transmissionFactor !== void 0 && (e.transmission = o.transmissionFactor), o.transmissionTexture !== void 0 && i.push(s.assignTexture(e, "transmissionMap", o.transmissionTexture)), Promise.all(i);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
class Gt {
|
|
1043
|
+
constructor(t) {
|
|
1044
|
+
this.parser = t, this.name = R.KHR_MATERIALS_VOLUME;
|
|
1045
|
+
}
|
|
1046
|
+
getMaterialType(t) {
|
|
1047
|
+
const s = this.parser.json.materials[t];
|
|
1048
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1049
|
+
}
|
|
1050
|
+
extendMaterialParams(t, e) {
|
|
1051
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1052
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1053
|
+
return Promise.resolve();
|
|
1054
|
+
const i = [], o = n.extensions[this.name];
|
|
1055
|
+
e.thickness = o.thicknessFactor !== void 0 ? o.thicknessFactor : 0, o.thicknessTexture !== void 0 && i.push(s.assignTexture(e, "thicknessMap", o.thicknessTexture)), e.attenuationDistance = o.attenuationDistance || 1 / 0;
|
|
1056
|
+
const a = o.attenuationColor || [1, 1, 1];
|
|
1057
|
+
return e.attenuationColor = new z().setRGB(a[0], a[1], a[2], v), Promise.all(i);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
class Ut {
|
|
1061
|
+
constructor(t) {
|
|
1062
|
+
this.parser = t, this.name = R.KHR_MATERIALS_IOR;
|
|
1063
|
+
}
|
|
1064
|
+
getMaterialType(t) {
|
|
1065
|
+
const s = this.parser.json.materials[t];
|
|
1066
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1067
|
+
}
|
|
1068
|
+
extendMaterialParams(t, e) {
|
|
1069
|
+
const n = this.parser.json.materials[t];
|
|
1070
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1071
|
+
return Promise.resolve();
|
|
1072
|
+
const i = n.extensions[this.name];
|
|
1073
|
+
return e.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
class Vt {
|
|
1077
|
+
constructor(t) {
|
|
1078
|
+
this.parser = t, this.name = R.KHR_MATERIALS_SPECULAR;
|
|
1079
|
+
}
|
|
1080
|
+
getMaterialType(t) {
|
|
1081
|
+
const s = this.parser.json.materials[t];
|
|
1082
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1083
|
+
}
|
|
1084
|
+
extendMaterialParams(t, e) {
|
|
1085
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1086
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1087
|
+
return Promise.resolve();
|
|
1088
|
+
const i = [], o = n.extensions[this.name];
|
|
1089
|
+
e.specularIntensity = o.specularFactor !== void 0 ? o.specularFactor : 1, o.specularTexture !== void 0 && i.push(s.assignTexture(e, "specularIntensityMap", o.specularTexture));
|
|
1090
|
+
const a = o.specularColorFactor || [1, 1, 1];
|
|
1091
|
+
return e.specularColor = new z().setRGB(a[0], a[1], a[2], v), o.specularColorTexture !== void 0 && i.push(s.assignTexture(e, "specularColorMap", o.specularColorTexture, K)), Promise.all(i);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
class jt {
|
|
1095
|
+
constructor(t) {
|
|
1096
|
+
this.parser = t, this.name = R.EXT_MATERIALS_BUMP;
|
|
1097
|
+
}
|
|
1098
|
+
getMaterialType(t) {
|
|
1099
|
+
const s = this.parser.json.materials[t];
|
|
1100
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1101
|
+
}
|
|
1102
|
+
extendMaterialParams(t, e) {
|
|
1103
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1104
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1105
|
+
return Promise.resolve();
|
|
1106
|
+
const i = [], o = n.extensions[this.name];
|
|
1107
|
+
return e.bumpScale = o.bumpFactor !== void 0 ? o.bumpFactor : 1, o.bumpTexture !== void 0 && i.push(s.assignTexture(e, "bumpMap", o.bumpTexture)), Promise.all(i);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
class Kt {
|
|
1111
|
+
constructor(t) {
|
|
1112
|
+
this.parser = t, this.name = R.KHR_MATERIALS_ANISOTROPY;
|
|
1113
|
+
}
|
|
1114
|
+
getMaterialType(t) {
|
|
1115
|
+
const s = this.parser.json.materials[t];
|
|
1116
|
+
return !s.extensions || !s.extensions[this.name] ? null : C;
|
|
1117
|
+
}
|
|
1118
|
+
extendMaterialParams(t, e) {
|
|
1119
|
+
const s = this.parser, n = s.json.materials[t];
|
|
1120
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1121
|
+
return Promise.resolve();
|
|
1122
|
+
const i = [], o = n.extensions[this.name];
|
|
1123
|
+
return o.anisotropyStrength !== void 0 && (e.anisotropy = o.anisotropyStrength), o.anisotropyRotation !== void 0 && (e.anisotropyRotation = o.anisotropyRotation), o.anisotropyTexture !== void 0 && i.push(s.assignTexture(e, "anisotropyMap", o.anisotropyTexture)), Promise.all(i);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
class Xt {
|
|
1127
|
+
constructor(t) {
|
|
1128
|
+
this.parser = t, this.name = R.KHR_TEXTURE_BASISU;
|
|
1129
|
+
}
|
|
1130
|
+
loadTexture(t) {
|
|
1131
|
+
const e = this.parser, s = e.json, n = s.textures[t];
|
|
1132
|
+
if (!n.extensions || !n.extensions[this.name])
|
|
1133
|
+
return null;
|
|
1134
|
+
const i = n.extensions[this.name], o = e.options.ktx2Loader;
|
|
1135
|
+
if (!o) {
|
|
1136
|
+
if (s.extensionsRequired && s.extensionsRequired.indexOf(this.name) >= 0)
|
|
1137
|
+
throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
return e.loadTextureImage(t, i.source, o);
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
class Wt {
|
|
1144
|
+
constructor(t) {
|
|
1145
|
+
this.parser = t, this.name = R.EXT_TEXTURE_WEBP, this.isSupported = null;
|
|
1146
|
+
}
|
|
1147
|
+
loadTexture(t) {
|
|
1148
|
+
const e = this.name, s = this.parser, n = s.json, i = n.textures[t];
|
|
1149
|
+
if (!i.extensions || !i.extensions[e])
|
|
1150
|
+
return null;
|
|
1151
|
+
const o = i.extensions[e], a = n.images[o.source];
|
|
1152
|
+
let r = s.textureLoader;
|
|
1153
|
+
if (a.uri) {
|
|
1154
|
+
const c = s.options.manager.getHandler(a.uri);
|
|
1155
|
+
c !== null && (r = c);
|
|
1156
|
+
}
|
|
1157
|
+
return this.detectSupport().then(function(c) {
|
|
1158
|
+
if (c) return s.loadTextureImage(t, o.source, r);
|
|
1159
|
+
if (n.extensionsRequired && n.extensionsRequired.indexOf(e) >= 0)
|
|
1160
|
+
throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");
|
|
1161
|
+
return s.loadTexture(t);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
detectSupport() {
|
|
1165
|
+
return this.isSupported || (this.isSupported = new Promise(function(t) {
|
|
1166
|
+
const e = new Image();
|
|
1167
|
+
e.src = "data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA", e.onload = e.onerror = function() {
|
|
1168
|
+
t(e.height === 1);
|
|
1169
|
+
};
|
|
1170
|
+
})), this.isSupported;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
class Yt {
|
|
1174
|
+
constructor(t) {
|
|
1175
|
+
this.parser = t, this.name = R.EXT_TEXTURE_AVIF, this.isSupported = null;
|
|
1176
|
+
}
|
|
1177
|
+
loadTexture(t) {
|
|
1178
|
+
const e = this.name, s = this.parser, n = s.json, i = n.textures[t];
|
|
1179
|
+
if (!i.extensions || !i.extensions[e])
|
|
1180
|
+
return null;
|
|
1181
|
+
const o = i.extensions[e], a = n.images[o.source];
|
|
1182
|
+
let r = s.textureLoader;
|
|
1183
|
+
if (a.uri) {
|
|
1184
|
+
const c = s.options.manager.getHandler(a.uri);
|
|
1185
|
+
c !== null && (r = c);
|
|
1186
|
+
}
|
|
1187
|
+
return this.detectSupport().then(function(c) {
|
|
1188
|
+
if (c) return s.loadTextureImage(t, o.source, r);
|
|
1189
|
+
if (n.extensionsRequired && n.extensionsRequired.indexOf(e) >= 0)
|
|
1190
|
+
throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");
|
|
1191
|
+
return s.loadTexture(t);
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
detectSupport() {
|
|
1195
|
+
return this.isSupported || (this.isSupported = new Promise(function(t) {
|
|
1196
|
+
const e = new Image();
|
|
1197
|
+
e.src = "data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=", e.onload = e.onerror = function() {
|
|
1198
|
+
t(e.height === 1);
|
|
1199
|
+
};
|
|
1200
|
+
})), this.isSupported;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
class Qt {
|
|
1204
|
+
constructor(t) {
|
|
1205
|
+
this.name = R.EXT_MESHOPT_COMPRESSION, this.parser = t;
|
|
1206
|
+
}
|
|
1207
|
+
loadBufferView(t) {
|
|
1208
|
+
const e = this.parser.json, s = e.bufferViews[t];
|
|
1209
|
+
if (s.extensions && s.extensions[this.name]) {
|
|
1210
|
+
const n = s.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), o = this.parser.options.meshoptDecoder;
|
|
1211
|
+
if (!o || !o.supported) {
|
|
1212
|
+
if (e.extensionsRequired && e.extensionsRequired.indexOf(this.name) >= 0)
|
|
1213
|
+
throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1216
|
+
return i.then(function(a) {
|
|
1217
|
+
const r = n.byteOffset || 0, c = n.byteLength || 0, u = n.count, h = n.byteStride, d = new Uint8Array(a, r, c);
|
|
1218
|
+
return o.decodeGltfBufferAsync ? o.decodeGltfBufferAsync(u, h, d, n.mode, n.filter).then(function(p) {
|
|
1219
|
+
return p.buffer;
|
|
1220
|
+
}) : o.ready.then(function() {
|
|
1221
|
+
const p = new ArrayBuffer(u * h);
|
|
1222
|
+
return o.decodeGltfBuffer(new Uint8Array(p), u, h, d, n.mode, n.filter), p;
|
|
1223
|
+
});
|
|
1224
|
+
});
|
|
1225
|
+
} else
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
class qt {
|
|
1230
|
+
constructor(t) {
|
|
1231
|
+
this.name = R.EXT_MESH_GPU_INSTANCING, this.parser = t;
|
|
1232
|
+
}
|
|
1233
|
+
createNodeMesh(t) {
|
|
1234
|
+
const e = this.parser.json, s = e.nodes[t];
|
|
1235
|
+
if (!s.extensions || !s.extensions[this.name] || s.mesh === void 0)
|
|
1236
|
+
return null;
|
|
1237
|
+
const n = e.meshes[s.mesh];
|
|
1238
|
+
for (const c of n.primitives)
|
|
1239
|
+
if (c.mode !== k.TRIANGLES && c.mode !== k.TRIANGLE_STRIP && c.mode !== k.TRIANGLE_FAN && c.mode !== void 0)
|
|
1240
|
+
return null;
|
|
1241
|
+
const o = s.extensions[this.name].attributes, a = [], r = {};
|
|
1242
|
+
for (const c in o)
|
|
1243
|
+
a.push(this.parser.getDependency("accessor", o[c]).then((u) => (r[c] = u, r[c])));
|
|
1244
|
+
return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(t)), Promise.all(a).then((c) => {
|
|
1245
|
+
const u = c.pop(), h = u.isGroup ? u.children : [u], d = c[0].count, p = [];
|
|
1246
|
+
for (const m of h) {
|
|
1247
|
+
const A = new W(), g = new H(), x = new Ee(), _ = new H(1, 1, 1), N = new Oe(m.geometry, m.material, d);
|
|
1248
|
+
for (let T = 0; T < d; T++)
|
|
1249
|
+
r.TRANSLATION && g.fromBufferAttribute(r.TRANSLATION, T), r.ROTATION && x.fromBufferAttribute(r.ROTATION, T), r.SCALE && _.fromBufferAttribute(r.SCALE, T), N.setMatrixAt(T, A.compose(g, x, _));
|
|
1250
|
+
for (const T in r)
|
|
1251
|
+
if (T === "_COLOR_0") {
|
|
1252
|
+
const S = r[T];
|
|
1253
|
+
N.instanceColor = new ze(S.array, S.itemSize, S.normalized);
|
|
1254
|
+
} else T !== "TRANSLATION" && T !== "ROTATION" && T !== "SCALE" && m.geometry.setAttribute(T, r[T]);
|
|
1255
|
+
we.prototype.copy.call(N, m), this.parser.assignFinalMaterial(N), p.push(N);
|
|
1256
|
+
}
|
|
1257
|
+
return u.isGroup ? (u.clear(), u.add(...p), u) : p[0];
|
|
1258
|
+
}));
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
const ke = "glTF", U = 12, Te = { JSON: 1313821514, BIN: 5130562 };
|
|
1262
|
+
class Zt {
|
|
1263
|
+
constructor(t) {
|
|
1264
|
+
this.name = R.KHR_BINARY_GLTF, this.content = null, this.body = null;
|
|
1265
|
+
const e = new DataView(t, 0, U), s = new TextDecoder();
|
|
1266
|
+
if (this.header = {
|
|
1267
|
+
magic: s.decode(new Uint8Array(t.slice(0, 4))),
|
|
1268
|
+
version: e.getUint32(4, !0),
|
|
1269
|
+
length: e.getUint32(8, !0)
|
|
1270
|
+
}, this.header.magic !== ke)
|
|
1271
|
+
throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
|
|
1272
|
+
if (this.header.version < 2)
|
|
1273
|
+
throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
|
|
1274
|
+
const n = this.header.length - U, i = new DataView(t, U);
|
|
1275
|
+
let o = 0;
|
|
1276
|
+
for (; o < n; ) {
|
|
1277
|
+
const a = i.getUint32(o, !0);
|
|
1278
|
+
o += 4;
|
|
1279
|
+
const r = i.getUint32(o, !0);
|
|
1280
|
+
if (o += 4, r === Te.JSON) {
|
|
1281
|
+
const c = new Uint8Array(t, U + o, a);
|
|
1282
|
+
this.content = s.decode(c);
|
|
1283
|
+
} else if (r === Te.BIN) {
|
|
1284
|
+
const c = U + o;
|
|
1285
|
+
this.body = t.slice(c, c + a);
|
|
1286
|
+
}
|
|
1287
|
+
o += a;
|
|
1288
|
+
}
|
|
1289
|
+
if (this.content === null)
|
|
1290
|
+
throw new Error("THREE.GLTFLoader: JSON content not found.");
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
class $t {
|
|
1294
|
+
constructor(t, e) {
|
|
1295
|
+
if (!e)
|
|
1296
|
+
throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
|
|
1297
|
+
this.name = R.KHR_DRACO_MESH_COMPRESSION, this.json = t, this.dracoLoader = e, this.dracoLoader.preload();
|
|
1298
|
+
}
|
|
1299
|
+
decodePrimitive(t, e) {
|
|
1300
|
+
const s = this.json, n = this.dracoLoader, i = t.extensions[this.name].bufferView, o = t.extensions[this.name].attributes, a = {}, r = {}, c = {};
|
|
1301
|
+
for (const u in o) {
|
|
1302
|
+
const h = re[u] || u.toLowerCase();
|
|
1303
|
+
a[h] = o[u];
|
|
1304
|
+
}
|
|
1305
|
+
for (const u in t.attributes) {
|
|
1306
|
+
const h = re[u] || u.toLowerCase();
|
|
1307
|
+
if (o[u] !== void 0) {
|
|
1308
|
+
const d = s.accessors[t.attributes[u]], p = G[d.componentType];
|
|
1309
|
+
c[h] = p.name, r[h] = d.normalized === !0;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return e.getDependency("bufferView", i).then(function(u) {
|
|
1313
|
+
return new Promise(function(h, d) {
|
|
1314
|
+
n.decodeDracoFile(u, function(p) {
|
|
1315
|
+
for (const m in p.attributes) {
|
|
1316
|
+
const A = p.attributes[m], g = r[m];
|
|
1317
|
+
g !== void 0 && (A.normalized = g);
|
|
1318
|
+
}
|
|
1319
|
+
h(p);
|
|
1320
|
+
}, a, c, v, d);
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
class Jt {
|
|
1326
|
+
constructor() {
|
|
1327
|
+
this.name = R.KHR_TEXTURE_TRANSFORM;
|
|
1328
|
+
}
|
|
1329
|
+
extendTexture(t, e) {
|
|
1330
|
+
return (e.texCoord === void 0 || e.texCoord === t.channel) && e.offset === void 0 && e.rotation === void 0 && e.scale === void 0 || (t = t.clone(), e.texCoord !== void 0 && (t.channel = e.texCoord), e.offset !== void 0 && t.offset.fromArray(e.offset), e.rotation !== void 0 && (t.rotation = e.rotation), e.scale !== void 0 && t.repeat.fromArray(e.scale), t.needsUpdate = !0), t;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
class en {
|
|
1334
|
+
constructor() {
|
|
1335
|
+
this.name = R.KHR_MESH_QUANTIZATION;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
class Ce extends mt {
|
|
1339
|
+
constructor(t, e, s, n) {
|
|
1340
|
+
super(t, e, s, n);
|
|
1341
|
+
}
|
|
1342
|
+
copySampleValue_(t) {
|
|
1343
|
+
const e = this.resultBuffer, s = this.sampleValues, n = this.valueSize, i = t * n * 3 + n;
|
|
1344
|
+
for (let o = 0; o !== n; o++)
|
|
1345
|
+
e[o] = s[i + o];
|
|
1346
|
+
return e;
|
|
1347
|
+
}
|
|
1348
|
+
interpolate_(t, e, s, n) {
|
|
1349
|
+
const i = this.resultBuffer, o = this.sampleValues, a = this.valueSize, r = a * 2, c = a * 3, u = n - e, h = (s - e) / u, d = h * h, p = d * h, m = t * c, A = m - c, g = -2 * p + 3 * d, x = p - d, _ = 1 - g, N = x - d + h;
|
|
1350
|
+
for (let T = 0; T !== a; T++) {
|
|
1351
|
+
const S = o[A + T + a], L = o[A + T + r] * u, E = o[m + T + a], I = o[m + T] * u;
|
|
1352
|
+
i[T] = _ * S + N * L + g * E + x * I;
|
|
1353
|
+
}
|
|
1354
|
+
return i;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
const tn = new Ee();
|
|
1358
|
+
class nn extends Ce {
|
|
1359
|
+
interpolate_(t, e, s, n) {
|
|
1360
|
+
const i = super.interpolate_(t, e, s, n);
|
|
1361
|
+
return tn.fromArray(i).normalize().toArray(i), i;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
const k = {
|
|
1365
|
+
POINTS: 0,
|
|
1366
|
+
LINES: 1,
|
|
1367
|
+
LINE_LOOP: 2,
|
|
1368
|
+
LINE_STRIP: 3,
|
|
1369
|
+
TRIANGLES: 4,
|
|
1370
|
+
TRIANGLE_STRIP: 5,
|
|
1371
|
+
TRIANGLE_FAN: 6
|
|
1372
|
+
}, G = {
|
|
1373
|
+
5120: Int8Array,
|
|
1374
|
+
5121: Uint8Array,
|
|
1375
|
+
5122: Int16Array,
|
|
1376
|
+
5123: Uint16Array,
|
|
1377
|
+
5125: Uint32Array,
|
|
1378
|
+
5126: Float32Array
|
|
1379
|
+
}, xe = {
|
|
1380
|
+
9728: We,
|
|
1381
|
+
9729: Se,
|
|
1382
|
+
9984: Xe,
|
|
1383
|
+
9985: Ke,
|
|
1384
|
+
9986: je,
|
|
1385
|
+
9987: Le
|
|
1386
|
+
}, _e = {
|
|
1387
|
+
33071: Qe,
|
|
1388
|
+
33648: Ye,
|
|
1389
|
+
10497: ie
|
|
1390
|
+
}, ee = {
|
|
1391
|
+
SCALAR: 1,
|
|
1392
|
+
VEC2: 2,
|
|
1393
|
+
VEC3: 3,
|
|
1394
|
+
VEC4: 4,
|
|
1395
|
+
MAT2: 4,
|
|
1396
|
+
MAT3: 9,
|
|
1397
|
+
MAT4: 16
|
|
1398
|
+
}, re = {
|
|
1399
|
+
POSITION: "position",
|
|
1400
|
+
NORMAL: "normal",
|
|
1401
|
+
TANGENT: "tangent",
|
|
1402
|
+
TEXCOORD_0: "uv",
|
|
1403
|
+
TEXCOORD_1: "uv1",
|
|
1404
|
+
TEXCOORD_2: "uv2",
|
|
1405
|
+
TEXCOORD_3: "uv3",
|
|
1406
|
+
COLOR_0: "color",
|
|
1407
|
+
WEIGHTS_0: "skinWeight",
|
|
1408
|
+
JOINTS_0: "skinIndex"
|
|
1409
|
+
}, F = {
|
|
1410
|
+
scale: "scale",
|
|
1411
|
+
translation: "position",
|
|
1412
|
+
rotation: "quaternion",
|
|
1413
|
+
weights: "morphTargetInfluences"
|
|
1414
|
+
}, sn = {
|
|
1415
|
+
CUBICSPLINE: void 0,
|
|
1416
|
+
// We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
|
1417
|
+
// keyframe track will be initialized with a default interpolation type, then modified.
|
|
1418
|
+
LINEAR: Ie,
|
|
1419
|
+
STEP: ft
|
|
1420
|
+
}, te = {
|
|
1421
|
+
OPAQUE: "OPAQUE",
|
|
1422
|
+
MASK: "MASK",
|
|
1423
|
+
BLEND: "BLEND"
|
|
1424
|
+
};
|
|
1425
|
+
function on(l) {
|
|
1426
|
+
return l.DefaultMaterial === void 0 && (l.DefaultMaterial = new be({
|
|
1427
|
+
color: 16777215,
|
|
1428
|
+
emissive: 0,
|
|
1429
|
+
metalness: 1,
|
|
1430
|
+
roughness: 1,
|
|
1431
|
+
transparent: !1,
|
|
1432
|
+
depthTest: !0,
|
|
1433
|
+
side: pt
|
|
1434
|
+
})), l.DefaultMaterial;
|
|
1435
|
+
}
|
|
1436
|
+
function D(l, t, e) {
|
|
1437
|
+
for (const s in e.extensions)
|
|
1438
|
+
l[s] === void 0 && (t.userData.gltfExtensions = t.userData.gltfExtensions || {}, t.userData.gltfExtensions[s] = e.extensions[s]);
|
|
1439
|
+
}
|
|
1440
|
+
function B(l, t) {
|
|
1441
|
+
t.extras !== void 0 && (typeof t.extras == "object" ? Object.assign(l.userData, t.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + t.extras));
|
|
1442
|
+
}
|
|
1443
|
+
function rn(l, t, e) {
|
|
1444
|
+
let s = !1, n = !1, i = !1;
|
|
1445
|
+
for (let c = 0, u = t.length; c < u; c++) {
|
|
1446
|
+
const h = t[c];
|
|
1447
|
+
if (h.POSITION !== void 0 && (s = !0), h.NORMAL !== void 0 && (n = !0), h.COLOR_0 !== void 0 && (i = !0), s && n && i) break;
|
|
1448
|
+
}
|
|
1449
|
+
if (!s && !n && !i) return Promise.resolve(l);
|
|
1450
|
+
const o = [], a = [], r = [];
|
|
1451
|
+
for (let c = 0, u = t.length; c < u; c++) {
|
|
1452
|
+
const h = t[c];
|
|
1453
|
+
if (s) {
|
|
1454
|
+
const d = h.POSITION !== void 0 ? e.getDependency("accessor", h.POSITION) : l.attributes.position;
|
|
1455
|
+
o.push(d);
|
|
1456
|
+
}
|
|
1457
|
+
if (n) {
|
|
1458
|
+
const d = h.NORMAL !== void 0 ? e.getDependency("accessor", h.NORMAL) : l.attributes.normal;
|
|
1459
|
+
a.push(d);
|
|
1460
|
+
}
|
|
1461
|
+
if (i) {
|
|
1462
|
+
const d = h.COLOR_0 !== void 0 ? e.getDependency("accessor", h.COLOR_0) : l.attributes.color;
|
|
1463
|
+
r.push(d);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return Promise.all([
|
|
1467
|
+
Promise.all(o),
|
|
1468
|
+
Promise.all(a),
|
|
1469
|
+
Promise.all(r)
|
|
1470
|
+
]).then(function(c) {
|
|
1471
|
+
const u = c[0], h = c[1], d = c[2];
|
|
1472
|
+
return s && (l.morphAttributes.position = u), n && (l.morphAttributes.normal = h), i && (l.morphAttributes.color = d), l.morphTargetsRelative = !0, l;
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
function an(l, t) {
|
|
1476
|
+
if (l.updateMorphTargets(), t.weights !== void 0)
|
|
1477
|
+
for (let e = 0, s = t.weights.length; e < s; e++)
|
|
1478
|
+
l.morphTargetInfluences[e] = t.weights[e];
|
|
1479
|
+
if (t.extras && Array.isArray(t.extras.targetNames)) {
|
|
1480
|
+
const e = t.extras.targetNames;
|
|
1481
|
+
if (l.morphTargetInfluences.length === e.length) {
|
|
1482
|
+
l.morphTargetDictionary = {};
|
|
1483
|
+
for (let s = 0, n = e.length; s < n; s++)
|
|
1484
|
+
l.morphTargetDictionary[e[s]] = s;
|
|
1485
|
+
} else
|
|
1486
|
+
console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
function cn(l) {
|
|
1490
|
+
let t;
|
|
1491
|
+
const e = l.extensions && l.extensions[R.KHR_DRACO_MESH_COMPRESSION];
|
|
1492
|
+
if (e ? t = "draco:" + e.bufferView + ":" + e.indices + ":" + ne(e.attributes) : t = l.indices + ":" + ne(l.attributes) + ":" + l.mode, l.targets !== void 0)
|
|
1493
|
+
for (let s = 0, n = l.targets.length; s < n; s++)
|
|
1494
|
+
t += ":" + ne(l.targets[s]);
|
|
1495
|
+
return t;
|
|
1496
|
+
}
|
|
1497
|
+
function ne(l) {
|
|
1498
|
+
let t = "";
|
|
1499
|
+
const e = Object.keys(l).sort();
|
|
1500
|
+
for (let s = 0, n = e.length; s < n; s++)
|
|
1501
|
+
t += e[s] + ":" + l[e[s]] + ";";
|
|
1502
|
+
return t;
|
|
1503
|
+
}
|
|
1504
|
+
function ae(l) {
|
|
1505
|
+
switch (l) {
|
|
1506
|
+
case Int8Array:
|
|
1507
|
+
return 1 / 127;
|
|
1508
|
+
case Uint8Array:
|
|
1509
|
+
return 1 / 255;
|
|
1510
|
+
case Int16Array:
|
|
1511
|
+
return 1 / 32767;
|
|
1512
|
+
case Uint16Array:
|
|
1513
|
+
return 1 / 65535;
|
|
1514
|
+
default:
|
|
1515
|
+
throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
function ln(l) {
|
|
1519
|
+
return l.search(/\.jpe?g($|\?)/i) > 0 || l.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : l.search(/\.webp($|\?)/i) > 0 || l.search(/^data\:image\/webp/) === 0 ? "image/webp" : "image/png";
|
|
1520
|
+
}
|
|
1521
|
+
const hn = new W();
|
|
1522
|
+
class un {
|
|
1523
|
+
constructor(t = {}, e = {}) {
|
|
1524
|
+
this.json = t, this.extensions = {}, this.plugins = {}, this.options = e, this.cache = new Ct(), this.associations = /* @__PURE__ */ new Map(), this.primitiveCache = {}, this.nodeCache = {}, this.meshCache = { refs: {}, uses: {} }, this.cameraCache = { refs: {}, uses: {} }, this.lightCache = { refs: {}, uses: {} }, this.sourceCache = {}, this.textureCache = {}, this.nodeNamesUsed = {};
|
|
1525
|
+
let s = !1, n = !1, i = -1;
|
|
1526
|
+
typeof navigator < "u" && (s = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) === !0, n = navigator.userAgent.indexOf("Firefox") > -1, i = n ? navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1] : -1), typeof createImageBitmap > "u" || s || n && i < 98 ? this.textureLoader = new He(this.options.manager) : this.textureLoader = new Ge(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new Me(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
|
|
1527
|
+
}
|
|
1528
|
+
setExtensions(t) {
|
|
1529
|
+
this.extensions = t;
|
|
1530
|
+
}
|
|
1531
|
+
setPlugins(t) {
|
|
1532
|
+
this.plugins = t;
|
|
1533
|
+
}
|
|
1534
|
+
parse(t, e) {
|
|
1535
|
+
const s = this, n = this.json, i = this.extensions;
|
|
1536
|
+
this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(o) {
|
|
1537
|
+
return o._markDefs && o._markDefs();
|
|
1538
|
+
}), Promise.all(this._invokeAll(function(o) {
|
|
1539
|
+
return o.beforeRoot && o.beforeRoot();
|
|
1540
|
+
})).then(function() {
|
|
1541
|
+
return Promise.all([
|
|
1542
|
+
s.getDependencies("scene"),
|
|
1543
|
+
s.getDependencies("animation"),
|
|
1544
|
+
s.getDependencies("camera")
|
|
1545
|
+
]);
|
|
1546
|
+
}).then(function(o) {
|
|
1547
|
+
const a = {
|
|
1548
|
+
scene: o[0][n.scene || 0],
|
|
1549
|
+
scenes: o[0],
|
|
1550
|
+
animations: o[1],
|
|
1551
|
+
cameras: o[2],
|
|
1552
|
+
asset: n.asset,
|
|
1553
|
+
parser: s,
|
|
1554
|
+
userData: {}
|
|
1555
|
+
};
|
|
1556
|
+
return D(i, a, n), B(a, n), Promise.all(s._invokeAll(function(r) {
|
|
1557
|
+
return r.afterRoot && r.afterRoot(a);
|
|
1558
|
+
})).then(function() {
|
|
1559
|
+
for (const r of a.scenes)
|
|
1560
|
+
r.updateMatrixWorld();
|
|
1561
|
+
t(a);
|
|
1562
|
+
});
|
|
1563
|
+
}).catch(e);
|
|
1564
|
+
}
|
|
1565
|
+
/**
|
|
1566
|
+
* Marks the special nodes/meshes in json for efficient parse.
|
|
1567
|
+
*/
|
|
1568
|
+
_markDefs() {
|
|
1569
|
+
const t = this.json.nodes || [], e = this.json.skins || [], s = this.json.meshes || [];
|
|
1570
|
+
for (let n = 0, i = e.length; n < i; n++) {
|
|
1571
|
+
const o = e[n].joints;
|
|
1572
|
+
for (let a = 0, r = o.length; a < r; a++)
|
|
1573
|
+
t[o[a]].isBone = !0;
|
|
1574
|
+
}
|
|
1575
|
+
for (let n = 0, i = t.length; n < i; n++) {
|
|
1576
|
+
const o = t[n];
|
|
1577
|
+
o.mesh !== void 0 && (this._addNodeRef(this.meshCache, o.mesh), o.skin !== void 0 && (s[o.mesh].isSkinnedMesh = !0)), o.camera !== void 0 && this._addNodeRef(this.cameraCache, o.camera);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Counts references to shared node / Object3D resources. These resources
|
|
1582
|
+
* can be reused, or "instantiated", at multiple nodes in the scene
|
|
1583
|
+
* hierarchy. Mesh, Camera, and Light instances are instantiated and must
|
|
1584
|
+
* be marked. Non-scenegraph resources (like Materials, Geometries, and
|
|
1585
|
+
* Textures) can be reused directly and are not marked here.
|
|
1586
|
+
*
|
|
1587
|
+
* Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
|
1588
|
+
*/
|
|
1589
|
+
_addNodeRef(t, e) {
|
|
1590
|
+
e !== void 0 && (t.refs[e] === void 0 && (t.refs[e] = t.uses[e] = 0), t.refs[e]++);
|
|
1591
|
+
}
|
|
1592
|
+
/** Returns a reference to a shared resource, cloning it if necessary. */
|
|
1593
|
+
_getNodeRef(t, e, s) {
|
|
1594
|
+
if (t.refs[e] <= 1) return s;
|
|
1595
|
+
const n = s.clone(), i = (o, a) => {
|
|
1596
|
+
const r = this.associations.get(o);
|
|
1597
|
+
r != null && this.associations.set(a, r);
|
|
1598
|
+
for (const [c, u] of o.children.entries())
|
|
1599
|
+
i(u, a.children[c]);
|
|
1600
|
+
};
|
|
1601
|
+
return i(s, n), n.name += "_instance_" + t.uses[e]++, n;
|
|
1602
|
+
}
|
|
1603
|
+
_invokeOne(t) {
|
|
1604
|
+
const e = Object.values(this.plugins);
|
|
1605
|
+
e.push(this);
|
|
1606
|
+
for (let s = 0; s < e.length; s++) {
|
|
1607
|
+
const n = t(e[s]);
|
|
1608
|
+
if (n) return n;
|
|
1609
|
+
}
|
|
1610
|
+
return null;
|
|
1611
|
+
}
|
|
1612
|
+
_invokeAll(t) {
|
|
1613
|
+
const e = Object.values(this.plugins);
|
|
1614
|
+
e.unshift(this);
|
|
1615
|
+
const s = [];
|
|
1616
|
+
for (let n = 0; n < e.length; n++) {
|
|
1617
|
+
const i = t(e[n]);
|
|
1618
|
+
i && s.push(i);
|
|
1619
|
+
}
|
|
1620
|
+
return s;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Requests the specified dependency asynchronously, with caching.
|
|
1624
|
+
* @param {string} type
|
|
1625
|
+
* @param {number} index
|
|
1626
|
+
* @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
|
|
1627
|
+
*/
|
|
1628
|
+
getDependency(t, e) {
|
|
1629
|
+
const s = t + ":" + e;
|
|
1630
|
+
let n = this.cache.get(s);
|
|
1631
|
+
if (!n) {
|
|
1632
|
+
switch (t) {
|
|
1633
|
+
case "scene":
|
|
1634
|
+
n = this.loadScene(e);
|
|
1635
|
+
break;
|
|
1636
|
+
case "node":
|
|
1637
|
+
n = this._invokeOne(function(i) {
|
|
1638
|
+
return i.loadNode && i.loadNode(e);
|
|
1639
|
+
});
|
|
1640
|
+
break;
|
|
1641
|
+
case "mesh":
|
|
1642
|
+
n = this._invokeOne(function(i) {
|
|
1643
|
+
return i.loadMesh && i.loadMesh(e);
|
|
1644
|
+
});
|
|
1645
|
+
break;
|
|
1646
|
+
case "accessor":
|
|
1647
|
+
n = this.loadAccessor(e);
|
|
1648
|
+
break;
|
|
1649
|
+
case "bufferView":
|
|
1650
|
+
n = this._invokeOne(function(i) {
|
|
1651
|
+
return i.loadBufferView && i.loadBufferView(e);
|
|
1652
|
+
});
|
|
1653
|
+
break;
|
|
1654
|
+
case "buffer":
|
|
1655
|
+
n = this.loadBuffer(e);
|
|
1656
|
+
break;
|
|
1657
|
+
case "material":
|
|
1658
|
+
n = this._invokeOne(function(i) {
|
|
1659
|
+
return i.loadMaterial && i.loadMaterial(e);
|
|
1660
|
+
});
|
|
1661
|
+
break;
|
|
1662
|
+
case "texture":
|
|
1663
|
+
n = this._invokeOne(function(i) {
|
|
1664
|
+
return i.loadTexture && i.loadTexture(e);
|
|
1665
|
+
});
|
|
1666
|
+
break;
|
|
1667
|
+
case "skin":
|
|
1668
|
+
n = this.loadSkin(e);
|
|
1669
|
+
break;
|
|
1670
|
+
case "animation":
|
|
1671
|
+
n = this._invokeOne(function(i) {
|
|
1672
|
+
return i.loadAnimation && i.loadAnimation(e);
|
|
1673
|
+
});
|
|
1674
|
+
break;
|
|
1675
|
+
case "camera":
|
|
1676
|
+
n = this.loadCamera(e);
|
|
1677
|
+
break;
|
|
1678
|
+
default:
|
|
1679
|
+
if (n = this._invokeOne(function(i) {
|
|
1680
|
+
return i != this && i.getDependency && i.getDependency(t, e);
|
|
1681
|
+
}), !n)
|
|
1682
|
+
throw new Error("Unknown type: " + t);
|
|
1683
|
+
break;
|
|
1684
|
+
}
|
|
1685
|
+
this.cache.add(s, n);
|
|
1686
|
+
}
|
|
1687
|
+
return n;
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Requests all dependencies of the specified type asynchronously, with caching.
|
|
1691
|
+
* @param {string} type
|
|
1692
|
+
* @return {Promise<Array<Object>>}
|
|
1693
|
+
*/
|
|
1694
|
+
getDependencies(t) {
|
|
1695
|
+
let e = this.cache.get(t);
|
|
1696
|
+
if (!e) {
|
|
1697
|
+
const s = this, n = this.json[t + (t === "mesh" ? "es" : "s")] || [];
|
|
1698
|
+
e = Promise.all(n.map(function(i, o) {
|
|
1699
|
+
return s.getDependency(t, o);
|
|
1700
|
+
})), this.cache.add(t, e);
|
|
1701
|
+
}
|
|
1702
|
+
return e;
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1706
|
+
* @param {number} bufferIndex
|
|
1707
|
+
* @return {Promise<ArrayBuffer>}
|
|
1708
|
+
*/
|
|
1709
|
+
loadBuffer(t) {
|
|
1710
|
+
const e = this.json.buffers[t], s = this.fileLoader;
|
|
1711
|
+
if (e.type && e.type !== "arraybuffer")
|
|
1712
|
+
throw new Error("THREE.GLTFLoader: " + e.type + " buffer type is not supported.");
|
|
1713
|
+
if (e.uri === void 0 && t === 0)
|
|
1714
|
+
return Promise.resolve(this.extensions[R.KHR_BINARY_GLTF].body);
|
|
1715
|
+
const n = this.options;
|
|
1716
|
+
return new Promise(function(i, o) {
|
|
1717
|
+
s.load(j.resolveURL(e.uri, n.path), i, void 0, function() {
|
|
1718
|
+
o(new Error('THREE.GLTFLoader: Failed to load buffer "' + e.uri + '".'));
|
|
1719
|
+
});
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
|
1724
|
+
* @param {number} bufferViewIndex
|
|
1725
|
+
* @return {Promise<ArrayBuffer>}
|
|
1726
|
+
*/
|
|
1727
|
+
loadBufferView(t) {
|
|
1728
|
+
const e = this.json.bufferViews[t];
|
|
1729
|
+
return this.getDependency("buffer", e.buffer).then(function(s) {
|
|
1730
|
+
const n = e.byteLength || 0, i = e.byteOffset || 0;
|
|
1731
|
+
return s.slice(i, i + n);
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
|
1736
|
+
* @param {number} accessorIndex
|
|
1737
|
+
* @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
|
|
1738
|
+
*/
|
|
1739
|
+
loadAccessor(t) {
|
|
1740
|
+
const e = this, s = this.json, n = this.json.accessors[t];
|
|
1741
|
+
if (n.bufferView === void 0 && n.sparse === void 0) {
|
|
1742
|
+
const o = ee[n.type], a = G[n.componentType], r = n.normalized === !0, c = new a(n.count * o);
|
|
1743
|
+
return Promise.resolve(new Q(c, o, r));
|
|
1744
|
+
}
|
|
1745
|
+
const i = [];
|
|
1746
|
+
return n.bufferView !== void 0 ? i.push(this.getDependency("bufferView", n.bufferView)) : i.push(null), n.sparse !== void 0 && (i.push(this.getDependency("bufferView", n.sparse.indices.bufferView)), i.push(this.getDependency("bufferView", n.sparse.values.bufferView))), Promise.all(i).then(function(o) {
|
|
1747
|
+
const a = o[0], r = ee[n.type], c = G[n.componentType], u = c.BYTES_PER_ELEMENT, h = u * r, d = n.byteOffset || 0, p = n.bufferView !== void 0 ? s.bufferViews[n.bufferView].byteStride : void 0, m = n.normalized === !0;
|
|
1748
|
+
let A, g;
|
|
1749
|
+
if (p && p !== h) {
|
|
1750
|
+
const x = Math.floor(d / p), _ = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + x + ":" + n.count;
|
|
1751
|
+
let N = e.cache.get(_);
|
|
1752
|
+
N || (A = new c(a, x * p, n.count * p / u), N = new Ue(A, p / u), e.cache.add(_, N)), g = new Ve(N, r, d % p / u, m);
|
|
1753
|
+
} else
|
|
1754
|
+
a === null ? A = new c(n.count * r) : A = new c(a, d, n.count * r), g = new Q(A, r, m);
|
|
1755
|
+
if (n.sparse !== void 0) {
|
|
1756
|
+
const x = ee.SCALAR, _ = G[n.sparse.indices.componentType], N = n.sparse.indices.byteOffset || 0, T = n.sparse.values.byteOffset || 0, S = new _(o[1], N, n.sparse.count * x), L = new c(o[2], T, n.sparse.count * r);
|
|
1757
|
+
a !== null && (g = new Q(g.array.slice(), g.itemSize, g.normalized));
|
|
1758
|
+
for (let E = 0, I = S.length; E < I; E++) {
|
|
1759
|
+
const P = S[E];
|
|
1760
|
+
if (g.setX(P, L[E * r]), r >= 2 && g.setY(P, L[E * r + 1]), r >= 3 && g.setZ(P, L[E * r + 2]), r >= 4 && g.setW(P, L[E * r + 3]), r >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
return g;
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
|
1768
|
+
* @param {number} textureIndex
|
|
1769
|
+
* @return {Promise<THREE.Texture|null>}
|
|
1770
|
+
*/
|
|
1771
|
+
loadTexture(t) {
|
|
1772
|
+
const e = this.json, s = this.options, i = e.textures[t].source, o = e.images[i];
|
|
1773
|
+
let a = this.textureLoader;
|
|
1774
|
+
if (o.uri) {
|
|
1775
|
+
const r = s.manager.getHandler(o.uri);
|
|
1776
|
+
r !== null && (a = r);
|
|
1777
|
+
}
|
|
1778
|
+
return this.loadTextureImage(t, i, a);
|
|
1779
|
+
}
|
|
1780
|
+
loadTextureImage(t, e, s) {
|
|
1781
|
+
const n = this, i = this.json, o = i.textures[t], a = i.images[e], r = (a.uri || a.bufferView) + ":" + o.sampler;
|
|
1782
|
+
if (this.textureCache[r])
|
|
1783
|
+
return this.textureCache[r];
|
|
1784
|
+
const c = this.loadImageSource(e, s).then(function(u) {
|
|
1785
|
+
u.flipY = !1, u.name = o.name || a.name || "", u.name === "" && typeof a.uri == "string" && a.uri.startsWith("data:image/") === !1 && (u.name = a.uri);
|
|
1786
|
+
const d = (i.samplers || {})[o.sampler] || {};
|
|
1787
|
+
return u.magFilter = xe[d.magFilter] || Se, u.minFilter = xe[d.minFilter] || Le, u.wrapS = _e[d.wrapS] || ie, u.wrapT = _e[d.wrapT] || ie, n.associations.set(u, { textures: t }), u;
|
|
1788
|
+
}).catch(function() {
|
|
1789
|
+
return null;
|
|
1790
|
+
});
|
|
1791
|
+
return this.textureCache[r] = c, c;
|
|
1792
|
+
}
|
|
1793
|
+
loadImageSource(t, e) {
|
|
1794
|
+
const s = this, n = this.json, i = this.options;
|
|
1795
|
+
if (this.sourceCache[t] !== void 0)
|
|
1796
|
+
return this.sourceCache[t].then((h) => h.clone());
|
|
1797
|
+
const o = n.images[t], a = self.URL || self.webkitURL;
|
|
1798
|
+
let r = o.uri || "", c = !1;
|
|
1799
|
+
if (o.bufferView !== void 0)
|
|
1800
|
+
r = s.getDependency("bufferView", o.bufferView).then(function(h) {
|
|
1801
|
+
c = !0;
|
|
1802
|
+
const d = new Blob([h], { type: o.mimeType });
|
|
1803
|
+
return r = a.createObjectURL(d), r;
|
|
1804
|
+
});
|
|
1805
|
+
else if (o.uri === void 0)
|
|
1806
|
+
throw new Error("THREE.GLTFLoader: Image " + t + " is missing URI and bufferView");
|
|
1807
|
+
const u = Promise.resolve(r).then(function(h) {
|
|
1808
|
+
return new Promise(function(d, p) {
|
|
1809
|
+
let m = d;
|
|
1810
|
+
e.isImageBitmapLoader === !0 && (m = function(A) {
|
|
1811
|
+
const g = new ce(A);
|
|
1812
|
+
g.needsUpdate = !0, d(g);
|
|
1813
|
+
}), e.load(j.resolveURL(h, i.path), m, void 0, p);
|
|
1814
|
+
});
|
|
1815
|
+
}).then(function(h) {
|
|
1816
|
+
return c === !0 && a.revokeObjectURL(r), B(h, o), h.userData.mimeType = o.mimeType || ln(o.uri), h;
|
|
1817
|
+
}).catch(function(h) {
|
|
1818
|
+
throw console.error("THREE.GLTFLoader: Couldn't load texture", r), h;
|
|
1819
|
+
});
|
|
1820
|
+
return this.sourceCache[t] = u, u;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Asynchronously assigns a texture to the given material parameters.
|
|
1824
|
+
* @param {Object} materialParams
|
|
1825
|
+
* @param {string} mapName
|
|
1826
|
+
* @param {Object} mapDef
|
|
1827
|
+
* @return {Promise<Texture>}
|
|
1828
|
+
*/
|
|
1829
|
+
assignTexture(t, e, s, n) {
|
|
1830
|
+
const i = this;
|
|
1831
|
+
return this.getDependency("texture", s.index).then(function(o) {
|
|
1832
|
+
if (!o) return null;
|
|
1833
|
+
if (s.texCoord !== void 0 && s.texCoord > 0 && (o = o.clone(), o.channel = s.texCoord), i.extensions[R.KHR_TEXTURE_TRANSFORM]) {
|
|
1834
|
+
const a = s.extensions !== void 0 ? s.extensions[R.KHR_TEXTURE_TRANSFORM] : void 0;
|
|
1835
|
+
if (a) {
|
|
1836
|
+
const r = i.associations.get(o);
|
|
1837
|
+
o = i.extensions[R.KHR_TEXTURE_TRANSFORM].extendTexture(o, a), i.associations.set(o, r);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return n !== void 0 && (o.colorSpace = n), t[e] = o, o;
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Assigns final material to a Mesh, Line, or Points instance. The instance
|
|
1845
|
+
* already has a material (generated from the glTF material options alone)
|
|
1846
|
+
* but reuse of the same glTF material may require multiple threejs materials
|
|
1847
|
+
* to accommodate different primitive types, defines, etc. New materials will
|
|
1848
|
+
* be created if necessary, and reused from a cache.
|
|
1849
|
+
* @param {Object3D} mesh Mesh, Line, or Points instance.
|
|
1850
|
+
*/
|
|
1851
|
+
assignFinalMaterial(t) {
|
|
1852
|
+
const e = t.geometry;
|
|
1853
|
+
let s = t.material;
|
|
1854
|
+
const n = e.attributes.tangent === void 0, i = e.attributes.color !== void 0, o = e.attributes.normal === void 0;
|
|
1855
|
+
if (t.isPoints) {
|
|
1856
|
+
const a = "PointsMaterial:" + s.uuid;
|
|
1857
|
+
let r = this.cache.get(a);
|
|
1858
|
+
r || (r = new qe(), q.prototype.copy.call(r, s), r.color.copy(s.color), r.map = s.map, r.sizeAttenuation = !1, this.cache.add(a, r)), s = r;
|
|
1859
|
+
} else if (t.isLine) {
|
|
1860
|
+
const a = "LineBasicMaterial:" + s.uuid;
|
|
1861
|
+
let r = this.cache.get(a);
|
|
1862
|
+
r || (r = new Ze(), q.prototype.copy.call(r, s), r.color.copy(s.color), r.map = s.map, this.cache.add(a, r)), s = r;
|
|
1863
|
+
}
|
|
1864
|
+
if (n || i || o) {
|
|
1865
|
+
let a = "ClonedMaterial:" + s.uuid + ":";
|
|
1866
|
+
n && (a += "derivative-tangents:"), i && (a += "vertex-colors:"), o && (a += "flat-shading:");
|
|
1867
|
+
let r = this.cache.get(a);
|
|
1868
|
+
r || (r = s.clone(), i && (r.vertexColors = !0), o && (r.flatShading = !0), n && (r.normalScale && (r.normalScale.y *= -1), r.clearcoatNormalScale && (r.clearcoatNormalScale.y *= -1)), this.cache.add(a, r), this.associations.set(r, this.associations.get(s))), s = r;
|
|
1869
|
+
}
|
|
1870
|
+
t.material = s;
|
|
1871
|
+
}
|
|
1872
|
+
getMaterialType() {
|
|
1873
|
+
return be;
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
|
1877
|
+
* @param {number} materialIndex
|
|
1878
|
+
* @return {Promise<Material>}
|
|
1879
|
+
*/
|
|
1880
|
+
loadMaterial(t) {
|
|
1881
|
+
const e = this, s = this.json, n = this.extensions, i = s.materials[t];
|
|
1882
|
+
let o;
|
|
1883
|
+
const a = {}, r = i.extensions || {}, c = [];
|
|
1884
|
+
if (r[R.KHR_MATERIALS_UNLIT]) {
|
|
1885
|
+
const h = n[R.KHR_MATERIALS_UNLIT];
|
|
1886
|
+
o = h.getMaterialType(), c.push(h.extendParams(a, i, e));
|
|
1887
|
+
} else {
|
|
1888
|
+
const h = i.pbrMetallicRoughness || {};
|
|
1889
|
+
if (a.color = new z(1, 1, 1), a.opacity = 1, Array.isArray(h.baseColorFactor)) {
|
|
1890
|
+
const d = h.baseColorFactor;
|
|
1891
|
+
a.color.setRGB(d[0], d[1], d[2], v), a.opacity = d[3];
|
|
1892
|
+
}
|
|
1893
|
+
h.baseColorTexture !== void 0 && c.push(e.assignTexture(a, "map", h.baseColorTexture, K)), a.metalness = h.metallicFactor !== void 0 ? h.metallicFactor : 1, a.roughness = h.roughnessFactor !== void 0 ? h.roughnessFactor : 1, h.metallicRoughnessTexture !== void 0 && (c.push(e.assignTexture(a, "metalnessMap", h.metallicRoughnessTexture)), c.push(e.assignTexture(a, "roughnessMap", h.metallicRoughnessTexture))), o = this._invokeOne(function(d) {
|
|
1894
|
+
return d.getMaterialType && d.getMaterialType(t);
|
|
1895
|
+
}), c.push(Promise.all(this._invokeAll(function(d) {
|
|
1896
|
+
return d.extendMaterialParams && d.extendMaterialParams(t, a);
|
|
1897
|
+
})));
|
|
1898
|
+
}
|
|
1899
|
+
i.doubleSided === !0 && (a.side = $e);
|
|
1900
|
+
const u = i.alphaMode || te.OPAQUE;
|
|
1901
|
+
if (u === te.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, u === te.MASK && (a.alphaTest = i.alphaCutoff !== void 0 ? i.alphaCutoff : 0.5)), i.normalTexture !== void 0 && o !== V && (c.push(e.assignTexture(a, "normalMap", i.normalTexture)), a.normalScale = new Ne(1, 1), i.normalTexture.scale !== void 0)) {
|
|
1902
|
+
const h = i.normalTexture.scale;
|
|
1903
|
+
a.normalScale.set(h, h);
|
|
1904
|
+
}
|
|
1905
|
+
if (i.occlusionTexture !== void 0 && o !== V && (c.push(e.assignTexture(a, "aoMap", i.occlusionTexture)), i.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = i.occlusionTexture.strength)), i.emissiveFactor !== void 0 && o !== V) {
|
|
1906
|
+
const h = i.emissiveFactor;
|
|
1907
|
+
a.emissive = new z().setRGB(h[0], h[1], h[2], v);
|
|
1908
|
+
}
|
|
1909
|
+
return i.emissiveTexture !== void 0 && o !== V && c.push(e.assignTexture(a, "emissiveMap", i.emissiveTexture, K)), Promise.all(c).then(function() {
|
|
1910
|
+
const h = new o(a);
|
|
1911
|
+
return i.name && (h.name = i.name), B(h, i), e.associations.set(h, { materials: t }), i.extensions && D(n, h, i), h;
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
/** When Object3D instances are targeted by animation, they need unique names. */
|
|
1915
|
+
createUniqueName(t) {
|
|
1916
|
+
const e = Je.sanitizeNodeName(t || "");
|
|
1917
|
+
return e in this.nodeNamesUsed ? e + "_" + ++this.nodeNamesUsed[e] : (this.nodeNamesUsed[e] = 0, e);
|
|
1918
|
+
}
|
|
1919
|
+
/**
|
|
1920
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
|
1921
|
+
*
|
|
1922
|
+
* Creates BufferGeometries from primitives.
|
|
1923
|
+
*
|
|
1924
|
+
* @param {Array<GLTF.Primitive>} primitives
|
|
1925
|
+
* @return {Promise<Array<BufferGeometry>>}
|
|
1926
|
+
*/
|
|
1927
|
+
loadGeometries(t) {
|
|
1928
|
+
const e = this, s = this.extensions, n = this.primitiveCache;
|
|
1929
|
+
function i(a) {
|
|
1930
|
+
return s[R.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, e).then(function(r) {
|
|
1931
|
+
return ye(r, a, e);
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
const o = [];
|
|
1935
|
+
for (let a = 0, r = t.length; a < r; a++) {
|
|
1936
|
+
const c = t[a], u = cn(c), h = n[u];
|
|
1937
|
+
if (h)
|
|
1938
|
+
o.push(h.promise);
|
|
1939
|
+
else {
|
|
1940
|
+
let d;
|
|
1941
|
+
c.extensions && c.extensions[R.KHR_DRACO_MESH_COMPRESSION] ? d = i(c) : d = ye(new et(), c, e), n[u] = { primitive: c, promise: d }, o.push(d);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return Promise.all(o);
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
|
1948
|
+
* @param {number} meshIndex
|
|
1949
|
+
* @return {Promise<Group|Mesh|SkinnedMesh>}
|
|
1950
|
+
*/
|
|
1951
|
+
loadMesh(t) {
|
|
1952
|
+
const e = this, s = this.json, n = this.extensions, i = s.meshes[t], o = i.primitives, a = [];
|
|
1953
|
+
for (let r = 0, c = o.length; r < c; r++) {
|
|
1954
|
+
const u = o[r].material === void 0 ? on(this.cache) : this.getDependency("material", o[r].material);
|
|
1955
|
+
a.push(u);
|
|
1956
|
+
}
|
|
1957
|
+
return a.push(e.loadGeometries(o)), Promise.all(a).then(function(r) {
|
|
1958
|
+
const c = r.slice(0, r.length - 1), u = r[r.length - 1], h = [];
|
|
1959
|
+
for (let p = 0, m = u.length; p < m; p++) {
|
|
1960
|
+
const A = u[p], g = o[p];
|
|
1961
|
+
let x;
|
|
1962
|
+
const _ = c[p];
|
|
1963
|
+
if (g.mode === k.TRIANGLES || g.mode === k.TRIANGLE_STRIP || g.mode === k.TRIANGLE_FAN || g.mode === void 0)
|
|
1964
|
+
x = i.isSkinnedMesh === !0 ? new tt(A, _) : new nt(A, _), x.isSkinnedMesh === !0 && x.normalizeSkinWeights(), g.mode === k.TRIANGLE_STRIP ? x.geometry = ge(x.geometry, Re) : g.mode === k.TRIANGLE_FAN && (x.geometry = ge(x.geometry, se));
|
|
1965
|
+
else if (g.mode === k.LINES)
|
|
1966
|
+
x = new st(A, _);
|
|
1967
|
+
else if (g.mode === k.LINE_STRIP)
|
|
1968
|
+
x = new it(A, _);
|
|
1969
|
+
else if (g.mode === k.LINE_LOOP)
|
|
1970
|
+
x = new ot(A, _);
|
|
1971
|
+
else if (g.mode === k.POINTS)
|
|
1972
|
+
x = new rt(A, _);
|
|
1973
|
+
else
|
|
1974
|
+
throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + g.mode);
|
|
1975
|
+
Object.keys(x.geometry.morphAttributes).length > 0 && an(x, i), x.name = e.createUniqueName(i.name || "mesh_" + t), B(x, i), g.extensions && D(n, x, g), e.assignFinalMaterial(x), h.push(x);
|
|
1976
|
+
}
|
|
1977
|
+
for (let p = 0, m = h.length; p < m; p++)
|
|
1978
|
+
e.associations.set(h[p], {
|
|
1979
|
+
meshes: t,
|
|
1980
|
+
primitives: p
|
|
1981
|
+
});
|
|
1982
|
+
if (h.length === 1)
|
|
1983
|
+
return i.extensions && D(n, h[0], i), h[0];
|
|
1984
|
+
const d = new Z();
|
|
1985
|
+
i.extensions && D(n, d, i), e.associations.set(d, { meshes: t });
|
|
1986
|
+
for (let p = 0, m = h.length; p < m; p++)
|
|
1987
|
+
d.add(h[p]);
|
|
1988
|
+
return d;
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
|
1993
|
+
* @param {number} cameraIndex
|
|
1994
|
+
* @return {Promise<THREE.Camera>}
|
|
1995
|
+
*/
|
|
1996
|
+
loadCamera(t) {
|
|
1997
|
+
let e;
|
|
1998
|
+
const s = this.json.cameras[t], n = s[s.type];
|
|
1999
|
+
if (!n) {
|
|
2000
|
+
console.warn("THREE.GLTFLoader: Missing camera parameters.");
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
return s.type === "perspective" ? e = new at(ct.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : s.type === "orthographic" && (e = new lt(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), s.name && (e.name = this.createUniqueName(s.name)), B(e, s), Promise.resolve(e);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
|
2007
|
+
* @param {number} skinIndex
|
|
2008
|
+
* @return {Promise<Skeleton>}
|
|
2009
|
+
*/
|
|
2010
|
+
loadSkin(t) {
|
|
2011
|
+
const e = this.json.skins[t], s = [];
|
|
2012
|
+
for (let n = 0, i = e.joints.length; n < i; n++)
|
|
2013
|
+
s.push(this._loadNodeShallow(e.joints[n]));
|
|
2014
|
+
return e.inverseBindMatrices !== void 0 ? s.push(this.getDependency("accessor", e.inverseBindMatrices)) : s.push(null), Promise.all(s).then(function(n) {
|
|
2015
|
+
const i = n.pop(), o = n, a = [], r = [];
|
|
2016
|
+
for (let c = 0, u = o.length; c < u; c++) {
|
|
2017
|
+
const h = o[c];
|
|
2018
|
+
if (h) {
|
|
2019
|
+
a.push(h);
|
|
2020
|
+
const d = new W();
|
|
2021
|
+
i !== null && d.fromArray(i.array, c * 16), r.push(d);
|
|
2022
|
+
} else
|
|
2023
|
+
console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', e.joints[c]);
|
|
2024
|
+
}
|
|
2025
|
+
return new ht(a, r);
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
|
2030
|
+
* @param {number} animationIndex
|
|
2031
|
+
* @return {Promise<AnimationClip>}
|
|
2032
|
+
*/
|
|
2033
|
+
loadAnimation(t) {
|
|
2034
|
+
const e = this.json, s = this, n = e.animations[t], i = n.name ? n.name : "animation_" + t, o = [], a = [], r = [], c = [], u = [];
|
|
2035
|
+
for (let h = 0, d = n.channels.length; h < d; h++) {
|
|
2036
|
+
const p = n.channels[h], m = n.samplers[p.sampler], A = p.target, g = A.node, x = n.parameters !== void 0 ? n.parameters[m.input] : m.input, _ = n.parameters !== void 0 ? n.parameters[m.output] : m.output;
|
|
2037
|
+
A.node !== void 0 && (o.push(this.getDependency("node", g)), a.push(this.getDependency("accessor", x)), r.push(this.getDependency("accessor", _)), c.push(m), u.push(A));
|
|
2038
|
+
}
|
|
2039
|
+
return Promise.all([
|
|
2040
|
+
Promise.all(o),
|
|
2041
|
+
Promise.all(a),
|
|
2042
|
+
Promise.all(r),
|
|
2043
|
+
Promise.all(c),
|
|
2044
|
+
Promise.all(u)
|
|
2045
|
+
]).then(function(h) {
|
|
2046
|
+
const d = h[0], p = h[1], m = h[2], A = h[3], g = h[4], x = [];
|
|
2047
|
+
for (let _ = 0, N = d.length; _ < N; _++) {
|
|
2048
|
+
const T = d[_], S = p[_], L = m[_], E = A[_], I = g[_];
|
|
2049
|
+
if (T === void 0) continue;
|
|
2050
|
+
T.updateMatrix && T.updateMatrix();
|
|
2051
|
+
const P = s._createAnimationTracks(T, S, L, E, I);
|
|
2052
|
+
if (P)
|
|
2053
|
+
for (let Y = 0; Y < P.length; Y++)
|
|
2054
|
+
x.push(P[Y]);
|
|
2055
|
+
}
|
|
2056
|
+
return new ut(i, void 0, x);
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
createNodeMesh(t) {
|
|
2060
|
+
const e = this.json, s = this, n = e.nodes[t];
|
|
2061
|
+
return n.mesh === void 0 ? null : s.getDependency("mesh", n.mesh).then(function(i) {
|
|
2062
|
+
const o = s._getNodeRef(s.meshCache, n.mesh, i);
|
|
2063
|
+
return n.weights !== void 0 && o.traverse(function(a) {
|
|
2064
|
+
if (a.isMesh)
|
|
2065
|
+
for (let r = 0, c = n.weights.length; r < c; r++)
|
|
2066
|
+
a.morphTargetInfluences[r] = n.weights[r];
|
|
2067
|
+
}), o;
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
|
2072
|
+
* @param {number} nodeIndex
|
|
2073
|
+
* @return {Promise<Object3D>}
|
|
2074
|
+
*/
|
|
2075
|
+
loadNode(t) {
|
|
2076
|
+
const e = this.json, s = this, n = e.nodes[t], i = s._loadNodeShallow(t), o = [], a = n.children || [];
|
|
2077
|
+
for (let c = 0, u = a.length; c < u; c++)
|
|
2078
|
+
o.push(s.getDependency("node", a[c]));
|
|
2079
|
+
const r = n.skin === void 0 ? Promise.resolve(null) : s.getDependency("skin", n.skin);
|
|
2080
|
+
return Promise.all([
|
|
2081
|
+
i,
|
|
2082
|
+
Promise.all(o),
|
|
2083
|
+
r
|
|
2084
|
+
]).then(function(c) {
|
|
2085
|
+
const u = c[0], h = c[1], d = c[2];
|
|
2086
|
+
d !== null && u.traverse(function(p) {
|
|
2087
|
+
p.isSkinnedMesh && p.bind(d, hn);
|
|
2088
|
+
});
|
|
2089
|
+
for (let p = 0, m = h.length; p < m; p++)
|
|
2090
|
+
u.add(h[p]);
|
|
2091
|
+
return u;
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
// ._loadNodeShallow() parses a single node.
|
|
2095
|
+
// skin and child nodes are created and added in .loadNode() (no '_' prefix).
|
|
2096
|
+
_loadNodeShallow(t) {
|
|
2097
|
+
const e = this.json, s = this.extensions, n = this;
|
|
2098
|
+
if (this.nodeCache[t] !== void 0)
|
|
2099
|
+
return this.nodeCache[t];
|
|
2100
|
+
const i = e.nodes[t], o = i.name ? n.createUniqueName(i.name) : "", a = [], r = n._invokeOne(function(c) {
|
|
2101
|
+
return c.createNodeMesh && c.createNodeMesh(t);
|
|
2102
|
+
});
|
|
2103
|
+
return r && a.push(r), i.camera !== void 0 && a.push(n.getDependency("camera", i.camera).then(function(c) {
|
|
2104
|
+
return n._getNodeRef(n.cameraCache, i.camera, c);
|
|
2105
|
+
})), n._invokeAll(function(c) {
|
|
2106
|
+
return c.createNodeAttachment && c.createNodeAttachment(t);
|
|
2107
|
+
}).forEach(function(c) {
|
|
2108
|
+
a.push(c);
|
|
2109
|
+
}), this.nodeCache[t] = Promise.all(a).then(function(c) {
|
|
2110
|
+
let u;
|
|
2111
|
+
if (i.isBone === !0 ? u = new dt() : c.length > 1 ? u = new Z() : c.length === 1 ? u = c[0] : u = new we(), u !== c[0])
|
|
2112
|
+
for (let h = 0, d = c.length; h < d; h++)
|
|
2113
|
+
u.add(c[h]);
|
|
2114
|
+
if (i.name && (u.userData.name = i.name, u.name = o), B(u, i), i.extensions && D(s, u, i), i.matrix !== void 0) {
|
|
2115
|
+
const h = new W();
|
|
2116
|
+
h.fromArray(i.matrix), u.applyMatrix4(h);
|
|
2117
|
+
} else
|
|
2118
|
+
i.translation !== void 0 && u.position.fromArray(i.translation), i.rotation !== void 0 && u.quaternion.fromArray(i.rotation), i.scale !== void 0 && u.scale.fromArray(i.scale);
|
|
2119
|
+
return n.associations.has(u) || n.associations.set(u, {}), n.associations.get(u).nodes = t, u;
|
|
2120
|
+
}), this.nodeCache[t];
|
|
2121
|
+
}
|
|
2122
|
+
/**
|
|
2123
|
+
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
|
2124
|
+
* @param {number} sceneIndex
|
|
2125
|
+
* @return {Promise<Group>}
|
|
2126
|
+
*/
|
|
2127
|
+
loadScene(t) {
|
|
2128
|
+
const e = this.extensions, s = this.json.scenes[t], n = this, i = new Z();
|
|
2129
|
+
s.name && (i.name = n.createUniqueName(s.name)), B(i, s), s.extensions && D(e, i, s);
|
|
2130
|
+
const o = s.nodes || [], a = [];
|
|
2131
|
+
for (let r = 0, c = o.length; r < c; r++)
|
|
2132
|
+
a.push(n.getDependency("node", o[r]));
|
|
2133
|
+
return Promise.all(a).then(function(r) {
|
|
2134
|
+
for (let u = 0, h = r.length; u < h; u++)
|
|
2135
|
+
i.add(r[u]);
|
|
2136
|
+
const c = (u) => {
|
|
2137
|
+
const h = /* @__PURE__ */ new Map();
|
|
2138
|
+
for (const [d, p] of n.associations)
|
|
2139
|
+
(d instanceof q || d instanceof ce) && h.set(d, p);
|
|
2140
|
+
return u.traverse((d) => {
|
|
2141
|
+
const p = n.associations.get(d);
|
|
2142
|
+
p != null && h.set(d, p);
|
|
2143
|
+
}), h;
|
|
2144
|
+
};
|
|
2145
|
+
return n.associations = c(i), i;
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
_createAnimationTracks(t, e, s, n, i) {
|
|
2149
|
+
const o = [], a = t.name ? t.name : t.uuid, r = [];
|
|
2150
|
+
F[i.path] === F.weights ? t.traverse(function(d) {
|
|
2151
|
+
d.morphTargetInfluences && r.push(d.name ? d.name : d.uuid);
|
|
2152
|
+
}) : r.push(a);
|
|
2153
|
+
let c;
|
|
2154
|
+
switch (F[i.path]) {
|
|
2155
|
+
case F.weights:
|
|
2156
|
+
c = he;
|
|
2157
|
+
break;
|
|
2158
|
+
case F.rotation:
|
|
2159
|
+
c = ue;
|
|
2160
|
+
break;
|
|
2161
|
+
case F.position:
|
|
2162
|
+
case F.scale:
|
|
2163
|
+
c = le;
|
|
2164
|
+
break;
|
|
2165
|
+
default:
|
|
2166
|
+
switch (s.itemSize) {
|
|
2167
|
+
case 1:
|
|
2168
|
+
c = he;
|
|
2169
|
+
break;
|
|
2170
|
+
case 2:
|
|
2171
|
+
case 3:
|
|
2172
|
+
default:
|
|
2173
|
+
c = le;
|
|
2174
|
+
break;
|
|
2175
|
+
}
|
|
2176
|
+
break;
|
|
2177
|
+
}
|
|
2178
|
+
const u = n.interpolation !== void 0 ? sn[n.interpolation] : Ie, h = this._getArrayFromAccessor(s);
|
|
2179
|
+
for (let d = 0, p = r.length; d < p; d++) {
|
|
2180
|
+
const m = new c(
|
|
2181
|
+
r[d] + "." + F[i.path],
|
|
2182
|
+
e.array,
|
|
2183
|
+
h,
|
|
2184
|
+
u
|
|
2185
|
+
);
|
|
2186
|
+
n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(m), o.push(m);
|
|
2187
|
+
}
|
|
2188
|
+
return o;
|
|
2189
|
+
}
|
|
2190
|
+
_getArrayFromAccessor(t) {
|
|
2191
|
+
let e = t.array;
|
|
2192
|
+
if (t.normalized) {
|
|
2193
|
+
const s = ae(e.constructor), n = new Float32Array(e.length);
|
|
2194
|
+
for (let i = 0, o = e.length; i < o; i++)
|
|
2195
|
+
n[i] = e[i] * s;
|
|
2196
|
+
e = n;
|
|
2197
|
+
}
|
|
2198
|
+
return e;
|
|
2199
|
+
}
|
|
2200
|
+
_createCubicSplineTrackInterpolant(t) {
|
|
2201
|
+
t.createInterpolant = function(s) {
|
|
2202
|
+
const n = this instanceof ue ? nn : Ce;
|
|
2203
|
+
return new n(this.times, this.values, this.getValueSize() / 3, s);
|
|
2204
|
+
}, t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
function dn(l, t, e) {
|
|
2208
|
+
const s = t.attributes, n = new gt();
|
|
2209
|
+
if (s.POSITION !== void 0) {
|
|
2210
|
+
const a = e.json.accessors[s.POSITION], r = a.min, c = a.max;
|
|
2211
|
+
if (r !== void 0 && c !== void 0) {
|
|
2212
|
+
if (n.set(
|
|
2213
|
+
new H(r[0], r[1], r[2]),
|
|
2214
|
+
new H(c[0], c[1], c[2])
|
|
2215
|
+
), a.normalized) {
|
|
2216
|
+
const u = ae(G[a.componentType]);
|
|
2217
|
+
n.min.multiplyScalar(u), n.max.multiplyScalar(u);
|
|
2218
|
+
}
|
|
2219
|
+
} else {
|
|
2220
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
} else
|
|
2224
|
+
return;
|
|
2225
|
+
const i = t.targets;
|
|
2226
|
+
if (i !== void 0) {
|
|
2227
|
+
const a = new H(), r = new H();
|
|
2228
|
+
for (let c = 0, u = i.length; c < u; c++) {
|
|
2229
|
+
const h = i[c];
|
|
2230
|
+
if (h.POSITION !== void 0) {
|
|
2231
|
+
const d = e.json.accessors[h.POSITION], p = d.min, m = d.max;
|
|
2232
|
+
if (p !== void 0 && m !== void 0) {
|
|
2233
|
+
if (r.setX(Math.max(Math.abs(p[0]), Math.abs(m[0]))), r.setY(Math.max(Math.abs(p[1]), Math.abs(m[1]))), r.setZ(Math.max(Math.abs(p[2]), Math.abs(m[2]))), d.normalized) {
|
|
2234
|
+
const A = ae(G[d.componentType]);
|
|
2235
|
+
r.multiplyScalar(A);
|
|
2236
|
+
}
|
|
2237
|
+
a.max(r);
|
|
2238
|
+
} else
|
|
2239
|
+
console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
n.expandByVector(a);
|
|
2243
|
+
}
|
|
2244
|
+
l.boundingBox = n;
|
|
2245
|
+
const o = new At();
|
|
2246
|
+
n.getCenter(o.center), o.radius = n.min.distanceTo(n.max) / 2, l.boundingSphere = o;
|
|
2247
|
+
}
|
|
2248
|
+
function ye(l, t, e) {
|
|
2249
|
+
const s = t.attributes, n = [];
|
|
2250
|
+
function i(o, a) {
|
|
2251
|
+
return e.getDependency("accessor", o).then(function(r) {
|
|
2252
|
+
l.setAttribute(a, r);
|
|
2253
|
+
});
|
|
2254
|
+
}
|
|
2255
|
+
for (const o in s) {
|
|
2256
|
+
const a = re[o] || o.toLowerCase();
|
|
2257
|
+
a in l.attributes || n.push(i(s[o], a));
|
|
2258
|
+
}
|
|
2259
|
+
if (t.indices !== void 0 && !l.index) {
|
|
2260
|
+
const o = e.getDependency("accessor", t.indices).then(function(a) {
|
|
2261
|
+
l.setIndex(a);
|
|
2262
|
+
});
|
|
2263
|
+
n.push(o);
|
|
2264
|
+
}
|
|
2265
|
+
return de.workingColorSpace !== v && "COLOR_0" in s && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${de.workingColorSpace}" not supported.`), B(l, t), dn(l, t, e), Promise.all(n).then(function() {
|
|
2266
|
+
return t.targets !== void 0 ? rn(l, t.targets, e) : l;
|
|
2267
|
+
});
|
|
2268
|
+
}
|
|
2269
|
+
const fn = "https://cdn.jsdelivr.net/npm/@mymo";
|
|
2270
|
+
class pn {
|
|
2271
|
+
constructor() {
|
|
2272
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
2273
|
+
}
|
|
2274
|
+
async load(t) {
|
|
2275
|
+
const e = this._resolve(t), s = this.cache.get(e);
|
|
2276
|
+
if (s) return s;
|
|
2277
|
+
const i = e.endsWith(".vrm") ? await this._loadVRM(e) : await this._loadGLB(e);
|
|
2278
|
+
return this.cache.set(e, i), i;
|
|
2279
|
+
}
|
|
2280
|
+
_resolve(t) {
|
|
2281
|
+
return t.startsWith("http") || t.startsWith("/") || t.endsWith(".glb") || t.endsWith(".vrm") ? t : `${fn}/model-${t}/latest/${t}.glb`;
|
|
2282
|
+
}
|
|
2283
|
+
async _loadGLB(t) {
|
|
2284
|
+
console.warn(
|
|
2285
|
+
"[mymo-avatar] GLB support is best-effort. For guaranteed expressions, gestures, lip sync, and blink, use a VRM model."
|
|
2286
|
+
);
|
|
2287
|
+
const e = new Ae(), s = await this._load(e, t);
|
|
2288
|
+
return this._prepareMeshes(s.scene), { scene: s.scene, animations: s.animations };
|
|
2289
|
+
}
|
|
2290
|
+
async _loadVRM(t) {
|
|
2291
|
+
const e = new Ae();
|
|
2292
|
+
e.register((i) => new Tt(i));
|
|
2293
|
+
const s = await this._load(e, t), n = s.userData.vrm;
|
|
2294
|
+
return this._prepareMeshes(n.scene), { scene: n.scene, animations: s.animations, vrm: n };
|
|
2295
|
+
}
|
|
2296
|
+
_prepareMeshes(t) {
|
|
2297
|
+
t.traverse((e) => {
|
|
2298
|
+
(e instanceof M.Mesh || e instanceof M.SkinnedMesh) && (e.castShadow = !0, e.receiveShadow = !0, e.morphTargetInfluences && e.morphTargetInfluences.fill(0));
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2301
|
+
_load(t, e) {
|
|
2302
|
+
return new Promise((s, n) => {
|
|
2303
|
+
t.load(
|
|
2304
|
+
e,
|
|
2305
|
+
s,
|
|
2306
|
+
void 0,
|
|
2307
|
+
(i) => n(new Error(`Failed to load model: ${e} — ${String(i)}`))
|
|
2308
|
+
);
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
clearCache() {
|
|
2312
|
+
this.cache.clear();
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
class mn {
|
|
2316
|
+
constructor() {
|
|
2317
|
+
this.installed = /* @__PURE__ */ new Map();
|
|
2318
|
+
}
|
|
2319
|
+
use(t, e, s) {
|
|
2320
|
+
this.installed.has(t.name) || (t.install(e, s), this.installed.set(t.name, t));
|
|
2321
|
+
}
|
|
2322
|
+
has(t) {
|
|
2323
|
+
return this.installed.has(t);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
const gn = {
|
|
2327
|
+
"pulse-blue": "rgba(96,165,250,0.7)",
|
|
2328
|
+
"pulse-green": "rgba(74,222,128,0.7)",
|
|
2329
|
+
"pulse-red": "rgba(248,113,113,0.7)",
|
|
2330
|
+
"pulse-orange": "rgba(251,146,60,0.7)"
|
|
2331
|
+
}, An = {
|
|
2332
|
+
model: "maya",
|
|
2333
|
+
position: "bottom-right",
|
|
2334
|
+
size: 180,
|
|
2335
|
+
theme: "light",
|
|
2336
|
+
framing: "full",
|
|
2337
|
+
draggable: !1,
|
|
2338
|
+
shadows: !1,
|
|
2339
|
+
idle: !0,
|
|
2340
|
+
idleInterval: 8e3,
|
|
2341
|
+
blink: !0,
|
|
2342
|
+
blinkInterval: 3500,
|
|
2343
|
+
lipSync: !0,
|
|
2344
|
+
followMouse: !1,
|
|
2345
|
+
autoHide: !1,
|
|
2346
|
+
zIndex: 99999,
|
|
2347
|
+
framingConfig: {},
|
|
2348
|
+
themeConfig: {}
|
|
2349
|
+
};
|
|
2350
|
+
class _n {
|
|
2351
|
+
constructor(t = {}) {
|
|
2352
|
+
this._boundMouseLook = (e) => {
|
|
2353
|
+
const s = e.clientX / window.innerWidth * 2 - 1, n = e.clientY / window.innerHeight * 2 - 1;
|
|
2354
|
+
this.animation.lookAt(s, n);
|
|
2355
|
+
}, this.options = { ...An, ...t }, this.events = new xt(), this.renderer = new Mt(), this.animation = new oe(), this.audio = new bt(), this.lipSync = new kt(this.audio, (e) => this.animation.setMouthMorph(e)), this.loader = new pn(), this.plugins = new mn(), this.renderer.setup(this.options), this.renderer.addTickCallback((e) => this.animation.update(e)), this._bindContainerEvents(), this._initialize().catch((e) => console.error("[mymo-avatar]", e));
|
|
2356
|
+
}
|
|
2357
|
+
async _initialize() {
|
|
2358
|
+
try {
|
|
2359
|
+
const t = await this.loader.load(this.options.model);
|
|
2360
|
+
this.renderer.setModel(t.scene), this.animation.init(t), this.options.idle && this.animation.startIdle(this.options.idleInterval), this.options.blink && this.animation.startBlink(this.options.blinkInterval), this.options.followMouse && this._bindMouseLook(), this.events.emit("loaded"), this.events.emit("modelLoaded", { model: this.options.model });
|
|
2361
|
+
} catch (t) {
|
|
2362
|
+
console.error("[mymo-avatar] Failed to load model:", t);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
_bindContainerEvents() {
|
|
2366
|
+
this.renderer.getContainer().addEventListener("click", () => {
|
|
2367
|
+
this.events.emit("click");
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
_bindMouseLook() {
|
|
2371
|
+
window.addEventListener("mousemove", this._boundMouseLook);
|
|
2372
|
+
}
|
|
2373
|
+
// ── Visibility ────────────────────────────────────────────────────────────
|
|
2374
|
+
debugBones(t) {
|
|
2375
|
+
return this.renderer.debugBones(t), this;
|
|
2376
|
+
}
|
|
2377
|
+
show() {
|
|
2378
|
+
return this.renderer.show(), this;
|
|
2379
|
+
}
|
|
2380
|
+
hide() {
|
|
2381
|
+
return this.renderer.hide(), this;
|
|
2382
|
+
}
|
|
2383
|
+
destroy() {
|
|
2384
|
+
window.removeEventListener("mousemove", this._boundMouseLook), this.animation.stopLook(), this.animation.dispose(), this.audio.dispose(), this.renderer.dispose(), this.events.removeAllListeners();
|
|
2385
|
+
}
|
|
2386
|
+
// ── Position & Size ───────────────────────────────────────────────────────
|
|
2387
|
+
move(t, e) {
|
|
2388
|
+
return this.renderer.moveTo(t, e), this;
|
|
2389
|
+
}
|
|
2390
|
+
position(t) {
|
|
2391
|
+
return this.renderer.setPosition(t), this;
|
|
2392
|
+
}
|
|
2393
|
+
scale(t) {
|
|
2394
|
+
const e = parseInt(this.renderer.getContainer().style.width, 10) || this.options.size;
|
|
2395
|
+
return this.renderer.setSize(e * t), this;
|
|
2396
|
+
}
|
|
2397
|
+
size(t) {
|
|
2398
|
+
return this.renderer.setSize(t), this;
|
|
2399
|
+
}
|
|
2400
|
+
frame(t) {
|
|
2401
|
+
return this.renderer.setFraming(t), this;
|
|
2402
|
+
}
|
|
2403
|
+
setFramingConfig(t) {
|
|
2404
|
+
return this.renderer.setFramingConfig(t), this;
|
|
2405
|
+
}
|
|
2406
|
+
setTheme(t) {
|
|
2407
|
+
return this.renderer.setTheme(t), this;
|
|
2408
|
+
}
|
|
2409
|
+
setThemeConfig(t) {
|
|
2410
|
+
return this.renderer.setThemeConfig(t), this;
|
|
2411
|
+
}
|
|
2412
|
+
// ── Expressions ───────────────────────────────────────────────────────────
|
|
2413
|
+
expression(t, e = 1) {
|
|
2414
|
+
return this.animation.setExpression(t, e), this;
|
|
2415
|
+
}
|
|
2416
|
+
smile() {
|
|
2417
|
+
return this.expression("smile");
|
|
2418
|
+
}
|
|
2419
|
+
sad() {
|
|
2420
|
+
return this.expression("sad");
|
|
2421
|
+
}
|
|
2422
|
+
happy() {
|
|
2423
|
+
return this.expression("happy");
|
|
2424
|
+
}
|
|
2425
|
+
angry() {
|
|
2426
|
+
return this.expression("angry");
|
|
2427
|
+
}
|
|
2428
|
+
surprised() {
|
|
2429
|
+
return this.expression("surprised");
|
|
2430
|
+
}
|
|
2431
|
+
thinking() {
|
|
2432
|
+
return this.expression("thinking");
|
|
2433
|
+
}
|
|
2434
|
+
confused() {
|
|
2435
|
+
return this.expression("confused");
|
|
2436
|
+
}
|
|
2437
|
+
sleep() {
|
|
2438
|
+
return this.expression("sleep");
|
|
2439
|
+
}
|
|
2440
|
+
idle() {
|
|
2441
|
+
return this.expression("idle");
|
|
2442
|
+
}
|
|
2443
|
+
// ── Gestures ──────────────────────────────────────────────────────────────
|
|
2444
|
+
wave() {
|
|
2445
|
+
return this._gesture("wave");
|
|
2446
|
+
}
|
|
2447
|
+
nod() {
|
|
2448
|
+
return this._gesture("nod");
|
|
2449
|
+
}
|
|
2450
|
+
shakeHead() {
|
|
2451
|
+
return this._gesture("shakeHead");
|
|
2452
|
+
}
|
|
2453
|
+
clap() {
|
|
2454
|
+
return this._gesture("clap");
|
|
2455
|
+
}
|
|
2456
|
+
jump() {
|
|
2457
|
+
return this._gesture("jump");
|
|
2458
|
+
}
|
|
2459
|
+
dance() {
|
|
2460
|
+
return this._gesture("dance");
|
|
2461
|
+
}
|
|
2462
|
+
yes() {
|
|
2463
|
+
return this._gesture("yes");
|
|
2464
|
+
}
|
|
2465
|
+
no() {
|
|
2466
|
+
return this._gesture("no");
|
|
2467
|
+
}
|
|
2468
|
+
thumbsUp() {
|
|
2469
|
+
return this._gesture("thumbsUp");
|
|
2470
|
+
}
|
|
2471
|
+
_gesture(t) {
|
|
2472
|
+
return this.events.emit("animationStart", { gesture: t }), this.animation.playGesture(t), this;
|
|
2473
|
+
}
|
|
2474
|
+
// ── Look ──────────────────────────────────────────────────────────────────
|
|
2475
|
+
lookAtMouse() {
|
|
2476
|
+
return this._bindMouseLook(), this;
|
|
2477
|
+
}
|
|
2478
|
+
lookAt(t, e) {
|
|
2479
|
+
const s = t / window.innerWidth * 2 - 1, n = e / window.innerHeight * 2 - 1;
|
|
2480
|
+
return this.animation.lookAt(s, n), this;
|
|
2481
|
+
}
|
|
2482
|
+
lookForward() {
|
|
2483
|
+
return window.removeEventListener("mousemove", this._boundMouseLook), this.animation.lookForward(), this;
|
|
2484
|
+
}
|
|
2485
|
+
randomLook() {
|
|
2486
|
+
return this.animation.startRandomLook(), this;
|
|
2487
|
+
}
|
|
2488
|
+
// ── Speech ────────────────────────────────────────────────────────────────
|
|
2489
|
+
async talk(t) {
|
|
2490
|
+
return this.events.emit("speechStart"), this.options.lipSync && this.lipSync.startAutoSync(), await this.audio.play(t), this.options.lipSync && this.lipSync.stopAutoSync(), this.events.emit("speechEnd"), this;
|
|
2491
|
+
}
|
|
2492
|
+
startTalking() {
|
|
2493
|
+
return this.events.emit("speechStart"), this.options.lipSync && this.lipSync.startAutoSync(), this;
|
|
2494
|
+
}
|
|
2495
|
+
stopTalking() {
|
|
2496
|
+
return this.audio.stop(), this.lipSync.stopAutoSync(), this.events.emit("speechEnd"), this;
|
|
2497
|
+
}
|
|
2498
|
+
pauseTalking() {
|
|
2499
|
+
return this.audio.pause(), this;
|
|
2500
|
+
}
|
|
2501
|
+
// ── Lip Sync ──────────────────────────────────────────────────────────────
|
|
2502
|
+
setViseme(t) {
|
|
2503
|
+
return this.lipSync.setViseme(t), this;
|
|
2504
|
+
}
|
|
2505
|
+
setMouth(t) {
|
|
2506
|
+
return this.lipSync.setMouth(t), this;
|
|
2507
|
+
}
|
|
2508
|
+
setVolume(t) {
|
|
2509
|
+
return this.lipSync.setVolume(t), this;
|
|
2510
|
+
}
|
|
2511
|
+
// ── States ────────────────────────────────────────────────────────────────
|
|
2512
|
+
setState(t) {
|
|
2513
|
+
const e = {
|
|
2514
|
+
loading: { expression: "thinking", animation: "Idle", ring: "pulse-blue" },
|
|
2515
|
+
success: { expression: "happy", animation: "Yes", ring: "pulse-green" },
|
|
2516
|
+
error: { expression: "sad", animation: "No", ring: "pulse-red" },
|
|
2517
|
+
warning: { expression: "surprised", animation: "Idle", ring: "pulse-orange" },
|
|
2518
|
+
typing: { expression: "thinking", animation: "Idle", ring: "" },
|
|
2519
|
+
listening: { expression: "smile", animation: "Idle", ring: "pulse-blue" },
|
|
2520
|
+
processing: { expression: "thinking", animation: "Idle", ring: "pulse-blue" },
|
|
2521
|
+
complete: { expression: "happy", animation: "ThumbsUp", ring: "pulse-green" }
|
|
2522
|
+
}, { expression: s, animation: n, ring: i } = e[t];
|
|
2523
|
+
this.animation.setExpression(s), this.animation.play(n);
|
|
2524
|
+
const o = this.renderer.getContainer();
|
|
2525
|
+
return o.dataset.state = t, o.style.setProperty("--ring-color", i ? gn[i] ?? "transparent" : "transparent"), this.events.emit("animationStart", { state: t }), this;
|
|
2526
|
+
}
|
|
2527
|
+
loading() {
|
|
2528
|
+
return this.setState("loading");
|
|
2529
|
+
}
|
|
2530
|
+
success() {
|
|
2531
|
+
return this.setState("success");
|
|
2532
|
+
}
|
|
2533
|
+
error() {
|
|
2534
|
+
return this.setState("error");
|
|
2535
|
+
}
|
|
2536
|
+
warning() {
|
|
2537
|
+
return this.setState("warning");
|
|
2538
|
+
}
|
|
2539
|
+
typing() {
|
|
2540
|
+
return this.setState("typing");
|
|
2541
|
+
}
|
|
2542
|
+
listening() {
|
|
2543
|
+
return this.setState("listening");
|
|
2544
|
+
}
|
|
2545
|
+
processing() {
|
|
2546
|
+
return this.setState("processing");
|
|
2547
|
+
}
|
|
2548
|
+
complete() {
|
|
2549
|
+
return this.setState("complete");
|
|
2550
|
+
}
|
|
2551
|
+
clearState() {
|
|
2552
|
+
this.animation.setExpression("idle"), this.animation.stop();
|
|
2553
|
+
const t = this.renderer.getContainer();
|
|
2554
|
+
return t.dataset.state = "", t.style.setProperty("--ring-color", "transparent"), this.events.emit("animationEnd"), this;
|
|
2555
|
+
}
|
|
2556
|
+
// ── Animations ────────────────────────────────────────────────────────────
|
|
2557
|
+
play(t) {
|
|
2558
|
+
return this.events.emit("animationStart", { name: t }), this.animation.play(t), this;
|
|
2559
|
+
}
|
|
2560
|
+
stop() {
|
|
2561
|
+
return this.animation.stop(), this.events.emit("animationEnd"), this;
|
|
2562
|
+
}
|
|
2563
|
+
// ── Models ────────────────────────────────────────────────────────────────
|
|
2564
|
+
async load(t) {
|
|
2565
|
+
const e = await this.loader.load(t);
|
|
2566
|
+
return this.animation.dispose(), this.renderer.setModel(e.scene), this.animation.init(e), this.options.idle && this.animation.startIdle(this.options.idleInterval), this.options.blink && this.animation.startBlink(this.options.blinkInterval), this.events.emit("modelLoaded", { model: t }), this;
|
|
2567
|
+
}
|
|
2568
|
+
// ── Events ────────────────────────────────────────────────────────────────
|
|
2569
|
+
on(t, e) {
|
|
2570
|
+
return this.events.on(t, e), this;
|
|
2571
|
+
}
|
|
2572
|
+
off(t, e) {
|
|
2573
|
+
return this.events.off(t, e), this;
|
|
2574
|
+
}
|
|
2575
|
+
// ── Plugins ───────────────────────────────────────────────────────────────
|
|
2576
|
+
use(t, e) {
|
|
2577
|
+
return this.plugins.use(t, this, e), this;
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
export {
|
|
2581
|
+
_n as A
|
|
2582
|
+
};
|
|
2583
|
+
//# sourceMappingURL=Avatar-DEkBZdcp.js.map
|