@davi-ai/react-bodyengine-three 1.0.33 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,42 +1,40 @@
1
- import D, { useState as te, useMemo as it, useEffect as j, useRef as Te, useCallback as $t, Suspense as Qt } from "react";
2
- import * as B from "three/webgpu";
3
- import { Vector3 as Bt, TempNode as He, NodeUpdateType as Xt, Vector2 as ve, RenderTarget as st, DepthTexture as pt, HalfFloatType as gt, NodeMaterial as Dt, NoBlending as Jt, Matrix4 as xe, RendererUtils as Ue, QuadMesh as zt, FloatType as es, UnsignedByteType as ft, RedFormat as ts, UnsignedInt101111Type as ss, RGBFormat as ns, MathUtils as os, DataTexture as as, RepeatWrapping as yt } from "three/webgpu";
4
- import { Object3D as Co } from "three/webgpu";
5
- import { CharacterState as de, surfaceId as rs, surfaceMask as We, SURFACE as Ke, CreationTool as Se, AvaturnLoader as is, AvatarSDKLoader as cs, CC3Loader as ls, Character as Ye } from "@davi-ai/bodyengine-three";
6
- import { CharacterState as Mo, CreationTool as _o, bmlTags as ko, emotionList as Po } from "@davi-ai/bodyengine-three";
7
- import { useDetectGPU as ds, PerformanceMonitor as us, PerspectiveCamera as hs, CameraControls as ms, Environment as ps } from "@react-three/drei";
8
- import { convertToTexture as qe, uniform as I, passTexture as ze, texture as Fe, OnBeforeRenderPipeline as gs, OnAfterRenderPipeline as fs, velocity as ct, struct as ys, Fn as Q, float as C, vec2 as K, If as he, vec4 as J, max as q, vec3 as ae, ivec2 as ke, luminance as Ae, add as xs, uv as Re, mix as Pe, logarithmicDepthToViewZ as Ft, viewZToPerspectiveDepth as nt, getViewPosition as Ie, viewZToOrthographicDepth as Ss, NodeUpdateType as Ot, reference as je, uint as oe, sub as bs, abs as pe, HALF_PI as Ze, sqrt as Et, PI as fe, Loop as Oe, pow as Ge, mul as $e, Break as Ts, normalize as be, dot as ie, clamp as _e, div as vs, ceil as As, shiftRight as ws, countOneBits as xt, sign as St, property as Ee, outputStruct as Cs, screenCoordinate as bt, interleavedGradientNoise as Ns, fract as Ms, rand as _s, cos as ot, sin as at, cross as Tt, acos as ks, bool as vt, getNormalFromDepth as Lt, nodeObject as rt, uniformArray as Ps, textureSize as Vs, mat2 as Is, int as At, min as ce, pass as Ut, mrt as jt, diffuseColor as Rs, output as Gt, packNormalToRGB as Bs, normalView as Ds, sample as zs, unpackRGBToNormal as Fs, exp as Os, perspectiveDepthToViewZ as Es } from "three/tsl";
9
- import { SimplexNoise as Ls } from "three/examples/jsm/math/SimplexNoise.js";
10
- import { Canvas as Us, useThree as js, useFrame as Ht } from "@react-three/fiber";
11
- import { createSpeechSynthesisPonyfill as Gs, SpeechSynthesisUtterance as Hs } from "@davi-ai/web-speech-cognitive-services-davi";
12
- const wt = (e) => {
1
+ import i, { useState as A, useMemo as _, useEffect as l, useRef as X, useCallback as pe, Suspense as fe } from "react";
2
+ import * as R from "three/webgpu";
3
+ import { Vector3 as ye } from "three/webgpu";
4
+ import { Object3D as $t } from "three/webgpu";
5
+ import { CharacterState as z, convertSPPASViseme as Ae, speechAudioClock as ke, playPendingVisemes as be, connectSpeechAudio as Ce, createHighPipeline as we, createTraaPipeline as Pe, Emotions as de, emotionsToActionUnits as Me, getCameraPositionVector as Ee, computeBodyFraming as Te, CreationTool as $, AvaturnLoader as Re, BodyMesh as ne, AvatarSDKLoader as ve, CC3Loader as De, Character as ae } from "@davi-ai/bodyengine-three";
6
+ import { CharacterState as qt, CreationTool as Jt, Distances as Qt, Positions as Yt, Rotations as Zt, bmlTags as _t, emotionList as en, cameraPresets as tn } from "@davi-ai/bodyengine-three";
7
+ import { useDetectGPU as Ve, PerformanceMonitor as xe, PerspectiveCamera as Fe, CameraControls as Ie, Environment as Le } from "@react-three/drei";
8
+ import { vec4 as oe, vec3 as ze } from "three/tsl";
9
+ import { Canvas as Be, useThree as Ue, useFrame as ge } from "@react-three/fiber";
10
+ import { createSpeechSynthesisPonyfill as Ge, SpeechSynthesisUtterance as Oe } from "@davi-ai/web-speech-cognitive-services-davi";
11
+ const re = (e) => {
13
12
  let t;
14
- const s = /* @__PURE__ */ new Set(), a = (v, S) => {
15
- const V = typeof v == "function" ? v(t) : v;
16
- if (!Object.is(V, t)) {
17
- const m = t;
18
- t = S ?? (typeof V != "object" || V === null) ? V : Object.assign({}, t, V), s.forEach((k) => k(t, m));
13
+ const n = /* @__PURE__ */ new Set(), r = (c, w) => {
14
+ const P = typeof c == "function" ? c(t) : c;
15
+ if (!Object.is(P, t)) {
16
+ const E = t;
17
+ t = w ?? (typeof P != "object" || P === null) ? P : Object.assign({}, t, P), n.forEach((D) => D(t, E));
19
18
  }
20
- }, r = () => t, f = { setState: a, getState: r, getInitialState: () => T, subscribe: (v) => (s.add(v), () => s.delete(v)) }, T = t = e(a, r, f);
21
- return f;
22
- }, qs = (e) => e ? wt(e) : wt, Ws = (e) => e;
23
- function Ks(e, t = Ws) {
24
- const s = D.useSyncExternalStore(
19
+ }, d = () => t, k = { setState: r, getState: d, getInitialState: () => C, subscribe: (c) => (n.add(c), () => n.delete(c)) }, C = t = e(r, d, k);
20
+ return k;
21
+ }, Ne = (e) => e ? re(e) : re, He = (e) => e;
22
+ function Ke(e, t = He) {
23
+ const n = i.useSyncExternalStore(
25
24
  e.subscribe,
26
- D.useCallback(() => t(e.getState()), [e, t]),
27
- D.useCallback(() => t(e.getInitialState()), [e, t])
25
+ i.useCallback(() => t(e.getState()), [e, t]),
26
+ () => t(e.getInitialState())
28
27
  );
29
- return D.useDebugValue(s), s;
28
+ return i.useDebugValue(n), n;
30
29
  }
31
- const Ys = (e) => {
32
- const t = qs(e), s = (a) => Ks(t, a);
33
- return Object.assign(s, t), s;
34
- }, Ce = (e) => Ys, O = Ce()(() => ({
30
+ const je = (e) => {
31
+ const t = Ne(e), n = (r) => Ke(t, r);
32
+ return Object.assign(n, t), n;
33
+ }, J = (e) => je, g = J()(() => ({
35
34
  character: null,
36
35
  managers: [],
37
36
  globalManager: null,
38
37
  lipSyncManager: null,
39
- blendshapeManager: null,
40
38
  eyeBlinkManager: null,
41
39
  animationManager: null,
42
40
  FACSManager: null,
@@ -47,1327 +45,502 @@ const Ys = (e) => {
47
45
  characterWidth: 0,
48
46
  characterHeight: 0,
49
47
  characterDepth: 0,
50
- characterState: de.idle
51
- })), Zs = (e) => {
52
- O.setState({ character: e }), O.setState({ managers: {
48
+ characterState: z.idle
49
+ })), We = (e) => {
50
+ g.setState({ character: e }), g.setState({ managers: {
53
51
  lipSyncManager: (e == null ? void 0 : e.lipSyncManager) || null,
54
- blendshapeManager: (e == null ? void 0 : e.blendshapeManager) || null,
55
52
  eyeBlinkManager: (e == null ? void 0 : e.eyeBlinkManager) || null,
56
53
  animationManager: (e == null ? void 0 : e.animationManager) || null
57
- } }), O.setState({ globalManager: (e == null ? void 0 : e.globalManager) || null }), O.setState({ lipSyncManager: (e == null ? void 0 : e.lipSyncManager) || null }), O.setState({ blendshapeManager: (e == null ? void 0 : e.blendshapeManager) || null }), O.setState({ eyeBlinkManager: (e == null ? void 0 : e.eyeBlinkManager) || null }), O.setState({ animationManager: (e == null ? void 0 : e.animationManager) || null }), O.setState({ FACSManager: (e == null ? void 0 : e.FACSManager) || null }), O.setState({ headPoseManager: (e == null ? void 0 : e.headPoseManager) || null }), O.setState({ gazeManager: (e == null ? void 0 : e.gazeManager) || null }), O.setState({ bmlManager: (e == null ? void 0 : e.bmlManager) || null });
58
- }, Ct = (e) => {
59
- O.setState({ animationsLoaded: e });
60
- }, $s = (e) => {
61
- O.setState({ characterWidth: e.x }), O.setState({ characterHeight: e.y }), O.setState({ characterDepth: e.z });
62
- }, Jn = () => O.getState().characterHeight, Nt = (e) => {
63
- O.setState({ characterState: e });
64
- }, se = Ce()(() => ({
54
+ } }), g.setState({ globalManager: (e == null ? void 0 : e.globalManager) || null }), g.setState({ lipSyncManager: (e == null ? void 0 : e.lipSyncManager) || null }), g.setState({ eyeBlinkManager: (e == null ? void 0 : e.eyeBlinkManager) || null }), g.setState({ animationManager: (e == null ? void 0 : e.animationManager) || null }), g.setState({ FACSManager: (e == null ? void 0 : e.FACSManager) || null }), g.setState({ headPoseManager: (e == null ? void 0 : e.headPoseManager) || null }), g.setState({ gazeManager: (e == null ? void 0 : e.gazeManager) || null }), g.setState({ bmlManager: (e == null ? void 0 : e.bmlManager) || null });
55
+ }, ie = (e) => {
56
+ g.setState({ animationsLoaded: e });
57
+ }, $e = (e) => {
58
+ g.setState({ characterWidth: e.x }), g.setState({ characterHeight: e.y }), g.setState({ characterDepth: e.z });
59
+ }, Mt = () => g.getState().characterHeight, ce = (e) => {
60
+ g.setState({ characterState: e });
61
+ }, M = J()(() => ({
65
62
  cameraRef: null,
66
- cameraPosition: new Bt(0, 0, 5),
63
+ cameraPosition: new ye(0, 0, 5),
67
64
  bodyCenter: null,
68
65
  defaultPositions: null,
69
66
  defaultDistances: null,
70
67
  lookAt: null,
71
68
  movable: !0
72
- })), Qs = (e) => {
73
- se.setState({ cameraRef: e });
74
- }, Mt = (e) => {
75
- se.setState({ cameraPosition: e });
76
- }, eo = () => se.getState().cameraPosition, Xs = (e) => {
77
- se.setState({ bodyCenter: e });
78
- }, Js = (e) => {
79
- se.setState({ defaultPositions: e });
80
- }, en = (e) => {
81
- se.setState({ defaultDistances: e });
82
- }, _t = (e) => {
83
- se.setState({ lookAt: e });
84
- }, to = () => se.getState().lookAt, tn = (e) => {
85
- se.setState({ movable: e });
86
- }, re = Ce()(() => ({
69
+ })), Xe = (e) => {
70
+ M.setState({ cameraRef: e });
71
+ }, le = (e) => {
72
+ M.setState({ cameraPosition: e });
73
+ }, Et = () => M.getState().cameraPosition, qe = (e) => {
74
+ M.setState({ bodyCenter: e });
75
+ }, Je = (e) => {
76
+ M.setState({ defaultPositions: e });
77
+ }, Qe = (e) => {
78
+ M.setState({ defaultDistances: e });
79
+ }, me = (e) => {
80
+ M.setState({ lookAt: e });
81
+ }, Tt = () => M.getState().lookAt, Ye = (e) => {
82
+ M.setState({ movable: e });
83
+ }, F = J()(() => ({
87
84
  currentAUs: null,
88
85
  currentGaze: null,
89
86
  currentHeadPose: null,
90
87
  lookAtCamera: !1,
91
88
  targets: [],
92
89
  showFirstTarget: !1
93
- })), sn = (e) => {
94
- re.setState({ targets: e });
95
- }, so = (e) => {
96
- re.setState({ currentAUs: e });
97
- }, no = (e) => {
98
- re.setState({ currentGaze: e });
99
- }, oo = (e) => {
100
- re.setState({ currentHeadPose: e });
101
- }, Qe = (e) => {
102
- re.setState({ lookAtCamera: e }), e ? nn() : on();
103
- }, nn = (e) => {
104
- const t = O.getState().globalManager;
90
+ })), Ze = (e) => {
91
+ F.setState({ targets: e });
92
+ }, _e = (e) => {
93
+ F.setState({ currentAUs: e });
94
+ }, Rt = (e) => {
95
+ F.setState({ currentGaze: e });
96
+ }, vt = (e) => {
97
+ F.setState({ currentHeadPose: e });
98
+ }, se = (e) => {
99
+ F.setState({ lookAtCamera: e }), e ? et() : tt();
100
+ }, et = (e) => {
101
+ const t = g.getState().globalManager;
105
102
  if (e)
106
103
  t == null || t.lookAtAndKeep(e);
107
104
  else {
108
- const s = se.getState().cameraRef;
109
- t == null || t.lookAtAndKeep(s);
105
+ const n = M.getState().cameraRef;
106
+ t == null || t.lookAtAndKeep(n);
110
107
  }
111
- }, on = () => {
108
+ }, tt = () => {
112
109
  var e;
113
- (e = O.getState().globalManager) == null || e.releaseLookAt();
114
- }, ao = (e) => {
115
- re.setState({ showFirstTarget: e });
116
- }, we = Ce()(() => ({
110
+ (e = g.getState().globalManager) == null || e.releaseLookAt();
111
+ }, Dt = (e) => {
112
+ F.setState({ showFirstTarget: e });
113
+ }, q = J()(() => ({
117
114
  animationsNames: [],
118
115
  animations: /* @__PURE__ */ new Map(),
119
116
  currentAnimation: null,
120
117
  autoPlay: !0
121
- })), an = (e) => {
122
- we.setState({ animationsNames: e });
123
- }, rn = (e) => {
124
- we.setState({ animations: e });
125
- }, ro = () => we.getState().animations, io = (e) => {
126
- we.setState({ autoPlay: e });
127
- }, co = (e) => {
128
- if (we.setState({ autoPlay: !1 }), we.getState().animationsNames.includes(e)) {
129
- const s = O.getState().animationManager;
130
- s == null || s.playAnimation(e);
131
- }
132
- };
133
- var $ = /* @__PURE__ */ ((e) => (e.eye = "eye", e.mouth = "mouth", e.neck = "neck", e.clavicle = "clavicle", e.torso = "torso", e.belly = "belly", e.lowerbelly = "lowerbelly", e.hips = "hips", e.higherthigh = "higherthigh", e.thigh = "thigh", e.knee = "knee", e.leg = "leg", e.feet = "feet", e))($ || {}), le = /* @__PURE__ */ ((e) => (e[e.face = 1] = "face", e[e.eighthleft = 2] = "eighthleft", e[e.thirdleft = 3] = "thirdleft", e[e.quarterleft = 4] = "quarterleft", e[e.halfleft = 5] = "halfleft", e[e.eighthright = 6] = "eighthright", e[e.thirdright = 7] = "thirdright", e[e.quarterright = 8] = "quarterright", e[e.halfright = 9] = "halfright", e))(le || {}), X = /* @__PURE__ */ ((e) => (e[e.veryclose = 1] = "veryclose", e[e.closer = 2] = "closer", e[e.close = 3] = "close", e[e.midclose = 4] = "midclose", e[e.medium = 5] = "medium", e[e.midfar = 6] = "midfar", e[e.far = 7] = "far", e[e.farther = 8] = "farther", e[e.veryfar = 9] = "veryfar", e))(X || {}), Le = /* @__PURE__ */ ((e) => (e.cc3 = "CC_Base_Body", e.avatarsdk = "AvatarBody", e.avaturn = "Body_Mesh", e))(Le || {}), lt = /* @__PURE__ */ ((e) => (e.Jay = "joy", e.Anger = "anger", e.Contempt = "contempt", e.Disgust = "disgust", e.Dislike = "dislike", e.Distress = "distress", e.Fear = "fear", e.Frustration = "frustration", e.Guilt = "guilt", e.Hope = "hope", e.Love = "love", e.Pride = "pride", e.Regret = "regret", e.Relief = "relief", e.Sadness = "sadness", e.Shame = "shame", e.Smile = "smile", e.Surprise = "surprise", e.Neutral = "neutral", e))(lt || {});
134
- const kt = /* @__PURE__ */ new Map([
135
- [0, "sil"],
136
- [1, "aa"],
137
- [2, "aa"],
138
- [3, "O"],
139
- [4, "E"],
140
- [5, "E"],
141
- [6, "I"],
142
- [7, "U"],
143
- [8, "O"],
144
- [9, "U"],
145
- [10, "O"],
146
- [11, "aa"],
147
- [12, "kk"],
148
- [13, "RR"],
149
- [14, "nn"],
150
- [15, "SS"],
151
- [16, "CH"],
152
- [17, "TH"],
153
- [18, "FF"],
154
- [19, "DD"],
155
- [20, "kk"],
156
- [21, "PP"]
157
- ]), cn = /* @__PURE__ */ new Map([
158
- ["#", "#"],
159
- ["p", "p"],
160
- ["b", "b"],
161
- ["t", "t"],
162
- ["d", "d"],
163
- ["k", "k"],
164
- ["g", "g"],
165
- ["f", "f"],
166
- ["s", "s"],
167
- ["S", "ʃ"],
168
- ["v", "v"],
169
- ["z", "z"],
170
- ["Z", "ʒ"],
171
- ["m", "m"],
172
- ["n", "n"],
173
- ["l", "l"],
174
- ["R", "ʁ"],
175
- ["j", "j"],
176
- ["w", "w"],
177
- ["H", "ɥ"],
178
- ["E", "ɛ"],
179
- ["A/", "ɑ"],
180
- ["9", "oe"],
181
- ["i", "i"],
182
- ["e", "e"],
183
- ["O/", "o"],
184
- ["u", "u"],
185
- ["y", "y"],
186
- ["2", "ø"],
187
- ["@", "ə"],
188
- ["a~", "ã"],
189
- ["U~/", "ɛ̃"],
190
- ["U~/", "oẽ"],
191
- ["O~", "ɔ̃"],
192
- ["a", "a"],
193
- ["A", "ɑ"],
194
- ["3", "ɜ"],
195
- ["I", "ɪ"],
196
- ["o", "o"],
197
- ["O", "ɔ"],
198
- ["U", "ʊ"],
199
- ["Y", "ʏ"],
200
- ["A~", "ɑ̃"],
201
- ["E~", "ɛ̃"],
202
- ["e~", "ɛ̃"],
203
- ["9~", "oẽ"],
204
- ["N", "ŋ"],
205
- ["J", "ɲ"]
206
- ]), ln = /* @__PURE__ */ new Map([
207
- ["#", 0],
208
- ["æ", 1],
209
- ["ə", 1],
210
- ["ʌ", 1],
211
- ["ɑ", 2],
212
- ["ɔ", 3],
213
- ["ɛ", 4],
214
- ["ʊ", 4],
215
- ["ɝ", 5],
216
- ["j", 6],
217
- ["i", 6],
218
- ["ɪ", 6],
219
- ["w", 7],
220
- ["u", 7],
221
- ["o", 8],
222
- ["aʊ", 9],
223
- ["ɔɪ", 10],
224
- ["aɪ", 11],
225
- ["h", 12],
226
- ["ɹ", 13],
227
- ["l", 14],
228
- ["s", 15],
229
- ["z", 15],
230
- ["ʃ", 16],
231
- ["tʃ", 16],
232
- ["dʒ", 16],
233
- ["ʒ", 16],
234
- ["ð", 17],
235
- ["f", 18],
236
- ["v", 18],
237
- ["d", 19],
238
- ["t", 19],
239
- ["n", 19],
240
- ["θ", 19],
241
- ["k", 20],
242
- ["g", 20],
243
- ["ŋ", 20],
244
- ["p", 21],
245
- ["b", 21],
246
- ["m", 21]
247
- ]), dn = {
248
- position: $.mouth,
249
- distance: X.farther,
250
- lookAt: $.lowerbelly
251
- }, un = {
252
- position: $.mouth,
253
- distance: X.close,
254
- lookAt: $.mouth
255
- }, hn = {
256
- position: $.mouth,
257
- distance: X.midclose,
258
- lookAt: $.mouth
259
- }, mn = {
260
- position: $.neck,
261
- distance: X.close,
262
- lookAt: $.neck
263
- }, pn = {
264
- position: $.eye,
265
- distance: X.medium,
266
- lookAt: $.neck
267
- }, gn = {
268
- position: $.eye,
269
- distance: X.medium,
270
- lookAt: $.clavicle
271
- }, fn = {
272
- position: $.eye,
273
- distance: X.midfar,
274
- lookAt: $.belly
275
- }, yn = {
276
- position: $.eye,
277
- distance: X.far,
278
- lookAt: $.lowerbelly
279
- }, lo = {
280
- default: dn,
281
- head: un,
282
- neck: hn,
283
- shoulders: mn,
284
- chest: pn,
285
- belly: gn,
286
- knees: fn,
287
- feet: yn
288
- }, z = Ce()(() => ({
118
+ })), nt = (e) => {
119
+ q.setState({ animationsNames: e });
120
+ }, at = (e) => {
121
+ q.setState({ animations: e });
122
+ }, Vt = () => q.getState().animations, xt = (e) => {
123
+ q.setState({ autoPlay: e });
124
+ }, Ft = (e) => {
125
+ if (q.setState({ autoPlay: !1 }), q.getState().animationsNames.includes(e)) {
126
+ const n = g.getState().animationManager;
127
+ n == null || n.playAnimation(e);
128
+ }
129
+ }, p = J()(() => ({
289
130
  credentials: void 0,
290
131
  currentUtterance: null,
291
132
  boundaries: [],
292
133
  visemes: [],
293
- blendshapes: [],
294
- currentVisemeIndex: 0,
295
- currentBlendshapeIndex: 0,
134
+ playedVisemeCount: 0,
296
135
  voice: null,
297
136
  voices: [],
298
137
  textToSpeak: null,
299
138
  visemeIntensity: 1,
300
- useBlendshapeManager: !1
301
- })), xn = (e) => {
302
- z.setState({ credentials: e });
303
- }, Sn = (e) => {
139
+ lipSyncFromAudio: !1
140
+ })), st = (e) => {
141
+ p.setState({ credentials: e });
142
+ }, ot = (e) => {
304
143
  if (e) {
305
- const t = z.getState().voice;
144
+ const t = p.getState().voice;
306
145
  t && (e.voice = t);
307
146
  }
308
- z.setState({ currentUtterance: e }), z.setState({ textToSpeak: null });
309
- }, uo = (e) => {
310
- z.setState({ visemes: e });
311
- }, ho = (e) => {
312
- z.setState({ blendshapes: e });
313
- }, qt = (e) => {
314
- z.setState({ visemes: [...z.getState().visemes, e] });
315
- }, mo = (e) => {
316
- z.setState({ blendshapes: [...z.getState().blendshapes, e] });
317
- }, po = (e, t) => {
318
- const s = cn.get(e.name);
319
- if (s) {
320
- const a = ln.get(s);
321
- a !== void 0 && qt({ ...e, name: `${a}`, elapsedTime: e.elapsedTime * (t || 1e7) });
322
- }
323
- }, bn = (e) => {
324
- z.setState({ currentVisemeIndex: e });
325
- }, Tn = (e) => {
326
- z.setState({ currentBlendshapeIndex: e });
327
- }, Wt = () => {
147
+ p.setState({ currentUtterance: e }), p.setState({ textToSpeak: null });
148
+ }, It = (e) => {
149
+ p.setState({ visemes: e });
150
+ }, he = (e) => {
151
+ p.setState({ visemes: [...p.getState().visemes, e] });
152
+ }, Lt = (e, t) => {
153
+ const n = Ae(e, t);
154
+ n && he(n);
155
+ }, rt = (e) => {
156
+ p.setState({ playedVisemeCount: e });
157
+ }, it = () => {
328
158
  var e;
329
- z.setState({
159
+ p.setState({
330
160
  visemes: [],
331
- currentVisemeIndex: 0
332
- }), (e = O.getState().lipSyncManager) == null || e.stop();
333
- }, Kt = () => {
334
- var e;
335
- z.setState({
336
- blendshapes: [],
337
- currentBlendshapeIndex: 0
338
- }), (e = O.getState().blendshapeManager) == null || e.stop();
339
- }, vn = (e) => {
340
- z.setState({ voice: e });
341
- }, Pt = (e) => {
342
- z.setState({ voices: e });
343
- }, go = (e) => {
344
- z.setState({ textToSpeak: e });
345
- }, fo = () => z.getState().voices, yo = (e) => {
346
- z.setState({ visemeIntensity: e });
347
- }, An = (e) => {
348
- e !== z.getState().useBlendshapeManager && (Wt(), Kt(), z.setState({ useBlendshapeManager: e }));
349
- }, wn = (e, t, s) => {
350
- let a = s[e.position || $.eye].getComponent(0);
351
- const r = s[e.position || $.mouth].getComponent(1);
352
- let o = 0;
353
- const d = typeof e.distance == "string" ? parseInt(e.distance) : e.distance, f = typeof e.rotation == "string" ? parseInt(e.rotation) : e.rotation;
354
- switch (d) {
355
- case X.veryclose:
356
- o = t.veryclose;
357
- break;
358
- case X.closer:
359
- o = t.closer;
360
- break;
361
- case X.close:
362
- o = t.close;
363
- break;
364
- case X.midclose:
365
- o = t.midclose;
366
- break;
367
- case X.medium:
368
- o = t.medium;
369
- break;
370
- case X.midfar:
371
- o = t.midfar;
372
- break;
373
- case X.far:
374
- o = t.far;
375
- break;
376
- case X.farther:
377
- case void 0:
378
- default:
379
- o = t.farther;
380
- break;
381
- case X.veryfar:
382
- o = t.veryfar;
383
- break;
384
- }
385
- if (f && f !== le.face)
386
- switch (f) {
387
- case le.eighthleft: {
388
- const T = 0.2588190451;
389
- a = a - o * T, o = o * Math.sqrt(1 - Math.pow(T, 2));
390
- break;
391
- }
392
- case le.thirdleft:
393
- a = a - o * (1 / 2), o = o * (Math.sqrt(3) / 2);
394
- break;
395
- case le.quarterleft:
396
- a = a - o * (Math.SQRT2 / 2), o = o * (Math.SQRT2 / 2);
397
- break;
398
- case le.halfleft:
399
- a = a - o, o = s.eye.getComponent(2);
400
- break;
401
- case le.eighthright: {
402
- const T = 0.2588190451;
403
- a = a + o * T, o = o * Math.sqrt(1 - Math.pow(T, 2));
404
- break;
405
- }
406
- case le.thirdright:
407
- a = a + o * (1 / 2), o = o * (Math.sqrt(3) / 2);
408
- break;
409
- case le.quarterright:
410
- a = a + o * (Math.SQRT2 / 2), o = o * (Math.SQRT2 / 2);
411
- break;
412
- case le.halfright:
413
- a = a + o, o = s.eye.getComponent(2);
414
- break;
415
- }
416
- return new B.Vector3(a, r, o);
417
- }, Xe = /* @__PURE__ */ new zt(), Vt = /* @__PURE__ */ new ve();
418
- let Je;
419
- class Cn extends He {
420
- static get type() {
421
- return "TRAANode";
422
- }
423
- /**
424
- * Constructs a new TRAA node.
425
- *
426
- * @param {TextureNode} beautyNode - The texture node that represents the input of the effect.
427
- * @param {TextureNode} depthNode - A node that represents the scene's depth.
428
- * @param {TextureNode} velocityNode - A node that represents the scene's velocity.
429
- * @param {Camera} camera - The camera the scene is rendered with.
430
- */
431
- constructor(t, s, a, r) {
432
- super("vec4"), this.isTRAANode = !0, this.updateBeforeType = Xt.FRAME, this.beautyNode = t, this.depthNode = s, this.velocityNode = a, this.camera = r, this.depthThreshold = 5e-4, this.edgeDepthDiff = 1e-3, this.maxVelocityLength = 32, this.useSubpixelCorrection = !0, this._jitterIndex = 0, this._invSize = I(new ve()), this._historyRenderTarget = new st(1, 1, { depthBuffer: !1, type: gt, depthTexture: new pt() }), this._historyRenderTarget.texture.name = "TRAANode.history", this._resolveRenderTarget = new st(1, 1, { depthBuffer: !1, type: gt }), this._resolveRenderTarget.texture.name = "TRAANode.resolve", this._resolveMaterial = new Dt(), this._resolveMaterial.name = "TRAA.resolve", this._resolveMaterial.blending = Jt, this._textureNode = ze(this, this._resolveRenderTarget.texture), this._originalProjectionMatrix = new xe(), this._cameraNearFar = I(new ve()), this._cameraWorldMatrix = I(new xe()), this._cameraWorldMatrixInverse = I(new xe()), this._cameraProjectionMatrixInverse = I(new xe()), this._previousCameraWorldMatrix = I(new xe()), this._previousCameraProjectionMatrixInverse = I(new xe()), this._previousDepthNode = Fe(new pt(1, 1)), this._needsPostProcessingSync = !1, this._velocityNode = null;
433
- }
434
- /**
435
- * Returns the result of the effect as a texture node.
436
- *
437
- * @return {PassTextureNode} A texture node that represents the result of the effect.
438
- */
439
- getTextureNode() {
440
- return this._textureNode;
441
- }
442
- /**
443
- * Returns the history buffer as a texture node. During the update of a new frame this
444
- * texture holds the *previous* frame's anti-aliased resolve, which makes it a cheap
445
- * feedback source for effects that want last frame's final lighting (e.g. feeding it
446
- * into SSGI as the beauty input turns single-bounce GI into infinite bounces).
447
- *
448
- * Note: this is intentionally a plain TextureNode (not a PassTextureNode) so referencing
449
- * it does not create a cyclic dependency in the node graph.
450
- *
451
- * @return {TextureNode} A texture node that represents the previous frame's resolve.
452
- */
453
- getHistoryTextureNode() {
454
- return this._historyTextureNode === void 0 && (this._historyTextureNode = Fe(this._historyRenderTarget.texture)), this._historyTextureNode;
455
- }
456
- /**
457
- * Sets the size of the effect.
458
- *
459
- * @param {number} width - The width of the effect.
460
- * @param {number} height - The height of the effect.
461
- */
462
- setSize(t, s) {
463
- this._historyRenderTarget.setSize(t, s), this._resolveRenderTarget.setSize(t, s), this._invSize.value.set(1 / t, 1 / s);
464
- }
465
- /**
466
- * Defines the TRAA's current jitter as a view offset
467
- * to the scene's camera.
468
- *
469
- * @param {number} width - The width of the effect.
470
- * @param {number} height - The height of the effect.
471
- */
472
- setViewOffset(t, s) {
473
- this.camera.updateProjectionMatrix(), this._originalProjectionMatrix.copy(this.camera.projectionMatrix), this._velocityNode.setProjectionMatrix(this._originalProjectionMatrix);
474
- const a = {
475
- fullWidth: t,
476
- fullHeight: s,
477
- offsetX: 0,
478
- offsetY: 0,
479
- width: t,
480
- height: s
481
- }, r = Rt[this._jitterIndex];
482
- this.camera.setViewOffset(
483
- a.fullWidth,
484
- a.fullHeight,
485
- a.offsetX + (r[0] - 0.5) * 1,
486
- a.offsetY + (r[1] - 0.5) * 1,
487
- a.width,
488
- a.height
489
- );
490
- }
491
- /**
492
- * Clears the view offset from the scene's camera.
493
- */
494
- clearViewOffset() {
495
- this.camera.clearViewOffset(), this._velocityNode.setProjectionMatrix(null), this._jitterIndex++, this._jitterIndex = this._jitterIndex % Rt.length;
496
- }
497
- /**
498
- * This method is used to render the effect once per frame.
499
- *
500
- * @param {NodeFrame} frame - The current node frame.
501
- */
502
- updateBefore(t) {
503
- const { renderer: s } = t;
504
- this._previousCameraWorldMatrix.value.copy(this._cameraWorldMatrix.value), this._previousCameraProjectionMatrixInverse.value.copy(this._cameraProjectionMatrixInverse.value), this._cameraNearFar.value.set(this.camera.near, this.camera.far), this._cameraWorldMatrix.value.copy(this.camera.matrixWorld), this._cameraWorldMatrixInverse.value.copy(this.camera.matrixWorldInverse), this._cameraProjectionMatrixInverse.value.copy(this.camera.projectionMatrixInverse);
505
- const a = this.beautyNode.isRTTNode ? this.beautyNode.renderTarget : this.beautyNode.passNode.renderTarget, r = a.texture.width, o = a.texture.height;
506
- this._needsPostProcessingSync === !0 && (this.setViewOffset(r, o), this._needsPostProcessingSync = !1), Je = Ue.resetRendererState(s, Je);
507
- const d = this._historyRenderTarget.width !== r || this._historyRenderTarget.height !== o;
508
- this.setSize(r, o), d === !0 && (s.initRenderTarget(this._historyRenderTarget), s.initRenderTarget(this._resolveRenderTarget), s.copyTextureToTexture(a.texture, this._historyRenderTarget.texture)), s.setClearColor(16777215, 0), s.setRenderTarget(this._resolveRenderTarget), Xe.material = this._resolveMaterial, Xe.name = "TRAA", Xe.render(s), s.setRenderTarget(null), s.copyTextureToTexture(this._resolveRenderTarget.texture, this._historyRenderTarget.texture);
509
- const f = s.getDrawingBufferSize(Vt);
510
- if (this._historyRenderTarget.height === f.height && this._historyRenderTarget.width === f.width) {
511
- const T = this.depthNode.value;
512
- s.copyTextureToTexture(T, this._historyRenderTarget.depthTexture), this._previousDepthNode.value = this._historyRenderTarget.depthTexture;
513
- }
514
- Ue.restoreRendererState(s, Je);
515
- }
516
- /**
517
- * This method is used to setup the effect's render targets and TSL code.
518
- *
519
- * @param {NodeBuilder} builder - The current node builder.
520
- * @return {PassTextureNode}
521
- */
522
- setup(t) {
523
- t.renderPipeline && !t.context.renderPipelineState.viewOffsetOwner && (t.context.renderPipelineState.viewOffsetOwner = this, this._needsPostProcessingSync = !0, gs(() => {
524
- const u = t.renderer.getDrawingBufferSize(Vt);
525
- this.setViewOffset(u.width, u.height);
526
- }), fs(() => {
527
- this.clearViewOffset();
528
- })), t.renderer.reversedDepthBuffer === !0 && (this._historyRenderTarget.depthTexture.type = es), t.context.velocity !== void 0 ? this._velocityNode = t.context.velocity : this._velocityNode = ct;
529
- const s = (u) => {
530
- const { x: g, y: i } = this._cameraNearFar, n = Ft(u, g, i);
531
- return nt(n, g, i);
532
- }, a = ys({
533
- closestDepth: "float",
534
- closestPositionTexel: "vec2",
535
- farthestDepth: "float"
536
- }), r = Q(([u]) => {
537
- const g = C(2).toVar(), i = K(0).toVar(), n = C(-1).toVar();
538
- for (let c = -1; c <= 1; ++c)
539
- for (let h = -1; h <= 1; ++h) {
540
- const y = u.add(K(c, h)).toVar();
541
- let p = this.depthNode.load(y).r;
542
- t.renderer.reversedDepthBuffer && (p = p.oneMinus()), t.renderer.logarithmicDepthBuffer && (p = s(p)), p = p.toVar(), he(p.lessThan(g), () => {
543
- g.assign(p), i.assign(y);
544
- }), he(p.greaterThan(n), () => {
545
- n.assign(p);
546
- });
547
- }
548
- return a(g, i, n);
549
- }), o = (u) => {
550
- let g = this._previousDepthNode.sample(u).r;
551
- t.renderer.reversedDepthBuffer && (g = g.oneMinus()), t.renderer.logarithmicDepthBuffer && (g = s(g));
552
- const i = Ie(u, g, this._previousCameraProjectionMatrixInverse), n = this._previousCameraWorldMatrix.mul(J(i, 1)).xyz, c = this._cameraWorldMatrixInverse.mul(J(n, 1)).z;
553
- return this.camera.isOrthographicCamera ? Ss(c, this._cameraNearFar.x, this._cameraNearFar.y) : nt(c, this._cameraNearFar.x, this._cameraNearFar.y);
554
- }, d = Q(([u, g, i, n]) => {
555
- const c = n.rgb.add(i.rgb).mul(0.5), h = n.rgb.sub(i.rgb).mul(0.5).add(1e-7), y = g.sub(J(c, u.a)), A = y.xyz.div(h).abs(), w = q(A.x, A.y, A.z);
556
- return w.greaterThan(1).select(
557
- J(c, u.a).add(y.div(w)),
558
- g
559
- );
560
- }).setLayout({
561
- name: "clipAABB",
562
- type: "vec4",
563
- inputs: [
564
- { name: "currentColor", type: "vec4" },
565
- { name: "historyColor", type: "vec4" },
566
- { name: "minColor", type: "vec4" },
567
- { name: "maxColor", type: "vec4" }
568
- ]
569
- }), f = Q(([u]) => ae(
570
- u.x.mul(0.25).add(u.y.mul(0.5)).add(u.z.mul(0.25)),
571
- u.x.mul(0.5).sub(u.z.mul(0.5)),
572
- u.x.mul(-0.25).add(u.y.mul(0.5)).sub(u.z.mul(0.25))
573
- )).setLayout({
574
- name: "RGBToYCoCg",
575
- type: "vec3",
576
- inputs: [{ name: "c", type: "vec3" }]
577
- }), T = Q(([u]) => ae(
578
- u.x.add(u.y).sub(u.z),
579
- u.x.add(u.z),
580
- u.x.sub(u.y).sub(u.z)
581
- )).setLayout({
582
- name: "YCoCgToRGB",
583
- type: "vec3",
584
- inputs: [{ name: "c", type: "vec3" }]
585
- }), v = Q(([u, g, i, n]) => {
586
- const c = [
587
- [-1, -1],
588
- [-1, 1],
589
- [1, -1],
590
- [1, 1],
591
- [1, 0],
592
- [0, -1],
593
- [0, 1],
594
- [-1, 0]
595
- ], h = J(f(g.rgb), g.a).toVar(), y = J(f(i.rgb), i.a).toVar(), p = h.toVar(), A = h.pow2().toVar();
596
- for (const [Z, G] of c) {
597
- const E = this.beautyNode.offset(ke(Z, G)).load(u).max(0), U = J(f(E.rgb), E.a).toVar();
598
- p.addAssign(U), A.addAssign(U.pow2());
599
- }
600
- const w = C(c.length + 1), l = p.div(w), b = A.div(w).sub(l.pow2()).max(0).sqrt().mul(n), M = l.sub(b), _ = l.add(b), x = d(l.clamp(M, _), y, M, _);
601
- return J(T(x.rgb), x.a);
602
- }), S = Q(([u, g]) => {
603
- const n = u.mul(g).fract().abs(), c = q(n, n.oneMinus());
604
- return c.x.mul(c.y).oneMinus().div(0.75);
605
- }).setLayout({
606
- name: "subpixelCorrection",
607
- type: "float",
608
- inputs: [
609
- { name: "velocityUV", type: "vec2" },
610
- { name: "textureSize", type: "ivec2" }
611
- ]
612
- }), V = Q(([u, g, i]) => {
613
- const n = i.oneMinus(), c = u.mul(C(1).div(q(u.r, u.g, u.b).add(1))), h = g.mul(C(1).div(q(g.r, g.g, g.b).add(1))), y = Ae(c.rgb), p = Ae(h.rgb);
614
- return i.mulAssign(C(1).div(y.add(1))), n.mulAssign(C(1).div(p.add(1))), xs(u.mul(i), g.mul(n)).div(q(i.add(n), 1e-5)).toVar();
615
- }), m = Fe(this._historyRenderTarget.texture), k = Q(([u, g]) => {
616
- const i = u.mul(g), n = i.sub(0.5).floor().add(0.5).toVar(), c = i.sub(n).toVar(), h = c.mul(c.mul(c.mul(-0.5).add(1)).sub(0.5)).toVar(), y = c.pow2().mul(c.mul(1.5).sub(2.5)).add(1).toVar(), p = c.mul(c.mul(c.mul(-1.5).add(2)).add(0.5)).toVar(), A = c.pow2().mul(c.mul(0.5).sub(0.5)).toVar(), w = y.add(p).toVar(), l = p.div(w).toVar(), b = n.sub(1).mul(this._invSize).toVar(), M = n.add(2).mul(this._invSize).toVar(), _ = n.add(l).mul(this._invSize).toVar();
617
- return m.sample(K(b.x, b.y)).mul(h.x.mul(h.y)).add(m.sample(K(_.x, b.y)).mul(w.x.mul(h.y))).add(m.sample(K(M.x, b.y)).mul(A.x.mul(h.y))).add(m.sample(K(b.x, _.y)).mul(h.x.mul(w.y))).add(m.sample(K(_.x, _.y)).mul(w.x.mul(w.y))).add(m.sample(K(M.x, _.y)).mul(A.x.mul(w.y))).add(m.sample(K(b.x, M.y)).mul(h.x.mul(A.y))).add(m.sample(K(_.x, M.y)).mul(w.x.mul(A.y))).add(m.sample(K(M.x, M.y)).mul(A.x.mul(A.y))).max(0);
618
- }), R = Q(() => {
619
- const u = Re(), g = this.beautyNode.size(), i = u.mul(g), n = r(i), c = n.get("closestDepth"), h = n.get("closestPositionTexel"), y = n.get("farthestDepth"), p = this.velocityNode.load(h).xy.mul(K(0.5, -0.5)), A = u.sub(p), w = o(A), l = A.greaterThanEqual(0).all().and(A.lessThanEqual(1).all()), b = y.sub(c).greaterThan(this.edgeDepthDiff), M = c.sub(w).greaterThan(this.depthThreshold), _ = l.and(b.or(M.not())), x = this.beautyNode.sample(u), Z = k(A, g), G = u.sub(A).mul(g).length().div(this.maxVelocityLength).saturate(), E = C(0.01).toVar();
620
- this.useSubpixelCorrection && E.addAssign(S(p, g).mul(0.2)), E.assign(_.select(E.add(G).saturate(), 1));
621
- const U = Pe(0.5, 1, G.oneMinus().pow2()), P = v(i, x, Z, U);
622
- return V(x, P, E);
623
- });
624
- return this._resolveMaterial.colorNode = R(), this._textureNode;
625
- }
626
- /**
627
- * Frees internal resources. This method should be called
628
- * when the effect is no longer required.
629
- */
630
- dispose() {
631
- this._historyRenderTarget.dispose(), this._resolveRenderTarget.dispose(), this._resolveMaterial.dispose();
632
- }
633
- }
634
- function It(e, t) {
635
- let s = 1, a = 0;
636
- for (; e > 0; )
637
- s /= t, a += s * (e % t), e = Math.floor(e / t);
638
- return a;
639
- }
640
- const Rt = /* @__PURE__ */ Array.from(
641
- { length: 16 },
642
- (e, t) => [It(t + 1, 2), It(t + 1, 3)]
643
- ), Yt = (e, t, s, a) => new Cn(qe(e), t, s, a), et = /* @__PURE__ */ new zt(), Nn = /* @__PURE__ */ new ve(), Mn = [60, 300, 180, 240, 120, 0], _n = [0, 0.5, 0.25, 0.75];
644
- let tt;
645
- class kn extends He {
646
- static get type() {
647
- return "SSGINode";
648
- }
649
- /**
650
- * Constructs a new SSGI node.
651
- *
652
- * @param {TextureNode} beautyNode - A texture node that represents the beauty or scene pass.
653
- * @param {TextureNode} depthNode - A texture node that represents the scene's depth.
654
- * @param {TextureNode} normalNode - A texture node that represents the scene's normals.
655
- * @param {PerspectiveCamera} camera - The camera the scene is rendered with.
656
- */
657
- constructor(t, s, a, r) {
658
- super("vec4"), this.beautyNode = t, this.depthNode = s, this.normalNode = a, this.updateBeforeType = Ot.FRAME, this.sliceCount = I(1, "uint"), this.stepCount = I(12, "uint"), this.aoIntensity = I(1, "float"), this.giIntensity = I(10, "float"), this.radius = I(12, "float"), this.useScreenSpaceSampling = I(!0, "bool"), this.expFactor = I(2, "float"), this.thickness = I(1, "float"), this.useLinearThickness = I(!1, "bool"), this.backfaceLighting = I(0, "float"), this.useTemporalFiltering = !0, this.resolutionScale = 1, this._resolution = I(new ve()), this._halfProjScale = I(1), this._temporalDirection = I(0), this._temporalOffset = I(0), this._cameraProjectionMatrix = I(r.projectionMatrix), this._cameraProjectionMatrixInverse = I(r.projectionMatrixInverse), this._cameraNear = je("near", "float", r), this._cameraFar = je("far", "float", r), this._camera = r, this._ssgiRenderTarget = new st(1, 1, { depthBuffer: !1, count: 3 });
659
- const o = this._ssgiRenderTarget.textures[0];
660
- o.name = "SSGI.AO", o.type = ft, o.format = ts;
661
- const d = this._ssgiRenderTarget.textures[1];
662
- d.name = "SSGI.GI", d.type = ss, d.format = ns;
663
- const f = this._ssgiRenderTarget.textures[2];
664
- f.name = "SSGI.BentNormals", f.type = ft, this._material = new Dt(), this._material.name = "SSGI", this._aoNode = ze(this, this._ssgiRenderTarget.textures[0]), this._giNode = ze(this, this._ssgiRenderTarget.textures[1]), this._bentNormalNode = ze(this, this._ssgiRenderTarget.textures[2]);
665
- }
666
- /**
667
- * Returns the AO result of the effect as a texture node.
668
- *
669
- * @return {PassTextureNode} A texture node that represents the AO result of the effect.
670
- */
671
- getAONode() {
672
- return this._aoNode;
673
- }
674
- /**
675
- * Returns the GI result of the effect as a texture node.
676
- *
677
- * @return {PassTextureNode} A texture node that represents the GI result of the effect.
678
- */
679
- getGINode() {
680
- return this._giNode;
681
- }
682
- /**
683
- * Returns the bent normals of the effect as a texture node. The bent normal is the
684
- * average unoccluded direction of the hemisphere, in view space, packed into `[0, 1]`
685
- * (unpack with `normal * 2 - 1`). It can be used for occlusion-aware environment
686
- * lighting (e.g. sampling IBL along the bent normal instead of the surface normal).
687
- *
688
- * @return {PassTextureNode} A texture node that represents the bent normals of the effect.
689
- */
690
- getBentNormalNode() {
691
- return this._bentNormalNode;
692
- }
693
- /**
694
- * Sets the size of the effect.
695
- *
696
- * @param {number} width - The width of the effect.
697
- * @param {number} height - The height of the effect.
698
- */
699
- setSize(t, s) {
700
- t = Math.max(1, Math.round(t * this.resolutionScale)), s = Math.max(1, Math.round(s * this.resolutionScale)), this._resolution.value.set(t, s), this._ssgiRenderTarget.setSize(t, s), this._halfProjScale.value = s / (Math.tan(this._camera.fov * os.DEG2RAD * 0.5) * 2) * 0.5;
701
- }
702
- /**
703
- * This method is used to render the effect once per frame.
704
- *
705
- * @param {NodeFrame} frame - The current node frame.
706
- */
707
- updateBefore(t) {
708
- const { renderer: s } = t;
709
- tt = Ue.resetRendererState(s, tt);
710
- const a = s.getDrawingBufferSize(Nn);
711
- if (this.setSize(a.width, a.height), this.useTemporalFiltering === !0) {
712
- const r = t.frameId;
713
- this._temporalDirection.value = Mn[r % 6] / 360, this._temporalOffset.value = _n[r % 4];
714
- } else
715
- this._temporalDirection.value = 1, this._temporalOffset.value = 1;
716
- et.material = this._material, et.name = "SSGI", s.setClearColor(16777215, 1), s.setRenderTarget(this._ssgiRenderTarget), et.render(s), Ue.restoreRendererState(s, tt);
717
- }
718
- /**
719
- * This method is used to setup the effect's TSL code.
720
- *
721
- * @param {NodeBuilder} builder - The current node builder.
722
- * @return {PassTextureNode}
723
- */
724
- setup(t) {
725
- const s = t.renderer;
726
- s.backend.isWebGPUBackend === !0 && s.hasFeature("rg11b10ufloat-renderable") === !1 && console.error('THREE.SSGINode: The device does not support the "rg11b10ufloat-renderable" feature which is required for SSGI.');
727
- const a = Re(), r = oe(32), o = oe(0), d = (i) => {
728
- const n = this.depthNode.sample(i).r;
729
- if (t.renderer.logarithmicDepthBuffer === !0) {
730
- const c = Ft(n, this._cameraNear, this._cameraFar);
731
- return nt(c, this._cameraNear, this._cameraFar);
732
- }
733
- return n;
734
- }, f = (i) => this.normalNode !== null ? this.normalNode.sample(i).rgb.normalize() : Lt(i, this.depthNode.value, this._cameraProjectionMatrixInverse), T = (i) => this.beautyNode.sample(i), v = Q(([i]) => C(0.25).mul(bs(i.y, i.x).bitAnd(3))).setLayout({
735
- name: "spatialOffsets",
736
- type: "float",
737
- inputs: [
738
- { name: "position", type: "vec2" }
739
- ]
740
- }), S = Q(([i]) => {
741
- const n = pe(i).mul(C(-0.156583)).add(Ze);
742
- n.mulAssign(Et(pe(i).oneMinus()));
743
- const c = i.x.greaterThanEqual(0).select(n.x, fe.sub(n.x)), h = i.y.greaterThanEqual(0).select(n.y, fe.sub(n.y));
744
- return K(c, h);
745
- }).setLayout({
746
- name: "GTAOFastAcos",
747
- type: "vec2",
748
- inputs: [
749
- { name: "value", type: "vec2" }
750
- ]
751
- }), V = Q(([i, n, c, h, y, p, A, w, l, b]) => {
752
- const M = this.stepCount.toConst(), _ = this.expFactor.toConst(), x = this.thickness.toConst(), Z = this.backfaceLighting.toConst(), G = i.select(K(1, -1), K(-1, 1)), E = i.select(1, -1), U = ae(0);
753
- return Oe({ start: oe(0), end: M, type: "uint", condition: "<" }, ({ i: P }) => {
754
- const N = Ge(pe($e(n, C(P).add(p)).div(c)), _).mul(c).toConst(), L = y.mul(q(N, C(P).add(1))).toConst(), H = A.add(L.mul(G)).toConst();
755
- he(H.x.lessThanEqual(0).or(H.y.lessThanEqual(0)).or(H.x.greaterThanEqual(1)).or(H.y.greaterThanEqual(1)), () => {
756
- Ts();
757
- });
758
- const ne = Ie(H, d(H), this._cameraProjectionMatrixInverse).toConst(), W = ne.sub(h).normalize().toConst(), ue = this.useLinearThickness.select(ne.z.negate().div(this._cameraFar).clamp().mul(100), C(1)), Y = be(ne.sub(ue.mul(w).mul(x)).sub(h));
759
- let F = K(ie(W, w), ie(Y, w));
760
- F = S(_e(F, -1, 1)), F = _e(vs($e(E, F.negate()).sub(b.sub(Ze)), fe)), F = i.select(F.yx, F.xy);
761
- const me = F.x.toConst(), ee = F.y.toConst(), Ne = oe(F.mul(C(r))).toConst(), Be = oe(As(ee.sub(me).mul(C(r)))).toConst();
762
- let ge = Be.greaterThan(oe(0)).select(oe(ws(oe(4294967295), oe(32).sub(r).add(r.sub(Be)))), oe(0)).toConst().shiftLeft(Ne);
763
- ge = ge.bitAnd(o.bitNot()), o.assign(o.bitOr(ge));
764
- const Me = xt(ge);
765
- he(Me.greaterThan(0), () => {
766
- const dt = T(H);
767
- he(Ae(dt).greaterThan(1e-3), () => {
768
- const ut = be(W), ht = _e(ie(l, ut));
769
- he(ht.greaterThan(1e-3), () => {
770
- const mt = f(H);
771
- let ye = ie(mt, ut.negate());
772
- const Zt = St(ye).lessThan(0).select(pe(ye).mul(Z), pe(ye));
773
- ye = Z.greaterThan(0).and(ie(mt, w).greaterThan(0)).select(Zt, _e(ye)), U.rgb.addAssign(C(Me).div(C(r)).mul(dt).mul(ht).mul(ye));
774
- });
775
- });
776
- });
777
- }), U;
778
- }), m = Ee("float"), k = Ee("vec3"), R = Ee("vec4"), u = Cs(m, k, R), g = Q(() => {
779
- const i = d(a).toVar();
780
- i.greaterThanEqual(1).discard();
781
- const n = Ie(a, i, this._cameraProjectionMatrixInverse).toVar(), c = f(a).toVar(), h = be(n.xyz.negate()).toVar(), y = v(bt), p = Ns(bt), A = this._temporalDirection.mul(0.02), w = Ms(y.add(this._temporalOffset)).add(_s(a.add(A).mul(2).sub(1))), l = C(0), b = ae(0), M = ae(0), _ = this.sliceCount.toConst(), x = this.stepCount.toConst(), Z = this.aoIntensity.toConst(), G = this.giIntensity.toConst(), E = this.radius.toConst(), U = C(0).toVar();
782
- he(this.useScreenSpaceSampling, () => {
783
- U.assign(E.mul(this._resolution.x.div(2)).div(C(16)));
784
- }).Else(() => {
785
- U.assign(q(E.mul(this._halfProjScale).div(n.z.negate()), C(x)));
786
- }), U.divAssign(C(x).add(1));
787
- const P = q(1, C(x.sub(1))).mul(U).toConst();
788
- Oe({ start: oe(0), end: _, type: "uint", condition: "<" }, ({ i: ne }) => {
789
- const W = $e(C(ne).add(p).add(this._temporalDirection), fe.div(C(_))).toConst(), ue = ae(K(ot(W), at(W)), 0).toConst(), Y = ue.xy.mul(C(1).div(this._resolution)).toConst(), F = be(Tt(ue, h)).toConst(), me = Tt(h, F).toConst(), ee = c.sub(F.mul(ie(c, F))).toConst(), Ne = be(ee).toConst(), Be = _e(ie(Ne, h), -1, 1).toConst(), De = St(ie(ee, me)).negate().mul(ks(Be)).toConst();
790
- o.assign(0), b.addAssign(V(vt(!0), U, P, n, Y, w, a, h, c, De)), b.addAssign(V(vt(!1), U, P, n, Y, w, a, h, c, De)), l.addAssign(C(xt(o)).div(C(r))), Oe({ start: oe(0), end: r, type: "uint", condition: "<", name: "j" }, ({ j: ge }) => {
791
- he(o.shiftRight(ge).bitAnd(oe(1)).equal(oe(0)), () => {
792
- const Me = Ze.sub(De).sub(C(ge).add(0.5).div(C(r)).mul(fe));
793
- M.addAssign(h.mul(ot(Me)).add(me.mul(at(Me))));
794
- });
795
- });
796
- }), l.divAssign(C(_)), l.assign(Ge(l.clamp().oneMinus(), Z).clamp()), b.divAssign(C(_)), b.mulAssign(G);
797
- const N = C(7).toConst(), L = Ae(b), H = L.greaterThan(N).select(N.div(L), C(1));
798
- return b.mulAssign(H), M.assign(be(M.add(c.mul(1e-4)))), m.assign(l), k.assign(b), R.assign(J(M.mul(0.5).add(0.5), 1)), J(0);
799
- });
800
- return this._material.colorNode = g().context(t.getSharedContext()), this._material.outputNode = u, this._material.needsUpdate = !0, this._aoNode;
801
- }
802
- /**
803
- * Frees internal resources. This method should be called
804
- * when the effect is no longer required.
805
- */
806
- dispose() {
807
- this._ssgiRenderTarget.dispose(), this._material.dispose();
808
- }
809
- }
810
- const Pn = (e, t, s, a) => new kn(qe(e), t, s, a);
811
- class Vn extends He {
812
- static get type() {
813
- return "DenoiseNode";
814
- }
815
- /**
816
- * Constructs a new denoise node.
817
- *
818
- * @param {TextureNode} textureNode - The texture node that represents the input of the effect (e.g. AO).
819
- * @param {Node<float>} depthNode - A node that represents the scene's depth.
820
- * @param {?Node<vec3>} normalNode - A node that represents the scene's normals.
821
- * @param {Camera} camera - The camera the scene is rendered with.
822
- */
823
- constructor(t, s, a, r) {
824
- super("vec4"), this.textureNode = t, this.depthNode = s, this.normalNode = a, this.noiseNode = Fe(Rn()), this.lumaPhi = I(5), this.depthPhi = I(5), this.normalPhi = I(5), this.radius = I(5), this.index = I(0), this.updateBeforeType = Ot.FRAME, this._resolution = I(new ve()), this._sampleVectors = Ps(In(16, 2, 1)), this._cameraProjectionMatrixInverse = I(r.projectionMatrixInverse);
825
- }
826
- /**
827
- * This method is used to update internal uniforms once per frame.
828
- *
829
- * @param {NodeFrame} frame - The current node frame.
830
- */
831
- updateBefore() {
832
- const t = this.textureNode.value;
833
- this._resolution.value.set(t.image.width, t.image.height);
834
- }
835
- /**
836
- * This method is used to setup the effect's TSL code.
837
- *
838
- * @param {NodeBuilder} builder - The current node builder.
839
- * @return {ShaderCallNodeInternal}
840
- */
841
- setup() {
842
- const t = Re(), s = (S) => this.textureNode.sample(S), a = (S) => this.depthNode.sample(S).x, r = (S) => this.normalNode !== null ? this.normalNode.sample(S).rgb.normalize() : Lt(S, this.depthNode.value, this._cameraProjectionMatrixInverse), o = (S) => this.noiseNode.sample(S), d = (S, V, m, k) => {
843
- const R = s(k).toVar(), u = a(k).toVar(), g = r(k).toVar(), i = Ie(k, u, this._cameraProjectionMatrixInverse).toVar(), n = ie(V, g), c = Ge(q(n, 0), this.normalPhi), h = pe(Ae(R.rgb).sub(Ae(S))), y = q(C(1).sub(h.div(this.lumaPhi)), 0), p = pe(ie(m.sub(i), V)), A = q(C(1).sub(p.div(this.depthPhi)), 0), w = y.mul(A).mul(c).toVar();
844
- return { color: R.mul(w), weight: w };
845
- }, f = Q(([S]) => {
846
- const V = a(S).toVar(), m = r(S).toVar(), k = s(S).toVar(), R = Ee("vec4");
847
- return he(V.greaterThanEqual(1).or(ie(m, m).equal(0)), () => {
848
- R.assign(k);
849
- }).Else(() => {
850
- const u = ae(k.rgb), g = Ie(S, V, this._cameraProjectionMatrixInverse).toConst(), i = Vs(this.noiseNode, 0);
851
- let n = K(S.x, S.y.oneMinus());
852
- n = n.mul(this._resolution.div(i));
853
- const c = o(n).toVar(), h = at(c.element(this.index.mod(4).mul(2).mul(fe))), y = ot(c.element(this.index.mod(4).mul(2).mul(fe))), p = K(h, y), A = Is(p.x, p.y.negate(), p.x, p.y), w = C(1).toVar(), l = J(k).toVar();
854
- Oe({ start: At(0), end: At(16), type: "int", condition: "<" }, ({ i: b }) => {
855
- const M = this._sampleVectors.element(b), _ = A.mul(M.xy.mul(C(1).add(M.z.mul(this.radius.sub(1))))).div(this._resolution), x = S.add(_), Z = d(u, m, g, x);
856
- l.addAssign(Z.color), w.addAssign(Z.weight);
857
- }), R.assign(l.div(w));
858
- }), R;
859
- });
860
- return Q(() => f(t))();
861
- }
862
- }
863
- function In(e, t, s) {
864
- const a = [];
865
- for (let r = 0; r < e; r++) {
866
- const o = 2 * Math.PI * t * r / e, d = Math.pow(r / (e - 1), s);
867
- a.push(new Bt(Math.cos(o), Math.sin(o), d));
868
- }
869
- return a;
870
- }
871
- function Rn(e = 64) {
872
- const t = new Ls(), s = e * e * 4, a = new Uint8Array(s);
873
- for (let o = 0; o < e; o++)
874
- for (let d = 0; d < e; d++) {
875
- const f = o, T = d;
876
- a[(o * e + d) * 4] = (t.noise(f, T) * 0.5 + 0.5) * 255, a[(o * e + d) * 4 + 1] = (t.noise(f + e, T) * 0.5 + 0.5) * 255, a[(o * e + d) * 4 + 2] = (t.noise(f, T + e) * 0.5 + 0.5) * 255, a[(o * e + d) * 4 + 3] = (t.noise(f + e, T + e) * 0.5 + 0.5) * 255;
877
- }
878
- const r = new as(a, e, e);
879
- return r.wrapS = yt, r.wrapT = yt, r.needsUpdate = !0, r;
880
- }
881
- const Bn = (e, t, s, a) => new Vn(qe(e), rt(t), rt(s), a);
882
- class Dn extends He {
883
- static get type() {
884
- return "CASNode";
885
- }
886
- /**
887
- * Constructs a new CAS node.
888
- *
889
- * @param {TextureNode} textureNode - The texture node to sharpen (premultiplied, linear).
890
- * @param {number} [amount=0.5] - Sharpening strength in [0,1]: 0 = off, 1 = RCAS maximum.
891
- * @param {boolean} [denoise=true] - Whether to attenuate sharpening where the 3×3 cross looks like noise.
892
- */
893
- constructor(t, s = 0.5, a = !0) {
894
- super("vec4"), this.isCASNode = !0, this.textureNode = t, this.amount = I(s), this.denoise = I(a ? 1 : 0);
895
- }
896
- /**
897
- * This method is used to setup the effect's TSL code.
898
- *
899
- * @param {NodeBuilder} builder - The current node builder.
900
- * @return {Node<vec4>}
901
- */
902
- setup() {
903
- const t = this.textureNode, s = (d) => Et(d.div(d.add(1))), a = (d) => {
904
- const f = d.pow2().min(0.9999);
905
- return f.div(f.oneMinus());
906
- }, r = (d) => d.g.add(d.r.add(d.b).mul(0.5));
907
- return Q(() => {
908
- const d = ke(t.size()).toConst(), f = d.sub(1).toConst(), T = ke(Re().mul(K(d))).toConst(), v = (U, P) => {
909
- const N = t.load(q(ce(T.add(ke(U, P)), f), ke(0))), L = N.a.saturate().toConst(), H = L.greaterThan(1 / 255).select(N.rgb.max(0).div(L), ae(0));
910
- return { p: s(H).toConst(), a: L };
911
- }, S = v(0, 0), V = v(0, -1), m = v(-1, 0), k = v(1, 0), R = v(0, 1), u = ce(ce(V.p, m.p), ce(k.p, R.p)).toConst(), g = q(q(V.p, m.p), q(k.p, R.p)).toConst(), i = C(0.25 - 1 / 16), n = ce(u, S.p).div(g.mul(4).max(1e-5)), c = ae(1).sub(q(g, S.p)).div(u.mul(4).sub(4)), h = q(n.negate(), c).toConst(), y = q(i.negate(), ce(q(h.r, q(h.g, h.b)), 0)).mul(this.amount).toVar(), p = r(V.p), A = r(m.p), w = r(S.p), l = r(k.p), b = r(R.p), M = p.add(A).add(l).add(b).mul(0.25).sub(w), _ = q(q(p, A), q(w, q(l, b))).sub(ce(ce(p, A), ce(w, ce(l, b)))), x = C(1).sub(pe(M).div(_.max(1 / 65536)).saturate().mul(0.5));
912
- y.mulAssign(this.denoise.greaterThan(0.5).select(x, 1));
913
- const Z = y.mul(4).add(1).reciprocal().toConst(), G = a(V.p.add(m.p).add(k.p).add(R.p).mul(y).add(S.p).mul(Z).max(0)), E = V.a.add(m.a).add(k.a).add(R.a).mul(y).add(S.a).mul(Z).saturate().toConst();
914
- return J(G.mul(E), E);
915
- })();
916
- }
917
- }
918
- const zn = (e, t, s) => new Dn(typeof e.getTextureNode == "function" ? e.getTextureNode() : qe(e), t, s);
919
- function Fn(e, t) {
920
- const s = Ut(e, t);
921
- s.setMRT(jt({
922
- output: Gt,
923
- diffuseColor: Rs,
924
- // alpha holds the kind of surface for the composite (SURFACE: eye / skin / hair / other,
925
- // 0 = background) in the byte the RGBA8 target already stores
926
- normal: J(Bs(Ds), rs),
927
- velocity: ct
928
- }));
929
- const a = s.getTextureNode("output"), r = s.getTextureNode("depth"), o = s.getTextureNode("normal"), d = s.getTextureNode("velocity"), f = s.getTextureNode("diffuseColor");
930
- s.getTexture("diffuseColor").type = B.UnsignedByteType, s.getTexture("normal").type = B.UnsignedByteType;
931
- const T = We(o.a, Ke.skin), v = We(o.a, Ke.eye), S = We(o.a, Ke.hair), V = zs((G) => Fs(o.sample(G))), m = Pn(a, r, V, t);
932
- m.resolutionScale = 0.5, m.aoIntensity.value = 1, m.giIntensity.value = 5, m.sliceCount.value = 2, m.stepCount.value = 8, m.thickness.value = 0.03, m.radius.value = 1, m.expFactor.value = 1, m.backfaceLighting.value = 0.1;
933
- const k = m.getAONode(), R = m.getGINode(), u = je("near", "float", t), g = je("far", "float", t), i = (G) => Es(r.sample(G).r, u, g), n = Q(() => {
934
- const G = Re(), E = K(m.getAONode().size()), U = G.mul(E).sub(0.5), P = U.floor(), N = U.sub(P), L = i(G), H = J(0).toVar(), ne = C(0).toVar();
935
- for (const [W, ue] of [[0, 0], [1, 0], [0, 1], [1, 1]]) {
936
- const Y = P.add(K(W + 0.5, ue + 0.5)).div(E), F = (W === 1 ? N.x : N.x.oneMinus()).mul(ue === 1 ? N.y : N.y.oneMinus()), me = Os(L.sub(i(Y)).abs().mul(-32)).add(1e-3), ee = F.mul(me);
937
- H.addAssign(J(R.sample(Y).rgb, k.sample(Y).r).mul(ee)), ne.addAssign(ee);
938
- }
939
- return H.div(ne);
940
- }), c = Bn(n(), r, V, t);
941
- c.radius.value = 8, c.depthPhi.value = 0.1, c.lumaPhi.value = 5;
942
- const h = rt(c), y = I(0.5), p = I(0.5), A = h.a.oneMinus().mul(Pe(C(1), y, S)).mul(Pe(C(1), p, v)).oneMinus(), w = Pe(a.rgb, f.rgb, f.a), l = Q(([G, E]) => {
943
- const U = E.mul(2.0404).sub(0.3324), P = E.mul(-4.7951).add(0.6417), N = E.mul(2.7552).add(0.6903);
944
- return ae(G).max(U.mul(G).add(P).mul(G).add(N).mul(G));
945
- }), b = I(new B.Vector3(0.45, 0.15, 0.05)), M = Pe(ae(A), Ge(ae(A), ae(1).sub(b)), T), _ = J(
946
- a.rgb.mul(l(M, w)).add(w.mul(h.rgb)),
947
- // indirect diffuse modulated by albedo
948
- a.a
949
- ), x = Yt(_, r, d, t);
950
- return x._resolveMaterial.needsUpdate = !0, { outputNode: zn(x, 0.5), scenePassColor: a, traaPass: x, giPass: m, denoisePass: c, ao: k, gi: R, hairAO: y, eyeAO: p };
951
- }
952
- function On(e, t) {
953
- const s = Ut(e, t);
954
- s.setMRT(jt({ output: Gt, velocity: ct }));
955
- const a = s.getTextureNode("output"), r = Yt(a, s.getTextureNode("depth"), s.getTextureNode("velocity"), t);
956
- return r._resolveMaterial.needsUpdate = !0, { outputNode: r, scenePassColor: a, traaPass: r };
957
- }
958
- const En = () => {
959
- const e = O((n) => n.animationsLoaded), t = O((n) => n.characterState), s = O((n) => n.lipSyncManager), a = O((n) => n.blendshapeManager), r = z((n) => n.credentials), o = z((n) => n.currentUtterance), d = z((n) => n.textToSpeak), f = z((n) => n.visemes), T = z((n) => n.blendshapes), v = z((n) => n.visemeIntensity), S = z((n) => n.currentVisemeIndex), V = z((n) => n.currentBlendshapeIndex), m = z((n) => n.useBlendshapeManager), [k, R] = te(!1), [u, g] = te(!1), i = it(() => r != null && r.region && (r.subscriptionKey || r.token) ? Gs({
161
+ playedVisemeCount: 0
162
+ }), (e = g.getState().lipSyncManager) == null || e.stop();
163
+ }, ct = (e) => {
164
+ p.setState({ voice: e });
165
+ }, ue = (e) => {
166
+ p.setState({ voices: e });
167
+ }, zt = (e) => {
168
+ p.setState({ textToSpeak: e });
169
+ }, Bt = () => p.getState().voices, Ut = (e) => {
170
+ p.setState({ visemeIntensity: e });
171
+ }, lt = (e) => {
172
+ p.setState({ lipSyncFromAudio: e });
173
+ }, mt = () => {
174
+ const e = g((o) => o.animationsLoaded), t = g((o) => o.characterState), n = g((o) => o.lipSyncManager), r = p((o) => o.credentials), d = p((o) => o.currentUtterance), s = p((o) => o.textToSpeak), m = p((o) => o.visemes), k = p((o) => o.visemeIntensity), C = p((o) => o.playedVisemeCount), c = p((o) => o.lipSyncFromAudio), [w, P] = A(!1), [E, D] = A(!1), h = _(() => r != null && r.region && (r.subscriptionKey || r.token) ? Ge({
960
175
  credentials: {
961
176
  region: r.region,
962
177
  authorizationToken: r.token,
963
178
  subscriptionKey: r.subscriptionKey
964
179
  }
965
- }) : null, [r]);
966
- return j(() => {
967
- if (i) {
968
- const n = i.speechSynthesis.getVoices();
969
- n && Array.isArray(n) && n.length ? (Pt(n), R(!0)) : i.speechSynthesis.onvoiceschanged = () => {
970
- Pt(i.speechSynthesis.getVoices()), R(!0);
180
+ }) : null, [r]), U = _(() => ke(() => h), [h]);
181
+ return l(() => {
182
+ if (h) {
183
+ const o = h.speechSynthesis.getVoices();
184
+ o && Array.isArray(o) && o.length ? (ue(o), P(!0)) : h.speechSynthesis.onvoiceschanged = () => {
185
+ ue(h.speechSynthesis.getVoices()), P(!0);
971
186
  };
972
187
  }
973
- }, [i]), j(() => {
974
- k && (m ? !!a : !!s) && e && g(!0);
975
- }, [k, s, a, e, m]), j(() => {
976
- if (d) {
977
- const n = new Hs(d);
978
- Sn(n);
188
+ }, [h]), l(() => {
189
+ w && n && e && D(!0);
190
+ }, [w, n, e]), l(() => {
191
+ if (s) {
192
+ const o = new Oe(s);
193
+ ot(o);
979
194
  }
980
- }, [d]), j(() => {
981
- var n, c;
982
- o && u ? (o.onstart = () => {
983
- console.log("Start"), Nt(de.speaking);
984
- }, o.onend = () => {
985
- console.log("End"), Nt(de.idle);
986
- }, o.onboundary = () => {
987
- }, o.onviseme = (h) => {
988
- qt(h);
989
- }, (n = i == null ? void 0 : i.speechSynthesis) == null || n.speak(o, null)) : (c = i == null ? void 0 : i.speechSynthesis) == null || c.cancel();
990
- }, [o]), j(() => {
991
- s && (s.visemeIntensity = v);
992
- }, [v]), j(() => {
993
- if (!m && s && t === de.speaking) {
994
- if (!s.isStarted && s.start(), f.length > 1 && S === 0)
995
- f.forEach((n) => {
996
- const c = parseInt(n.name);
997
- if (!isNaN(c)) {
998
- const h = kt.get(c);
999
- h && s.PlayVisemeAsync(h, n.elapsedTime / 1e4);
1000
- }
1001
- });
1002
- else
1003
- for (let n = S + 1; n < f.length; n++) {
1004
- const c = f[n], h = parseInt(c.name);
1005
- if (!isNaN(h)) {
1006
- const y = kt.get(h);
1007
- y && s.PlayVisemeAsync(y, c.elapsedTime / 1e4);
1008
- }
1009
- }
1010
- bn(f.length - 1);
1011
- }
1012
- }, [t, f, s, m]), j(() => {
1013
- if (m && a && t === de.speaking) {
1014
- if (!a.isStarted && a.start(), T.length > 1 && V === 0)
1015
- T.forEach((n) => {
1016
- a.PlayBlendShapeAsync(n);
1017
- });
1018
- else
1019
- for (let n = V + 1; n < T.length; n++) {
1020
- const c = T[n];
1021
- a.PlayBlendShapeAsync(c);
1022
- }
1023
- Tn(T.length - 1);
1024
- }
1025
- }, [t, T, a, m]), j(() => {
1026
- t !== de.speaking && (Wt(), Kt());
195
+ }, [s]), l(() => {
196
+ var o, T;
197
+ d && E ? (d.onstart = () => {
198
+ console.log("Start"), ce(z.speaking);
199
+ }, d.onend = () => {
200
+ console.log("End"), ce(z.idle);
201
+ }, d.onboundary = () => {
202
+ }, d.onviseme = (y) => {
203
+ he(y);
204
+ }, n == null || n.setSpeechText(d.text), (o = h == null ? void 0 : h.speechSynthesis) == null || o.speak(d, null)) : (T = h == null ? void 0 : h.speechSynthesis) == null || T.cancel();
205
+ }, [d]), l(() => {
206
+ n && (n.visemeIntensity = k);
207
+ }, [k]), l(() => {
208
+ c || n && t === z.speaking && rt(be(n, m, C, U));
209
+ }, [t, m, n, c]), l(() => {
210
+ n && (t === z.speaking ? c && Ce(n, h) : n.disconnectAudio());
211
+ }, [t, n]), l(() => {
212
+ t !== z.speaking && it();
1027
213
  }, [t]), null;
1028
- }, Ln = ({ points: e, color: t = "red" }) => {
1029
- const s = it(() => {
1030
- const a = new B.BufferGeometry().setFromPoints(e), r = new B.LineBasicMaterial({ color: t, toneMapped: !1 });
1031
- return new B.Line(a, r);
214
+ }, ut = ({ points: e, color: t = "red" }) => {
215
+ const n = _(() => {
216
+ const r = new R.BufferGeometry().setFromPoints(e), d = new R.LineBasicMaterial({ color: t, toneMapped: !1 });
217
+ return new R.Line(r, d);
1032
218
  }, [e, t]);
1033
- return /* @__PURE__ */ D.createElement("primitive", { object: s });
1034
- }, Un = ({ parentGpuTier: e, setIsGpuAvailable: t, children: s, tonemapping: a, inspector: r = !1 }) => {
1035
- const o = se((l) => l.cameraPosition), d = se((l) => l.lookAt), f = se((l) => l.movable), T = re((l) => l.targets), v = re((l) => l.showFirstTarget), [S, V] = te(e || ds()), [m, k] = te(
219
+ return /* @__PURE__ */ i.createElement("primitive", { object: n });
220
+ }, dt = async (e) => {
221
+ const t = new R.WebGPURenderer({
222
+ canvas: e,
223
+ antialias: !1,
224
+ alpha: !0,
225
+ powerPreference: "high-performance"
226
+ });
227
+ return t.setClearColor(new R.Color("#000000"), 0), t.setPixelRatio(Math.min(devicePixelRatio, 1.5)), t.shadowMap.type = R.PCFShadowMap, t.forceContextLoss = () => {
228
+ t.dispose();
229
+ }, await t.init(), t;
230
+ }, gt = ({ parentGpuTier: e, setIsGpuAvailable: t, children: n, tonemapping: r, inspector: d = !1 }) => {
231
+ const s = M((a) => a.cameraPosition), m = M((a) => a.lookAt), k = M((a) => a.movable), C = F((a) => a.targets), c = F((a) => a.showFirstTarget), [w, P] = A(e || Ve()), [E, D] = A(
1036
232
  "low"
1037
233
  /* low */
1038
- ), [R, u] = te(null), [g, i] = te(void 0), n = Te(null), c = Te(null), h = Te(null), y = (l) => {
1039
- l.preventDefault(), l.stopPropagation();
234
+ ), [h, U] = A(null), [o, T] = A(void 0), y = X(null), [I, H] = A(null), G = X(null), b = (a) => {
235
+ a.preventDefault(), a.stopPropagation();
1040
236
  };
1041
- j(() => {
1042
- Qs(c.current);
1043
- }, [c.current]), j(() => {
1044
- var l, b, M, _;
1045
- if (f)
1046
- R == null || R.abort(), u(null);
237
+ l(() => {
238
+ var a, v, V, u;
239
+ if (k)
240
+ h == null || h.abort(), U(null);
1047
241
  else {
1048
242
  const x = new AbortController();
1049
- u(x), (l = n.current) == null || l.addEventListener("wheel", y, { passive: !1, signal: x.signal }), (b = n.current) == null || b.addEventListener("pointerdown", y, { passive: !1, signal: x.signal }), (M = n.current) == null || M.addEventListener("pointermove", y, { passive: !1, signal: x.signal }), (_ = n.current) == null || _.addEventListener("click", y, { passive: !1, signal: x.signal });
243
+ U(x), (a = y.current) == null || a.addEventListener("wheel", b, { passive: !1, signal: x.signal }), (v = y.current) == null || v.addEventListener("pointerdown", b, { passive: !1, signal: x.signal }), (V = y.current) == null || V.addEventListener("pointermove", b, { passive: !1, signal: x.signal }), (u = y.current) == null || u.addEventListener("click", b, { passive: !1, signal: x.signal });
244
+ }
245
+ }, [k]), l(() => {
246
+ if (I && m && s) {
247
+ const a = G.current === I;
248
+ I.setLookAt(s.x, s.y, s.z, m.x, m.y, m.z, a), G.current = I;
1050
249
  }
1051
- }, [f]), j(() => {
1052
- h != null && h.current && d && o && h.current.setLookAt(o.x, o.y, o.z, d.x, d.y, d.z, !0);
1053
- }, [o, d]), j(() => {
1054
- e && V(e);
1055
- }, [e]), j(() => {
1056
- if (S)
1057
- if (S.type === "FALLBACK") {
1058
- const l = typeof navigator < "u" && /Macintosh|Mac OS X/.test(navigator.userAgent);
1059
- k(
1060
- l ? "medium" : "low"
250
+ }, [I, s, m]), l(() => {
251
+ e && P(e);
252
+ }, [e]), l(() => {
253
+ if (w)
254
+ if (w.type === "FALLBACK") {
255
+ const a = typeof navigator < "u" && /Macintosh|Mac OS X/.test(navigator.userAgent);
256
+ D(
257
+ a ? "medium" : "low"
1061
258
  /* low */
1062
259
  );
1063
260
  } else
1064
- switch (S.tier) {
261
+ switch (w.tier) {
1065
262
  case 0:
1066
263
  case 1:
1067
- k(
264
+ D(
1068
265
  "low"
1069
266
  /* low */
1070
267
  );
1071
268
  break;
1072
269
  case 2:
1073
- k(
270
+ D(
1074
271
  "medium"
1075
272
  /* medium */
1076
273
  );
1077
274
  break;
1078
275
  case 3:
1079
- k(
276
+ D(
1080
277
  "high"
1081
278
  /* high */
1082
279
  );
1083
280
  break;
1084
281
  default:
1085
- k(
282
+ D(
1086
283
  "low"
1087
284
  /* low */
1088
285
  );
1089
286
  break;
1090
287
  }
1091
- }, [S]), j(() => {
1092
- switch (m && (p.current = m), m) {
288
+ }, [w]), l(() => {
289
+ switch (E && (f.current = E), E) {
1093
290
  case "low":
1094
291
  console.warn("Retorik React-Bodyengine-Three > GPU tier too low, no rendering available"), t(!1);
1095
292
  break;
1096
293
  case "medium":
1097
- i([0.8, 1]), console.log(`Retorik React-Bodyengine-Three > GPU tier detected : ${m}`), t(!0);
294
+ T([0.8, 1]), console.log(`Retorik React-Bodyengine-Three > GPU tier detected : ${E}`), t(!0);
1098
295
  break;
1099
296
  case "high":
1100
- i([1, 1.5]), console.log(`Retorik React-Bodyengine-Three > GPU tier detected : ${m}`), t(!0);
297
+ T([1, 1.5]), console.log(`Retorik React-Bodyengine-Three > GPU tier detected : ${E}`), t(!0);
1101
298
  break;
1102
299
  }
1103
- }, [m]);
1104
- const p = Te(void 0), A = $t(async (l) => {
1105
- const b = new B.WebGPURenderer({
1106
- canvas: l.canvas,
1107
- antialias: !1,
1108
- alpha: !0,
1109
- powerPreference: "high-performance"
1110
- });
1111
- return b.setClearColor(new B.Color("#000000"), 0), b.setPixelRatio(Math.min(devicePixelRatio, 1.5)), b.shadowMap.type = B.PCFShadowMap, await b.init(), b;
1112
- }, []), w = it(() => {
1113
- if (T.length) {
1114
- const l = T[0], b = new B.Vector3(l.position.x - 0.5, l.position.y, l.position.z - 0.1), M = new B.Vector3(l.position.x + 0.5, l.position.y, l.position.z - 0.1);
1115
- return [b, M];
1116
- } else if (o) {
1117
- const l = new B.Vector3(o.x - 0.5, o.y, o.z - 0.1), b = new B.Vector3(o.x + 0.5, o.y, o.z - 0.1);
1118
- return [l, b];
300
+ }, [E]);
301
+ const f = X(void 0), L = X(null), O = pe((a) => ((!L.current || L.current.canvas !== a.canvas) && (L.current = { canvas: a.canvas, renderer: dt(a.canvas) }), L.current.renderer), []), W = _(() => {
302
+ if (C.length) {
303
+ const a = C[0], v = new R.Vector3(a.position.x - 0.5, a.position.y, a.position.z - 0.1), V = new R.Vector3(a.position.x + 0.5, a.position.y, a.position.z - 0.1);
304
+ return [v, V];
305
+ } else if (s) {
306
+ const a = new R.Vector3(s.x - 0.5, s.y, s.z - 0.1), v = new R.Vector3(s.x + 0.5, s.y, s.z - 0.1);
307
+ return [a, v];
1119
308
  }
1120
309
  return [];
1121
- }, [T, o]);
1122
- return g ? (
310
+ }, [C, s]);
311
+ return o ? (
1123
312
  // "percentage" = PCFShadowMap; shadows={true} would make R3F set the removed PCFSoftShadowMap
1124
- /* @__PURE__ */ D.createElement(Us, { gl: A, dpr: g, ref: n, shadows: "percentage" }, /* @__PURE__ */ D.createElement(us, { iterations: 5, ms: 100, threshold: 0.75 }, /* @__PURE__ */ D.createElement(jn, { tonemapping: a, processedTier: m, inspector: r }), /* @__PURE__ */ D.createElement(En, null), /* @__PURE__ */ D.createElement(hs, { ref: c, makeDefault: !0, fov: 28 }), /* @__PURE__ */ D.createElement(ms, { ref: h }), v && w.length && /* @__PURE__ */ D.createElement(Ln, { points: w, color: "red" }), /* @__PURE__ */ D.createElement(Qt, { fallback: null }, s)))
1125
- ) : /* @__PURE__ */ D.createElement(D.Fragment, null);
1126
- }, jn = ({ tonemapping: e, processedTier: t, inspector: s = !1 }) => {
1127
- const [a, r] = te(!1), { gl: o, scene: d, camera: f, size: T } = js(), [v] = te(new B.Vector3(-3, 2, 2)), [S] = te(new B.Vector3(0, 1, 0)), [V] = te(3.5), [m] = te(-2e-4), [k] = te(0.57), [R] = te(0.25), u = Te(null), g = Te(null);
1128
- return j(() => {
1129
- o && (o.shadowMap.type = B.PCFShadowMap, o.toneMapping = e, t !== "low" ? d.environmentIntensity = R : d.environmentIntensity = 1);
1130
- }, [o, e]), j(() => {
1131
- d.environmentIntensity = R;
1132
- }, [R]), j(() => {
1133
- if (!s || !o || a) return;
1134
- let i = !1;
1135
- return import("three/addons/inspector/Inspector.js").then(({ Inspector: n }) => {
1136
- i || (o.inspector = new n(), r(!0));
1137
- }).catch((n) => console.warn("Scene: could not load three's Inspector", n)), () => {
1138
- i = !0;
313
+ /* @__PURE__ */ i.createElement(Be, { gl: O, dpr: o, ref: y, shadows: "percentage" }, /* @__PURE__ */ i.createElement(xe, { iterations: 5, ms: 100, threshold: 0.75 }, /* @__PURE__ */ i.createElement(ht, { tonemapping: r, processedTier: E, inspector: d }), /* @__PURE__ */ i.createElement(mt, null), /* @__PURE__ */ i.createElement(Fe, { ref: Xe, makeDefault: !0, fov: 28 }), /* @__PURE__ */ i.createElement(Ie, { ref: H }), c && W.length && /* @__PURE__ */ i.createElement(ut, { points: W, color: "red" }), /* @__PURE__ */ i.createElement(fe, { fallback: null }, n)))
314
+ ) : /* @__PURE__ */ i.createElement(i.Fragment, null);
315
+ }, ht = ({ tonemapping: e, processedTier: t, inspector: n = !1 }) => {
316
+ const [r, d] = A(!1), { gl: s, scene: m, camera: k, size: C } = Ue(), [c] = A(new R.Vector3(-3, 2, 2)), [w] = A(new R.Vector3(0, 1, 0)), [P] = A(3.5), [E] = A(-2e-4), [D] = A(0.57), [h] = A(0.25), U = X(null), o = X(null);
317
+ return l(() => {
318
+ s && (s.shadowMap.type = R.PCFShadowMap, s.toneMapping = e, t !== "low" ? m.environmentIntensity = h : m.environmentIntensity = 1);
319
+ }, [s, e]), l(() => {
320
+ m.environmentIntensity = h;
321
+ }, [h]), l(() => {
322
+ if (!n || !s || r) return;
323
+ let T = !1;
324
+ return import("three/addons/inspector/Inspector.js").then(({ Inspector: y }) => {
325
+ T || (s.inspector = new y(), d(!0));
326
+ }).catch((y) => console.warn("Scene: could not load three's Inspector", y)), () => {
327
+ T = !0;
1139
328
  };
1140
- }, [s, o, a]), j(() => {
1141
- if (!o || !d || !f || !t) return;
1142
- d.background = null;
1143
- const i = t === "high", n = i ? Fn(d, f) : On(d, f), { outputNode: c, scenePassColor: h, traaPass: y, giPass: p, ao: A, gi: w, hairAO: l, eyeAO: b } = n, M = new B.RenderPipeline(o);
1144
- if (M.outputNode = c, g.current = M, s && a && o.inspector) {
1145
- const _ = () => {
1146
- M.needsUpdate = !0;
1147
- }, x = o.inspector.createParameters(i ? "SSGI + TRAA" : "TRAA");
1148
- if (i) {
1149
- const Z = { output: 0, feedback: !1 }, G = { Combined: 0, AO: 1, GI: 2, Direct: 3 };
1150
- x.add(Z, "output", G).name("output").onChange((E) => {
1151
- const U = Number(E);
1152
- M.outputNode = U === 1 ? J(ae(A.r), 1) : U === 2 ? J(w.rgb, 1) : U === 3 ? h : c, _();
1153
- }), x.add(p.sliceCount, "value", 1, 4, 1).name("slice count"), x.add(p.stepCount, "value", 1, 32, 1).name("step count"), x.add(p.radius, "value", 0.1, 2).name("radius"), x.add(p.expFactor, "value", 1e-3, 10).name("exp factor"), x.add(p.thickness, "value", 1e-3, 0.1).name("thickness"), x.add(p.backfaceLighting, "value", 0, 1).name("backface lighting"), x.add(p.aoIntensity, "value", 0, 4).name("AO intensity"), x.add(p.giIntensity, "value", 0, 20).name("GI intensity"), x.add(p, "resolutionScale", 0.25, 1).name("SSGI resolution scale"), x.add(l, "value", 0, 1).name("SSGI AO on hair"), x.add(b, "value", 0, 1).name("SSGI AO on eyes"), x.add(Z, "feedback").name("SSGI 2nd bounce (TRAA history)").onChange((E) => {
1154
- p.beautyNode = E ? y.getHistoryTextureNode() : h, _();
329
+ }, [n, s, r]), l(() => {
330
+ if (!s || !m || !k || !t) return;
331
+ m.background = null;
332
+ const T = t === "high", y = { inspector: n && r && !!s.inspector }, I = T ? we(m, k, y) : Pe(m, k, y), { outputNode: H, scenePassColor: G, traaPass: b, giPass: f, ao: L, gi: O, hairAO: W, eyeAO: a } = I, v = new R.RenderPipeline(s);
333
+ if (v.outputNode = H, o.current = v, n && r && s.inspector) {
334
+ const V = () => {
335
+ v.needsUpdate = !0;
336
+ }, u = s.inspector.createParameters(T ? "SSGI + TRAA" : "TRAA");
337
+ if (T) {
338
+ const x = { output: 0, feedback: !1 }, ee = { Combined: 0, AO: 1, GI: 2, Direct: 3 };
339
+ u.add(x, "output", ee).name("output").onChange((Q) => {
340
+ const Y = Number(Q);
341
+ v.outputNode = Y === 1 ? oe(ze(L.r), 1) : Y === 2 ? oe(O.rgb, 1) : Y === 3 ? G : H, V();
342
+ }), u.add(f.sliceCount, "value", 1, 4, 1).name("slice count"), u.add(f.stepCount, "value", 1, 32, 1).name("step count"), u.add(f.radius, "value", 0.1, 2).name("radius"), u.add(f.expFactor, "value", 1e-3, 10).name("exp factor"), u.add(f.thickness, "value", 1e-3, 0.1).name("thickness"), u.add(f.backfaceLighting, "value", 0, 1).name("backface lighting"), u.add(f.aoIntensity, "value", 0, 4).name("AO intensity"), u.add(f.giIntensity, "value", 0, 20).name("GI intensity"), u.add(f, "resolutionScale", 0.25, 1).name("SSGI resolution scale"), u.add(W, "value", 0, 1).name("SSGI AO on hair"), u.add(a, "value", 0, 1).name("SSGI AO on eyes"), u.add(x, "feedback").name("SSGI 2nd bounce (TRAA history)").onChange((Q) => {
343
+ f.beautyNode = Q ? b.getHistoryTextureNode() : G, V();
1155
344
  });
1156
345
  }
1157
- x.add(y, "maxVelocityLength", 4, 128, 1).name("TRAA max velocity").onChange(_), x.add(y, "depthThreshold", 1e-4, 0.01).name("TRAA depth threshold").onChange(_), x.add(y, "edgeDepthDiff", 1e-4, 0.01).name("TRAA edge depth diff").onChange(_), x.add(y, "useSubpixelCorrection").name("TRAA subpixel correction").onChange(_);
346
+ u.add(b, "maxVelocityLength", 4, 128, 1).name("TRAA max velocity").onChange(V), u.add(b, "depthThreshold", 1e-4, 0.01).name("TRAA depth threshold").onChange(V), u.add(b, "edgeDepthDiff", 1e-4, 0.01).name("TRAA edge depth diff").onChange(V), u.add(b, "useSubpixelCorrection").name("TRAA subpixel correction").onChange(V), u.add(b.maskedMotionWeight, "value", 0, 1, 0.01).name("TRAA hair motion weight"), u.add(b.maskedClipWidening, "value", 0, 2, 0.05).name("TRAA hair clip widening (still)"), u.add(b.maskedClipFadeVelocity, "value", 0.05, 4, 0.05).name("TRAA hair clip fade (px/frame)");
1158
347
  }
1159
348
  return () => {
1160
- M.dispose(), g.current = null;
349
+ v.dispose(), o.current = null;
1161
350
  };
1162
- }, [o, d, f, t, s, a]), j(() => {
1163
- !o || !T || o.setSize(T.width, T.height);
1164
- }, [T]), Ht(({ gl: i, scene: n, camera: c }) => {
1165
- g.current && g.current.render();
1166
- }, 1), /* @__PURE__ */ D.createElement(D.Fragment, null, t !== "low" && o && /* @__PURE__ */ D.createElement(D.Fragment, null, /* @__PURE__ */ D.createElement("directionalLight", { ref: u, color: "white", position: v.toArray(), "target-position": S.toArray(), intensity: V, castShadow: !0, "shadow-mapSize-width": 1024, "shadow-mapSize-height": 1024, "shadow-bias": m, "shadow-normalBias": 3e-3, "shadow-intensity": 0.6, "shadow-radius": 2.5 }, /* @__PURE__ */ D.createElement("orthographicCamera", { attach: "shadow-camera", args: [-1, 1, 2, -0.5, 2, 5] })), t === "high" && /* @__PURE__ */ D.createElement("directionalLight", { name: "RimLight", color: "#fff4e8", position: [0.9, 2.3, -3.2], "target-position": [0, 1.6, 0], intensity: k })));
1167
- }, Gn = ({ character: e, autoLookAt: t }) => {
1168
- const s = O((v) => v.characterState), a = re((v) => v.currentAUs), r = re((v) => v.currentGaze), o = re((v) => v.currentHeadPose), d = re((v) => v.lookAtCamera), f = se((v) => v.cameraPosition), T = re((v) => v.targets);
1169
- return Ht((v, S) => {
1170
- const V = {
1171
- deltaTime: S,
1172
- timestamp: v.clock.oldTime,
1173
- AU: a,
1174
- gaze: r,
1175
- headPose: o,
1176
- characterState: s,
1177
- lookAt: d ? f : void 0,
1178
- targets: T
351
+ }, [s, m, k, t, n, r]), l(() => {
352
+ !s || !C || s.setSize(C.width, C.height);
353
+ }, [C]), ge(({ gl: T, scene: y, camera: I }) => {
354
+ o.current && o.current.render();
355
+ }, 1), /* @__PURE__ */ i.createElement(i.Fragment, null, t !== "low" && s && /* @__PURE__ */ i.createElement(i.Fragment, null, /* @__PURE__ */ i.createElement("directionalLight", { ref: U, color: "white", position: c.toArray(), "target-position": w.toArray(), intensity: P, castShadow: !0, "shadow-mapSize-width": 1024, "shadow-mapSize-height": 1024, "shadow-bias": E, "shadow-normalBias": 3e-3, "shadow-intensity": 0.6, "shadow-radius": 2.5 }, /* @__PURE__ */ i.createElement("orthographicCamera", { attach: "shadow-camera", args: [-1, 1, 2, -0.5, 2, 5] })), t === "high" && /* @__PURE__ */ i.createElement("directionalLight", { name: "RimLight", color: "#fff4e8", position: [0.9, 2.3, -3.2], "target-position": [0, 1.6, 0], intensity: D })));
356
+ }, St = ({ character: e, autoLookAt: t }) => {
357
+ const n = g((c) => c.characterState), r = F((c) => c.currentAUs), d = F((c) => c.currentGaze), s = F((c) => c.currentHeadPose), m = F((c) => c.lookAtCamera), k = M((c) => c.cameraPosition), C = F((c) => c.targets);
358
+ return ge((c, w) => {
359
+ const P = {
360
+ deltaTime: w,
361
+ timestamp: c.clock.oldTime,
362
+ AU: r,
363
+ gaze: d,
364
+ headPose: s,
365
+ characterState: n,
366
+ lookAt: m ? k : void 0,
367
+ targets: C
1179
368
  };
1180
- e.update(V);
1181
- }), j(() => {
369
+ e.update(P);
370
+ }), l(() => {
1182
371
  if (t)
1183
- switch (s) {
1184
- case de.idle:
1185
- case de.waiting:
1186
- Qe(!1);
372
+ switch (n) {
373
+ case z.idle:
374
+ case z.waiting:
375
+ se(!1);
1187
376
  break;
1188
- case de.listening:
1189
- case de.speaking:
1190
- Qe(!0);
377
+ case z.listening:
378
+ case z.speaking:
379
+ se(!0);
1191
380
  break;
1192
381
  }
1193
382
  else
1194
- Qe(!1);
1195
- }, [s, t]), j(() => {
1196
- Zs(e);
383
+ se(!1);
384
+ }, [n, t]), l(() => {
385
+ We(e);
1197
386
  }, [e]), null;
1198
- }, xo = ({ url: e, type: t, animationsUrl: s, gender: a, speechSynthesis: r, camera: o, onLoadingCompleted: d, autoLookAt: f, breathing: T, disableAnimations: v, debug: S, inspector: V, enableBml: m, animationWeights: k, license: R, detectGpuData: u, environmentPreset: g = "apartment", tonemapping: i = B.NeutralToneMapping, targets: n, useBlendshapeManager: c = !1 }) => {
1199
- const h = O((P) => P.animationsLoaded), y = se((P) => P.defaultPositions), p = se((P) => P.defaultDistances), [A, w] = te(), [l, b] = te(null), [M, _] = te(), [x, Z] = te(!1), G = async (P) => {
387
+ }, pt = {
388
+ emotions: [],
389
+ currentTopEmotion: de.Neutral,
390
+ useTopEmotionOnly: !0,
391
+ autoDecay: !1
392
+ }, j = J()(() => pt), Gt = (e) => {
393
+ if (j.setState({ emotions: e || [] }), e != null && e.length) {
394
+ const t = e.reduce((n, r) => n.value > r.value ? n : r);
395
+ j.setState({ currentTopEmotion: t.emotion });
396
+ } else
397
+ j.setState({ currentTopEmotion: de.Neutral });
398
+ }, Ot = (e) => {
399
+ j.setState({ useTopEmotionOnly: e });
400
+ }, Nt = (e) => {
401
+ j.setState({ autoDecay: e });
402
+ }, Ht = (e) => {
403
+ const t = g.getState().FACSManager;
404
+ t == null || t.playFacialAnimation({ ...e });
405
+ }, ft = ({ animationsLoaded: e }) => {
406
+ const t = j((r) => r.emotions), n = j((r) => r.useTopEmotionOnly);
407
+ return l(() => {
408
+ e && _e(Me(t, { topOnly: n }));
409
+ }, [t, n, e]), null;
410
+ }, Kt = ({ url: e, type: t, animationsUrl: n, gender: r, speechSynthesis: d, camera: s, onLoadingCompleted: m, autoLookAt: k, breathing: C, disableAnimations: c, debug: w, inspector: P, enableBml: E, animationWeights: D, license: h, detectGpuData: U, environmentPreset: o = "apartment", tonemapping: T = R.NeutralToneMapping, targets: y, lipSyncFromAudio: I = !1, lipSyncAudio: H, lipSyncAudioContext: G }) => {
411
+ const b = g((S) => S.animationsLoaded), f = M((S) => S.defaultPositions), L = M((S) => S.defaultDistances), [O, W] = A(), [a, v] = A(null), [V, u] = A(), [x, ee] = A(!1), Q = async (S, K) => {
1200
412
  let N = null;
1201
413
  switch (t) {
1202
- case Se.cc3:
1203
- N = new ls(), _(Le.cc3);
414
+ case $.cc3:
415
+ N = new De(), u(ne.cc3);
1204
416
  break;
1205
- case Se.avatarsdk:
1206
- N = new cs(), _(Le.avatarsdk);
417
+ case $.avatarsdk:
418
+ N = new ve(), u(ne.avatarsdk);
1207
419
  break;
1208
- case Se.avaturn:
1209
- N = new is(), _(Le.avaturn);
420
+ case $.avaturn:
421
+ N = new Re(), u(ne.avaturn);
1210
422
  break;
1211
423
  }
1212
- const L = await N.loadAsync(P).catch((H) => console.warn("Error loading character : ", H));
1213
- if (L) {
1214
- let H = null;
1215
- const ne = {
1216
- mesh: L,
1217
- onAnimationsLoaded: E,
1218
- animationsUrl: s,
1219
- gender: a || "male",
424
+ const Z = await N.loadAsync(S).catch((B) => console.warn("Error loading character : ", B));
425
+ if (Z && !K()) {
426
+ let B = null;
427
+ const te = {
428
+ mesh: Z,
429
+ onAnimationsLoaded: Y,
430
+ animationsUrl: n,
431
+ gender: r || "male",
1220
432
  type: t,
1221
- debug: S,
1222
- enableBmlManager: !!m,
1223
- animationWeights: k,
1224
- useBlendshapeManager: c,
1225
- license: R
433
+ debug: w,
434
+ enableBmlManager: !!E,
435
+ animationWeights: D,
436
+ license: h
1226
437
  };
1227
438
  switch (t) {
1228
- case Se.cc3:
1229
- H = await Ye.fromCharacterCreator(ne);
439
+ case $.cc3:
440
+ B = await ae.fromCharacterCreator(te);
1230
441
  break;
1231
- case Se.avatarsdk:
1232
- H = await Ye.fromAvatarSDK(ne);
442
+ case $.avatarsdk:
443
+ B = await ae.fromAvatarSDK(te);
1233
444
  break;
1234
- case Se.avaturn:
1235
- H = await Ye.fromAvaturn(ne);
445
+ case $.avaturn:
446
+ B = await ae.fromAvaturn(te);
1236
447
  break;
1237
448
  }
1238
- H && b(H);
449
+ B && K() ? B.dispose() : B && v(B);
1239
450
  }
1240
- }, E = () => {
1241
- Ct(!0);
451
+ }, Y = () => {
452
+ ie(!0);
1242
453
  };
1243
- j(() => {
1244
- var P, N;
1245
- l && h && (T === !1 && ((N = (P = l.animationManager) == null ? void 0 : P.disableBreathing) == null || N.call(P)), x ? (an(l.getAllAnimationNames()), rn(l.getAllAnimations()), setTimeout(() => {
1246
- d == null || d();
1247
- }, 1e3)) : U());
1248
- }, [l, h, x]), j(() => {
1249
- sn(n || []);
1250
- }, [n]), j(() => {
1251
- Ct(!1), A !== void 0 && (A ? G(e) : d == null || d());
1252
- }, [e, A]), j(() => {
1253
- if (x && p && y)
1254
- if (o) {
1255
- const P = wn(o, p, y);
1256
- Mt(P), _t(o.lookAt ? y[o.lookAt] : y.lowerbelly), tn(!!o.movable);
454
+ l(() => {
455
+ var S, K;
456
+ if (a && b)
457
+ if (C === !1 && ((K = (S = a.animationManager) == null ? void 0 : S.disableBreathing) == null || K.call(S)), x) {
458
+ nt(a.getAllAnimationNames()), at(a.getAllAnimations());
459
+ const N = setTimeout(() => {
460
+ m == null || m();
461
+ }, 1e3);
462
+ return () => clearTimeout(N);
463
+ } else
464
+ Se();
465
+ }, [a, b, x]), l(() => {
466
+ Ze(y || []);
467
+ }, [y]), l(() => {
468
+ ie(!1);
469
+ let S = !1;
470
+ return O !== void 0 && (O ? Q(e, () => S) : m == null || m()), () => {
471
+ S = !0;
472
+ };
473
+ }, [e, O]), l(() => () => {
474
+ a == null || a.dispose();
475
+ }, [a]), l(() => {
476
+ if (x && L && f)
477
+ if (s) {
478
+ const S = Ee(s, L, f);
479
+ le(S), me(s.lookAt ? f[s.lookAt] : f.lowerbelly), Ye(!!s.movable);
1257
480
  } else {
1258
- const P = y.mouth.clone();
1259
- P.setComponent(2, p.farther), Mt(P), _t(y.lowerbelly);
481
+ const S = f.mouth.clone();
482
+ S.setComponent(2, L.farther), le(S), me(f.lowerbelly);
1260
483
  }
1261
- }, [x, o, p, y]), j(() => {
1262
- r && (r.credentials && xn(r.credentials), r.voice && vn(r.voice));
1263
- }, [r]), j(() => {
1264
- An(c);
1265
- }, [c]);
1266
- const U = () => {
1267
- if (l && M) {
484
+ }, [x, s, L, f]), l(() => {
485
+ d && (d.credentials && st(d.credentials), d.voice && ct(d.voice));
486
+ }, [d]), l(() => {
487
+ lt(I);
488
+ }, [I]), l(() => {
489
+ a == null || a.lipSyncManager.setAudioSource(H ?? null, G);
490
+ }, [a, H, G]);
491
+ const Se = () => {
492
+ if (a && V) {
1268
493
  try {
1269
- const P = new B.Box3().setFromObject(l), N = P.max, L = P.min, H = new B.Vector3((N.x + L.x) / 2, (N.y + L.y) / 2, (N.z + L.z) / 2);
1270
- Xs(H);
1271
- const ne = Math.abs(N.x - L.x), W = Math.abs(N.y - L.y), ue = Math.abs(N.z - L.z);
1272
- $s({
1273
- x: ne,
1274
- y: W,
1275
- z: ue
1276
- });
1277
- const Y = (N.x + L.x) / 2, F = (N.z + L.z) / 2, me = {
1278
- eye: new B.Vector3(Y, N.y - W / 16, F),
1279
- mouth: new B.Vector3(Y, N.y - W / 12, F),
1280
- neck: new B.Vector3(Y, N.y - W / 8, F),
1281
- clavicle: new B.Vector3(Y, N.y - W / 6, F),
1282
- torso: new B.Vector3(Y, N.y - W / 4, F),
1283
- belly: new B.Vector3(Y, N.y - W / 8 * 3, F),
1284
- lowerbelly: new B.Vector3(Y, N.y - W / 32 * 15, F),
1285
- hips: H,
1286
- higherthigh: new B.Vector3(Y, L.y + W / 32 * 15, F),
1287
- thigh: new B.Vector3(Y, L.y + W / 8 * 3, F),
1288
- knee: new B.Vector3(Y, L.y + W / 4, F),
1289
- leg: new B.Vector3(Y, L.y + W / 8, F),
1290
- feet: new B.Vector3(Y, L.y, F)
1291
- }, ee = (N.y - (L.y + W / 7 * 2)) / 2 / Math.tan(25 * (Math.PI / 180)), Ne = {
1292
- veryclose: ee / 4,
1293
- closer: ee / 3,
1294
- close: ee / 2.5,
1295
- midclose: ee / 2,
1296
- medium: ee,
1297
- midfar: ee * 2,
1298
- far: ee * 2.5,
1299
- farther: ee * 3,
1300
- veryfar: ee * 4
1301
- };
1302
- Js(me), en(Ne);
1303
- } catch (P) {
1304
- console.warn(P);
494
+ const { center: S, dimensions: K, defaultPositions: N, defaultDistances: Z } = Te(a);
495
+ qe(S), $e(K), Je(N), Qe(Z);
496
+ } catch (S) {
497
+ console.warn(S);
1305
498
  }
1306
- Z(!0);
499
+ ee(!0);
1307
500
  }
1308
501
  };
1309
- return /* @__PURE__ */ D.createElement(Un, { parentGpuTier: u, setIsGpuAvailable: w, tonemapping: i, inspector: V }, A ? /* @__PURE__ */ D.createElement(D.Fragment, null, l && /* @__PURE__ */ D.createElement(Gn, { character: l, autoLookAt: !!f }), l && /* @__PURE__ */ D.createElement(D.Fragment, null, /* @__PURE__ */ D.createElement(ps, { preset: g }), /* @__PURE__ */ D.createElement("primitive", { object: l, castShadow: !0, receiveShadow: !0 }))) : /* @__PURE__ */ D.createElement(D.Fragment, null));
1310
- }, Hn = {
1311
- emotions: [],
1312
- currentTopEmotion: lt.Neutral,
1313
- useTopEmotionOnly: !0,
1314
- autoDecay: !1
1315
- }, Ve = Ce()(() => Hn), So = (e) => {
1316
- if (Ve.setState({ emotions: e || [] }), e != null && e.length) {
1317
- const t = e.reduce((s, a) => s.value > a.value ? s : a);
1318
- Ve.setState({ currentTopEmotion: t.emotion });
1319
- } else
1320
- Ve.setState({ currentTopEmotion: lt.Neutral });
1321
- }, bo = (e) => {
1322
- Ve.setState({ useTopEmotionOnly: e });
1323
- }, To = (e) => {
1324
- Ve.setState({ autoDecay: e });
1325
- }, vo = (e) => {
1326
- const t = O.getState().FACSManager;
1327
- t == null || t.playFacialAnimation({ ...e });
502
+ return /* @__PURE__ */ i.createElement(gt, { parentGpuTier: U, setIsGpuAvailable: W, tonemapping: T, inspector: P }, O ? /* @__PURE__ */ i.createElement(i.Fragment, null, a && /* @__PURE__ */ i.createElement(St, { character: a, autoLookAt: !!k }), a && /* @__PURE__ */ i.createElement(ft, { animationsLoaded: b }), a && /* @__PURE__ */ i.createElement(i.Fragment, null, /* @__PURE__ */ i.createElement(Le, { preset: o }), /* @__PURE__ */ i.createElement("primitive", { object: a, castShadow: !0, receiveShadow: !0 }))) : /* @__PURE__ */ i.createElement(i.Fragment, null));
1328
503
  };
1329
504
  export {
1330
- xo as Character,
1331
- Mo as CharacterState,
1332
- _o as CreationTool,
1333
- X as Distances,
1334
- Co as Object3D,
1335
- $ as Positions,
1336
- le as Rotations,
1337
- mo as addBlendshape,
1338
- po as addSPPASViseme,
1339
- qt as addViseme,
1340
- ko as bmlTags,
1341
- Po as emotionList,
1342
- Kt as flushBlendshapeData,
1343
- Wt as flushLipSyncData,
1344
- ro as getAnimationsMap,
1345
- eo as getCameraPosition,
1346
- Jn as getCharacterHeight,
1347
- to as getLookAt,
1348
- fo as getVoices,
1349
- nn as lookAtAndKeep,
1350
- co as playAnimationByName,
1351
- vo as playFacialAnimation,
1352
- lo as presets,
1353
- on as releaseLookAt,
1354
- To as setAutoDecay,
1355
- io as setAutoPlay,
1356
- ho as setBlendshapes,
1357
- Mt as setCameraPosition,
1358
- Nt as setCharacterState,
1359
- so as setCurrentAUs,
1360
- no as setCurrentGaze,
1361
- oo as setCurrentHeadPose,
1362
- Sn as setCurrentUtterance,
1363
- So as setEmotions,
1364
- Qe as setLookAtCamera,
1365
- tn as setMovable,
1366
- ao as setShowFirstTarget,
1367
- go as setTextToSpeak,
1368
- bo as setUseTopEmotionOnly,
1369
- yo as setVisemeIntensity,
1370
- uo as setVisemes,
1371
- vn as setVoice,
1372
- O as useCharacterStore
505
+ Kt as Character,
506
+ qt as CharacterState,
507
+ Jt as CreationTool,
508
+ Qt as Distances,
509
+ $t as Object3D,
510
+ Yt as Positions,
511
+ Zt as Rotations,
512
+ Lt as addSPPASViseme,
513
+ he as addViseme,
514
+ _t as bmlTags,
515
+ en as emotionList,
516
+ it as flushLipSyncData,
517
+ Vt as getAnimationsMap,
518
+ Et as getCameraPosition,
519
+ Mt as getCharacterHeight,
520
+ Tt as getLookAt,
521
+ Bt as getVoices,
522
+ et as lookAtAndKeep,
523
+ Ft as playAnimationByName,
524
+ Ht as playFacialAnimation,
525
+ tn as presets,
526
+ tt as releaseLookAt,
527
+ Nt as setAutoDecay,
528
+ xt as setAutoPlay,
529
+ le as setCameraPosition,
530
+ ce as setCharacterState,
531
+ _e as setCurrentAUs,
532
+ Rt as setCurrentGaze,
533
+ vt as setCurrentHeadPose,
534
+ ot as setCurrentUtterance,
535
+ Gt as setEmotions,
536
+ lt as setLipSyncFromAudio,
537
+ se as setLookAtCamera,
538
+ Ye as setMovable,
539
+ Dt as setShowFirstTarget,
540
+ zt as setTextToSpeak,
541
+ Ot as setUseTopEmotionOnly,
542
+ Ut as setVisemeIntensity,
543
+ It as setVisemes,
544
+ ct as setVoice,
545
+ g as useCharacterStore
1373
546
  };