@streamoji/avatar-widget 0.2.0 → 0.2.2

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.
@@ -1,1788 +1,96 @@
1
- import { jsx as N, jsxs as de } from "react/jsx-runtime";
2
- import { memo as bn, useMemo as gt, useRef as L, useState as K, useEffect as ie, useCallback as Ye, useLayoutEffect as _n, Suspense as xn } from "react";
3
- import { useFrame as wn, Canvas as Rn, useThree as Sn } from "@react-three/fiber";
4
- import { useGLTF as ct, Environment as yn } from "@react-three/drei";
5
- import * as Ge from "three";
6
- import { TrianglesDrawMode as An, TriangleFanDrawMode as Tt, TriangleStripDrawMode as Wt, Loader as En, LoaderUtils as Ke, FileLoader as Xt, MeshPhysicalMaterial as ge, Vector2 as zt, Color as ve, LinearSRGBColorSpace as Re, SRGBColorSpace as We, SpotLight as Ln, PointLight as Mn, DirectionalLight as In, Matrix4 as Qe, Vector3 as Oe, Quaternion as $t, InstancedMesh as vn, InstancedBufferAttribute as kn, Object3D as qt, TextureLoader as Nn, ImageBitmapLoader as Cn, BufferAttribute as ut, InterleavedBuffer as On, InterleavedBufferAttribute as Dn, LinearMipmapLinearFilter as Yt, NearestMipmapLinearFilter as Fn, LinearMipmapNearestFilter as Pn, NearestMipmapNearestFilter as Un, LinearFilter as bt, NearestFilter as Jt, RepeatWrapping as _t, MirroredRepeatWrapping as Hn, ClampToEdgeWrapping as Bn, PointsMaterial as Gn, Material as lt, LineBasicMaterial as jn, MeshStandardMaterial as Qt, DoubleSide as Vn, MeshBasicMaterial as Ve, PropertyBinding as Kn, BufferGeometry as Wn, SkinnedMesh as Xn, Mesh as zn, LineSegments as $n, Line as qn, LineLoop as Yn, Points as Jn, Group as dt, PerspectiveCamera as Qn, MathUtils as Zn, OrthographicCamera as es, Skeleton as ts, AnimationClip as ns, Bone as ss, InterpolateDiscrete as rs, InterpolateLinear as Zt, Texture as Nt, VectorKeyframeTrack as Ct, NumberKeyframeTrack as Ot, QuaternionKeyframeTrack as Dt, ColorManagement as Ft, FrontSide as is, Interpolant as os, Box3 as as, Sphere as cs } from "three";
7
- function Pt(d, t) {
8
- if (t === An)
9
- return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."), d;
10
- if (t === Tt || t === Wt) {
11
- let e = d.getIndex();
12
- if (e === null) {
13
- const s = [], a = d.getAttribute("position");
14
- if (a !== void 0) {
15
- for (let o = 0; o < a.count; o++)
16
- s.push(o);
17
- d.setIndex(s), e = d.getIndex();
18
- } else
19
- return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."), d;
20
- }
21
- const r = e.count - 2, n = [];
22
- if (t === Tt)
23
- for (let s = 1; s <= r; s++)
24
- n.push(e.getX(0)), n.push(e.getX(s)), n.push(e.getX(s + 1));
25
- else
26
- for (let s = 0; s < r; s++)
27
- s % 2 === 0 ? (n.push(e.getX(s)), n.push(e.getX(s + 1)), n.push(e.getX(s + 2))) : (n.push(e.getX(s + 2)), n.push(e.getX(s + 1)), n.push(e.getX(s)));
28
- n.length / 3 !== r && console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");
29
- const i = d.clone();
30
- return i.setIndex(n), i.clearGroups(), i;
31
- } else
32
- return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:", t), d;
33
- }
34
- class us extends En {
35
- /**
36
- * Constructs a new glTF loader.
37
- *
38
- * @param {LoadingManager} [manager] - The loading manager.
39
- */
40
- constructor(t) {
41
- super(t), this.dracoLoader = null, this.ktx2Loader = null, this.meshoptDecoder = null, this.pluginCallbacks = [], this.register(function(e) {
42
- return new ps(e);
43
- }), this.register(function(e) {
44
- return new ms(e);
45
- }), this.register(function(e) {
46
- return new ys(e);
47
- }), this.register(function(e) {
48
- return new As(e);
49
- }), this.register(function(e) {
50
- return new Es(e);
51
- }), this.register(function(e) {
52
- return new Ts(e);
53
- }), this.register(function(e) {
54
- return new bs(e);
55
- }), this.register(function(e) {
56
- return new _s(e);
57
- }), this.register(function(e) {
58
- return new xs(e);
59
- }), this.register(function(e) {
60
- return new hs(e);
61
- }), this.register(function(e) {
62
- return new ws(e);
63
- }), this.register(function(e) {
64
- return new gs(e);
65
- }), this.register(function(e) {
66
- return new Ss(e);
67
- }), this.register(function(e) {
68
- return new Rs(e);
69
- }), this.register(function(e) {
70
- return new ds(e);
71
- }), this.register(function(e) {
72
- return new Ls(e);
73
- }), this.register(function(e) {
74
- return new Ms(e);
75
- });
76
- }
77
- /**
78
- * Starts loading from the given URL and passes the loaded glTF asset
79
- * to the `onLoad()` callback.
80
- *
81
- * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
82
- * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
83
- * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
84
- * @param {onErrorCallback} onError - Executed when errors occur.
85
- */
86
- load(t, e, r, n) {
87
- const i = this;
88
- let s;
89
- if (this.resourcePath !== "")
90
- s = this.resourcePath;
91
- else if (this.path !== "") {
92
- const c = Ke.extractUrlBase(t);
93
- s = Ke.resolveURL(c, this.path);
94
- } else
95
- s = Ke.extractUrlBase(t);
96
- this.manager.itemStart(t);
97
- const a = function(c) {
98
- n ? n(c) : console.error(c), i.manager.itemError(t), i.manager.itemEnd(t);
99
- }, o = new Xt(this.manager);
100
- o.setPath(this.path), o.setResponseType("arraybuffer"), o.setRequestHeader(this.requestHeader), o.setWithCredentials(this.withCredentials), o.load(t, function(c) {
101
- try {
102
- i.parse(c, s, function(u) {
103
- e(u), i.manager.itemEnd(t);
104
- }, a);
105
- } catch (u) {
106
- a(u);
107
- }
108
- }, r, a);
109
- }
110
- /**
111
- * Sets the given Draco loader to this loader. Required for decoding assets
112
- * compressed with the `KHR_draco_mesh_compression` extension.
113
- *
114
- * @param {DRACOLoader} dracoLoader - The Draco loader to set.
115
- * @return {GLTFLoader} A reference to this loader.
116
- */
117
- setDRACOLoader(t) {
118
- return this.dracoLoader = t, this;
119
- }
120
- /**
121
- * Sets the given KTX2 loader to this loader. Required for loading KTX2
122
- * compressed textures.
123
- *
124
- * @param {KTX2Loader} ktx2Loader - The KTX2 loader to set.
125
- * @return {GLTFLoader} A reference to this loader.
126
- */
127
- setKTX2Loader(t) {
128
- return this.ktx2Loader = t, this;
129
- }
130
- /**
131
- * Sets the given meshopt decoder. Required for decoding assets
132
- * compressed with the `EXT_meshopt_compression` extension.
133
- *
134
- * @param {Object} meshoptDecoder - The meshopt decoder to set.
135
- * @return {GLTFLoader} A reference to this loader.
136
- */
137
- setMeshoptDecoder(t) {
138
- return this.meshoptDecoder = t, this;
139
- }
140
- /**
141
- * Registers a plugin callback. This API is internally used to implement the various
142
- * glTF extensions but can also used by third-party code to add additional logic
143
- * to the loader.
144
- *
145
- * @param {function(parser:GLTFParser)} callback - The callback function to register.
146
- * @return {GLTFLoader} A reference to this loader.
147
- */
148
- register(t) {
149
- return this.pluginCallbacks.indexOf(t) === -1 && this.pluginCallbacks.push(t), this;
150
- }
151
- /**
152
- * Unregisters a plugin callback.
153
- *
154
- * @param {Function} callback - The callback function to unregister.
155
- * @return {GLTFLoader} A reference to this loader.
156
- */
157
- unregister(t) {
158
- return this.pluginCallbacks.indexOf(t) !== -1 && this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t), 1), this;
159
- }
160
- /**
161
- * Parses the given FBX data and returns the resulting group.
162
- *
163
- * @param {string|ArrayBuffer} data - The raw glTF data.
164
- * @param {string} path - The URL base path.
165
- * @param {function(GLTFLoader~LoadObject)} onLoad - Executed when the loading process has been finished.
166
- * @param {onErrorCallback} onError - Executed when errors occur.
167
- */
168
- parse(t, e, r, n) {
169
- let i;
170
- const s = {}, a = {}, o = new TextDecoder();
171
- if (typeof t == "string")
172
- i = JSON.parse(t);
173
- else if (t instanceof ArrayBuffer)
174
- if (o.decode(new Uint8Array(t, 0, 4)) === en) {
175
- try {
176
- s[k.KHR_BINARY_GLTF] = new Is(t);
177
- } catch (l) {
178
- n && n(l);
179
- return;
180
- }
181
- i = JSON.parse(s[k.KHR_BINARY_GLTF].content);
182
- } else
183
- i = JSON.parse(o.decode(t));
184
- else
185
- i = t;
186
- if (i.asset === void 0 || i.asset.version[0] < 2) {
187
- n && n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));
188
- return;
189
- }
190
- const c = new js(i, {
191
- path: e || this.resourcePath || "",
192
- crossOrigin: this.crossOrigin,
193
- requestHeader: this.requestHeader,
194
- manager: this.manager,
195
- ktx2Loader: this.ktx2Loader,
196
- meshoptDecoder: this.meshoptDecoder
197
- });
198
- c.fileLoader.setRequestHeader(this.requestHeader);
199
- for (let u = 0; u < this.pluginCallbacks.length; u++) {
200
- const l = this.pluginCallbacks[u](c);
201
- l.name || console.error("THREE.GLTFLoader: Invalid plugin found: missing name"), a[l.name] = l, s[l.name] = !0;
202
- }
203
- if (i.extensionsUsed)
204
- for (let u = 0; u < i.extensionsUsed.length; ++u) {
205
- const l = i.extensionsUsed[u], f = i.extensionsRequired || [];
206
- switch (l) {
207
- case k.KHR_MATERIALS_UNLIT:
208
- s[l] = new fs();
209
- break;
210
- case k.KHR_DRACO_MESH_COMPRESSION:
211
- s[l] = new vs(i, this.dracoLoader);
212
- break;
213
- case k.KHR_TEXTURE_TRANSFORM:
214
- s[l] = new ks();
215
- break;
216
- case k.KHR_MESH_QUANTIZATION:
217
- s[l] = new Ns();
218
- break;
219
- default:
220
- f.indexOf(l) >= 0 && a[l] === void 0 && console.warn('THREE.GLTFLoader: Unknown extension "' + l + '".');
221
- }
222
- }
223
- c.setExtensions(s), c.setPlugins(a), c.parse(r, n);
224
- }
225
- /**
226
- * Async version of {@link GLTFLoader#parse}.
227
- *
228
- * @async
229
- * @param {string|ArrayBuffer} data - The raw glTF data.
230
- * @param {string} path - The URL base path.
231
- * @return {Promise<GLTFLoader~LoadObject>} A Promise that resolves with the loaded glTF when the parsing has been finished.
232
- */
233
- parseAsync(t, e) {
234
- const r = this;
235
- return new Promise(function(n, i) {
236
- r.parse(t, e, n, i);
237
- });
238
- }
239
- }
240
- function ls() {
241
- let d = {};
242
- return {
243
- get: function(t) {
244
- return d[t];
245
- },
246
- add: function(t, e) {
247
- d[t] = e;
248
- },
249
- remove: function(t) {
250
- delete d[t];
251
- },
252
- removeAll: function() {
253
- d = {};
254
- }
255
- };
256
- }
257
- const k = {
258
- KHR_BINARY_GLTF: "KHR_binary_glTF",
259
- KHR_DRACO_MESH_COMPRESSION: "KHR_draco_mesh_compression",
260
- KHR_LIGHTS_PUNCTUAL: "KHR_lights_punctual",
261
- KHR_MATERIALS_CLEARCOAT: "KHR_materials_clearcoat",
262
- KHR_MATERIALS_DISPERSION: "KHR_materials_dispersion",
263
- KHR_MATERIALS_IOR: "KHR_materials_ior",
264
- KHR_MATERIALS_SHEEN: "KHR_materials_sheen",
265
- KHR_MATERIALS_SPECULAR: "KHR_materials_specular",
266
- KHR_MATERIALS_TRANSMISSION: "KHR_materials_transmission",
267
- KHR_MATERIALS_IRIDESCENCE: "KHR_materials_iridescence",
268
- KHR_MATERIALS_ANISOTROPY: "KHR_materials_anisotropy",
269
- KHR_MATERIALS_UNLIT: "KHR_materials_unlit",
270
- KHR_MATERIALS_VOLUME: "KHR_materials_volume",
271
- KHR_TEXTURE_BASISU: "KHR_texture_basisu",
272
- KHR_TEXTURE_TRANSFORM: "KHR_texture_transform",
273
- KHR_MESH_QUANTIZATION: "KHR_mesh_quantization",
274
- KHR_MATERIALS_EMISSIVE_STRENGTH: "KHR_materials_emissive_strength",
275
- EXT_MATERIALS_BUMP: "EXT_materials_bump",
276
- EXT_TEXTURE_WEBP: "EXT_texture_webp",
277
- EXT_TEXTURE_AVIF: "EXT_texture_avif",
278
- EXT_MESHOPT_COMPRESSION: "EXT_meshopt_compression",
279
- EXT_MESH_GPU_INSTANCING: "EXT_mesh_gpu_instancing"
280
- };
281
- class ds {
282
- constructor(t) {
283
- this.parser = t, this.name = k.KHR_LIGHTS_PUNCTUAL, this.cache = { refs: {}, uses: {} };
284
- }
285
- _markDefs() {
286
- const t = this.parser, e = this.parser.json.nodes || [];
287
- for (let r = 0, n = e.length; r < n; r++) {
288
- const i = e[r];
289
- i.extensions && i.extensions[this.name] && i.extensions[this.name].light !== void 0 && t._addNodeRef(this.cache, i.extensions[this.name].light);
290
- }
291
- }
292
- _loadLight(t) {
293
- const e = this.parser, r = "light:" + t;
294
- let n = e.cache.get(r);
295
- if (n) return n;
296
- const i = e.json, o = ((i.extensions && i.extensions[this.name] || {}).lights || [])[t];
297
- let c;
298
- const u = new ve(16777215);
299
- o.color !== void 0 && u.setRGB(o.color[0], o.color[1], o.color[2], Re);
300
- const l = o.range !== void 0 ? o.range : 0;
301
- switch (o.type) {
302
- case "directional":
303
- c = new In(u), c.target.position.set(0, 0, -1), c.add(c.target);
304
- break;
305
- case "point":
306
- c = new Mn(u), c.distance = l;
307
- break;
308
- case "spot":
309
- c = new Ln(u), c.distance = l, o.spot = o.spot || {}, o.spot.innerConeAngle = o.spot.innerConeAngle !== void 0 ? o.spot.innerConeAngle : 0, o.spot.outerConeAngle = o.spot.outerConeAngle !== void 0 ? o.spot.outerConeAngle : Math.PI / 4, c.angle = o.spot.outerConeAngle, c.penumbra = 1 - o.spot.innerConeAngle / o.spot.outerConeAngle, c.target.position.set(0, 0, -1), c.add(c.target);
310
- break;
311
- default:
312
- throw new Error("THREE.GLTFLoader: Unexpected light type: " + o.type);
313
- }
314
- return c.position.set(0, 0, 0), me(c, o), o.intensity !== void 0 && (c.intensity = o.intensity), c.name = e.createUniqueName(o.name || "light_" + t), n = Promise.resolve(c), e.cache.add(r, n), n;
315
- }
316
- getDependency(t, e) {
317
- if (t === "light")
318
- return this._loadLight(e);
319
- }
320
- createNodeAttachment(t) {
321
- const e = this, r = this.parser, i = r.json.nodes[t], a = (i.extensions && i.extensions[this.name] || {}).light;
322
- return a === void 0 ? null : this._loadLight(a).then(function(o) {
323
- return r._getNodeRef(e.cache, a, o);
324
- });
325
- }
326
- }
327
- class fs {
328
- constructor() {
329
- this.name = k.KHR_MATERIALS_UNLIT;
330
- }
331
- getMaterialType() {
332
- return Ve;
333
- }
334
- extendParams(t, e, r) {
335
- const n = [];
336
- t.color = new ve(1, 1, 1), t.opacity = 1;
337
- const i = e.pbrMetallicRoughness;
338
- if (i) {
339
- if (Array.isArray(i.baseColorFactor)) {
340
- const s = i.baseColorFactor;
341
- t.color.setRGB(s[0], s[1], s[2], Re), t.opacity = s[3];
342
- }
343
- i.baseColorTexture !== void 0 && n.push(r.assignTexture(t, "map", i.baseColorTexture, We));
344
- }
345
- return Promise.all(n);
346
- }
347
- }
348
- class hs {
349
- constructor(t) {
350
- this.parser = t, this.name = k.KHR_MATERIALS_EMISSIVE_STRENGTH;
351
- }
352
- extendMaterialParams(t, e) {
353
- const n = this.parser.json.materials[t];
354
- if (!n.extensions || !n.extensions[this.name])
355
- return Promise.resolve();
356
- const i = n.extensions[this.name].emissiveStrength;
357
- return i !== void 0 && (e.emissiveIntensity = i), Promise.resolve();
358
- }
359
- }
360
- class ps {
361
- constructor(t) {
362
- this.parser = t, this.name = k.KHR_MATERIALS_CLEARCOAT;
363
- }
364
- getMaterialType(t) {
365
- const r = this.parser.json.materials[t];
366
- return !r.extensions || !r.extensions[this.name] ? null : ge;
367
- }
368
- extendMaterialParams(t, e) {
369
- const r = this.parser, n = r.json.materials[t];
370
- if (!n.extensions || !n.extensions[this.name])
371
- return Promise.resolve();
372
- const i = [], s = n.extensions[this.name];
373
- if (s.clearcoatFactor !== void 0 && (e.clearcoat = s.clearcoatFactor), s.clearcoatTexture !== void 0 && i.push(r.assignTexture(e, "clearcoatMap", s.clearcoatTexture)), s.clearcoatRoughnessFactor !== void 0 && (e.clearcoatRoughness = s.clearcoatRoughnessFactor), s.clearcoatRoughnessTexture !== void 0 && i.push(r.assignTexture(e, "clearcoatRoughnessMap", s.clearcoatRoughnessTexture)), s.clearcoatNormalTexture !== void 0 && (i.push(r.assignTexture(e, "clearcoatNormalMap", s.clearcoatNormalTexture)), s.clearcoatNormalTexture.scale !== void 0)) {
374
- const a = s.clearcoatNormalTexture.scale;
375
- e.clearcoatNormalScale = new zt(a, a);
376
- }
377
- return Promise.all(i);
378
- }
379
- }
380
- class ms {
381
- constructor(t) {
382
- this.parser = t, this.name = k.KHR_MATERIALS_DISPERSION;
383
- }
384
- getMaterialType(t) {
385
- const r = this.parser.json.materials[t];
386
- return !r.extensions || !r.extensions[this.name] ? null : ge;
387
- }
388
- extendMaterialParams(t, e) {
389
- const n = this.parser.json.materials[t];
390
- if (!n.extensions || !n.extensions[this.name])
391
- return Promise.resolve();
392
- const i = n.extensions[this.name];
393
- return e.dispersion = i.dispersion !== void 0 ? i.dispersion : 0, Promise.resolve();
394
- }
395
- }
396
- class gs {
397
- constructor(t) {
398
- this.parser = t, this.name = k.KHR_MATERIALS_IRIDESCENCE;
399
- }
400
- getMaterialType(t) {
401
- const r = this.parser.json.materials[t];
402
- return !r.extensions || !r.extensions[this.name] ? null : ge;
403
- }
404
- extendMaterialParams(t, e) {
405
- const r = this.parser, n = r.json.materials[t];
406
- if (!n.extensions || !n.extensions[this.name])
407
- return Promise.resolve();
408
- const i = [], s = n.extensions[this.name];
409
- return s.iridescenceFactor !== void 0 && (e.iridescence = s.iridescenceFactor), s.iridescenceTexture !== void 0 && i.push(r.assignTexture(e, "iridescenceMap", s.iridescenceTexture)), s.iridescenceIor !== void 0 && (e.iridescenceIOR = s.iridescenceIor), e.iridescenceThicknessRange === void 0 && (e.iridescenceThicknessRange = [100, 400]), s.iridescenceThicknessMinimum !== void 0 && (e.iridescenceThicknessRange[0] = s.iridescenceThicknessMinimum), s.iridescenceThicknessMaximum !== void 0 && (e.iridescenceThicknessRange[1] = s.iridescenceThicknessMaximum), s.iridescenceThicknessTexture !== void 0 && i.push(r.assignTexture(e, "iridescenceThicknessMap", s.iridescenceThicknessTexture)), Promise.all(i);
410
- }
411
- }
412
- class Ts {
413
- constructor(t) {
414
- this.parser = t, this.name = k.KHR_MATERIALS_SHEEN;
415
- }
416
- getMaterialType(t) {
417
- const r = this.parser.json.materials[t];
418
- return !r.extensions || !r.extensions[this.name] ? null : ge;
419
- }
420
- extendMaterialParams(t, e) {
421
- const r = this.parser, n = r.json.materials[t];
422
- if (!n.extensions || !n.extensions[this.name])
423
- return Promise.resolve();
424
- const i = [];
425
- e.sheenColor = new ve(0, 0, 0), e.sheenRoughness = 0, e.sheen = 1;
426
- const s = n.extensions[this.name];
427
- if (s.sheenColorFactor !== void 0) {
428
- const a = s.sheenColorFactor;
429
- e.sheenColor.setRGB(a[0], a[1], a[2], Re);
430
- }
431
- return s.sheenRoughnessFactor !== void 0 && (e.sheenRoughness = s.sheenRoughnessFactor), s.sheenColorTexture !== void 0 && i.push(r.assignTexture(e, "sheenColorMap", s.sheenColorTexture, We)), s.sheenRoughnessTexture !== void 0 && i.push(r.assignTexture(e, "sheenRoughnessMap", s.sheenRoughnessTexture)), Promise.all(i);
432
- }
433
- }
434
- class bs {
435
- constructor(t) {
436
- this.parser = t, this.name = k.KHR_MATERIALS_TRANSMISSION;
437
- }
438
- getMaterialType(t) {
439
- const r = this.parser.json.materials[t];
440
- return !r.extensions || !r.extensions[this.name] ? null : ge;
441
- }
442
- extendMaterialParams(t, e) {
443
- const r = this.parser, n = r.json.materials[t];
444
- if (!n.extensions || !n.extensions[this.name])
445
- return Promise.resolve();
446
- const i = [], s = n.extensions[this.name];
447
- return s.transmissionFactor !== void 0 && (e.transmission = s.transmissionFactor), s.transmissionTexture !== void 0 && i.push(r.assignTexture(e, "transmissionMap", s.transmissionTexture)), Promise.all(i);
448
- }
449
- }
450
- class _s {
451
- constructor(t) {
452
- this.parser = t, this.name = k.KHR_MATERIALS_VOLUME;
453
- }
454
- getMaterialType(t) {
455
- const r = this.parser.json.materials[t];
456
- return !r.extensions || !r.extensions[this.name] ? null : ge;
457
- }
458
- extendMaterialParams(t, e) {
459
- const r = this.parser, n = r.json.materials[t];
460
- if (!n.extensions || !n.extensions[this.name])
461
- return Promise.resolve();
462
- const i = [], s = n.extensions[this.name];
463
- e.thickness = s.thicknessFactor !== void 0 ? s.thicknessFactor : 0, s.thicknessTexture !== void 0 && i.push(r.assignTexture(e, "thicknessMap", s.thicknessTexture)), e.attenuationDistance = s.attenuationDistance || 1 / 0;
464
- const a = s.attenuationColor || [1, 1, 1];
465
- return e.attenuationColor = new ve().setRGB(a[0], a[1], a[2], Re), Promise.all(i);
466
- }
467
- }
468
- class xs {
469
- constructor(t) {
470
- this.parser = t, this.name = k.KHR_MATERIALS_IOR;
471
- }
472
- getMaterialType(t) {
473
- const r = this.parser.json.materials[t];
474
- return !r.extensions || !r.extensions[this.name] ? null : ge;
475
- }
476
- extendMaterialParams(t, e) {
477
- const n = this.parser.json.materials[t];
478
- if (!n.extensions || !n.extensions[this.name])
479
- return Promise.resolve();
480
- const i = n.extensions[this.name];
481
- return e.ior = i.ior !== void 0 ? i.ior : 1.5, Promise.resolve();
482
- }
483
- }
484
- class ws {
485
- constructor(t) {
486
- this.parser = t, this.name = k.KHR_MATERIALS_SPECULAR;
487
- }
488
- getMaterialType(t) {
489
- const r = this.parser.json.materials[t];
490
- return !r.extensions || !r.extensions[this.name] ? null : ge;
491
- }
492
- extendMaterialParams(t, e) {
493
- const r = this.parser, n = r.json.materials[t];
494
- if (!n.extensions || !n.extensions[this.name])
495
- return Promise.resolve();
496
- const i = [], s = n.extensions[this.name];
497
- e.specularIntensity = s.specularFactor !== void 0 ? s.specularFactor : 1, s.specularTexture !== void 0 && i.push(r.assignTexture(e, "specularIntensityMap", s.specularTexture));
498
- const a = s.specularColorFactor || [1, 1, 1];
499
- return e.specularColor = new ve().setRGB(a[0], a[1], a[2], Re), s.specularColorTexture !== void 0 && i.push(r.assignTexture(e, "specularColorMap", s.specularColorTexture, We)), Promise.all(i);
500
- }
501
- }
502
- class Rs {
503
- constructor(t) {
504
- this.parser = t, this.name = k.EXT_MATERIALS_BUMP;
505
- }
506
- getMaterialType(t) {
507
- const r = this.parser.json.materials[t];
508
- return !r.extensions || !r.extensions[this.name] ? null : ge;
509
- }
510
- extendMaterialParams(t, e) {
511
- const r = this.parser, n = r.json.materials[t];
512
- if (!n.extensions || !n.extensions[this.name])
513
- return Promise.resolve();
514
- const i = [], s = n.extensions[this.name];
515
- return e.bumpScale = s.bumpFactor !== void 0 ? s.bumpFactor : 1, s.bumpTexture !== void 0 && i.push(r.assignTexture(e, "bumpMap", s.bumpTexture)), Promise.all(i);
516
- }
517
- }
518
- class Ss {
519
- constructor(t) {
520
- this.parser = t, this.name = k.KHR_MATERIALS_ANISOTROPY;
521
- }
522
- getMaterialType(t) {
523
- const r = this.parser.json.materials[t];
524
- return !r.extensions || !r.extensions[this.name] ? null : ge;
525
- }
526
- extendMaterialParams(t, e) {
527
- const r = this.parser, n = r.json.materials[t];
528
- if (!n.extensions || !n.extensions[this.name])
529
- return Promise.resolve();
530
- const i = [], s = n.extensions[this.name];
531
- return s.anisotropyStrength !== void 0 && (e.anisotropy = s.anisotropyStrength), s.anisotropyRotation !== void 0 && (e.anisotropyRotation = s.anisotropyRotation), s.anisotropyTexture !== void 0 && i.push(r.assignTexture(e, "anisotropyMap", s.anisotropyTexture)), Promise.all(i);
532
- }
533
- }
534
- class ys {
535
- constructor(t) {
536
- this.parser = t, this.name = k.KHR_TEXTURE_BASISU;
537
- }
538
- loadTexture(t) {
539
- const e = this.parser, r = e.json, n = r.textures[t];
540
- if (!n.extensions || !n.extensions[this.name])
541
- return null;
542
- const i = n.extensions[this.name], s = e.options.ktx2Loader;
543
- if (!s) {
544
- if (r.extensionsRequired && r.extensionsRequired.indexOf(this.name) >= 0)
545
- throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");
546
- return null;
547
- }
548
- return e.loadTextureImage(t, i.source, s);
549
- }
550
- }
551
- class As {
552
- constructor(t) {
553
- this.parser = t, this.name = k.EXT_TEXTURE_WEBP;
554
- }
555
- loadTexture(t) {
556
- const e = this.name, r = this.parser, n = r.json, i = n.textures[t];
557
- if (!i.extensions || !i.extensions[e])
558
- return null;
559
- const s = i.extensions[e], a = n.images[s.source];
560
- let o = r.textureLoader;
561
- if (a.uri) {
562
- const c = r.options.manager.getHandler(a.uri);
563
- c !== null && (o = c);
564
- }
565
- return r.loadTextureImage(t, s.source, o);
566
- }
567
- }
568
- class Es {
569
- constructor(t) {
570
- this.parser = t, this.name = k.EXT_TEXTURE_AVIF;
571
- }
572
- loadTexture(t) {
573
- const e = this.name, r = this.parser, n = r.json, i = n.textures[t];
574
- if (!i.extensions || !i.extensions[e])
575
- return null;
576
- const s = i.extensions[e], a = n.images[s.source];
577
- let o = r.textureLoader;
578
- if (a.uri) {
579
- const c = r.options.manager.getHandler(a.uri);
580
- c !== null && (o = c);
581
- }
582
- return r.loadTextureImage(t, s.source, o);
583
- }
584
- }
585
- class Ls {
586
- constructor(t) {
587
- this.name = k.EXT_MESHOPT_COMPRESSION, this.parser = t;
588
- }
589
- loadBufferView(t) {
590
- const e = this.parser.json, r = e.bufferViews[t];
591
- if (r.extensions && r.extensions[this.name]) {
592
- const n = r.extensions[this.name], i = this.parser.getDependency("buffer", n.buffer), s = this.parser.options.meshoptDecoder;
593
- if (!s || !s.supported) {
594
- if (e.extensionsRequired && e.extensionsRequired.indexOf(this.name) >= 0)
595
- throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");
596
- return null;
597
- }
598
- return i.then(function(a) {
599
- const o = n.byteOffset || 0, c = n.byteLength || 0, u = n.count, l = n.byteStride, f = new Uint8Array(a, o, c);
600
- return s.decodeGltfBufferAsync ? s.decodeGltfBufferAsync(u, l, f, n.mode, n.filter).then(function(h) {
601
- return h.buffer;
602
- }) : s.ready.then(function() {
603
- const h = new ArrayBuffer(u * l);
604
- return s.decodeGltfBuffer(new Uint8Array(h), u, l, f, n.mode, n.filter), h;
605
- });
606
- });
607
- } else
608
- return null;
609
- }
610
- }
611
- class Ms {
612
- constructor(t) {
613
- this.name = k.EXT_MESH_GPU_INSTANCING, this.parser = t;
614
- }
615
- createNodeMesh(t) {
616
- const e = this.parser.json, r = e.nodes[t];
617
- if (!r.extensions || !r.extensions[this.name] || r.mesh === void 0)
618
- return null;
619
- const n = e.meshes[r.mesh];
620
- for (const c of n.primitives)
621
- if (c.mode !== ce.TRIANGLES && c.mode !== ce.TRIANGLE_STRIP && c.mode !== ce.TRIANGLE_FAN && c.mode !== void 0)
622
- return null;
623
- const s = r.extensions[this.name].attributes, a = [], o = {};
624
- for (const c in s)
625
- a.push(this.parser.getDependency("accessor", s[c]).then((u) => (o[c] = u, o[c])));
626
- return a.length < 1 ? null : (a.push(this.parser.createNodeMesh(t)), Promise.all(a).then((c) => {
627
- const u = c.pop(), l = u.isGroup ? u.children : [u], f = c[0].count, h = [];
628
- for (const T of l) {
629
- const m = new Qe(), b = new Oe(), S = new $t(), P = new Oe(1, 1, 1), D = new vn(T.geometry, T.material, f);
630
- for (let y = 0; y < f; y++)
631
- o.TRANSLATION && b.fromBufferAttribute(o.TRANSLATION, y), o.ROTATION && S.fromBufferAttribute(o.ROTATION, y), o.SCALE && P.fromBufferAttribute(o.SCALE, y), D.setMatrixAt(y, m.compose(b, S, P));
632
- for (const y in o)
633
- if (y === "_COLOR_0") {
634
- const F = o[y];
635
- D.instanceColor = new kn(F.array, F.itemSize, F.normalized);
636
- } else y !== "TRANSLATION" && y !== "ROTATION" && y !== "SCALE" && T.geometry.setAttribute(y, o[y]);
637
- qt.prototype.copy.call(D, T), this.parser.assignFinalMaterial(D), h.push(D);
638
- }
639
- return u.isGroup ? (u.clear(), u.add(...h), u) : h[0];
640
- }));
641
- }
642
- }
643
- const en = "glTF", je = 12, Ut = { JSON: 1313821514, BIN: 5130562 };
644
- class Is {
645
- constructor(t) {
646
- this.name = k.KHR_BINARY_GLTF, this.content = null, this.body = null;
647
- const e = new DataView(t, 0, je), r = new TextDecoder();
648
- if (this.header = {
649
- magic: r.decode(new Uint8Array(t.slice(0, 4))),
650
- version: e.getUint32(4, !0),
651
- length: e.getUint32(8, !0)
652
- }, this.header.magic !== en)
653
- throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");
654
- if (this.header.version < 2)
655
- throw new Error("THREE.GLTFLoader: Legacy binary file detected.");
656
- const n = this.header.length - je, i = new DataView(t, je);
657
- let s = 0;
658
- for (; s < n; ) {
659
- const a = i.getUint32(s, !0);
660
- s += 4;
661
- const o = i.getUint32(s, !0);
662
- if (s += 4, o === Ut.JSON) {
663
- const c = new Uint8Array(t, je + s, a);
664
- this.content = r.decode(c);
665
- } else if (o === Ut.BIN) {
666
- const c = je + s;
667
- this.body = t.slice(c, c + a);
668
- }
669
- s += a;
670
- }
671
- if (this.content === null)
672
- throw new Error("THREE.GLTFLoader: JSON content not found.");
673
- }
674
- }
675
- class vs {
676
- constructor(t, e) {
677
- if (!e)
678
- throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");
679
- this.name = k.KHR_DRACO_MESH_COMPRESSION, this.json = t, this.dracoLoader = e, this.dracoLoader.preload();
680
- }
681
- decodePrimitive(t, e) {
682
- const r = this.json, n = this.dracoLoader, i = t.extensions[this.name].bufferView, s = t.extensions[this.name].attributes, a = {}, o = {}, c = {};
683
- for (const u in s) {
684
- const l = xt[u] || u.toLowerCase();
685
- a[l] = s[u];
686
- }
687
- for (const u in t.attributes) {
688
- const l = xt[u] || u.toLowerCase();
689
- if (s[u] !== void 0) {
690
- const f = r.accessors[t.attributes[u]], h = De[f.componentType];
691
- c[l] = h.name, o[l] = f.normalized === !0;
692
- }
693
- }
694
- return e.getDependency("bufferView", i).then(function(u) {
695
- return new Promise(function(l, f) {
696
- n.decodeDracoFile(u, function(h) {
697
- for (const T in h.attributes) {
698
- const m = h.attributes[T], b = o[T];
699
- b !== void 0 && (m.normalized = b);
700
- }
701
- l(h);
702
- }, a, c, Re, f);
703
- });
704
- });
705
- }
706
- }
707
- class ks {
708
- constructor() {
709
- this.name = k.KHR_TEXTURE_TRANSFORM;
710
- }
711
- extendTexture(t, e) {
712
- 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;
713
- }
714
- }
715
- class Ns {
716
- constructor() {
717
- this.name = k.KHR_MESH_QUANTIZATION;
718
- }
719
- }
720
- class tn extends os {
721
- constructor(t, e, r, n) {
722
- super(t, e, r, n);
723
- }
724
- copySampleValue_(t) {
725
- const e = this.resultBuffer, r = this.sampleValues, n = this.valueSize, i = t * n * 3 + n;
726
- for (let s = 0; s !== n; s++)
727
- e[s] = r[i + s];
728
- return e;
729
- }
730
- interpolate_(t, e, r, n) {
731
- const i = this.resultBuffer, s = this.sampleValues, a = this.valueSize, o = a * 2, c = a * 3, u = n - e, l = (r - e) / u, f = l * l, h = f * l, T = t * c, m = T - c, b = -2 * h + 3 * f, S = h - f, P = 1 - b, D = S - f + l;
732
- for (let y = 0; y !== a; y++) {
733
- const F = s[m + y + a], C = s[m + y + o] * u, H = s[T + y + a], B = s[T + y] * u;
734
- i[y] = P * F + D * C + b * H + S * B;
735
- }
736
- return i;
737
- }
738
- }
739
- const Cs = new $t();
740
- class Os extends tn {
741
- interpolate_(t, e, r, n) {
742
- const i = super.interpolate_(t, e, r, n);
743
- return Cs.fromArray(i).normalize().toArray(i), i;
744
- }
745
- }
746
- const ce = {
747
- POINTS: 0,
748
- LINES: 1,
749
- LINE_LOOP: 2,
750
- LINE_STRIP: 3,
751
- TRIANGLES: 4,
752
- TRIANGLE_STRIP: 5,
753
- TRIANGLE_FAN: 6
754
- }, De = {
755
- 5120: Int8Array,
756
- 5121: Uint8Array,
757
- 5122: Int16Array,
758
- 5123: Uint16Array,
759
- 5125: Uint32Array,
760
- 5126: Float32Array
761
- }, Ht = {
762
- 9728: Jt,
763
- 9729: bt,
764
- 9984: Un,
765
- 9985: Pn,
766
- 9986: Fn,
767
- 9987: Yt
768
- }, Bt = {
769
- 33071: Bn,
770
- 33648: Hn,
771
- 10497: _t
772
- }, ft = {
773
- SCALAR: 1,
774
- VEC2: 2,
775
- VEC3: 3,
776
- VEC4: 4,
777
- MAT2: 4,
778
- MAT3: 9,
779
- MAT4: 16
780
- }, xt = {
781
- POSITION: "position",
782
- NORMAL: "normal",
783
- TANGENT: "tangent",
784
- TEXCOORD_0: "uv",
785
- TEXCOORD_1: "uv1",
786
- TEXCOORD_2: "uv2",
787
- TEXCOORD_3: "uv3",
788
- COLOR_0: "color",
789
- WEIGHTS_0: "skinWeight",
790
- JOINTS_0: "skinIndex"
791
- }, Se = {
792
- scale: "scale",
793
- translation: "position",
794
- rotation: "quaternion",
795
- weights: "morphTargetInfluences"
796
- }, Ds = {
797
- CUBICSPLINE: void 0,
798
- // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
799
- // keyframe track will be initialized with a default interpolation type, then modified.
800
- LINEAR: Zt,
801
- STEP: rs
802
- }, ht = {
803
- OPAQUE: "OPAQUE",
804
- MASK: "MASK",
805
- BLEND: "BLEND"
806
- };
807
- function Fs(d) {
808
- return d.DefaultMaterial === void 0 && (d.DefaultMaterial = new Qt({
809
- color: 16777215,
810
- emissive: 0,
811
- metalness: 1,
812
- roughness: 1,
813
- transparent: !1,
814
- depthTest: !0,
815
- side: is
816
- })), d.DefaultMaterial;
817
- }
818
- function Ie(d, t, e) {
819
- for (const r in e.extensions)
820
- d[r] === void 0 && (t.userData.gltfExtensions = t.userData.gltfExtensions || {}, t.userData.gltfExtensions[r] = e.extensions[r]);
821
- }
822
- function me(d, t) {
823
- t.extras !== void 0 && (typeof t.extras == "object" ? Object.assign(d.userData, t.extras) : console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, " + t.extras));
824
- }
825
- function Ps(d, t, e) {
826
- let r = !1, n = !1, i = !1;
827
- for (let c = 0, u = t.length; c < u; c++) {
828
- const l = t[c];
829
- if (l.POSITION !== void 0 && (r = !0), l.NORMAL !== void 0 && (n = !0), l.COLOR_0 !== void 0 && (i = !0), r && n && i) break;
830
- }
831
- if (!r && !n && !i) return Promise.resolve(d);
832
- const s = [], a = [], o = [];
833
- for (let c = 0, u = t.length; c < u; c++) {
834
- const l = t[c];
835
- if (r) {
836
- const f = l.POSITION !== void 0 ? e.getDependency("accessor", l.POSITION) : d.attributes.position;
837
- s.push(f);
838
- }
839
- if (n) {
840
- const f = l.NORMAL !== void 0 ? e.getDependency("accessor", l.NORMAL) : d.attributes.normal;
841
- a.push(f);
842
- }
843
- if (i) {
844
- const f = l.COLOR_0 !== void 0 ? e.getDependency("accessor", l.COLOR_0) : d.attributes.color;
845
- o.push(f);
846
- }
847
- }
848
- return Promise.all([
849
- Promise.all(s),
850
- Promise.all(a),
851
- Promise.all(o)
852
- ]).then(function(c) {
853
- const u = c[0], l = c[1], f = c[2];
854
- return r && (d.morphAttributes.position = u), n && (d.morphAttributes.normal = l), i && (d.morphAttributes.color = f), d.morphTargetsRelative = !0, d;
855
- });
856
- }
857
- function Us(d, t) {
858
- if (d.updateMorphTargets(), t.weights !== void 0)
859
- for (let e = 0, r = t.weights.length; e < r; e++)
860
- d.morphTargetInfluences[e] = t.weights[e];
861
- if (t.extras && Array.isArray(t.extras.targetNames)) {
862
- const e = t.extras.targetNames;
863
- if (d.morphTargetInfluences.length === e.length) {
864
- d.morphTargetDictionary = {};
865
- for (let r = 0, n = e.length; r < n; r++)
866
- d.morphTargetDictionary[e[r]] = r;
867
- } else
868
- console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.");
869
- }
870
- }
871
- function Hs(d) {
872
- let t;
873
- const e = d.extensions && d.extensions[k.KHR_DRACO_MESH_COMPRESSION];
874
- if (e ? t = "draco:" + e.bufferView + ":" + e.indices + ":" + pt(e.attributes) : t = d.indices + ":" + pt(d.attributes) + ":" + d.mode, d.targets !== void 0)
875
- for (let r = 0, n = d.targets.length; r < n; r++)
876
- t += ":" + pt(d.targets[r]);
877
- return t;
878
- }
879
- function pt(d) {
880
- let t = "";
881
- const e = Object.keys(d).sort();
882
- for (let r = 0, n = e.length; r < n; r++)
883
- t += e[r] + ":" + d[e[r]] + ";";
884
- return t;
885
- }
886
- function wt(d) {
887
- switch (d) {
888
- case Int8Array:
889
- return 1 / 127;
890
- case Uint8Array:
891
- return 1 / 255;
892
- case Int16Array:
893
- return 1 / 32767;
894
- case Uint16Array:
895
- return 1 / 65535;
896
- default:
897
- throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.");
898
- }
899
- }
900
- function Bs(d) {
901
- return d.search(/\.jpe?g($|\?)/i) > 0 || d.search(/^data\:image\/jpeg/) === 0 ? "image/jpeg" : d.search(/\.webp($|\?)/i) > 0 || d.search(/^data\:image\/webp/) === 0 ? "image/webp" : d.search(/\.ktx2($|\?)/i) > 0 || d.search(/^data\:image\/ktx2/) === 0 ? "image/ktx2" : "image/png";
902
- }
903
- const Gs = new Qe();
904
- class js {
905
- constructor(t = {}, e = {}) {
906
- this.json = t, this.extensions = {}, this.plugins = {}, this.options = e, this.cache = new ls(), 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 = {};
907
- let r = !1, n = -1, i = !1, s = -1;
908
- if (typeof navigator < "u") {
909
- const a = navigator.userAgent;
910
- r = /^((?!chrome|android).)*safari/i.test(a) === !0;
911
- const o = a.match(/Version\/(\d+)/);
912
- n = r && o ? parseInt(o[1], 10) : -1, i = a.indexOf("Firefox") > -1, s = i ? a.match(/Firefox\/([0-9]+)\./)[1] : -1;
913
- }
914
- typeof createImageBitmap > "u" || r && n < 17 || i && s < 98 ? this.textureLoader = new Nn(this.options.manager) : this.textureLoader = new Cn(this.options.manager), this.textureLoader.setCrossOrigin(this.options.crossOrigin), this.textureLoader.setRequestHeader(this.options.requestHeader), this.fileLoader = new Xt(this.options.manager), this.fileLoader.setResponseType("arraybuffer"), this.options.crossOrigin === "use-credentials" && this.fileLoader.setWithCredentials(!0);
915
- }
916
- setExtensions(t) {
917
- this.extensions = t;
918
- }
919
- setPlugins(t) {
920
- this.plugins = t;
921
- }
922
- parse(t, e) {
923
- const r = this, n = this.json, i = this.extensions;
924
- this.cache.removeAll(), this.nodeCache = {}, this._invokeAll(function(s) {
925
- return s._markDefs && s._markDefs();
926
- }), Promise.all(this._invokeAll(function(s) {
927
- return s.beforeRoot && s.beforeRoot();
928
- })).then(function() {
929
- return Promise.all([
930
- r.getDependencies("scene"),
931
- r.getDependencies("animation"),
932
- r.getDependencies("camera")
933
- ]);
934
- }).then(function(s) {
935
- const a = {
936
- scene: s[0][n.scene || 0],
937
- scenes: s[0],
938
- animations: s[1],
939
- cameras: s[2],
940
- asset: n.asset,
941
- parser: r,
942
- userData: {}
943
- };
944
- return Ie(i, a, n), me(a, n), Promise.all(r._invokeAll(function(o) {
945
- return o.afterRoot && o.afterRoot(a);
946
- })).then(function() {
947
- for (const o of a.scenes)
948
- o.updateMatrixWorld();
949
- t(a);
950
- });
951
- }).catch(e);
952
- }
953
- /**
954
- * Marks the special nodes/meshes in json for efficient parse.
955
- *
956
- * @private
957
- */
958
- _markDefs() {
959
- const t = this.json.nodes || [], e = this.json.skins || [], r = this.json.meshes || [];
960
- for (let n = 0, i = e.length; n < i; n++) {
961
- const s = e[n].joints;
962
- for (let a = 0, o = s.length; a < o; a++)
963
- t[s[a]].isBone = !0;
964
- }
965
- for (let n = 0, i = t.length; n < i; n++) {
966
- const s = t[n];
967
- s.mesh !== void 0 && (this._addNodeRef(this.meshCache, s.mesh), s.skin !== void 0 && (r[s.mesh].isSkinnedMesh = !0)), s.camera !== void 0 && this._addNodeRef(this.cameraCache, s.camera);
968
- }
969
- }
970
- /**
971
- * Counts references to shared node / Object3D resources. These resources
972
- * can be reused, or "instantiated", at multiple nodes in the scene
973
- * hierarchy. Mesh, Camera, and Light instances are instantiated and must
974
- * be marked. Non-scenegraph resources (like Materials, Geometries, and
975
- * Textures) can be reused directly and are not marked here.
976
- *
977
- * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
978
- *
979
- * @private
980
- * @param {Object} cache
981
- * @param {Object3D} index
982
- */
983
- _addNodeRef(t, e) {
984
- e !== void 0 && (t.refs[e] === void 0 && (t.refs[e] = t.uses[e] = 0), t.refs[e]++);
985
- }
986
- /**
987
- * Returns a reference to a shared resource, cloning it if necessary.
988
- *
989
- * @private
990
- * @param {Object} cache
991
- * @param {number} index
992
- * @param {Object} object
993
- * @return {Object}
994
- */
995
- _getNodeRef(t, e, r) {
996
- if (t.refs[e] <= 1) return r;
997
- const n = r.clone(), i = (s, a) => {
998
- const o = this.associations.get(s);
999
- o != null && this.associations.set(a, o);
1000
- for (const [c, u] of s.children.entries())
1001
- i(u, a.children[c]);
1002
- };
1003
- return i(r, n), n.name += "_instance_" + t.uses[e]++, n;
1004
- }
1005
- _invokeOne(t) {
1006
- const e = Object.values(this.plugins);
1007
- e.push(this);
1008
- for (let r = 0; r < e.length; r++) {
1009
- const n = t(e[r]);
1010
- if (n) return n;
1011
- }
1012
- return null;
1013
- }
1014
- _invokeAll(t) {
1015
- const e = Object.values(this.plugins);
1016
- e.unshift(this);
1017
- const r = [];
1018
- for (let n = 0; n < e.length; n++) {
1019
- const i = t(e[n]);
1020
- i && r.push(i);
1021
- }
1022
- return r;
1023
- }
1024
- /**
1025
- * Requests the specified dependency asynchronously, with caching.
1026
- *
1027
- * @private
1028
- * @param {string} type
1029
- * @param {number} index
1030
- * @return {Promise<Object3D|Material|Texture|AnimationClip|ArrayBuffer|Object>}
1031
- */
1032
- getDependency(t, e) {
1033
- const r = t + ":" + e;
1034
- let n = this.cache.get(r);
1035
- if (!n) {
1036
- switch (t) {
1037
- case "scene":
1038
- n = this.loadScene(e);
1039
- break;
1040
- case "node":
1041
- n = this._invokeOne(function(i) {
1042
- return i.loadNode && i.loadNode(e);
1043
- });
1044
- break;
1045
- case "mesh":
1046
- n = this._invokeOne(function(i) {
1047
- return i.loadMesh && i.loadMesh(e);
1048
- });
1049
- break;
1050
- case "accessor":
1051
- n = this.loadAccessor(e);
1052
- break;
1053
- case "bufferView":
1054
- n = this._invokeOne(function(i) {
1055
- return i.loadBufferView && i.loadBufferView(e);
1056
- });
1057
- break;
1058
- case "buffer":
1059
- n = this.loadBuffer(e);
1060
- break;
1061
- case "material":
1062
- n = this._invokeOne(function(i) {
1063
- return i.loadMaterial && i.loadMaterial(e);
1064
- });
1065
- break;
1066
- case "texture":
1067
- n = this._invokeOne(function(i) {
1068
- return i.loadTexture && i.loadTexture(e);
1069
- });
1070
- break;
1071
- case "skin":
1072
- n = this.loadSkin(e);
1073
- break;
1074
- case "animation":
1075
- n = this._invokeOne(function(i) {
1076
- return i.loadAnimation && i.loadAnimation(e);
1077
- });
1078
- break;
1079
- case "camera":
1080
- n = this.loadCamera(e);
1081
- break;
1082
- default:
1083
- if (n = this._invokeOne(function(i) {
1084
- return i != this && i.getDependency && i.getDependency(t, e);
1085
- }), !n)
1086
- throw new Error("Unknown type: " + t);
1087
- break;
1088
- }
1089
- this.cache.add(r, n);
1090
- }
1091
- return n;
1092
- }
1093
- /**
1094
- * Requests all dependencies of the specified type asynchronously, with caching.
1095
- *
1096
- * @private
1097
- * @param {string} type
1098
- * @return {Promise<Array<Object>>}
1099
- */
1100
- getDependencies(t) {
1101
- let e = this.cache.get(t);
1102
- if (!e) {
1103
- const r = this, n = this.json[t + (t === "mesh" ? "es" : "s")] || [];
1104
- e = Promise.all(n.map(function(i, s) {
1105
- return r.getDependency(t, s);
1106
- })), this.cache.add(t, e);
1107
- }
1108
- return e;
1109
- }
1110
- /**
1111
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1112
- *
1113
- * @private
1114
- * @param {number} bufferIndex
1115
- * @return {Promise<ArrayBuffer>}
1116
- */
1117
- loadBuffer(t) {
1118
- const e = this.json.buffers[t], r = this.fileLoader;
1119
- if (e.type && e.type !== "arraybuffer")
1120
- throw new Error("THREE.GLTFLoader: " + e.type + " buffer type is not supported.");
1121
- if (e.uri === void 0 && t === 0)
1122
- return Promise.resolve(this.extensions[k.KHR_BINARY_GLTF].body);
1123
- const n = this.options;
1124
- return new Promise(function(i, s) {
1125
- r.load(Ke.resolveURL(e.uri, n.path), i, void 0, function() {
1126
- s(new Error('THREE.GLTFLoader: Failed to load buffer "' + e.uri + '".'));
1127
- });
1128
- });
1129
- }
1130
- /**
1131
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
1132
- *
1133
- * @private
1134
- * @param {number} bufferViewIndex
1135
- * @return {Promise<ArrayBuffer>}
1136
- */
1137
- loadBufferView(t) {
1138
- const e = this.json.bufferViews[t];
1139
- return this.getDependency("buffer", e.buffer).then(function(r) {
1140
- const n = e.byteLength || 0, i = e.byteOffset || 0;
1141
- return r.slice(i, i + n);
1142
- });
1143
- }
1144
- /**
1145
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
1146
- *
1147
- * @private
1148
- * @param {number} accessorIndex
1149
- * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
1150
- */
1151
- loadAccessor(t) {
1152
- const e = this, r = this.json, n = this.json.accessors[t];
1153
- if (n.bufferView === void 0 && n.sparse === void 0) {
1154
- const s = ft[n.type], a = De[n.componentType], o = n.normalized === !0, c = new a(n.count * s);
1155
- return Promise.resolve(new ut(c, s, o));
1156
- }
1157
- const i = [];
1158
- 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(s) {
1159
- const a = s[0], o = ft[n.type], c = De[n.componentType], u = c.BYTES_PER_ELEMENT, l = u * o, f = n.byteOffset || 0, h = n.bufferView !== void 0 ? r.bufferViews[n.bufferView].byteStride : void 0, T = n.normalized === !0;
1160
- let m, b;
1161
- if (h && h !== l) {
1162
- const S = Math.floor(f / h), P = "InterleavedBuffer:" + n.bufferView + ":" + n.componentType + ":" + S + ":" + n.count;
1163
- let D = e.cache.get(P);
1164
- D || (m = new c(a, S * h, n.count * h / u), D = new On(m, h / u), e.cache.add(P, D)), b = new Dn(D, o, f % h / u, T);
1165
- } else
1166
- a === null ? m = new c(n.count * o) : m = new c(a, f, n.count * o), b = new ut(m, o, T);
1167
- if (n.sparse !== void 0) {
1168
- const S = ft.SCALAR, P = De[n.sparse.indices.componentType], D = n.sparse.indices.byteOffset || 0, y = n.sparse.values.byteOffset || 0, F = new P(s[1], D, n.sparse.count * S), C = new c(s[2], y, n.sparse.count * o);
1169
- a !== null && (b = new ut(b.array.slice(), b.itemSize, b.normalized)), b.normalized = !1;
1170
- for (let H = 0, B = F.length; H < B; H++) {
1171
- const O = F[H];
1172
- if (b.setX(O, C[H * o]), o >= 2 && b.setY(O, C[H * o + 1]), o >= 3 && b.setZ(O, C[H * o + 2]), o >= 4 && b.setW(O, C[H * o + 3]), o >= 5) throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.");
1173
- }
1174
- b.normalized = T;
1175
- }
1176
- return b;
1177
- });
1178
- }
1179
- /**
1180
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
1181
- *
1182
- * @private
1183
- * @param {number} textureIndex
1184
- * @return {Promise<?Texture>}
1185
- */
1186
- loadTexture(t) {
1187
- const e = this.json, r = this.options, i = e.textures[t].source, s = e.images[i];
1188
- let a = this.textureLoader;
1189
- if (s.uri) {
1190
- const o = r.manager.getHandler(s.uri);
1191
- o !== null && (a = o);
1192
- }
1193
- return this.loadTextureImage(t, i, a);
1194
- }
1195
- loadTextureImage(t, e, r) {
1196
- const n = this, i = this.json, s = i.textures[t], a = i.images[e], o = (a.uri || a.bufferView) + ":" + s.sampler;
1197
- if (this.textureCache[o])
1198
- return this.textureCache[o];
1199
- const c = this.loadImageSource(e, r).then(function(u) {
1200
- u.flipY = !1, u.name = s.name || a.name || "", u.name === "" && typeof a.uri == "string" && a.uri.startsWith("data:image/") === !1 && (u.name = a.uri);
1201
- const f = (i.samplers || {})[s.sampler] || {};
1202
- return u.magFilter = Ht[f.magFilter] || bt, u.minFilter = Ht[f.minFilter] || Yt, u.wrapS = Bt[f.wrapS] || _t, u.wrapT = Bt[f.wrapT] || _t, u.generateMipmaps = !u.isCompressedTexture && u.minFilter !== Jt && u.minFilter !== bt, n.associations.set(u, { textures: t }), u;
1203
- }).catch(function() {
1204
- return null;
1205
- });
1206
- return this.textureCache[o] = c, c;
1207
- }
1208
- loadImageSource(t, e) {
1209
- const r = this, n = this.json, i = this.options;
1210
- if (this.sourceCache[t] !== void 0)
1211
- return this.sourceCache[t].then((l) => l.clone());
1212
- const s = n.images[t], a = self.URL || self.webkitURL;
1213
- let o = s.uri || "", c = !1;
1214
- if (s.bufferView !== void 0)
1215
- o = r.getDependency("bufferView", s.bufferView).then(function(l) {
1216
- c = !0;
1217
- const f = new Blob([l], { type: s.mimeType });
1218
- return o = a.createObjectURL(f), o;
1219
- });
1220
- else if (s.uri === void 0)
1221
- throw new Error("THREE.GLTFLoader: Image " + t + " is missing URI and bufferView");
1222
- const u = Promise.resolve(o).then(function(l) {
1223
- return new Promise(function(f, h) {
1224
- let T = f;
1225
- e.isImageBitmapLoader === !0 && (T = function(m) {
1226
- const b = new Nt(m);
1227
- b.needsUpdate = !0, f(b);
1228
- }), e.load(Ke.resolveURL(l, i.path), T, void 0, h);
1229
- });
1230
- }).then(function(l) {
1231
- return c === !0 && a.revokeObjectURL(o), me(l, s), l.userData.mimeType = s.mimeType || Bs(s.uri), l;
1232
- }).catch(function(l) {
1233
- throw console.error("THREE.GLTFLoader: Couldn't load texture", o), l;
1234
- });
1235
- return this.sourceCache[t] = u, u;
1236
- }
1237
- /**
1238
- * Asynchronously assigns a texture to the given material parameters.
1239
- *
1240
- * @private
1241
- * @param {Object} materialParams
1242
- * @param {string} mapName
1243
- * @param {Object} mapDef
1244
- * @param {string} [colorSpace]
1245
- * @return {Promise<Texture>}
1246
- */
1247
- assignTexture(t, e, r, n) {
1248
- const i = this;
1249
- return this.getDependency("texture", r.index).then(function(s) {
1250
- if (!s) return null;
1251
- if (r.texCoord !== void 0 && r.texCoord > 0 && (s = s.clone(), s.channel = r.texCoord), i.extensions[k.KHR_TEXTURE_TRANSFORM]) {
1252
- const a = r.extensions !== void 0 ? r.extensions[k.KHR_TEXTURE_TRANSFORM] : void 0;
1253
- if (a) {
1254
- const o = i.associations.get(s);
1255
- s = i.extensions[k.KHR_TEXTURE_TRANSFORM].extendTexture(s, a), i.associations.set(s, o);
1256
- }
1257
- }
1258
- return n !== void 0 && (s.colorSpace = n), t[e] = s, s;
1259
- });
1260
- }
1261
- /**
1262
- * Assigns final material to a Mesh, Line, or Points instance. The instance
1263
- * already has a material (generated from the glTF material options alone)
1264
- * but reuse of the same glTF material may require multiple threejs materials
1265
- * to accommodate different primitive types, defines, etc. New materials will
1266
- * be created if necessary, and reused from a cache.
1267
- *
1268
- * @private
1269
- * @param {Object3D} mesh Mesh, Line, or Points instance.
1270
- */
1271
- assignFinalMaterial(t) {
1272
- const e = t.geometry;
1273
- let r = t.material;
1274
- const n = e.attributes.tangent === void 0, i = e.attributes.color !== void 0, s = e.attributes.normal === void 0;
1275
- if (t.isPoints) {
1276
- const a = "PointsMaterial:" + r.uuid;
1277
- let o = this.cache.get(a);
1278
- o || (o = new Gn(), lt.prototype.copy.call(o, r), o.color.copy(r.color), o.map = r.map, o.sizeAttenuation = !1, this.cache.add(a, o)), r = o;
1279
- } else if (t.isLine) {
1280
- const a = "LineBasicMaterial:" + r.uuid;
1281
- let o = this.cache.get(a);
1282
- o || (o = new jn(), lt.prototype.copy.call(o, r), o.color.copy(r.color), o.map = r.map, this.cache.add(a, o)), r = o;
1283
- }
1284
- if (n || i || s) {
1285
- let a = "ClonedMaterial:" + r.uuid + ":";
1286
- n && (a += "derivative-tangents:"), i && (a += "vertex-colors:"), s && (a += "flat-shading:");
1287
- let o = this.cache.get(a);
1288
- o || (o = r.clone(), i && (o.vertexColors = !0), s && (o.flatShading = !0), n && (o.normalScale && (o.normalScale.y *= -1), o.clearcoatNormalScale && (o.clearcoatNormalScale.y *= -1)), this.cache.add(a, o), this.associations.set(o, this.associations.get(r))), r = o;
1289
- }
1290
- t.material = r;
1291
- }
1292
- getMaterialType() {
1293
- return Qt;
1294
- }
1295
- /**
1296
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
1297
- *
1298
- * @private
1299
- * @param {number} materialIndex
1300
- * @return {Promise<Material>}
1301
- */
1302
- loadMaterial(t) {
1303
- const e = this, r = this.json, n = this.extensions, i = r.materials[t];
1304
- let s;
1305
- const a = {}, o = i.extensions || {}, c = [];
1306
- if (o[k.KHR_MATERIALS_UNLIT]) {
1307
- const l = n[k.KHR_MATERIALS_UNLIT];
1308
- s = l.getMaterialType(), c.push(l.extendParams(a, i, e));
1309
- } else {
1310
- const l = i.pbrMetallicRoughness || {};
1311
- if (a.color = new ve(1, 1, 1), a.opacity = 1, Array.isArray(l.baseColorFactor)) {
1312
- const f = l.baseColorFactor;
1313
- a.color.setRGB(f[0], f[1], f[2], Re), a.opacity = f[3];
1314
- }
1315
- l.baseColorTexture !== void 0 && c.push(e.assignTexture(a, "map", l.baseColorTexture, We)), a.metalness = l.metallicFactor !== void 0 ? l.metallicFactor : 1, a.roughness = l.roughnessFactor !== void 0 ? l.roughnessFactor : 1, l.metallicRoughnessTexture !== void 0 && (c.push(e.assignTexture(a, "metalnessMap", l.metallicRoughnessTexture)), c.push(e.assignTexture(a, "roughnessMap", l.metallicRoughnessTexture))), s = this._invokeOne(function(f) {
1316
- return f.getMaterialType && f.getMaterialType(t);
1317
- }), c.push(Promise.all(this._invokeAll(function(f) {
1318
- return f.extendMaterialParams && f.extendMaterialParams(t, a);
1319
- })));
1320
- }
1321
- i.doubleSided === !0 && (a.side = Vn);
1322
- const u = i.alphaMode || ht.OPAQUE;
1323
- if (u === ht.BLEND ? (a.transparent = !0, a.depthWrite = !1) : (a.transparent = !1, u === ht.MASK && (a.alphaTest = i.alphaCutoff !== void 0 ? i.alphaCutoff : 0.5)), i.normalTexture !== void 0 && s !== Ve && (c.push(e.assignTexture(a, "normalMap", i.normalTexture)), a.normalScale = new zt(1, 1), i.normalTexture.scale !== void 0)) {
1324
- const l = i.normalTexture.scale;
1325
- a.normalScale.set(l, l);
1326
- }
1327
- if (i.occlusionTexture !== void 0 && s !== Ve && (c.push(e.assignTexture(a, "aoMap", i.occlusionTexture)), i.occlusionTexture.strength !== void 0 && (a.aoMapIntensity = i.occlusionTexture.strength)), i.emissiveFactor !== void 0 && s !== Ve) {
1328
- const l = i.emissiveFactor;
1329
- a.emissive = new ve().setRGB(l[0], l[1], l[2], Re);
1330
- }
1331
- return i.emissiveTexture !== void 0 && s !== Ve && c.push(e.assignTexture(a, "emissiveMap", i.emissiveTexture, We)), Promise.all(c).then(function() {
1332
- const l = new s(a);
1333
- return i.name && (l.name = i.name), me(l, i), e.associations.set(l, { materials: t }), i.extensions && Ie(n, l, i), l;
1334
- });
1335
- }
1336
- /**
1337
- * When Object3D instances are targeted by animation, they need unique names.
1338
- *
1339
- * @private
1340
- * @param {string} originalName
1341
- * @return {string}
1342
- */
1343
- createUniqueName(t) {
1344
- const e = Kn.sanitizeNodeName(t || "");
1345
- return e in this.nodeNamesUsed ? e + "_" + ++this.nodeNamesUsed[e] : (this.nodeNamesUsed[e] = 0, e);
1346
- }
1347
- /**
1348
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
1349
- *
1350
- * Creates BufferGeometries from primitives.
1351
- *
1352
- * @private
1353
- * @param {Array<GLTF.Primitive>} primitives
1354
- * @return {Promise<Array<BufferGeometry>>}
1355
- */
1356
- loadGeometries(t) {
1357
- const e = this, r = this.extensions, n = this.primitiveCache;
1358
- function i(a) {
1359
- return r[k.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a, e).then(function(o) {
1360
- return Gt(o, a, e);
1361
- });
1362
- }
1363
- const s = [];
1364
- for (let a = 0, o = t.length; a < o; a++) {
1365
- const c = t[a], u = Hs(c), l = n[u];
1366
- if (l)
1367
- s.push(l.promise);
1368
- else {
1369
- let f;
1370
- c.extensions && c.extensions[k.KHR_DRACO_MESH_COMPRESSION] ? f = i(c) : f = Gt(new Wn(), c, e), n[u] = { primitive: c, promise: f }, s.push(f);
1371
- }
1372
- }
1373
- return Promise.all(s);
1374
- }
1375
- /**
1376
- * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
1377
- *
1378
- * @private
1379
- * @param {number} meshIndex
1380
- * @return {Promise<Group|Mesh|SkinnedMesh|Line|Points>}
1381
- */
1382
- loadMesh(t) {
1383
- const e = this, r = this.json, n = this.extensions, i = r.meshes[t], s = i.primitives, a = [];
1384
- for (let o = 0, c = s.length; o < c; o++) {
1385
- const u = s[o].material === void 0 ? Fs(this.cache) : this.getDependency("material", s[o].material);
1386
- a.push(u);
1387
- }
1388
- return a.push(e.loadGeometries(s)), Promise.all(a).then(function(o) {
1389
- const c = o.slice(0, o.length - 1), u = o[o.length - 1], l = [];
1390
- for (let h = 0, T = u.length; h < T; h++) {
1391
- const m = u[h], b = s[h];
1392
- let S;
1393
- const P = c[h];
1394
- if (b.mode === ce.TRIANGLES || b.mode === ce.TRIANGLE_STRIP || b.mode === ce.TRIANGLE_FAN || b.mode === void 0)
1395
- S = i.isSkinnedMesh === !0 ? new Xn(m, P) : new zn(m, P), S.isSkinnedMesh === !0 && S.normalizeSkinWeights(), b.mode === ce.TRIANGLE_STRIP ? S.geometry = Pt(S.geometry, Wt) : b.mode === ce.TRIANGLE_FAN && (S.geometry = Pt(S.geometry, Tt));
1396
- else if (b.mode === ce.LINES)
1397
- S = new $n(m, P);
1398
- else if (b.mode === ce.LINE_STRIP)
1399
- S = new qn(m, P);
1400
- else if (b.mode === ce.LINE_LOOP)
1401
- S = new Yn(m, P);
1402
- else if (b.mode === ce.POINTS)
1403
- S = new Jn(m, P);
1404
- else
1405
- throw new Error("THREE.GLTFLoader: Primitive mode unsupported: " + b.mode);
1406
- Object.keys(S.geometry.morphAttributes).length > 0 && Us(S, i), S.name = e.createUniqueName(i.name || "mesh_" + t), me(S, i), b.extensions && Ie(n, S, b), e.assignFinalMaterial(S), l.push(S);
1407
- }
1408
- for (let h = 0, T = l.length; h < T; h++)
1409
- e.associations.set(l[h], {
1410
- meshes: t,
1411
- primitives: h
1412
- });
1413
- if (l.length === 1)
1414
- return i.extensions && Ie(n, l[0], i), l[0];
1415
- const f = new dt();
1416
- i.extensions && Ie(n, f, i), e.associations.set(f, { meshes: t });
1417
- for (let h = 0, T = l.length; h < T; h++)
1418
- f.add(l[h]);
1419
- return f;
1420
- });
1421
- }
1422
- /**
1423
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
1424
- *
1425
- * @private
1426
- * @param {number} cameraIndex
1427
- * @return {Promise<Camera>|undefined}
1428
- */
1429
- loadCamera(t) {
1430
- let e;
1431
- const r = this.json.cameras[t], n = r[r.type];
1432
- if (!n) {
1433
- console.warn("THREE.GLTFLoader: Missing camera parameters.");
1434
- return;
1435
- }
1436
- return r.type === "perspective" ? e = new Qn(Zn.radToDeg(n.yfov), n.aspectRatio || 1, n.znear || 1, n.zfar || 2e6) : r.type === "orthographic" && (e = new es(-n.xmag, n.xmag, n.ymag, -n.ymag, n.znear, n.zfar)), r.name && (e.name = this.createUniqueName(r.name)), me(e, r), Promise.resolve(e);
1437
- }
1438
- /**
1439
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
1440
- *
1441
- * @private
1442
- * @param {number} skinIndex
1443
- * @return {Promise<Skeleton>}
1444
- */
1445
- loadSkin(t) {
1446
- const e = this.json.skins[t], r = [];
1447
- for (let n = 0, i = e.joints.length; n < i; n++)
1448
- r.push(this._loadNodeShallow(e.joints[n]));
1449
- return e.inverseBindMatrices !== void 0 ? r.push(this.getDependency("accessor", e.inverseBindMatrices)) : r.push(null), Promise.all(r).then(function(n) {
1450
- const i = n.pop(), s = n, a = [], o = [];
1451
- for (let c = 0, u = s.length; c < u; c++) {
1452
- const l = s[c];
1453
- if (l) {
1454
- a.push(l);
1455
- const f = new Qe();
1456
- i !== null && f.fromArray(i.array, c * 16), o.push(f);
1457
- } else
1458
- console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', e.joints[c]);
1459
- }
1460
- return new ts(a, o);
1461
- });
1462
- }
1463
- /**
1464
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
1465
- *
1466
- * @private
1467
- * @param {number} animationIndex
1468
- * @return {Promise<AnimationClip>}
1469
- */
1470
- loadAnimation(t) {
1471
- const e = this.json, r = this, n = e.animations[t], i = n.name ? n.name : "animation_" + t, s = [], a = [], o = [], c = [], u = [];
1472
- for (let l = 0, f = n.channels.length; l < f; l++) {
1473
- const h = n.channels[l], T = n.samplers[h.sampler], m = h.target, b = m.node, S = n.parameters !== void 0 ? n.parameters[T.input] : T.input, P = n.parameters !== void 0 ? n.parameters[T.output] : T.output;
1474
- m.node !== void 0 && (s.push(this.getDependency("node", b)), a.push(this.getDependency("accessor", S)), o.push(this.getDependency("accessor", P)), c.push(T), u.push(m));
1475
- }
1476
- return Promise.all([
1477
- Promise.all(s),
1478
- Promise.all(a),
1479
- Promise.all(o),
1480
- Promise.all(c),
1481
- Promise.all(u)
1482
- ]).then(function(l) {
1483
- const f = l[0], h = l[1], T = l[2], m = l[3], b = l[4], S = [];
1484
- for (let D = 0, y = f.length; D < y; D++) {
1485
- const F = f[D], C = h[D], H = T[D], B = m[D], O = b[D];
1486
- if (F === void 0) continue;
1487
- F.updateMatrix && F.updateMatrix();
1488
- const U = r._createAnimationTracks(F, C, H, B, O);
1489
- if (U)
1490
- for (let Z = 0; Z < U.length; Z++)
1491
- S.push(U[Z]);
1492
- }
1493
- const P = new ns(i, void 0, S);
1494
- return me(P, n), P;
1495
- });
1496
- }
1497
- createNodeMesh(t) {
1498
- const e = this.json, r = this, n = e.nodes[t];
1499
- return n.mesh === void 0 ? null : r.getDependency("mesh", n.mesh).then(function(i) {
1500
- const s = r._getNodeRef(r.meshCache, n.mesh, i);
1501
- return n.weights !== void 0 && s.traverse(function(a) {
1502
- if (a.isMesh)
1503
- for (let o = 0, c = n.weights.length; o < c; o++)
1504
- a.morphTargetInfluences[o] = n.weights[o];
1505
- }), s;
1506
- });
1507
- }
1508
- /**
1509
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
1510
- *
1511
- * @private
1512
- * @param {number} nodeIndex
1513
- * @return {Promise<Object3D>}
1514
- */
1515
- loadNode(t) {
1516
- const e = this.json, r = this, n = e.nodes[t], i = r._loadNodeShallow(t), s = [], a = n.children || [];
1517
- for (let c = 0, u = a.length; c < u; c++)
1518
- s.push(r.getDependency("node", a[c]));
1519
- const o = n.skin === void 0 ? Promise.resolve(null) : r.getDependency("skin", n.skin);
1520
- return Promise.all([
1521
- i,
1522
- Promise.all(s),
1523
- o
1524
- ]).then(function(c) {
1525
- const u = c[0], l = c[1], f = c[2];
1526
- f !== null && u.traverse(function(h) {
1527
- h.isSkinnedMesh && h.bind(f, Gs);
1528
- });
1529
- for (let h = 0, T = l.length; h < T; h++)
1530
- u.add(l[h]);
1531
- return u;
1532
- });
1533
- }
1534
- // ._loadNodeShallow() parses a single node.
1535
- // skin and child nodes are created and added in .loadNode() (no '_' prefix).
1536
- _loadNodeShallow(t) {
1537
- const e = this.json, r = this.extensions, n = this;
1538
- if (this.nodeCache[t] !== void 0)
1539
- return this.nodeCache[t];
1540
- const i = e.nodes[t], s = i.name ? n.createUniqueName(i.name) : "", a = [], o = n._invokeOne(function(c) {
1541
- return c.createNodeMesh && c.createNodeMesh(t);
1542
- });
1543
- return o && a.push(o), i.camera !== void 0 && a.push(n.getDependency("camera", i.camera).then(function(c) {
1544
- return n._getNodeRef(n.cameraCache, i.camera, c);
1545
- })), n._invokeAll(function(c) {
1546
- return c.createNodeAttachment && c.createNodeAttachment(t);
1547
- }).forEach(function(c) {
1548
- a.push(c);
1549
- }), this.nodeCache[t] = Promise.all(a).then(function(c) {
1550
- let u;
1551
- if (i.isBone === !0 ? u = new ss() : c.length > 1 ? u = new dt() : c.length === 1 ? u = c[0] : u = new qt(), u !== c[0])
1552
- for (let l = 0, f = c.length; l < f; l++)
1553
- u.add(c[l]);
1554
- if (i.name && (u.userData.name = i.name, u.name = s), me(u, i), i.extensions && Ie(r, u, i), i.matrix !== void 0) {
1555
- const l = new Qe();
1556
- l.fromArray(i.matrix), u.applyMatrix4(l);
1557
- } else
1558
- 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);
1559
- if (!n.associations.has(u))
1560
- n.associations.set(u, {});
1561
- else if (i.mesh !== void 0 && n.meshCache.refs[i.mesh] > 1) {
1562
- const l = n.associations.get(u);
1563
- n.associations.set(u, { ...l });
1564
- }
1565
- return n.associations.get(u).nodes = t, u;
1566
- }), this.nodeCache[t];
1567
- }
1568
- /**
1569
- * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
1570
- *
1571
- * @private
1572
- * @param {number} sceneIndex
1573
- * @return {Promise<Group>}
1574
- */
1575
- loadScene(t) {
1576
- const e = this.extensions, r = this.json.scenes[t], n = this, i = new dt();
1577
- r.name && (i.name = n.createUniqueName(r.name)), me(i, r), r.extensions && Ie(e, i, r);
1578
- const s = r.nodes || [], a = [];
1579
- for (let o = 0, c = s.length; o < c; o++)
1580
- a.push(n.getDependency("node", s[o]));
1581
- return Promise.all(a).then(function(o) {
1582
- for (let u = 0, l = o.length; u < l; u++)
1583
- i.add(o[u]);
1584
- const c = (u) => {
1585
- const l = /* @__PURE__ */ new Map();
1586
- for (const [f, h] of n.associations)
1587
- (f instanceof lt || f instanceof Nt) && l.set(f, h);
1588
- return u.traverse((f) => {
1589
- const h = n.associations.get(f);
1590
- h != null && l.set(f, h);
1591
- }), l;
1592
- };
1593
- return n.associations = c(i), i;
1594
- });
1595
- }
1596
- _createAnimationTracks(t, e, r, n, i) {
1597
- const s = [], a = t.name ? t.name : t.uuid, o = [];
1598
- Se[i.path] === Se.weights ? t.traverse(function(f) {
1599
- f.morphTargetInfluences && o.push(f.name ? f.name : f.uuid);
1600
- }) : o.push(a);
1601
- let c;
1602
- switch (Se[i.path]) {
1603
- case Se.weights:
1604
- c = Ot;
1605
- break;
1606
- case Se.rotation:
1607
- c = Dt;
1608
- break;
1609
- case Se.translation:
1610
- case Se.scale:
1611
- c = Ct;
1612
- break;
1613
- default:
1614
- r.itemSize === 1 ? c = Ot : c = Ct;
1615
- break;
1616
- }
1617
- const u = n.interpolation !== void 0 ? Ds[n.interpolation] : Zt, l = this._getArrayFromAccessor(r);
1618
- for (let f = 0, h = o.length; f < h; f++) {
1619
- const T = new c(
1620
- o[f] + "." + Se[i.path],
1621
- e.array,
1622
- l,
1623
- u
1624
- );
1625
- n.interpolation === "CUBICSPLINE" && this._createCubicSplineTrackInterpolant(T), s.push(T);
1626
- }
1627
- return s;
1628
- }
1629
- _getArrayFromAccessor(t) {
1630
- let e = t.array;
1631
- if (t.normalized) {
1632
- const r = wt(e.constructor), n = new Float32Array(e.length);
1633
- for (let i = 0, s = e.length; i < s; i++)
1634
- n[i] = e[i] * r;
1635
- e = n;
1636
- }
1637
- return e;
1638
- }
1639
- _createCubicSplineTrackInterpolant(t) {
1640
- t.createInterpolant = function(r) {
1641
- const n = this instanceof Dt ? Os : tn;
1642
- return new n(this.times, this.values, this.getValueSize() / 3, r);
1643
- }, t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = !0;
1644
- }
1645
- }
1646
- function Vs(d, t, e) {
1647
- const r = t.attributes, n = new as();
1648
- if (r.POSITION !== void 0) {
1649
- const a = e.json.accessors[r.POSITION], o = a.min, c = a.max;
1650
- if (o !== void 0 && c !== void 0) {
1651
- if (n.set(
1652
- new Oe(o[0], o[1], o[2]),
1653
- new Oe(c[0], c[1], c[2])
1654
- ), a.normalized) {
1655
- const u = wt(De[a.componentType]);
1656
- n.min.multiplyScalar(u), n.max.multiplyScalar(u);
1657
- }
1658
- } else {
1659
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
1660
- return;
1661
- }
1662
- } else
1663
- return;
1664
- const i = t.targets;
1665
- if (i !== void 0) {
1666
- const a = new Oe(), o = new Oe();
1667
- for (let c = 0, u = i.length; c < u; c++) {
1668
- const l = i[c];
1669
- if (l.POSITION !== void 0) {
1670
- const f = e.json.accessors[l.POSITION], h = f.min, T = f.max;
1671
- if (h !== void 0 && T !== void 0) {
1672
- if (o.setX(Math.max(Math.abs(h[0]), Math.abs(T[0]))), o.setY(Math.max(Math.abs(h[1]), Math.abs(T[1]))), o.setZ(Math.max(Math.abs(h[2]), Math.abs(T[2]))), f.normalized) {
1673
- const m = wt(De[f.componentType]);
1674
- o.multiplyScalar(m);
1675
- }
1676
- a.max(o);
1677
- } else
1678
- console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");
1679
- }
1680
- }
1681
- n.expandByVector(a);
1682
- }
1683
- d.boundingBox = n;
1684
- const s = new cs();
1685
- n.getCenter(s.center), s.radius = n.min.distanceTo(n.max) / 2, d.boundingSphere = s;
1686
- }
1687
- function Gt(d, t, e) {
1688
- const r = t.attributes, n = [];
1689
- function i(s, a) {
1690
- return e.getDependency("accessor", s).then(function(o) {
1691
- d.setAttribute(a, o);
1692
- });
1693
- }
1694
- for (const s in r) {
1695
- const a = xt[s] || s.toLowerCase();
1696
- a in d.attributes || n.push(i(r[s], a));
1697
- }
1698
- if (t.indices !== void 0 && !d.index) {
1699
- const s = e.getDependency("accessor", t.indices).then(function(a) {
1700
- d.setIndex(a);
1701
- });
1702
- n.push(s);
1703
- }
1704
- return Ft.workingColorSpace !== Re && "COLOR_0" in r && console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Ft.workingColorSpace}" not supported.`), me(d, t), Vs(d, t, e), Promise.all(n).then(function() {
1705
- return t.targets !== void 0 ? Ps(d, t.targets, e) : d;
1706
- });
1707
- }
1708
- const Q = (...d) => {
1709
- }, Ks = (...d) => {
1710
- }, jt = ({ analyser: d }) => {
1711
- const t = L(null), e = L(null);
1712
- return ie(() => {
1713
- const r = t.current;
1714
- if (!r) return;
1715
- const n = r.getContext("2d", { alpha: !0 });
1716
- if (!n) return;
1717
- let i, s = null;
1718
- d && (d.fftSize = 128, s = new Uint8Array(d.frequencyBinCount));
1719
- const a = () => {
1720
- i = requestAnimationFrame(a), (r.width !== r.offsetWidth || r.height !== r.offsetHeight) && (r.width = r.offsetWidth, r.height = r.offsetHeight);
1721
- const o = r.width, c = r.height;
1722
- if (o === 0 || c === 0) return;
1723
- const u = c / 2;
1724
- n.clearRect(0, 0, o, c), n.fillStyle = "#1e293b";
1725
- const l = 2, h = l + 2, T = o * 0.95, m = Math.floor(T / h);
1726
- (!e.current || e.current.length !== m) && (e.current = new Float32Array(m).fill(2));
1727
- const b = m * h, S = (o - b) / 2;
1728
- d && s && d.getByteFrequencyData(s);
1729
- const P = s ? s.length : 0, y = Math.floor(P * 0.7) / m, F = new Float32Array(m);
1730
- for (let C = 0; C < m; C++) {
1731
- let H = 0;
1732
- if (s && y > 0) {
1733
- const U = Math.floor(C * y), Z = Math.floor((C + 1) * y);
1734
- for (let ue = U; ue < Z; ue++) {
1735
- const Te = s[ue] || 0;
1736
- Te > H && (H = Te);
1
+ import { jsx as f, jsxs as ne } from "react/jsx-runtime";
2
+ import { useGLTF as Qe, Environment as Mt } from "@react-three/drei";
3
+ import { useFrame as Tt, Canvas as It, useThree as Ct } from "@react-three/fiber";
4
+ import { memo as Dt, useMemo as et, useRef as o, useState as y, useEffect as z, useCallback as $e, useLayoutEffect as Ot, Suspense as Ft } from "react";
5
+ import * as Fe from "three";
6
+ import { GLTFLoader as Ut } from "three/examples/jsm/loaders/GLTFLoader.js";
7
+ const B = (...u) => {
8
+ }, Nt = (...u) => {
9
+ }, ut = ({ analyser: u }) => {
10
+ const x = o(null), w = o(null);
11
+ return z(() => {
12
+ const p = x.current;
13
+ if (!p) return;
14
+ const D = p.getContext("2d", { alpha: !0 });
15
+ if (!D) return;
16
+ let M, L = null;
17
+ u && (u.fftSize = 128, L = new Uint8Array(u.frequencyBinCount));
18
+ const he = () => {
19
+ M = requestAnimationFrame(he), (p.width !== p.offsetWidth || p.height !== p.offsetHeight) && (p.width = p.offsetWidth, p.height = p.offsetHeight);
20
+ const re = p.width, O = p.height;
21
+ if (re === 0 || O === 0) return;
22
+ const k = O / 2;
23
+ D.clearRect(0, 0, re, O), D.fillStyle = "#1e293b";
24
+ const Q = 2, E = Q + 2, ce = re * 0.95, g = Math.floor(ce / E);
25
+ (!w.current || w.current.length !== g) && (w.current = new Float32Array(g).fill(2));
26
+ const ke = g * E, Z = (re - ke) / 2;
27
+ u && L && u.getByteFrequencyData(L);
28
+ const pe = L ? L.length : 0, J = Math.floor(pe * 0.7) / g, I = new Float32Array(g);
29
+ for (let m = 0; m < g; m++) {
30
+ let $ = 0;
31
+ if (L && J > 0) {
32
+ const b = Math.floor(m * J), K = Math.floor((m + 1) * J);
33
+ for (let q = b; q < K; q++) {
34
+ const le = L[q] || 0;
35
+ le > $ && ($ = le);
1737
36
  }
1738
37
  }
1739
- H < 10 && (H = 0);
1740
- const B = H / 255, O = H > 0 ? Math.max(2, Math.pow(B, 1.4) * c * 0.25) : 2;
1741
- F[C] = O;
38
+ $ < 10 && ($ = 0);
39
+ const R = $ / 255, v = $ > 0 ? Math.max(2, Math.pow(R, 1.4) * O * 0.25) : 2;
40
+ I[m] = v;
1742
41
  }
1743
- for (let C = 0; C < m; C++) {
1744
- const H = m - 1 - C, B = Math.max(F[C], F[H]), O = e.current[C] + (B - e.current[C]) * 0.3;
1745
- e.current[C] = O;
1746
- const U = S + C * h, Z = u - O / 2;
1747
- n.beginPath(), n.roundRect ? n.roundRect(U, Z, l, O, 4) : n.fillRect(U, Z, l, O), n.fill();
42
+ for (let m = 0; m < g; m++) {
43
+ const $ = g - 1 - m, R = Math.max(I[m], I[$]), v = w.current[m] + (R - w.current[m]) * 0.3;
44
+ w.current[m] = v;
45
+ const b = Z + m * E, K = k - v / 2;
46
+ D.beginPath(), D.roundRect ? D.roundRect(b, K, Q, v, 4) : D.fillRect(b, K, Q, v), D.fill();
1748
47
  }
1749
48
  };
1750
- return a(), () => {
1751
- cancelAnimationFrame(i);
49
+ return he(), () => {
50
+ cancelAnimationFrame(M);
1752
51
  };
1753
- }, [d]), /* @__PURE__ */ N("canvas", { ref: t, style: { width: "100%", height: "100%", display: "block" } });
1754
- }, Vt = "https://ai.streamoji.com", Ws = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev";
1755
- async function Xs(d) {
1756
- const t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(d));
1757
- return Array.from(new Uint8Array(t)).map((e) => e.toString(16).padStart(2, "0")).join("");
52
+ }, [u]), /* @__PURE__ */ f(
53
+ "canvas",
54
+ {
55
+ ref: x,
56
+ style: { width: "100%", height: "100%", display: "block" }
57
+ }
58
+ );
59
+ }, dt = "https://ai.streamoji.com", Wt = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", ft = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/fullbodyavatarmale.glb";
60
+ async function Pt(u) {
61
+ const x = await crypto.subtle.digest(
62
+ "SHA-256",
63
+ new TextEncoder().encode(u)
64
+ );
65
+ return Array.from(new Uint8Array(x)).map((w) => w.toString(16).padStart(2, "0")).join("");
1758
66
  }
1759
- function zs(d) {
1760
- const [t, e] = K(null);
1761
- return ie(() => {
1762
- if (!d) {
1763
- e(null);
67
+ function Vt(u) {
68
+ const [x, w] = y(null);
69
+ return z(() => {
70
+ if (!u) {
71
+ w(null);
1764
72
  return;
1765
73
  }
1766
- let r = !1;
1767
- return Xs(d).then((n) => {
1768
- if (r) return;
1769
- const i = `${Ws}/${n}.glb`;
1770
- fetch(i, { method: "HEAD" }).then((s) => {
1771
- r || e(s.ok ? i : null);
74
+ let p = !1;
75
+ return Pt(u).then((D) => {
76
+ if (p) return;
77
+ const M = `${Wt}/${D}.glb`;
78
+ fetch(M, { method: "HEAD" }).then((L) => {
79
+ p || w(L.ok ? M : ft);
1772
80
  }).catch(() => {
1773
- r || e(null);
81
+ p || w(ft);
1774
82
  });
1775
83
  }), () => {
1776
- r = !0;
84
+ p = !0;
1777
85
  };
1778
- }, [d]), t;
86
+ }, [u]), x;
1779
87
  }
1780
- const $s = [
88
+ const Bt = [
1781
89
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
1782
90
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
1783
91
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
1784
92
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
1785
- ], qs = [
93
+ ], $t = [
1786
94
  {
1787
95
  id: "m_expr_01",
1788
96
  name: "Friendly Wave",
@@ -1948,517 +256,806 @@ const $s = [
1948
256
  name: "Take It Easy",
1949
257
  url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
1950
258
  }
1951
- ], Ys = [
259
+ ], Ht = [
1952
260
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
1953
261
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb"
1954
- ], Js = {
262
+ ], jt = {
1955
263
  zoom: 0.85,
1956
264
  position: [0.15, -0.8, 0],
1957
265
  scale: 1.5,
1958
266
  rotation: [0.15, 0.02, 0]
1959
- }, Qs = [-0.45, 1.9, 0.1], Zs = {
267
+ }, Jt = [-0.45, 1.9, 0.1], qt = {
1960
268
  browInnerUp: 0.2
1961
- }, mt = 0.18, er = 1, Je = {
269
+ }, Ze = 0.18, Gt = 1, He = {
1962
270
  neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
1963
- happy: { mouthSmileLeft: 0.2, mouthSmileRight: 0.2, eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
1964
- sad: { eyeLookDownLeft: 0.2, eyeLookDownRight: 0.2, browDownRight: 0.1, browInnerUp: 0.6, browOuterUpRight: 0.2, eyeSquintLeft: 0.7, eyeSquintRight: 0.7, mouthFrownLeft: 0.8, mouthFrownRight: 0.8, mouthLeft: 0.2, mouthPucker: 0.5, mouthRollLower: 0.2, mouthRollUpper: 0.2, mouthShrugLower: 0.2, mouthShrugUpper: 0.2, mouthStretchLeft: 0.4 },
1965
- angry: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1, browDownLeft: 0.6, browDownRight: 0.6, jawForward: 0.3, mouthFrownLeft: 0.7, mouthFrownRight: 0.7, mouthRollLower: 0.2, mouthShrugLower: 0.3 },
1966
- fear: { browInnerUp: 0.7, eyeSquintLeft: 0.5, eyeSquintRight: 0.5, eyeWideLeft: 0.6, eyeWideRight: 0.6, mouthClose: 0.1, mouthFunnel: 0.3, mouthShrugLower: 0.5, mouthShrugUpper: 0.5 },
1967
- disgust: { browDownLeft: 0.7, browDownRight: 0.1, browInnerUp: 0.3, eyeSquintLeft: 1, eyeSquintRight: 1, eyeWideLeft: 0.5, eyeWideRight: 0.5, mouthLeft: 0.4, mouthPressLeft: 0.3, mouthRollLower: 0.3, mouthShrugLower: 0.3, mouthShrugUpper: 0.8, mouthUpperUpLeft: 0.3, noseSneerLeft: 1, noseSneerRight: 0.7 },
1968
- love: { browInnerUp: 0.4, browOuterUpLeft: 0.2, browOuterUpRight: 0.2, mouthSmileLeft: 0.2, mouthSmileRight: 0.2, eyeBlinkLeft: 0.6, eyeBlinkRight: 0.6, eyeWideLeft: 0.7, eyeWideRight: 0.7, mouthDimpleLeft: 0.1, mouthDimpleRight: 0.1, mouthPressLeft: 0.2, mouthShrugUpper: 0.2, mouthUpperUpLeft: 0.1, mouthUpperUpRight: 0.1 }
1969
- }, tr = [
271
+ happy: {
272
+ mouthSmileLeft: 0.2,
273
+ mouthSmileRight: 0.2,
274
+ eyeLookDownLeft: 0.1,
275
+ eyeLookDownRight: 0.1
276
+ },
277
+ sad: {
278
+ eyeLookDownLeft: 0.2,
279
+ eyeLookDownRight: 0.2,
280
+ browDownRight: 0.1,
281
+ browInnerUp: 0.6,
282
+ browOuterUpRight: 0.2,
283
+ eyeSquintLeft: 0.7,
284
+ eyeSquintRight: 0.7,
285
+ mouthFrownLeft: 0.8,
286
+ mouthFrownRight: 0.8,
287
+ mouthLeft: 0.2,
288
+ mouthPucker: 0.5,
289
+ mouthRollLower: 0.2,
290
+ mouthRollUpper: 0.2,
291
+ mouthShrugLower: 0.2,
292
+ mouthShrugUpper: 0.2,
293
+ mouthStretchLeft: 0.4
294
+ },
295
+ angry: {
296
+ eyeLookDownLeft: 0.1,
297
+ eyeLookDownRight: 0.1,
298
+ browDownLeft: 0.6,
299
+ browDownRight: 0.6,
300
+ jawForward: 0.3,
301
+ mouthFrownLeft: 0.7,
302
+ mouthFrownRight: 0.7,
303
+ mouthRollLower: 0.2,
304
+ mouthShrugLower: 0.3
305
+ },
306
+ fear: {
307
+ browInnerUp: 0.7,
308
+ eyeSquintLeft: 0.5,
309
+ eyeSquintRight: 0.5,
310
+ eyeWideLeft: 0.6,
311
+ eyeWideRight: 0.6,
312
+ mouthClose: 0.1,
313
+ mouthFunnel: 0.3,
314
+ mouthShrugLower: 0.5,
315
+ mouthShrugUpper: 0.5
316
+ },
317
+ disgust: {
318
+ browDownLeft: 0.7,
319
+ browDownRight: 0.1,
320
+ browInnerUp: 0.3,
321
+ eyeSquintLeft: 1,
322
+ eyeSquintRight: 1,
323
+ eyeWideLeft: 0.5,
324
+ eyeWideRight: 0.5,
325
+ mouthLeft: 0.4,
326
+ mouthPressLeft: 0.3,
327
+ mouthRollLower: 0.3,
328
+ mouthShrugLower: 0.3,
329
+ mouthShrugUpper: 0.8,
330
+ mouthUpperUpLeft: 0.3,
331
+ noseSneerLeft: 1,
332
+ noseSneerRight: 0.7
333
+ },
334
+ love: {
335
+ browInnerUp: 0.4,
336
+ browOuterUpLeft: 0.2,
337
+ browOuterUpRight: 0.2,
338
+ mouthSmileLeft: 0.2,
339
+ mouthSmileRight: 0.2,
340
+ eyeBlinkLeft: 0.6,
341
+ eyeBlinkRight: 0.6,
342
+ eyeWideLeft: 0.7,
343
+ eyeWideRight: 0.7,
344
+ mouthDimpleLeft: 0.1,
345
+ mouthDimpleRight: 0.1,
346
+ mouthPressLeft: 0.2,
347
+ mouthShrugUpper: 0.2,
348
+ mouthUpperUpLeft: 0.1,
349
+ mouthUpperUpRight: 0.1
350
+ }
351
+ }, zt = [
1970
352
  { key: "viseme_aa", mix: { jawOpen: 0.6 } },
1971
- { key: "viseme_E", mix: { mouthPressLeft: 0.8, mouthPressRight: 0.8, mouthDimpleLeft: 1, mouthDimpleRight: 1, jawOpen: 0.3 } },
1972
- { key: "viseme_I", mix: { mouthPressLeft: 0.6, mouthPressRight: 0.6, mouthDimpleLeft: 0.6, mouthDimpleRight: 0.6, jawOpen: 0.2 } },
353
+ {
354
+ key: "viseme_E",
355
+ mix: {
356
+ mouthPressLeft: 0.8,
357
+ mouthPressRight: 0.8,
358
+ mouthDimpleLeft: 1,
359
+ mouthDimpleRight: 1,
360
+ jawOpen: 0.3
361
+ }
362
+ },
363
+ {
364
+ key: "viseme_I",
365
+ mix: {
366
+ mouthPressLeft: 0.6,
367
+ mouthPressRight: 0.6,
368
+ mouthDimpleLeft: 0.6,
369
+ mouthDimpleRight: 0.6,
370
+ jawOpen: 0.2
371
+ }
372
+ },
1973
373
  { key: "viseme_O", mix: { mouthPucker: 1, jawForward: 0.6, jawOpen: 0.2 } },
1974
374
  { key: "viseme_U", mix: { mouthFunnel: 1 } },
1975
- { key: "viseme_PP", mix: { mouthRollLower: 0.3, mouthRollUpper: 0.3, mouthUpperUpLeft: 0.3, mouthUpperUpRight: 0.3 } },
1976
- { key: "viseme_FF", mix: { mouthPucker: 1, mouthShrugUpper: 1, mouthLowerDownLeft: 0.2, mouthLowerDownRight: 0.2, mouthDimpleLeft: 1, mouthDimpleRight: 1, mouthRollLower: 0.3 } },
1977
- { key: "viseme_DD", mix: { mouthPressLeft: 0.8, mouthPressRight: 0.8, mouthFunnel: 0.5, jawOpen: 0.2 } },
1978
- { key: "viseme_SS", mix: { mouthPressLeft: 0.8, mouthPressRight: 0.8, mouthLowerDownLeft: 0.5, mouthLowerDownRight: 0.5, jawOpen: 0.1 } },
1979
- { key: "viseme_TH", mix: { mouthRollUpper: 0.3, jawOpen: 0.2, tongueOut: 0.4 } },
375
+ {
376
+ key: "viseme_PP",
377
+ mix: {
378
+ mouthRollLower: 0.3,
379
+ mouthRollUpper: 0.3,
380
+ mouthUpperUpLeft: 0.3,
381
+ mouthUpperUpRight: 0.3
382
+ }
383
+ },
384
+ {
385
+ key: "viseme_FF",
386
+ mix: {
387
+ mouthPucker: 1,
388
+ mouthShrugUpper: 1,
389
+ mouthLowerDownLeft: 0.2,
390
+ mouthLowerDownRight: 0.2,
391
+ mouthDimpleLeft: 1,
392
+ mouthDimpleRight: 1,
393
+ mouthRollLower: 0.3
394
+ }
395
+ },
396
+ {
397
+ key: "viseme_DD",
398
+ mix: {
399
+ mouthPressLeft: 0.8,
400
+ mouthPressRight: 0.8,
401
+ mouthFunnel: 0.5,
402
+ jawOpen: 0.2
403
+ }
404
+ },
405
+ {
406
+ key: "viseme_SS",
407
+ mix: {
408
+ mouthPressLeft: 0.8,
409
+ mouthPressRight: 0.8,
410
+ mouthLowerDownLeft: 0.5,
411
+ mouthLowerDownRight: 0.5,
412
+ jawOpen: 0.1
413
+ }
414
+ },
415
+ {
416
+ key: "viseme_TH",
417
+ mix: { mouthRollUpper: 0.3, jawOpen: 0.2, tongueOut: 0.4 }
418
+ },
1980
419
  { key: "viseme_CH", mix: { mouthPucker: 0.5, jawOpen: 0.2 } },
1981
420
  { key: "viseme_RR", mix: { mouthPucker: 0.5, jawOpen: 0.2 } },
1982
- { key: "viseme_kk", mix: { mouthLowerDownLeft: 0.4, mouthLowerDownRight: 0.4, mouthDimpleLeft: 0.3, mouthDimpleRight: 0.3, mouthFunnel: 0.3, mouthPucker: 0.3, jawOpen: 0.15 } },
1983
- { key: "viseme_nn", mix: { mouthLowerDownLeft: 0.4, mouthLowerDownRight: 0.4, mouthDimpleLeft: 0.3, mouthDimpleRight: 0.3, mouthFunnel: 0.3, mouthPucker: 0.3, jawOpen: 0.15, tongueOut: 0.2 } },
421
+ {
422
+ key: "viseme_kk",
423
+ mix: {
424
+ mouthLowerDownLeft: 0.4,
425
+ mouthLowerDownRight: 0.4,
426
+ mouthDimpleLeft: 0.3,
427
+ mouthDimpleRight: 0.3,
428
+ mouthFunnel: 0.3,
429
+ mouthPucker: 0.3,
430
+ jawOpen: 0.15
431
+ }
432
+ },
433
+ {
434
+ key: "viseme_nn",
435
+ mix: {
436
+ mouthLowerDownLeft: 0.4,
437
+ mouthLowerDownRight: 0.4,
438
+ mouthDimpleLeft: 0.3,
439
+ mouthDimpleRight: 0.3,
440
+ mouthFunnel: 0.3,
441
+ mouthPucker: 0.3,
442
+ jawOpen: 0.15,
443
+ tongueOut: 0.2
444
+ }
445
+ },
1984
446
  { key: "viseme_sil", mix: {} }
1985
- ], nr = {
1986
- aei: [{ v: "E", w: 0.8 }, { v: "I", w: 0.2 }],
447
+ ], Yt = {
448
+ aei: [
449
+ { v: "E", w: 0.8 },
450
+ { v: "I", w: 0.2 }
451
+ ],
1987
452
  ee: [{ v: "I", w: 1 }],
1988
453
  oo: [{ v: "O", w: 1 }],
1989
454
  u: [{ v: "U", w: 1 }],
1990
455
  aa: [{ v: "aa", w: 1 }],
1991
- ah: [{ v: "aa", w: 0.7 }, { v: "O", w: 0.3 }],
456
+ ah: [
457
+ { v: "aa", w: 0.7 },
458
+ { v: "O", w: 0.3 }
459
+ ],
1992
460
  bmp: [{ v: "PP", w: 1 }],
1993
461
  fv: [{ v: "FF", w: 1 }],
1994
462
  th: [{ v: "TH", w: 1 }],
1995
463
  l: [{ v: "nn", w: 1 }],
1996
464
  r: [{ v: "RR", w: 1 }],
1997
- qw: [{ v: "U", w: 0.6 }, { v: "O", w: 0.4 }],
465
+ qw: [
466
+ { v: "U", w: 0.6 },
467
+ { v: "O", w: 0.4 }
468
+ ],
1998
469
  chjsh: [{ v: "CH", w: 1 }],
1999
- cdgknstxyz: [{ v: "DD", w: 0.6 }, { v: "SS", w: 0.4 }],
470
+ cdgknstxyz: [
471
+ { v: "DD", w: 0.6 },
472
+ { v: "SS", w: 0.4 }
473
+ ],
2000
474
  sil: [{ v: "sil", w: 1 }]
2001
475
  };
2002
- function sr(d) {
2003
- if (!d) return [{ v: "sil", w: 1 }];
2004
- const t = d.toLowerCase();
2005
- return nr[t] ?? [{ v: "sil", w: 1 }];
476
+ function Xt(u) {
477
+ if (!u) return [{ v: "sil", w: 1 }];
478
+ const x = u.toLowerCase();
479
+ return Yt[x] ?? [{ v: "sil", w: 1 }];
2006
480
  }
2007
- function rr({ target: d }) {
2008
- const { camera: t } = Sn();
2009
- return ie(() => {
2010
- t.lookAt(...d);
2011
- }, [t, d]), null;
481
+ function Kt({ target: u }) {
482
+ const { camera: x } = Ct();
483
+ return z(() => {
484
+ x.lookAt(...u);
485
+ }, [x, u]), null;
2012
486
  }
2013
- function ne(d, t, e) {
2014
- if (!d || !d.morphTargetDictionary) return;
2015
- const r = d, n = r.morphTargetDictionary, i = r.morphTargetInfluences;
2016
- if (i)
2017
- for (const s in n)
2018
- s.toLowerCase() === t.toLowerCase() && (i[n[s]] = e);
487
+ function G(u, x, w) {
488
+ if (!u || !u.morphTargetDictionary)
489
+ return;
490
+ const p = u, D = p.morphTargetDictionary, M = p.morphTargetInfluences;
491
+ if (M)
492
+ for (const L in D)
493
+ L.toLowerCase() === x.toLowerCase() && (M[D[L]] = w);
2019
494
  }
2020
- function Kt(d, t = 0.97) {
2021
- if (!d) return;
2022
- const e = d;
2023
- if (e.morphTargetInfluences)
2024
- for (let r = 0; r < e.morphTargetInfluences.length; r++)
2025
- e.morphTargetInfluences[r] *= t;
495
+ function ht(u, x = 0.97) {
496
+ if (!u) return;
497
+ const w = u;
498
+ if (w.morphTargetInfluences)
499
+ for (let p = 0; p < w.morphTargetInfluences.length; p++)
500
+ w.morphTargetInfluences[p] *= x;
2026
501
  }
2027
- const ir = bn(({ avatarUrl: d, isPlayingRef: t, visemeQueueRef: e, audioContextRef: r, responseAudioStartTimeRef: n, adjustments: i, mood: s, expression: a, agentResponse: o, isSpeaking: c, nextStartTimeRef: u, stopPlayback: l, setIsSpeaking: f, expressionUrl: h, onExpressionFinished: T }) => {
2028
- const { scene: m } = ct(d), b = ct($s), S = gt(() => b.flatMap((v) => v.animations), [b]), P = ct(Ys), D = gt(() => P.flatMap((v) => v.animations), [P]), y = L(null), F = L(null), C = L(null), H = L([]), [B] = K(() => new Ge.AnimationMixer(m)), O = L({}), U = L(null), Z = L(0), ue = L(!1), Te = L(0), ye = L(null);
2029
- ie(() => {
2030
- if (!(!S || !m)) {
2031
- if (S.forEach((v, A) => {
2032
- const x = `idle_${A}`;
2033
- if (!O.current[x]) {
2034
- const g = B.clipAction(v, m);
2035
- g.name = x, g.setLoop(Ge.LoopOnce, 1), g.clampWhenFinished = !0, O.current[x] = g;
2036
- }
2037
- }), D.forEach((v, A) => {
2038
- const x = `talk_${A}`;
2039
- if (!O.current[x]) {
2040
- const g = B.clipAction(v, m);
2041
- g.name = x, g.setLoop(Ge.LoopOnce, 1), g.clampWhenFinished = !0, O.current[x] = g;
502
+ const Qt = Dt(
503
+ ({
504
+ avatarUrl: u,
505
+ isPlayingRef: x,
506
+ visemeQueueRef: w,
507
+ audioContextRef: p,
508
+ responseAudioStartTimeRef: D,
509
+ adjustments: M,
510
+ mood: L,
511
+ expression: he,
512
+ agentResponse: re,
513
+ isSpeaking: O,
514
+ nextStartTimeRef: k,
515
+ stopPlayback: Q,
516
+ setIsSpeaking: U,
517
+ expressionUrl: E,
518
+ onExpressionFinished: ce
519
+ }) => {
520
+ const { scene: g } = Qe(u), ke = Qe(Bt), Z = et(
521
+ () => ke.flatMap((d) => d.animations),
522
+ [ke]
523
+ ), pe = Qe(Ht), se = et(
524
+ () => pe.flatMap((d) => d.animations),
525
+ [pe]
526
+ ), J = o(null), I = o(null), m = o(null), $ = o([]), [R] = y(() => new Fe.AnimationMixer(g)), v = o({}), b = o(null), K = o(0), q = o(!1), le = o(0), ee = o(null);
527
+ z(() => {
528
+ if (!(!Z || !g)) {
529
+ if (Z.forEach((d, c) => {
530
+ const s = `idle_${c}`;
531
+ if (!v.current[s]) {
532
+ const n = R.clipAction(d, g);
533
+ n.name = s, n.setLoop(Fe.LoopOnce, 1), n.clampWhenFinished = !0, v.current[s] = n;
534
+ }
535
+ }), se.forEach((d, c) => {
536
+ const s = `talk_${c}`;
537
+ if (!v.current[s]) {
538
+ const n = R.clipAction(d, g);
539
+ n.name = s, n.setLoop(Fe.LoopOnce, 1), n.clampWhenFinished = !0, v.current[s] = n;
540
+ }
541
+ }), Z.length > 0) {
542
+ const d = v.current.idle_0, c = b.current && R.existingAction(b.current.getClip());
543
+ d && !c && (d.reset().fadeIn(0.5).play(), b.current = d);
2042
544
  }
2043
- }), S.length > 0) {
2044
- const v = O.current.idle_0, A = U.current && B.existingAction(U.current.getClip());
2045
- v && !A && (v.reset().fadeIn(0.5).play(), U.current = v);
545
+ return () => {
546
+ R.stopAllAction(), v.current = {}, b.current = null;
547
+ };
2046
548
  }
2047
- return () => {
2048
- B.stopAllAction(), O.current = {}, U.current = null;
549
+ }, [Z, se, g, R]);
550
+ const Re = o("");
551
+ z(() => {
552
+ if (!E || !g || E === Re.current) return;
553
+ Re.current = E, ee.current = E, new Ut().load(
554
+ E,
555
+ (c) => {
556
+ if (c.animations && c.animations.length > 0) {
557
+ const s = c.animations[0], n = R.clipAction(s, g);
558
+ if (n.name = `EXPR_${E}`, n.setLoop(Fe.LoopOnce, 1), n.clampWhenFinished = !0, v.current[`EXPR_${E}`] = n, O && ee.current === E) {
559
+ const h = b.current;
560
+ n.reset().fadeIn(0.3).play(), h && h !== n && h.crossFadeTo(n, 0.3, !0), b.current = n, ee.current = null;
561
+ }
562
+ }
563
+ },
564
+ void 0,
565
+ (c) => {
566
+ console.error(`[ANIMATION] Failed to load ${E}`, c);
567
+ }
568
+ );
569
+ }, [E, g, R, O]), z(() => {
570
+ const d = (c) => {
571
+ const s = c.action, n = s.name || "";
572
+ if (n.startsWith("idle_")) {
573
+ const H = (parseInt(n.split("_")[1]) + 1) % Z.length, Y = v.current[`idle_${H}`];
574
+ Y && (Y.reset().fadeIn(0.5).play(), s.crossFadeTo(Y, 0.5, !0), b.current = Y);
575
+ } else if (n.startsWith("EXPR_")) {
576
+ if (O) {
577
+ const h = v.current.talk_0;
578
+ h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), b.current = h);
579
+ } else {
580
+ const h = v.current.idle_0;
581
+ h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), b.current = h);
582
+ }
583
+ ce && ce();
584
+ } else if (n.startsWith("talk_"))
585
+ if (O) {
586
+ const H = (parseInt(n.split("_")[1]) + 1) % se.length, Y = v.current[`talk_${H}`];
587
+ Y && (Y.reset().fadeIn(0.3).play(), s.crossFadeTo(Y, 0.3, !0), b.current = Y);
588
+ } else {
589
+ const h = v.current.idle_0;
590
+ h && (h.reset().fadeIn(0.5).play(), s.crossFadeTo(h, 0.5, !0), b.current = h);
591
+ }
2049
592
  };
2050
- }
2051
- }, [S, D, m, B]);
2052
- const Xe = L("");
2053
- ie(() => {
2054
- if (!h || !m || h === Xe.current) return;
2055
- Xe.current = h, ye.current = h, new us().load(h, (A) => {
2056
- if (A.animations && A.animations.length > 0) {
2057
- const x = A.animations[0], g = B.clipAction(x, m);
2058
- if (g.name = `EXPR_${h}`, g.setLoop(Ge.LoopOnce, 1), g.clampWhenFinished = !0, O.current[`EXPR_${h}`] = g, c && ye.current === h) {
2059
- const M = U.current;
2060
- g.reset().fadeIn(0.3).play(), M && M !== g && M.crossFadeTo(g, 0.3, !0), U.current = g, ye.current = null;
593
+ return R.addEventListener("finished", d), () => R.removeEventListener("finished", d);
594
+ }, [
595
+ R,
596
+ Z,
597
+ se,
598
+ O,
599
+ ce
600
+ ]), z(() => {
601
+ if (O && g) {
602
+ const d = b.current, c = d?.name || "";
603
+ if (c.startsWith("idle_") || c.startsWith("talk_") || c === "") {
604
+ const s = ee.current;
605
+ if (s) {
606
+ const n = v.current[`EXPR_${s}`];
607
+ if (n) {
608
+ n.reset().fadeIn(0.3).play(), d && d !== n && d.crossFadeTo(n, 0.3, !0), b.current = n, ee.current = null;
609
+ return;
610
+ }
611
+ }
612
+ if (c.startsWith("idle_") || c === "") {
613
+ const n = v.current.talk_0;
614
+ n && (n.reset().fadeIn(0.5).play(), d && d.crossFadeTo(n, 0.5, !0), b.current = n);
615
+ }
2061
616
  }
2062
- }
2063
- }, void 0, (A) => {
2064
- console.error(`[ANIMATION] Failed to load ${h}`, A);
2065
- });
2066
- }, [h, m, B, c]), ie(() => {
2067
- const v = (A) => {
2068
- const x = A.action, g = x.name || "";
2069
- if (g.startsWith("idle_")) {
2070
- const ee = (parseInt(g.split("_")[1]) + 1) % S.length, X = O.current[`idle_${ee}`];
2071
- X && (X.reset().fadeIn(0.5).play(), x.crossFadeTo(X, 0.5, !0), U.current = X);
2072
- } else if (g.startsWith("EXPR_")) {
2073
- if (c) {
2074
- const M = O.current.talk_0;
2075
- M && (M.reset().fadeIn(0.5).play(), x.crossFadeTo(M, 0.5, !0), U.current = M);
2076
- } else {
2077
- const M = O.current.idle_0;
2078
- M && (M.reset().fadeIn(0.5).play(), x.crossFadeTo(M, 0.5, !0), U.current = M);
617
+ } else if (!O && g) {
618
+ const d = b.current, c = d?.name || "";
619
+ if (c.startsWith("talk_") || c.startsWith("EXPR_")) {
620
+ const s = v.current.idle_0;
621
+ s && (s.reset().fadeIn(0.5).play(), d && d.crossFadeTo(s, 0.5, !0), b.current = s);
2079
622
  }
2080
- T && T();
2081
- } else if (g.startsWith("talk_"))
2082
- if (c) {
2083
- const ee = (parseInt(g.split("_")[1]) + 1) % D.length, X = O.current[`talk_${ee}`];
2084
- X && (X.reset().fadeIn(0.3).play(), x.crossFadeTo(X, 0.3, !0), U.current = X);
2085
- } else {
2086
- const M = O.current.idle_0;
2087
- M && (M.reset().fadeIn(0.5).play(), x.crossFadeTo(M, 0.5, !0), U.current = M);
623
+ }
624
+ }, [O, g, E]), z(() => {
625
+ if (!g) return;
626
+ g.traverse((s) => {
627
+ if (s.isMesh && s.morphTargetDictionary) {
628
+ const n = s.name.toLowerCase();
629
+ (n.includes("head") || n.includes("avatar")) && (I.current = s, B(`[ANIMATION] Found head mesh: ${s.name}`)), n.includes("teeth") && (m.current = s, B(`[ANIMATION] Found teeth mesh: ${s.name}`));
2088
630
  }
2089
- };
2090
- return B.addEventListener("finished", v), () => B.removeEventListener("finished", v);
2091
- }, [B, S, D, c, T]), ie(() => {
2092
- if (c && m) {
2093
- const v = U.current, A = v?.name || "";
2094
- if (A.startsWith("idle_") || A.startsWith("talk_") || A === "") {
2095
- const x = ye.current;
2096
- if (x) {
2097
- const g = O.current[`EXPR_${x}`];
2098
- if (g) {
2099
- g.reset().fadeIn(0.3).play(), v && v !== g && v.crossFadeTo(g, 0.3, !0), U.current = g, ye.current = null;
2100
- return;
2101
- }
631
+ });
632
+ const d = I.current?.morphTargetDictionary;
633
+ d && Object.keys(d).filter(
634
+ (s) => s.toLowerCase().includes("brow")
635
+ );
636
+ const c = [];
637
+ g.traverse((s) => {
638
+ if (s.isMesh) {
639
+ const h = s.morphTargetDictionary;
640
+ h && Object.keys(h).some((H) => H.toLowerCase().includes("brow")) && c.push(s);
2102
641
  }
2103
- if (A.startsWith("idle_") || A === "") {
2104
- const g = O.current.talk_0;
2105
- g && (g.reset().fadeIn(0.5).play(), v && v.crossFadeTo(g, 0.5, !0), U.current = g);
642
+ }), $.current = c, c.length > 0 && B("[ANIMATION] Meshes with brow morphs:", c.length);
643
+ }, [g]);
644
+ const Ue = (d, c = 1) => {
645
+ const s = `viseme_${d}`.toLowerCase(), n = zt.find((h) => h.key.toLowerCase() === s);
646
+ if (n)
647
+ for (const h in n.mix) {
648
+ const H = n.mix[h] * c;
649
+ G(I.current, h, H), G(m.current, h, H);
2106
650
  }
651
+ }, Ce = (d) => {
652
+ const c = He[d] ?? He.neutral;
653
+ for (const s in c)
654
+ G(I.current, s, c[s]), G(m.current, s, c[s]);
655
+ };
656
+ return Tt((d, c) => {
657
+ const s = Math.pow(0.88, 60 * c);
658
+ ht(I.current, s), ht(m.current, s), Ce(L);
659
+ const n = d.clock.elapsedTime;
660
+ let h = 0;
661
+ if (Math.floor(n) % 5 === 0 && Math.floor((n - c) % 5) !== 0) {
662
+ let j = null;
663
+ g.traverse((W) => {
664
+ W.name.toLowerCase().includes("hips") && (j = W);
665
+ });
666
+ const ie = j ? `Hips Y: ${j.position.y.toFixed(4)}` : "Hips not found";
667
+ B(`[ANIMATION] Mixer Time: ${R.time.toFixed(2)}, ${ie}`);
2107
668
  }
2108
- } else if (!c && m) {
2109
- const v = U.current, A = v?.name || "";
2110
- if (A.startsWith("talk_") || A.startsWith("EXPR_")) {
2111
- const x = O.current.idle_0;
2112
- x && (x.reset().fadeIn(0.5).play(), v && v.crossFadeTo(x, 0.5, !0), U.current = x);
2113
- }
2114
- }
2115
- }, [c, m, h]), ie(() => {
2116
- if (!m) return;
2117
- m.traverse((x) => {
2118
- if (x.isMesh && x.morphTargetDictionary) {
2119
- const g = x.name.toLowerCase();
2120
- (g.includes("head") || g.includes("avatar")) && (F.current = x, Q(`[ANIMATION] Found head mesh: ${x.name}`)), g.includes("teeth") && (C.current = x, Q(`[ANIMATION] Found teeth mesh: ${x.name}`));
2121
- }
2122
- });
2123
- const v = F.current?.morphTargetDictionary;
2124
- v && Object.keys(v).filter((x) => x.toLowerCase().includes("brow"));
2125
- const A = [];
2126
- m.traverse((x) => {
2127
- if (x.isMesh) {
2128
- const M = x.morphTargetDictionary;
2129
- M && Object.keys(M).some((ee) => ee.toLowerCase().includes("brow")) && A.push(x);
2130
- }
2131
- }), H.current = A, A.length > 0 && Q("[ANIMATION] Meshes with brow morphs:", A.length);
2132
- }, [m]);
2133
- const Ze = (v, A = 1) => {
2134
- const x = `viseme_${v}`.toLowerCase(), g = tr.find((M) => M.key.toLowerCase() === x);
2135
- if (g)
2136
- for (const M in g.mix) {
2137
- const ee = g.mix[M] * A;
2138
- ne(F.current, M, ee), ne(C.current, M, ee);
669
+ if (R.update(c), n > K.current && !q.current && (q.current = !0, le.current = n), q.current) {
670
+ const ie = (n - le.current) / 0.3;
671
+ if (ie >= 1)
672
+ q.current = !1, K.current = n + 2 + Math.random() * 5;
673
+ else {
674
+ const W = ie < 0.5 ? ie * 2 : (1 - ie) * 2;
675
+ G(I.current, "eyeBlinkLeft", W), G(I.current, "eyeBlinkRight", W), G(m.current, "eyeBlinkLeft", W), G(m.current, "eyeBlinkRight", W), h = W * qt.browInnerUp;
676
+ }
2139
677
  }
2140
- }, et = (v) => {
2141
- const A = Je[v] ?? Je.neutral;
2142
- for (const x in A)
2143
- ne(F.current, x, A[x]), ne(C.current, x, A[x]);
2144
- };
2145
- return wn((v, A) => {
2146
- const x = Math.pow(0.88, 60 * A);
2147
- Kt(F.current, x), Kt(C.current, x), et(s);
2148
- const g = v.clock.elapsedTime;
2149
- let M = 0;
2150
- if (Math.floor(g) % 5 === 0 && Math.floor((g - A) % 5) !== 0) {
2151
- let te = null;
2152
- m.traverse((se) => {
2153
- se.name.toLowerCase().includes("hips") && (te = se);
2154
- });
2155
- const _e = te ? `Hips Y: ${te.position.y.toFixed(4)}` : "Hips not found";
2156
- Q(`[ANIMATION] Mixer Time: ${B.time.toFixed(2)}, ${_e}`);
2157
- }
2158
- if (B.update(A), g > Z.current && !ue.current && (ue.current = !0, Te.current = g), ue.current) {
2159
- const _e = (g - Te.current) / 0.3;
2160
- if (_e >= 1)
2161
- ue.current = !1, Z.current = g + 2 + Math.random() * 5;
2162
- else {
2163
- const se = _e < 0.5 ? _e * 2 : (1 - _e) * 2;
2164
- ne(F.current, "eyeBlinkLeft", se), ne(F.current, "eyeBlinkRight", se), ne(C.current, "eyeBlinkLeft", se), ne(C.current, "eyeBlinkRight", se), M = se * Zs.browInnerUp;
678
+ const H = He[L] ?? He.neutral, Y = H.browInnerUp ?? 0, be = H.browOuterUpLeft ?? 0, me = H.browOuterUpRight ?? 0, Ae = n * Gt, ge = Ze * Math.sin(Ae), _e = Ze * 0.7 * Math.sin(Ae + 0.7), De = Ze * 0.7 * Math.sin(Ae + 1.3), we = (j) => Math.max(0, Math.min(1, j)), Oe = we(Y + ge), Le = we(be + _e), je = we(me + De), Ne = we(Oe + h);
679
+ if (G(I.current, "browInnerUp", Ne), G(m.current, "browInnerUp", Ne), G(I.current, "browOuterUpLeft", Le), G(m.current, "browOuterUpLeft", Le), G(I.current, "browOuterUpRight", je), G(m.current, "browOuterUpRight", je), J.current) {
680
+ const j = x.current ? 0 : M.rotation[1];
681
+ J.current.rotation.y = Fe.MathUtils.lerp(
682
+ J.current.rotation.y,
683
+ j,
684
+ 0.1
685
+ ), J.current.position.set(...M.position), J.current.scale.setScalar(M.scale), J.current.rotation.x = M.rotation[0], J.current.rotation.z = M.rotation[2];
2165
686
  }
2166
- }
2167
- const ee = Je[s] ?? Je.neutral, X = ee.browInnerUp ?? 0, Ae = ee.browOuterUpLeft ?? 0, Fe = ee.browOuterUpRight ?? 0, ke = g * er, Pe = mt * Math.sin(ke), Ue = mt * 0.7 * Math.sin(ke + 0.7), Rt = mt * 0.7 * Math.sin(ke + 1.3), Ne = (te) => Math.max(0, Math.min(1, te)), He = Ne(X + Pe), Be = Ne(Ae + Ue), be = Ne(Fe + Rt), Ee = Ne(He + M);
2168
- if (ne(F.current, "browInnerUp", Ee), ne(C.current, "browInnerUp", Ee), ne(F.current, "browOuterUpLeft", Be), ne(C.current, "browOuterUpLeft", Be), ne(F.current, "browOuterUpRight", be), ne(C.current, "browOuterUpRight", be), y.current) {
2169
- const te = t.current ? 0 : i.rotation[1];
2170
- y.current.rotation.y = Ge.MathUtils.lerp(y.current.rotation.y, te, 0.1), y.current.position.set(...i.position), y.current.scale.setScalar(i.scale), y.current.rotation.x = i.rotation[0], y.current.rotation.z = i.rotation[2];
2171
- }
2172
- if (t.current && r.current) {
2173
- const te = r.current.currentTime, oe = (te - n.current) * 1e3 - -150;
2174
- for (let fe = 0; fe < e.current.length; fe++) {
2175
- const ae = e.current[fe];
2176
- oe >= ae.vtime && oe < ae.vtime + ae.vduration && Ze(ae.viseme, ae.weight ?? 1);
687
+ if (x.current && p.current) {
688
+ const j = p.current.currentTime, ve = (j - D.current) * 1e3 - -150;
689
+ for (let Ee = 0; Ee < w.current.length; Ee++) {
690
+ const Se = w.current[Ee];
691
+ ve >= Se.vtime && ve < Se.vtime + Se.vduration && Ue(Se.viseme, Se.weight ?? 1);
692
+ }
693
+ j > k.current + 0.5 && (Q(), U(!1));
2177
694
  }
2178
- te > u.current + 0.5 && (l(), f(!1));
2179
- }
2180
- }), /* @__PURE__ */ N("group", { ref: y, children: /* @__PURE__ */ N("primitive", { object: m }) });
2181
- });
2182
- function or(d) {
2183
- return d ? d.charAt(0).toUpperCase() + d.slice(1).toLowerCase() : "";
695
+ }), /* @__PURE__ */ f("group", { ref: J, children: /* @__PURE__ */ f("primitive", { object: g }) });
696
+ }
697
+ );
698
+ function Zt(u) {
699
+ return u ? u.charAt(0).toUpperCase() + u.slice(1).toLowerCase() : "";
2184
700
  }
2185
- const ar = ({ token: d, agentToken: t, onNavigationRequested: e } = {}) => {
2186
- const r = d ?? t ?? "", n = zs(r || void 0), [i, s] = K(""), [a, o] = K(""), [c, u] = K("Ready"), [l, f] = K(!1), [h, T] = K(!1), m = L(!1), b = L([]), S = L(0), P = L(!1), D = L([]), y = L(null), F = L([]);
2187
- L([]);
2188
- const C = L([]), H = L(0), B = L(0), O = L(0), U = L(0), [Z, ue] = K(null), Te = L(null), [ye, Xe] = K("neutral"), [Ze, et] = K(""), [v, A] = K(""), [x, g] = K("Chat with us"), [M, ee] = K(null), [X, Ae] = K("hidden"), [Fe, ke] = K(""), Pe = L(null), Ue = L(X);
2189
- Ue.current = X;
2190
- const [Rt, Ne] = K(null), He = L(null), Be = L(null), [be, Ee] = K("hidden"), [te, _e] = K(""), se = L(be);
2191
- se.current = be;
2192
- const oe = L(""), fe = L(!1), ae = L(""), Ce = gt(() => c === "Thinking..." || c === "Processing Voice..." ? c : M != null && M !== "" && M !== "none" && M !== "<none>" ? `Enter ${or(M)}` : null, [c, M]), ze = Ce != null && Ce !== "";
2193
- ie(() => {
2194
- const p = Ue.current;
2195
- if (!(p === "exiting" || p === "entering")) {
2196
- if (p === "hidden") {
2197
- ze && (ke(Ce ?? ""), Ae("entering"));
701
+ const en = ({
702
+ token: u,
703
+ agentToken: x,
704
+ onNavigationRequested: w
705
+ } = {}) => {
706
+ const p = u ?? x ?? "", D = Vt(p || void 0), [M, L] = y(""), [he, re] = y(""), [O, k] = y("Ready"), [Q, U] = y(!1), [E, ce] = y(!1), [g, ke] = y(
707
+ () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
708
+ );
709
+ z(() => {
710
+ const e = window.matchMedia("(max-width: 480px)"), t = () => ke(e.matches);
711
+ return e.addEventListener("change", t), () => e.removeEventListener("change", t);
712
+ }, []);
713
+ const Z = g ? 80 : 600, pe = o(!1), se = o([]), J = o(0), I = o(!1), m = o([]), $ = o(null), R = o([]);
714
+ o([]);
715
+ const v = o([]), b = o(0), K = o(0), q = o(0), le = o(0), ee = o(!1), [Re, Ue] = y(
716
+ null
717
+ ), Ce = o(null), [d, c] = y("neutral"), [s, n] = y(""), [h, H] = y(""), [Y, be] = y("Chat with us"), [me, Ae] = y(
718
+ null
719
+ ), [ge, _e] = y("hidden"), [De, we] = y(""), Oe = o(null), Le = o(ge);
720
+ Le.current = ge;
721
+ const [je, Ne] = y(null), j = o(null), ie = o(null), [W, ve] = y("hidden"), [Ee, Se] = y(""), Je = o(W);
722
+ Je.current = W;
723
+ const ue = o(""), Me = o(!1), Te = o(""), Ie = et(() => O === "Thinking..." || O === "Processing Voice..." ? O : me != null && me !== "" && me !== "none" && me !== "<none>" ? `Enter ${Zt(me)}` : null, [O, me]), We = Ie != null && Ie !== "";
724
+ z(() => {
725
+ const e = Le.current;
726
+ if (!(e === "exiting" || e === "entering")) {
727
+ if (e === "hidden") {
728
+ We && (we(Ie ?? ""), _e("entering"));
2198
729
  return;
2199
730
  }
2200
- p === "visible" && (!ze || Ce !== Fe) && (Pe.current = ze ? Ce : null, Ae("exiting"));
731
+ e === "visible" && (!We || Ie !== De) && (Oe.current = We ? Ie : null, _e("exiting"));
2201
732
  }
2202
- }, [ze, Ce, X, Fe]);
2203
- const nn = Ye(() => {
2204
- const p = Ue.current;
2205
- if (p === "exiting") {
2206
- Ae("hidden");
2207
- const w = Pe.current;
2208
- Pe.current = null, w != null && w !== "" && (ke(w), Ae("entering"));
2209
- } else p === "entering" && Ae("visible");
2210
- }, []), sn = (p) => {
2211
- if (!p) return;
2212
- if (p.mood != null) {
2213
- const _ = String(p.mood).toLowerCase();
2214
- Xe(_);
733
+ }, [
734
+ We,
735
+ Ie,
736
+ ge,
737
+ De
738
+ ]);
739
+ const pt = $e(() => {
740
+ const e = Le.current;
741
+ if (e === "exiting") {
742
+ _e("hidden");
743
+ const t = Oe.current;
744
+ Oe.current = null, t != null && t !== "" && (we(t), _e("entering"));
745
+ } else e === "entering" && _e("visible");
746
+ }, []), mt = (e) => {
747
+ if (!e) return;
748
+ if (e.mood != null) {
749
+ const r = String(e.mood).toLowerCase();
750
+ c(r);
2215
751
  }
2216
- if (p.expression != null) {
2217
- const _ = String(p.expression).trim();
2218
- et(_);
2219
- const I = qs.find((G) => G.name.toLowerCase() === _.toLowerCase());
2220
- Q(`[STREAM] Animation match for "${_}": ${I ? I.name : "NONE"}`), A(I?.url ?? "");
752
+ if (e.expression != null) {
753
+ const r = String(e.expression).trim();
754
+ n(r);
755
+ const l = $t.find(
756
+ (_) => _.name.toLowerCase() === r.toLowerCase()
757
+ );
758
+ B(
759
+ `[STREAM] Animation match for "${r}": ${l ? l.name : "NONE"}`
760
+ ), H(l?.url ?? "");
2221
761
  }
2222
- if (p.navigation != null) {
2223
- const _ = String(p.navigation).trim();
2224
- _ !== "" && (e ? e(_) : window.location.href = _);
762
+ if (e.navigation != null) {
763
+ const r = String(e.navigation).trim();
764
+ r !== "" && (w ? w(r) : window.open(r, "_blank"));
2225
765
  }
2226
- const w = p.ask_for || p.lead_capture?.ask_for, R = w ? String(w).trim().toLowerCase() : "", E = R === "none" || R === "<none>";
2227
- if (w && !E) {
2228
- const _ = R;
2229
- ee(_ || null), g(_ === "email" ? "Enter your email" : _ === "name" ? "Enter your name" : _ === "phone" ? "Enter your phone number" : "Chat with us");
2230
- } else (E || p.ask_for === null || p.lead_capture && p.lead_capture.ask_for === null || p.ask_for === "none") && (ee(null), x !== "Chat with us" && g("Chat with us"));
2231
- p.collected, p.valid;
2232
- }, rn = (p) => {
2233
- const w = p.trim();
2234
- if (!w) return null;
2235
- if (w.startsWith("{"))
766
+ const t = e.ask_for || e.lead_capture?.ask_for, i = t ? String(t).trim().toLowerCase() : "", a = i === "none" || i === "<none>";
767
+ if (t && !a) {
768
+ const r = i;
769
+ Ae(r || null), be(r === "email" ? "Enter your email" : r === "name" ? "Enter your name" : r === "phone" ? "Enter your phone number" : "Chat with us");
770
+ } else (a || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Ae(null), Y !== "Chat with us" && be("Chat with us"));
771
+ e.collected, e.valid;
772
+ }, gt = (e) => {
773
+ const t = e.trim();
774
+ if (!t) return null;
775
+ if (t.startsWith("{"))
2236
776
  try {
2237
- return JSON.parse(w);
777
+ return JSON.parse(t);
2238
778
  } catch {
2239
779
  return null;
2240
780
  }
2241
- if (w.includes(":")) {
2242
- const R = w.split(":"), E = R[0].trim().toLowerCase(), _ = R.slice(1).join(":").trim();
2243
- return { [E]: _ };
781
+ if (t.includes(":")) {
782
+ const i = t.split(":"), a = i[0].trim().toLowerCase(), r = i.slice(1).join(":").trim();
783
+ return { [a]: r };
2244
784
  }
2245
785
  return null;
2246
- }, on = Ye(() => {
2247
- }, []), St = (p) => {
2248
- if (fe.current)
2249
- p === "§" ? fe.current = !1 : (ae.current += p, o((w) => w + p));
2250
- else if (p === "§") {
2251
- fe.current = !0;
786
+ }, bt = $e(() => {
787
+ }, []), tt = (e) => {
788
+ if (Me.current)
789
+ e === "§" ? Me.current = !1 : (Te.current += e, re((t) => t + e));
790
+ else if (e === "§") {
791
+ Me.current = !0;
2252
792
  return;
2253
793
  } else
2254
- for (oe.current += p; oe.current.includes(`
794
+ for (ue.current += e; ue.current.includes(`
2255
795
  `); ) {
2256
- const w = oe.current.indexOf(`
2257
- `), R = oe.current.slice(0, w).trim();
2258
- oe.current = oe.current.slice(w + 1);
2259
- const E = rn(R);
2260
- E && sn(E);
796
+ const t = ue.current.indexOf(`
797
+ `), i = ue.current.slice(0, t).trim();
798
+ ue.current = ue.current.slice(t + 1);
799
+ const a = gt(i);
800
+ a && mt(a);
2261
801
  }
2262
802
  };
2263
- ie(() => {
803
+ z(() => {
2264
804
  (async () => {
2265
- if (!sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID")) {
2266
- const R = "secret", E = Math.floor(Date.now() / 1e3).toString();
805
+ if (!sessionStorage.getItem(
806
+ "STREAMOJI_LEADS_SESSION_LEAD_ID"
807
+ )) {
808
+ const i = "secret", a = Math.floor(Date.now() / 1e3).toString();
2267
809
  try {
2268
- const _ = new TextEncoder(), I = await crypto.subtle.importKey(
810
+ const r = new TextEncoder(), l = await crypto.subtle.importKey(
2269
811
  "raw",
2270
- _.encode(R),
812
+ r.encode(i),
2271
813
  { name: "HMAC", hash: "SHA-256" },
2272
814
  !1,
2273
815
  ["sign"]
2274
- ), G = await crypto.subtle.sign(
816
+ ), _ = await crypto.subtle.sign(
2275
817
  "HMAC",
2276
- I,
2277
- _.encode(E)
2278
- ), q = Array.from(new Uint8Array(G)).map((j) => j.toString(16).padStart(2, "0")).join("");
2279
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", q), Q("[SESSION] New HMAC UID generated and saved:", q);
2280
- } catch (_) {
2281
- console.error("[SESSION] HMAC generation failed:", _);
2282
- const I = Math.random().toString(36) + Date.now().toString();
2283
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", I);
818
+ l,
819
+ r.encode(a)
820
+ ), P = Array.from(new Uint8Array(_)).map((S) => S.toString(16).padStart(2, "0")).join("");
821
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", P), B("[SESSION] New HMAC UID generated and saved:", P);
822
+ } catch (r) {
823
+ console.error("[SESSION] HMAC generation failed:", r);
824
+ const l = Math.random().toString(36) + Date.now().toString();
825
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", l);
2284
826
  }
2285
827
  }
2286
- sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES", JSON.stringify([]));
828
+ sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || sessionStorage.setItem(
829
+ "STREAMOJI_LEADS_SESSION_MESSAGES",
830
+ JSON.stringify([])
831
+ );
2287
832
  })();
2288
833
  }, []);
2289
- const yt = () => {
834
+ const nt = () => {
2290
835
  try {
2291
- return JSON.parse(sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]");
836
+ return JSON.parse(
837
+ sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
838
+ );
2292
839
  } catch {
2293
840
  return [];
2294
841
  }
2295
- }, an = (p) => {
2296
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_MESSAGES", JSON.stringify(p));
2297
- }, [tt, nt] = K(!1), [At, st] = K(0), he = L(null), $e = L([]), Et = L(0), [Lt, cn] = K(null), [un, rt] = K(null), xe = L(null), Le = L(null), it = Ye(() => {
2298
- D.current = [], P.current = !1, T(!1), H.current = 0, B.current = 0, O.current = 0, F.current.forEach((p) => {
842
+ }, _t = (e) => {
843
+ sessionStorage.setItem(
844
+ "STREAMOJI_LEADS_SESSION_MESSAGES",
845
+ JSON.stringify(e)
846
+ );
847
+ }, [qe, Ge] = y(!1), [rt, ze] = y(0), oe = o(null), Pe = o([]), st = o(0), [it, wt] = y(
848
+ null
849
+ ), [vt, Ye] = y(
850
+ null
851
+ ), de = o(null), ye = o(
852
+ null
853
+ ), Ve = $e((e = !1) => {
854
+ e && (ee.current = !0, U(!1), k("Ready")), m.current = [], se.current = [], I.current = !1, ce(!1), b.current = 0, K.current = 0, q.current = 0, R.current.forEach((t) => {
2299
855
  try {
2300
- p.stop();
856
+ t.stop();
2301
857
  } catch {
2302
858
  }
2303
- }), He.current && (clearTimeout(He.current), He.current = null), Ne(null), A(""), F.current = [];
2304
- }, []), ln = async () => {
859
+ }), j.current && (clearTimeout(j.current), j.current = null), Ne(null), H(""), R.current = [];
860
+ }, []), St = async () => {
2305
861
  try {
2306
- const p = await navigator.mediaDevices.getUserMedia({ audio: !0 }), w = window.AudioContext || window.webkitAudioContext, R = new w(), E = R.createMediaStreamSource(p), _ = R.createAnalyser();
2307
- _.fftSize = 64, E.connect(_), xe.current = R, Le.current = E, rt(_);
2308
- const I = new MediaRecorder(p);
2309
- he.current = I, $e.current = [], I.ondataavailable = (G) => {
2310
- G.data.size > 0 && $e.current.push(G.data);
2311
- }, I.onstop = async () => {
2312
- const G = Date.now() - Et.current;
2313
- if (rt(null), Le.current && (Le.current.disconnect(), Le.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), G < 1e3) {
2314
- u("Recording too short. Hold or click longer."), f(!1);
862
+ const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, i = new t(), a = i.createMediaStreamSource(e), r = i.createAnalyser();
863
+ r.fftSize = 64, a.connect(r), de.current = i, ye.current = a, Ye(r);
864
+ const l = new MediaRecorder(e);
865
+ oe.current = l, Pe.current = [], l.ondataavailable = (_) => {
866
+ _.data.size > 0 && Pe.current.push(_.data);
867
+ }, l.onstop = async () => {
868
+ const _ = Date.now() - st.current;
869
+ if (Ye(null), ye.current && (ye.current.disconnect(), ye.current = null), de.current && de.current.state !== "closed" && (de.current.close(), de.current = null), _ < 1e3) {
870
+ k("Recording too short. Hold or click longer."), U(!1);
2315
871
  return;
2316
872
  }
2317
- const V = new Blob($e.current, { type: "audio/wav" });
2318
- await pn(V);
2319
- }, Et.current = Date.now(), I.start(100), nt(!0), u("Listening...");
2320
- } catch (p) {
2321
- console.error("Error accessing microphone:", p), u("Mic Access Error");
873
+ const A = new Blob(Pe.current, {
874
+ type: "audio/wav"
875
+ });
876
+ await Rt(A);
877
+ }, st.current = Date.now(), l.start(100), Ge(!0), k("Listening...");
878
+ } catch (e) {
879
+ console.error("Error accessing microphone:", e), k("Mic Access Error");
2322
880
  }
2323
- }, dn = () => {
2324
- he.current && he.current.state !== "inactive" && (he.current.stop(), he.current.stream.getTracks().forEach((p) => p.stop()), nt(!1));
2325
- }, fn = () => {
2326
- he.current && he.current.state !== "inactive" && (he.current.onstop = null, he.current.stop(), he.current.stream.getTracks().forEach((p) => p.stop()), rt(null), Le.current && (Le.current.disconnect(), Le.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), nt(!1), $e.current = [], u("Ready"));
881
+ }, yt = () => {
882
+ oe.current && oe.current.state !== "inactive" && (oe.current.stop(), oe.current.stream.getTracks().forEach((e) => e.stop()), Ge(!1));
883
+ }, xt = () => {
884
+ oe.current && oe.current.state !== "inactive" && (oe.current.onstop = null, oe.current.stop(), oe.current.stream.getTracks().forEach((e) => e.stop()), Ye(null), ye.current && (ye.current.disconnect(), ye.current = null), de.current && de.current.state !== "closed" && (de.current.close(), de.current = null), Ge(!1), Pe.current = [], k("Ready"));
2327
885
  };
2328
- ie(() => {
2329
- if (!h) return;
2330
- const p = () => {
2331
- const w = O.current;
2332
- if (w <= 0) return;
2333
- const R = y.current, E = H.current;
2334
- if (!R) return;
2335
- const _ = R.currentTime - E, I = Math.min(Math.max(0, _), w), G = a.trim().length;
2336
- if (G <= 0) return;
2337
- const V = Math.min(
2338
- Math.round(I / w * G),
2339
- G
886
+ z(() => {
887
+ if (!E) return;
888
+ const e = () => {
889
+ const t = q.current;
890
+ if (t <= 0) return;
891
+ const i = $.current, a = b.current;
892
+ if (!i) return;
893
+ const r = i.currentTime - a, l = Math.min(Math.max(0, r), t), _ = he.trim().length;
894
+ if (_ <= 0) return;
895
+ const A = Math.min(
896
+ Math.round(l / t * _),
897
+ _
2340
898
  );
2341
- ue(V);
899
+ Ue(A);
2342
900
  };
2343
- return clearInterval(Te.current ?? void 0), Te.current = setInterval(p, 90), () => clearInterval(Te.current ?? void 0);
2344
- }, [h, a, O.current]), ie(() => {
2345
- let p;
2346
- return tt ? (st(0), p = window.setInterval(() => {
2347
- st((w) => w + 1);
2348
- }, 1e3)) : st(0), () => clearInterval(p);
2349
- }, [tt]);
2350
- const hn = (p) => {
2351
- const w = p.numberOfChannels, R = p.length * w * 2 + 44, E = new ArrayBuffer(R), _ = new DataView(E);
2352
- let I = 0;
2353
- const G = (z) => {
2354
- _.setUint16(I, z, !0), I += 2;
2355
- }, V = (z) => {
2356
- _.setUint32(I, z, !0), I += 4;
901
+ return clearInterval(Ce.current ?? void 0), Ce.current = setInterval(e, 90), () => clearInterval(Ce.current ?? void 0);
902
+ }, [E, he, q.current]), z(() => {
903
+ let e;
904
+ return qe ? (ze(0), e = window.setInterval(() => {
905
+ ze((t) => t + 1);
906
+ }, 1e3)) : ze(0), () => clearInterval(e);
907
+ }, [qe]);
908
+ const kt = (e) => {
909
+ const t = e.numberOfChannels, i = e.length * t * 2 + 44, a = new ArrayBuffer(i), r = new DataView(a);
910
+ let l = 0;
911
+ const _ = (F) => {
912
+ r.setUint16(l, F, !0), l += 2;
913
+ }, A = (F) => {
914
+ r.setUint32(l, F, !0), l += 4;
2357
915
  };
2358
- V(1179011410), V(R - 8), V(1163280727), V(544501094), V(16), G(1), G(w), V(p.sampleRate), V(p.sampleRate * 2 * w), G(w * 2), G(16), V(1635017060), V(R - I - 4);
2359
- const q = [];
2360
- for (let z = 0; z < w; z++) q.push(p.getChannelData(z));
2361
- let j = 0;
2362
- for (; I < R; ) {
2363
- for (let z = 0; z < w; z++) {
2364
- let Y = Math.max(-1, Math.min(1, q[z][j]));
2365
- Y = Y < 0 ? Y * 32768 : Y * 32767, _.setInt16(I, Y, !0), I += 2;
916
+ A(1179011410), A(i - 8), A(1163280727), A(544501094), A(16), _(1), _(t), A(e.sampleRate), A(e.sampleRate * 2 * t), _(t * 2), _(16), A(1635017060), A(i - l - 4);
917
+ const P = [];
918
+ for (let F = 0; F < t; F++) P.push(e.getChannelData(F));
919
+ let S = 0;
920
+ for (; l < i; ) {
921
+ for (let F = 0; F < t; F++) {
922
+ let N = Math.max(-1, Math.min(1, P[F][S]));
923
+ N = N < 0 ? N * 32768 : N * 32767, r.setInt16(l, N, !0), l += 2;
2366
924
  }
2367
- j++;
925
+ S++;
2368
926
  }
2369
- return new Blob([E], { type: "audio/wav" });
2370
- }, ot = async (p, w, R = !1) => {
2371
- if (m.current) {
2372
- b.current.push({ audio: p, visemes: w, isNewSegment: R });
2373
- return;
2374
- }
2375
- m.current = !0;
2376
- try {
2377
- const E = window.AudioContext || window.webkitAudioContext, _ = y.current ?? new E();
2378
- _.state === "suspended" && await _.resume(), y.current = _;
2379
- const I = window.atob(p), G = new Uint8Array(I.length);
2380
- for (let $ = 0; $ < I.length; $++) G[$] = I.charCodeAt($);
2381
- const V = await _.decodeAudioData(G.buffer.slice(0));
2382
- O.current += V.duration;
2383
- const q = _.currentTime;
2384
- let j = B.current;
2385
- const z = !P.current;
2386
- j < q && (j = q + 0.1), B.current = j + V.duration;
2387
- const Y = _.createBufferSource();
2388
- Y.buffer = V;
2389
- let J = Lt;
2390
- if ((!J || J.context !== _) && (J = _.createAnalyser(), J.fftSize = 64, J.connect(_.destination), cn(J)), Y.connect(J), F.current.push(Y), z) {
2391
- P.current = !0, T(!0), Q(`[AUDIO] setIsSpeaking(true) - First chunk starting at ${j.toFixed(3)}`), H.current = j;
2392
- const $ = (j - q) * 1e3;
2393
- S.current = performance.now() + $, Q(`[AUDIO] Response started. Initial startTime: ${j.toFixed(3)}, CT: ${q.toFixed(3)}`);
927
+ return new Blob([a], { type: "audio/wav" });
928
+ }, Xe = async (e, t, i = !1) => {
929
+ if (!ee.current) {
930
+ if (pe.current) {
931
+ se.current.push({
932
+ audio: e,
933
+ visemes: t,
934
+ isNewSegment: i
935
+ });
936
+ return;
2394
937
  }
2395
- Y.start(j);
2396
- const re = (j - H.current) * 1e3;
2397
- R && (U.current = re, Q(`[AUDIO] New segment detected at +${re.toFixed(0)}ms. Resetting segment offset.`)), w.forEach(($, we) => {
2398
- const W = $.symbol ?? "";
2399
- if (W) {
2400
- const le = sr(W), pe = Math.round($.start * 1e3), Me = Math.round(($.duration ?? 0) * 1e3), vt = U.current + pe;
2401
- we < 3 && Q(`[AUDIO] Viseme "${W}": segment_relative=${pe}ms, segment_offset=${U.current.toFixed(0)}ms => vtime=${vt}ms`), le.forEach((kt) => {
2402
- D.current.push({ viseme: kt.v, weight: kt.w, vtime: vt, vduration: Me });
2403
- });
938
+ pe.current = !0;
939
+ try {
940
+ const a = window.AudioContext || window.webkitAudioContext, r = $.current ?? new a();
941
+ r.state === "suspended" && await r.resume(), $.current = r;
942
+ const l = window.atob(e), _ = new Uint8Array(l.length);
943
+ for (let T = 0; T < l.length; T++)
944
+ _[T] = l.charCodeAt(T);
945
+ const A = await r.decodeAudioData(_.buffer.slice(0));
946
+ q.current += A.duration;
947
+ const P = r.currentTime;
948
+ let S = K.current;
949
+ const F = !I.current;
950
+ S < P && (S = P + 0.1), K.current = S + A.duration;
951
+ const N = r.createBufferSource();
952
+ N.buffer = A;
953
+ let V = it;
954
+ if ((!V || V.context !== r) && (V = r.createAnalyser(), V.fftSize = 64, V.connect(r.destination), wt(V)), N.connect(V), R.current.push(N), ee.current) {
955
+ R.current = R.current.filter((T) => T !== N);
956
+ return;
957
+ }
958
+ if (F) {
959
+ I.current = !0, ce(!0), B(
960
+ `[AUDIO] setIsSpeaking(true) - First chunk starting at ${S.toFixed(
961
+ 3
962
+ )}`
963
+ ), b.current = S;
964
+ const T = (S - P) * 1e3;
965
+ J.current = performance.now() + T, B(
966
+ `[AUDIO] Response started. Initial startTime: ${S.toFixed(
967
+ 3
968
+ )}, CT: ${P.toFixed(3)}`
969
+ );
970
+ }
971
+ N.start(S);
972
+ const X = (S - b.current) * 1e3;
973
+ i && (le.current = X, B(
974
+ `[AUDIO] New segment detected at +${X.toFixed(
975
+ 0
976
+ )}ms. Resetting segment offset.`
977
+ )), t.forEach((T, fe) => {
978
+ const C = T.symbol ?? "";
979
+ if (C) {
980
+ const te = Xt(C), ae = Math.round(T.start * 1e3), xe = Math.round((T.duration ?? 0) * 1e3), ct = le.current + ae;
981
+ fe < 3 && B(
982
+ `[AUDIO] Viseme "${C}": segment_relative=${ae}ms, segment_offset=${le.current.toFixed(
983
+ 0
984
+ )}ms => vtime=${ct}ms`
985
+ ), te.forEach((lt) => {
986
+ m.current.push({
987
+ viseme: lt.v,
988
+ weight: lt.w,
989
+ vtime: ct,
990
+ vduration: xe
991
+ });
992
+ });
993
+ }
994
+ }), k("Speaking...");
995
+ } finally {
996
+ if (pe.current = !1, se.current.length > 0) {
997
+ const a = se.current.shift();
998
+ a && Xe(a.audio, a.visemes, a.isNewSegment);
2404
999
  }
2405
- }), u("Speaking...");
2406
- } finally {
2407
- if (m.current = !1, b.current.length > 0) {
2408
- const E = b.current.shift();
2409
- E && ot(E.audio, E.visemes, E.isNewSegment);
2410
1000
  }
2411
1001
  }
2412
- }, pn = async (p) => {
1002
+ }, Rt = async (e) => {
2413
1003
  try {
2414
- f(!0), ae.current = "", o(""), u("Processing Voice...");
2415
- const w = await p.arrayBuffer(), E = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(w), _ = hn(E), I = new FileReader();
2416
- I.readAsDataURL(_), I.onloadend = async () => {
2417
- const G = I.result.split(",")[1];
2418
- it(), s(""), oe.current = "", fe.current = !1;
2419
- const V = `${Vt}/stt?token=${encodeURIComponent(r)}`, q = await fetch(V, {
1004
+ U(!0), Te.current = "", re(""), k("Processing Voice...");
1005
+ const t = await e.arrayBuffer(), a = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), r = kt(a), l = new FileReader();
1006
+ l.readAsDataURL(r), l.onloadend = async () => {
1007
+ const _ = l.result.split(",")[1];
1008
+ Ve(), L(""), ue.current = "", Me.current = !1;
1009
+ const A = `${dt}/stt?token=${encodeURIComponent(
1010
+ p
1011
+ )}`, P = await fetch(A, {
2420
1012
  method: "POST",
2421
1013
  headers: { "Content-Type": "application/json" },
2422
- body: JSON.stringify({ audio_base64: G, audio_format: "wav" })
1014
+ body: JSON.stringify({
1015
+ audio_base64: _,
1016
+ audio_format: "wav"
1017
+ })
2423
1018
  });
2424
- if (!q.ok) {
2425
- const we = await q.text();
2426
- let W = "STT Failed";
1019
+ if (!P.ok) {
1020
+ const fe = await P.text();
1021
+ let C = "STT Failed";
2427
1022
  try {
2428
- W = JSON.parse(we).error || W;
1023
+ C = JSON.parse(fe).error || C;
2429
1024
  } catch {
2430
- we && (W = we.slice(0, 200));
1025
+ fe && (C = fe.slice(0, 200));
2431
1026
  }
2432
- throw new Error(W);
1027
+ throw new Error(C);
2433
1028
  }
2434
- const j = q.body;
2435
- if (Q("this is body" + j), !j) {
2436
- u("STT Failed"), f(!1);
1029
+ const S = P.body;
1030
+ if (B("this is body" + S), !S) {
1031
+ k("STT Failed"), U(!1);
2437
1032
  return;
2438
1033
  }
2439
- const z = j.getReader(), Y = new TextDecoder();
2440
- let J = "", re = !1;
2441
- const $ = async (we, W) => {
2442
- switch (we) {
1034
+ const F = S.getReader();
1035
+ ee.current = !1;
1036
+ const N = new TextDecoder();
1037
+ let V = "", X = !1;
1038
+ const T = async (fe, C) => {
1039
+ switch (fe) {
2443
1040
  case "transcript":
2444
- W.transcript != null && s(String(W.transcript));
1041
+ C.transcript != null && L(String(C.transcript));
2445
1042
  break;
2446
1043
  case "text": {
2447
- const le = W.delta ?? W.text ?? "";
2448
- le && St(le);
1044
+ const te = C.delta ?? C.text ?? "";
1045
+ te && tt(te);
2449
1046
  break;
2450
1047
  }
2451
1048
  case "audio": {
2452
- const le = W.chunk, pe = W.visemes ?? [], Me = !!W.is_new_segment;
2453
- le && await ot(le, pe, Me);
1049
+ const te = C.chunk, ae = C.visemes ?? [], xe = !!C.is_new_segment;
1050
+ te && await Xe(te, ae, xe);
2454
1051
  break;
2455
1052
  }
2456
1053
  case "done": {
2457
- re = !0, u("Ready"), f(!1);
1054
+ X = !0, k("Ready"), U(!1);
2458
1055
  break;
2459
1056
  }
2460
1057
  case "error": {
2461
- re = !0, u("STT Failed"), f(!1);
1058
+ X = !0, k("STT Failed"), U(!1);
2462
1059
  break;
2463
1060
  }
2464
1061
  default:
@@ -2466,292 +1063,435 @@ const ar = ({ token: d, agentToken: t, onNavigationRequested: e } = {}) => {
2466
1063
  }
2467
1064
  };
2468
1065
  for (; ; ) {
2469
- const { done: we, value: W } = await z.read();
2470
- W && (J += Y.decode(W, { stream: !0 }));
2471
- const le = J.split(`
1066
+ const { done: fe, value: C } = await F.read();
1067
+ C && (V += N.decode(C, { stream: !0 }));
1068
+ const te = V.split(`
2472
1069
 
2473
1070
  `);
2474
- J = le.pop() ?? "";
2475
- for (const pe of le) {
2476
- const Me = qe(pe);
2477
- Me && await $(Me.event, Me.data);
1071
+ V = te.pop() ?? "";
1072
+ for (const ae of te) {
1073
+ const xe = Be(ae);
1074
+ xe && await T(xe.event, xe.data);
2478
1075
  }
2479
- if (we) {
2480
- if (J.trim()) {
2481
- const pe = qe(J.trim());
2482
- pe && await $(pe.event, pe.data);
1076
+ if (fe) {
1077
+ if (V.trim()) {
1078
+ const ae = Be(V.trim());
1079
+ ae && await T(ae.event, ae.data);
2483
1080
  }
2484
- re || (u("Ready"), f(!1));
1081
+ X || (k("Ready"), U(!1));
2485
1082
  break;
2486
1083
  }
2487
1084
  }
2488
1085
  };
2489
- } catch (w) {
2490
- console.error("Audio Submission Error:", w), u("STT Failed"), f(!1);
1086
+ } catch (t) {
1087
+ console.error("Audio Submission Error:", t), k("STT Failed"), U(!1);
2491
1088
  }
2492
- }, mn = async (p) => {
2493
- p && p.preventDefault(), ae.current = "", o(""), !(!i || l) && await gn(i);
2494
- }, qe = (p) => {
2495
- const w = p.split(/\r?\n/);
2496
- let R = "", E = "";
2497
- for (const I of w)
2498
- I.startsWith("event:") ? R = I.slice(6).trim() : I.startsWith("data:") && (E = I.slice(5).trim());
2499
- if (!R) return null;
2500
- let _ = {};
2501
- if (E)
1089
+ }, At = async (e) => {
1090
+ e && e.preventDefault(), Te.current = "", re(""), !(!M || Q) && await Lt(M);
1091
+ }, Be = (e) => {
1092
+ const t = e.split(/\r?\n/);
1093
+ let i = "", a = "";
1094
+ for (const l of t)
1095
+ l.startsWith("event:") ? i = l.slice(6).trim() : l.startsWith("data:") && (a = l.slice(5).trim());
1096
+ if (!i) return null;
1097
+ let r = {};
1098
+ if (a)
2502
1099
  try {
2503
- _ = JSON.parse(E);
1100
+ r = JSON.parse(a);
2504
1101
  } catch {
2505
- _ = { raw: E };
1102
+ r = { raw: a };
2506
1103
  }
2507
- return { event: R, data: _ };
2508
- }, Mt = (p, w) => {
2509
- switch (p) {
1104
+ return { event: i, data: r };
1105
+ }, ot = (e, t) => {
1106
+ switch (e) {
2510
1107
  case "connected":
2511
- oe.current = "", fe.current = !1;
1108
+ ue.current = "", Me.current = !1;
2512
1109
  break;
2513
1110
  case "text": {
2514
- const R = w.delta ?? "";
2515
- R && St(R);
1111
+ const i = t.delta ?? "";
1112
+ i && tt(i);
2516
1113
  break;
2517
1114
  }
2518
1115
  case "audio": {
2519
- const R = w.chunk, E = w.visemes ?? [];
2520
- R && ot(R, E);
1116
+ const i = t.chunk, a = t.visemes ?? [];
1117
+ i && Xe(i, a);
2521
1118
  break;
2522
1119
  }
2523
1120
  case "done": {
2524
- const R = yt(), E = ae.current.trim(), _ = [
2525
- ...R,
2526
- { role: "user", content: i || "..." },
2527
- { role: "assistant", content: E }
1121
+ const i = nt(), a = Te.current.trim(), r = [
1122
+ ...i,
1123
+ { role: "user", content: M || "..." },
1124
+ { role: "assistant", content: a }
2528
1125
  ];
2529
- an(_), C.current = [...D.current], u("Ready"), f(!1), s("");
1126
+ _t(r), v.current = [...m.current], k("Ready"), U(!1), L("");
2530
1127
  break;
2531
1128
  }
2532
1129
  case "error": {
2533
- const R = w.message ?? "Unknown error";
2534
- ae.current = R, o(R), u("Agent Failed"), f(!1);
1130
+ const i = t.message ?? "Unknown error";
1131
+ Te.current = i, re(i), k("Agent Failed"), U(!1);
2535
1132
  break;
2536
1133
  }
2537
1134
  }
2538
- }, gn = async (p) => {
2539
- f(!0), u("Thinking..."), ae.current = "", oe.current = "", fe.current = !1, it(), O.current = 0, ue(0);
2540
- const w = `${Vt}/agent/chat?token=${encodeURIComponent(r)}`;
1135
+ }, Lt = async (e) => {
1136
+ U(!0), k("Thinking..."), Te.current = "", ue.current = "", Me.current = !1, Ve(), q.current = 0, Ue(0);
1137
+ const t = `${dt}/agent/chat?token=${encodeURIComponent(
1138
+ p
1139
+ )}`;
2541
1140
  try {
2542
- const R = yt();
2543
- let E = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
2544
- E || (Ks("[CHAT] Session UID missing at send time! Generating emergency backup."), E = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", E));
2545
- const _ = {
2546
- history: R,
2547
- question: p,
2548
- lead_id: E
1141
+ const i = nt();
1142
+ let a = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1143
+ a || (Nt(
1144
+ "[CHAT] Session UID missing at send time! Generating emergency backup."
1145
+ ), a = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", a));
1146
+ const r = {
1147
+ history: i,
1148
+ question: e,
1149
+ lead_id: a
2549
1150
  };
2550
- Q("[CHAT] Sending payload:", _);
2551
- const I = await fetch(w, {
1151
+ B("[CHAT] Sending payload:", r);
1152
+ const l = await fetch(t, {
2552
1153
  method: "POST",
2553
1154
  headers: {
2554
1155
  "Content-Type": "application/json"
2555
1156
  },
2556
- body: JSON.stringify(_),
1157
+ body: JSON.stringify(r),
2557
1158
  cache: "default"
2558
1159
  });
2559
- if (!I.ok)
1160
+ if (!l.ok)
2560
1161
  throw new Error("Agent request failed");
2561
- const G = I.body;
2562
- if (!G) {
2563
- u("Agent Failed"), f(!1);
1162
+ const _ = l.body;
1163
+ if (!_) {
1164
+ k("Agent Failed"), U(!1);
2564
1165
  return;
2565
1166
  }
2566
- const V = G.getReader(), q = new TextDecoder();
2567
- let j = "";
1167
+ const A = _.getReader();
1168
+ ee.current = !1;
1169
+ const P = new TextDecoder();
1170
+ let S = "";
2568
1171
  for (; ; ) {
2569
- const { done: z, value: Y } = await V.read();
2570
- Q(`[SSE] Chunk received. done=${z}, length=${Y?.length || 0}`), Y && (j += q.decode(Y, { stream: !0 }));
2571
- const J = j.split(`
1172
+ const { done: F, value: N } = await A.read();
1173
+ B(
1174
+ `[SSE] Chunk received. done=${F}, length=${N?.length || 0}`
1175
+ ), N && (S += P.decode(N, { stream: !0 }));
1176
+ const V = S.split(`
2572
1177
 
2573
1178
  `);
2574
- j = J.pop() ?? "";
2575
- for (const re of J) {
2576
- Q(`[SSE] Processing block: ${re.slice(0, 50)}...`);
2577
- const $ = qe(re);
2578
- $ && (Q(`[SSE] Event: ${$.event}`), Mt($.event, $.data));
1179
+ S = V.pop() ?? "";
1180
+ for (const X of V) {
1181
+ B(`[SSE] Processing block: ${X.slice(0, 50)}...`);
1182
+ const T = Be(X);
1183
+ T && (B(`[SSE] Event: ${T.event}`), ot(T.event, T.data));
2579
1184
  }
2580
- if (z) {
2581
- if (Q("[SSE] Stream finished"), j.trim()) {
2582
- const re = qe(j.trim());
2583
- re && Mt(re.event, re.data);
1185
+ if (F) {
1186
+ if (B("[SSE] Stream finished"), S.trim()) {
1187
+ const X = Be(S.trim());
1188
+ X && ot(X.event, X.data);
2584
1189
  }
2585
- u("Ready"), f(!1), s("");
1190
+ k("Ready"), U(!1), L("");
2586
1191
  break;
2587
1192
  }
2588
1193
  }
2589
- } catch (R) {
2590
- console.error("Chat Error:", R), u("Agent Failed"), f(!1);
1194
+ } catch (i) {
1195
+ console.error("Chat Error:", i), k("Agent Failed"), U(!1);
2591
1196
  }
2592
- }, It = a.trim(), at = It && h ? It.slice(0, Z != null && Z > 0 ? Z : 0) : "";
2593
- ie(() => {
2594
- const p = se.current;
2595
- p !== "exiting" && (at ? (_e(at), p === "hidden" && Ee("entering")) : (p === "visible" || p === "entering") && Ee("exiting"));
2596
- }, [at, be]);
2597
- const Tn = Ye(() => {
2598
- const p = se.current;
2599
- p === "entering" ? Ee("visible") : p === "exiting" && Ee("hidden");
1197
+ }, at = he.trim(), Ke = at && E ? at.slice(
1198
+ 0,
1199
+ Re != null && Re > 0 ? Re : 0
1200
+ ) : "";
1201
+ z(() => {
1202
+ const e = Je.current;
1203
+ e !== "exiting" && (Ke ? (Se(Ke), e === "hidden" && ve("entering")) : (e === "visible" || e === "entering") && ve("exiting"));
1204
+ }, [Ke, W]);
1205
+ const Et = $e(() => {
1206
+ const e = Je.current;
1207
+ e === "entering" ? ve("visible") : e === "exiting" && ve("hidden");
2600
1208
  }, []);
2601
- return _n(() => {
2602
- const p = Be.current;
2603
- p && (p.scrollTop = p.scrollHeight);
2604
- }, [te]), /* @__PURE__ */ de("div", { className: "avatar-widget-container", children: [
2605
- /* @__PURE__ */ de("div", { className: "avatar-input-area", children: [
2606
- X !== "hidden" ? /* @__PURE__ */ N(
1209
+ return Ot(() => {
1210
+ const e = ie.current;
1211
+ e && (e.scrollTop = e.scrollHeight);
1212
+ }, [Ee]), /* @__PURE__ */ ne("div", { className: "avatar-widget-container", children: [
1213
+ /* @__PURE__ */ ne("div", { className: "avatar-input-area", children: [
1214
+ ge !== "hidden" ? /* @__PURE__ */ f(
2607
1215
  "div",
2608
1216
  {
2609
- className: `avatar-thinking-tab${X === "exiting" ? " avatar-thinking-tab--exiting" : X === "entering" ? " avatar-thinking-tab--entering" : ""}`,
2610
- onAnimationEnd: nn,
2611
- children: Fe
1217
+ className: `avatar-thinking-tab${ge === "exiting" ? " avatar-thinking-tab--exiting" : ge === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1218
+ onAnimationEnd: pt,
1219
+ children: De
2612
1220
  }
2613
1221
  ) : null,
2614
- /* @__PURE__ */ N("div", { className: "avatar-input-container", children: /* @__PURE__ */ N("div", { style: { display: "flex", alignItems: "center", width: "100%", height: "100%" }, children: tt ? /* @__PURE__ */ de("div", { className: "avatar-input-recording", children: [
2615
- /* @__PURE__ */ N(
2616
- "button",
2617
- {
2618
- type: "button",
2619
- className: "avatar-recording-cancel",
2620
- onClick: fn,
2621
- title: "Cancel",
2622
- children: /* @__PURE__ */ de("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", style: { display: "block" }, children: [
2623
- /* @__PURE__ */ N("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
2624
- /* @__PURE__ */ N("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
2625
- ] })
2626
- }
2627
- ),
2628
- /* @__PURE__ */ de("div", { style: { flex: 1, height: "100%", position: "relative", display: "flex", alignItems: "center", minWidth: 0 }, children: [
2629
- /* @__PURE__ */ N("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ N(jt, { analyser: un }) }),
2630
- /* @__PURE__ */ de("span", { style: {
2631
- fontSize: "0.75rem",
2632
- color: "#64748b",
2633
- fontWeight: 500,
2634
- marginLeft: "4px",
2635
- minWidth: "32px",
2636
- textAlign: "right",
2637
- fontVariantNumeric: "tabular-nums"
2638
- }, children: [
2639
- Math.floor(At / 60),
2640
- ":",
2641
- String(At % 60).padStart(2, "0")
2642
- ] })
2643
- ] }),
2644
- /* @__PURE__ */ N(
2645
- "button",
2646
- {
2647
- type: "button",
2648
- className: "avatar-recording-confirm",
2649
- onClick: dn,
2650
- title: "Send",
2651
- children: /* @__PURE__ */ N("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", style: { display: "block" }, children: /* @__PURE__ */ N("polyline", { points: "20 6 9 17 4 12" }) })
2652
- }
2653
- )
2654
- ] }) : h ? /* @__PURE__ */ N("div", { style: { flex: 1, height: "100%", display: "flex", alignItems: "center", paddingRight: "8px" }, children: /* @__PURE__ */ N(jt, { analyser: Lt }) }) : l ? /* @__PURE__ */ N("div", { style: { flex: 1, height: "100%", display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ N("div", { className: "avatar-input-loader" }) }) : /* @__PURE__ */ de("form", { onSubmit: mn, style: { flex: 1, display: "flex", height: "100%", alignItems: "center" }, children: [
2655
- /* @__PURE__ */ N(
2656
- "input",
2657
- {
2658
- id: "avatar-text-input",
2659
- type: "text",
2660
- value: i,
2661
- onChange: (p) => s(p.target.value),
2662
- placeholder: "Ask me anything",
2663
- disabled: l,
2664
- autoComplete: "off",
2665
- style: { width: "100%", height: "100%" }
2666
- }
2667
- ),
2668
- i.trim() === "" ? /* @__PURE__ */ N(
2669
- "button",
2670
- {
2671
- type: "button",
2672
- className: "mic-button",
2673
- onClick: ln,
2674
- disabled: l,
2675
- style: { backgroundColor: "#1e4a5e" },
2676
- children: /* @__PURE__ */ de("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2677
- /* @__PURE__ */ N("path", { d: "M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z", fill: "white" }),
2678
- /* @__PURE__ */ N("path", { d: "M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z", fill: "white" })
2679
- ] })
2680
- }
2681
- ) : /* @__PURE__ */ N(
2682
- "button",
2683
- {
2684
- type: "submit",
2685
- className: "mic-button",
2686
- disabled: l,
2687
- style: { backgroundColor: "#1e4a5e" },
2688
- title: "Send",
2689
- children: /* @__PURE__ */ de("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
2690
- /* @__PURE__ */ N("path", { d: "M22 2L11 13", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
2691
- /* @__PURE__ */ N("path", { d: "M22 2L15 22L11 13L2 9L22 2Z", stroke: "white", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
2692
- ] })
2693
- }
2694
- )
2695
- ] }) }) })
1222
+ /* @__PURE__ */ f("div", { className: "avatar-input-container", children: /* @__PURE__ */ f(
1223
+ "div",
1224
+ {
1225
+ style: {
1226
+ display: "flex",
1227
+ alignItems: "center",
1228
+ width: "100%",
1229
+ height: "100%"
1230
+ },
1231
+ children: qe ? /* @__PURE__ */ ne("div", { className: "avatar-input-recording", children: [
1232
+ /* @__PURE__ */ f(
1233
+ "button",
1234
+ {
1235
+ type: "button",
1236
+ className: "avatar-recording-cancel",
1237
+ onClick: xt,
1238
+ title: "Cancel",
1239
+ children: /* @__PURE__ */ ne(
1240
+ "svg",
1241
+ {
1242
+ width: "18",
1243
+ height: "18",
1244
+ viewBox: "0 0 24 24",
1245
+ fill: "none",
1246
+ stroke: "currentColor",
1247
+ strokeWidth: "2.5",
1248
+ strokeLinecap: "round",
1249
+ strokeLinejoin: "round",
1250
+ style: { display: "block" },
1251
+ children: [
1252
+ /* @__PURE__ */ f("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1253
+ /* @__PURE__ */ f("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1254
+ ]
1255
+ }
1256
+ )
1257
+ }
1258
+ ),
1259
+ /* @__PURE__ */ ne(
1260
+ "div",
1261
+ {
1262
+ style: {
1263
+ flex: 1,
1264
+ height: "100%",
1265
+ position: "relative",
1266
+ display: "flex",
1267
+ alignItems: "center",
1268
+ minWidth: 0
1269
+ },
1270
+ children: [
1271
+ /* @__PURE__ */ f("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ f(ut, { analyser: vt }) }),
1272
+ /* @__PURE__ */ ne(
1273
+ "span",
1274
+ {
1275
+ style: {
1276
+ fontSize: "0.75rem",
1277
+ color: "#64748b",
1278
+ fontWeight: 500,
1279
+ marginLeft: "4px",
1280
+ minWidth: "32px",
1281
+ textAlign: "right",
1282
+ fontVariantNumeric: "tabular-nums"
1283
+ },
1284
+ children: [
1285
+ Math.floor(rt / 60),
1286
+ ":",
1287
+ String(rt % 60).padStart(2, "0")
1288
+ ]
1289
+ }
1290
+ )
1291
+ ]
1292
+ }
1293
+ ),
1294
+ /* @__PURE__ */ f(
1295
+ "button",
1296
+ {
1297
+ type: "button",
1298
+ className: "avatar-recording-confirm",
1299
+ onClick: yt,
1300
+ title: "Send",
1301
+ children: /* @__PURE__ */ f(
1302
+ "svg",
1303
+ {
1304
+ width: "18",
1305
+ height: "18",
1306
+ viewBox: "0 0 24 24",
1307
+ fill: "none",
1308
+ stroke: "currentColor",
1309
+ strokeWidth: "2.5",
1310
+ strokeLinecap: "round",
1311
+ strokeLinejoin: "round",
1312
+ style: { display: "block" },
1313
+ children: /* @__PURE__ */ f("polyline", { points: "20 6 9 17 4 12" })
1314
+ }
1315
+ )
1316
+ }
1317
+ )
1318
+ ] }) : E ? /* @__PURE__ */ ne("div", { className: "avatar-input-speaking", children: [
1319
+ /* @__PURE__ */ f(
1320
+ "div",
1321
+ {
1322
+ style: {
1323
+ flex: 1,
1324
+ height: "100%",
1325
+ display: "flex",
1326
+ alignItems: "center",
1327
+ paddingRight: "8px"
1328
+ },
1329
+ children: /* @__PURE__ */ f(ut, { analyser: it })
1330
+ }
1331
+ ),
1332
+ /* @__PURE__ */ f(
1333
+ "button",
1334
+ {
1335
+ type: "button",
1336
+ className: "avatar-speaking-stop",
1337
+ onClick: () => Ve(!0),
1338
+ title: "Stop",
1339
+ children: /* @__PURE__ */ f("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
1340
+ }
1341
+ )
1342
+ ] }) : Q ? /* @__PURE__ */ f(
1343
+ "div",
1344
+ {
1345
+ style: {
1346
+ flex: 1,
1347
+ height: "100%",
1348
+ display: "flex",
1349
+ alignItems: "center",
1350
+ justifyContent: "center"
1351
+ },
1352
+ children: /* @__PURE__ */ f("div", { className: "avatar-input-loader" })
1353
+ }
1354
+ ) : /* @__PURE__ */ ne(
1355
+ "form",
1356
+ {
1357
+ onSubmit: At,
1358
+ style: {
1359
+ flex: 1,
1360
+ display: "flex",
1361
+ height: "100%",
1362
+ alignItems: "center"
1363
+ },
1364
+ children: [
1365
+ /* @__PURE__ */ f(
1366
+ "input",
1367
+ {
1368
+ id: "avatar-text-input",
1369
+ type: "text",
1370
+ value: M,
1371
+ onChange: (e) => L(e.target.value),
1372
+ placeholder: "Ask me anything",
1373
+ disabled: Q,
1374
+ autoComplete: "off",
1375
+ style: { width: "100%", height: "100%" }
1376
+ }
1377
+ ),
1378
+ M.trim() === "" ? /* @__PURE__ */ f(
1379
+ "button",
1380
+ {
1381
+ type: "button",
1382
+ className: "mic-button",
1383
+ onClick: St,
1384
+ disabled: Q,
1385
+ style: { backgroundColor: "#1e4a5e" },
1386
+ children: /* @__PURE__ */ ne(
1387
+ "svg",
1388
+ {
1389
+ width: "28",
1390
+ height: "28",
1391
+ viewBox: "0 0 24 24",
1392
+ fill: "none",
1393
+ xmlns: "http://www.w3.org/2000/svg",
1394
+ children: [
1395
+ /* @__PURE__ */ f(
1396
+ "path",
1397
+ {
1398
+ d: "M12 14C13.66 14 15 12.66 15 11V5C15 3.34 13.66 2 12 2C10.34 2 9 3.34 9 5V11C9 12.66 10.34 14 12 14Z",
1399
+ fill: "white"
1400
+ }
1401
+ ),
1402
+ /* @__PURE__ */ f(
1403
+ "path",
1404
+ {
1405
+ d: "M17 11C17 13.76 14.76 16 12 16C9.24 16 7 13.76 7 11H5C5 14.53 7.61 17.43 11 17.93V21H13V17.93C16.39 17.43 19 14.53 19 11H17Z",
1406
+ fill: "white"
1407
+ }
1408
+ )
1409
+ ]
1410
+ }
1411
+ )
1412
+ }
1413
+ ) : /* @__PURE__ */ f(
1414
+ "button",
1415
+ {
1416
+ type: "submit",
1417
+ className: "mic-button",
1418
+ disabled: Q,
1419
+ style: { backgroundColor: "#1e4a5e" },
1420
+ title: "Send",
1421
+ children: /* @__PURE__ */ f("img", { src: "/assets/leadmoji-logo-send.png", alt: "Send", width: 24, height: 24 })
1422
+ }
1423
+ )
1424
+ ]
1425
+ }
1426
+ )
1427
+ }
1428
+ ) })
2696
1429
  ] }),
2697
- /* @__PURE__ */ N("div", { className: "avatar-wrapper", children: /* @__PURE__ */ de("div", { className: "avatar-scene-wrapper", children: [
2698
- be !== "hidden" && /* @__PURE__ */ N(
1430
+ /* @__PURE__ */ f("div", { className: "avatar-wrapper", children: /* @__PURE__ */ ne("div", { className: "avatar-scene-wrapper", children: [
1431
+ W !== "hidden" && /* @__PURE__ */ f(
2699
1432
  "div",
2700
1433
  {
2701
- className: `avatar-bubble${be === "entering" ? " avatar-bubble--entering" : be === "exiting" ? " avatar-bubble--exiting" : ""}`,
2702
- onAnimationEnd: Tn,
2703
- children: /* @__PURE__ */ N("div", { ref: Be, className: "avatar-bubble__content", children: te })
1434
+ className: `avatar-bubble${W === "entering" ? " avatar-bubble--entering" : W === "exiting" ? " avatar-bubble--exiting" : ""}`,
1435
+ onAnimationEnd: Et,
1436
+ children: /* @__PURE__ */ f("div", { ref: ie, className: "avatar-bubble__content", children: Ee })
2704
1437
  }
2705
1438
  ),
2706
- /* @__PURE__ */ N("div", { className: "avatar-canvas-layer", style: { width: 600, height: 600 }, children: /* @__PURE__ */ de(
2707
- Rn,
1439
+ /* @__PURE__ */ f(
1440
+ "div",
2708
1441
  {
2709
- shadows: !0,
2710
- camera: { position: [0.2, 1.4, 3], fov: 42 },
2711
- gl: { alpha: !0 },
2712
- dpr: 1.8,
2713
- style: { pointerEvents: "none", width: "100%", height: "100%" },
2714
- children: [
2715
- /* @__PURE__ */ N(rr, { target: Qs }),
2716
- /* @__PURE__ */ N("ambientLight", { intensity: 0.7 }),
2717
- /* @__PURE__ */ N("directionalLight", { position: [0, 2, 2], intensity: 1 }),
2718
- /* @__PURE__ */ N(yn, { preset: "city" }),
2719
- /* @__PURE__ */ N(xn, { fallback: null, children: n !== null && /* @__PURE__ */ N(
2720
- ir,
2721
- {
2722
- avatarUrl: n,
2723
- isPlayingRef: P,
2724
- visemeQueueRef: D,
2725
- audioContextRef: y,
2726
- responseAudioStartTimeRef: H,
2727
- adjustments: Js,
2728
- mood: ye,
2729
- expression: Ze,
2730
- agentResponse: a,
2731
- isSpeaking: h,
2732
- nextStartTimeRef: B,
2733
- stopPlayback: it,
2734
- setIsSpeaking: T,
2735
- expressionUrl: v,
2736
- onExpressionFinished: on
2737
- }
2738
- ) })
2739
- ]
1442
+ className: "avatar-canvas-layer",
1443
+ style: { width: Z, height: Z },
1444
+ children: /* @__PURE__ */ ne(
1445
+ It,
1446
+ {
1447
+ shadows: !0,
1448
+ camera: { position: [0.2, 1.4, 3], fov: 42 },
1449
+ gl: { alpha: !0 },
1450
+ dpr: 1.8,
1451
+ style: { pointerEvents: "none", width: "100%", height: "100%" },
1452
+ children: [
1453
+ /* @__PURE__ */ f(Kt, { target: Jt }),
1454
+ /* @__PURE__ */ f("ambientLight", { intensity: 0.7 }),
1455
+ /* @__PURE__ */ f("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1456
+ /* @__PURE__ */ f(Mt, { preset: "city" }),
1457
+ /* @__PURE__ */ f(Ft, { fallback: null, children: D !== null && /* @__PURE__ */ f(
1458
+ Qt,
1459
+ {
1460
+ avatarUrl: D,
1461
+ isPlayingRef: I,
1462
+ visemeQueueRef: m,
1463
+ audioContextRef: $,
1464
+ responseAudioStartTimeRef: b,
1465
+ adjustments: jt,
1466
+ mood: d,
1467
+ expression: s,
1468
+ agentResponse: he,
1469
+ isSpeaking: E,
1470
+ nextStartTimeRef: K,
1471
+ stopPlayback: Ve,
1472
+ setIsSpeaking: ce,
1473
+ expressionUrl: h,
1474
+ onExpressionFinished: bt
1475
+ }
1476
+ ) })
1477
+ ]
1478
+ }
1479
+ )
2740
1480
  }
2741
- ) })
1481
+ )
2742
1482
  ] }) })
2743
1483
  ] });
2744
- }, hr = ({
2745
- token: d,
2746
- onNavigationRequested: t
2747
- }) => /* @__PURE__ */ N(
2748
- ar,
1484
+ }, an = ({
1485
+ token: u,
1486
+ onNavigationRequested: x
1487
+ }) => /* @__PURE__ */ f(
1488
+ en,
2749
1489
  {
2750
- token: d,
2751
- onNavigationRequested: t
1490
+ token: u,
1491
+ onNavigationRequested: x
2752
1492
  }
2753
1493
  );
2754
1494
  export {
2755
- hr as AvatarWidget
1495
+ an as AvatarWidget
2756
1496
  };
2757
1497
  //# sourceMappingURL=avatar-widget.js.map