@davi-ai/react-bodyengine-three 1.0.34 → 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 ee, useMemo as it, useEffect as q, useRef as Pe, 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 Te, 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 w, vec2 as Y, If as he, vec4 as J, max as W, vec3 as ae, ivec2 as _e, luminance as ve, add as xs, uv as Re, mix as ke, 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 Me, 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, x) => {
15
- const V = typeof v == "function" ? v(t) : v;
16
- if (!Object.is(V, t)) {
17
- const m = t;
18
- t = x ?? (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
- }, we = (e) => Ys, O = we()(() => ({
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,1328 +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 = we()(() => ({
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 = we()(() => ({
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
- }, Ae = we()(() => ({
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
- Ae.setState({ animationsNames: e });
123
- }, rn = (e) => {
124
- Ae.setState({ animations: e });
125
- }, ro = () => Ae.getState().animations, io = (e) => {
126
- Ae.setState({ autoPlay: e });
127
- }, co = (e) => {
128
- if (Ae.setState({ autoPlay: !1 }), Ae.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 = we()(() => ({
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 l = typeof e.distance == "string" ? parseInt(e.distance) : e.distance, f = typeof e.rotation == "string" ? parseInt(e.rotation) : e.rotation;
354
- switch (l) {
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 Te();
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 Te()), 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 Te()), 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 l = this._historyRenderTarget.width !== r || this._historyRenderTarget.height !== o;
508
- this.setSize(r, o), l === !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 d = t.renderer.getDrawingBufferSize(Vt);
525
- this.setViewOffset(d.width, d.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 = (d) => {
530
- const { x: g, y: c } = this._cameraNearFar, n = Ft(d, g, c);
531
- return nt(n, g, c);
532
- }, a = ys({
533
- closestDepth: "float",
534
- closestPositionTexel: "vec2",
535
- farthestDepth: "float"
536
- }), r = Q(([d]) => {
537
- const g = w(2).toVar(), c = Y(0).toVar(), n = w(-1).toVar();
538
- for (let i = -1; i <= 1; ++i)
539
- for (let p = -1; p <= 1; ++p) {
540
- const y = d.add(Y(i, p)).toVar();
541
- let h = this.depthNode.load(y).r;
542
- t.renderer.reversedDepthBuffer && (h = h.oneMinus()), t.renderer.logarithmicDepthBuffer && (h = s(h)), h = h.toVar(), he(h.lessThan(g), () => {
543
- g.assign(h), c.assign(y);
544
- }), he(h.greaterThan(n), () => {
545
- n.assign(h);
546
- });
547
- }
548
- return a(g, c, n);
549
- }), o = (d) => {
550
- let g = this._previousDepthNode.sample(d).r;
551
- t.renderer.reversedDepthBuffer && (g = g.oneMinus()), t.renderer.logarithmicDepthBuffer && (g = s(g));
552
- const c = Ie(d, g, this._previousCameraProjectionMatrixInverse), n = this._previousCameraWorldMatrix.mul(J(c, 1)).xyz, i = this._cameraWorldMatrixInverse.mul(J(n, 1)).z;
553
- return this.camera.isOrthographicCamera ? Ss(i, this._cameraNearFar.x, this._cameraNearFar.y) : nt(i, this._cameraNearFar.x, this._cameraNearFar.y);
554
- }, l = Q(([d, g, c, n]) => {
555
- const i = n.rgb.add(c.rgb).mul(0.5), p = n.rgb.sub(c.rgb).mul(0.5).add(1e-7), y = g.sub(J(i, d.a)), A = y.xyz.div(p).abs(), C = W(A.x, A.y, A.z);
556
- return C.greaterThan(1).select(
557
- J(i, d.a).add(y.div(C)),
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(([d]) => ae(
570
- d.x.mul(0.25).add(d.y.mul(0.5)).add(d.z.mul(0.25)),
571
- d.x.mul(0.5).sub(d.z.mul(0.5)),
572
- d.x.mul(-0.25).add(d.y.mul(0.5)).sub(d.z.mul(0.25))
573
- )).setLayout({
574
- name: "RGBToYCoCg",
575
- type: "vec3",
576
- inputs: [{ name: "c", type: "vec3" }]
577
- }), T = Q(([d]) => ae(
578
- d.x.add(d.y).sub(d.z),
579
- d.x.add(d.z),
580
- d.x.sub(d.y).sub(d.z)
581
- )).setLayout({
582
- name: "YCoCgToRGB",
583
- type: "vec3",
584
- inputs: [{ name: "c", type: "vec3" }]
585
- }), v = Q(([d, g, c, n]) => {
586
- const i = [
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
- ], p = J(f(g.rgb), g.a).toVar(), y = J(f(c.rgb), c.a).toVar(), h = p.toVar(), A = p.pow2().toVar();
596
- for (const [j, G] of i) {
597
- const E = this.beautyNode.offset(_e(j, G)).load(d).max(0), U = J(f(E.rgb), E.a).toVar();
598
- h.addAssign(U), A.addAssign(U.pow2());
599
- }
600
- const C = w(i.length + 1), N = h.div(C), u = A.div(C).sub(N.pow2()).max(0).sqrt().mul(n), S = N.sub(u), M = N.add(u), b = l(N.clamp(S, M), y, S, M);
601
- return J(T(b.rgb), b.a);
602
- }), x = Q(([d, g]) => {
603
- const n = d.mul(g).fract().abs(), i = W(n, n.oneMinus());
604
- return i.x.mul(i.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(([d, g, c]) => {
613
- const n = c.oneMinus(), i = d.mul(w(1).div(W(d.r, d.g, d.b).add(1))), p = g.mul(w(1).div(W(g.r, g.g, g.b).add(1))), y = ve(i.rgb), h = ve(p.rgb);
614
- return c.mulAssign(w(1).div(y.add(1))), n.mulAssign(w(1).div(h.add(1))), xs(d.mul(c), g.mul(n)).div(W(c.add(n), 1e-5)).toVar();
615
- }), m = Fe(this._historyRenderTarget.texture), k = Q(([d, g]) => {
616
- const c = d.mul(g), n = c.sub(0.5).floor().add(0.5).toVar(), i = c.sub(n).toVar(), p = i.mul(i.mul(i.mul(-0.5).add(1)).sub(0.5)).toVar(), y = i.pow2().mul(i.mul(1.5).sub(2.5)).add(1).toVar(), h = i.mul(i.mul(i.mul(-1.5).add(2)).add(0.5)).toVar(), A = i.pow2().mul(i.mul(0.5).sub(0.5)).toVar(), C = y.add(h).toVar(), N = h.div(C).toVar(), u = n.sub(1).mul(this._invSize).toVar(), S = n.add(2).mul(this._invSize).toVar(), M = n.add(N).mul(this._invSize).toVar();
617
- return m.sample(Y(u.x, u.y)).mul(p.x.mul(p.y)).add(m.sample(Y(M.x, u.y)).mul(C.x.mul(p.y))).add(m.sample(Y(S.x, u.y)).mul(A.x.mul(p.y))).add(m.sample(Y(u.x, M.y)).mul(p.x.mul(C.y))).add(m.sample(Y(M.x, M.y)).mul(C.x.mul(C.y))).add(m.sample(Y(S.x, M.y)).mul(A.x.mul(C.y))).add(m.sample(Y(u.x, S.y)).mul(p.x.mul(A.y))).add(m.sample(Y(M.x, S.y)).mul(C.x.mul(A.y))).add(m.sample(Y(S.x, S.y)).mul(A.x.mul(A.y))).max(0);
618
- }), R = Q(() => {
619
- const d = Re(), g = this.beautyNode.size(), c = d.mul(g), n = r(c), i = n.get("closestDepth"), p = n.get("closestPositionTexel"), y = n.get("farthestDepth"), h = this.velocityNode.load(p).xy.mul(Y(0.5, -0.5)), A = d.sub(h), C = o(A), N = A.greaterThanEqual(0).all().and(A.lessThanEqual(1).all()), u = y.sub(i).greaterThan(this.edgeDepthDiff), S = i.sub(C).greaterThan(this.depthThreshold), M = N.and(u.or(S.not())), b = this.beautyNode.sample(d), j = k(A, g), G = d.sub(A).mul(g).length().div(this.maxVelocityLength).saturate(), E = w(0.01).toVar();
620
- this.useSubpixelCorrection && E.addAssign(x(h, g).mul(0.2)), E.assign(M.select(E.add(G).saturate(), 1));
621
- const U = ke(0.5, 1, G.oneMinus().pow2()), P = v(c, b, j, U);
622
- return V(b, 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 Te(), 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 Te()), 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 l = this._ssgiRenderTarget.textures[1];
662
- l.name = "SSGI.GI", l.type = ss, l.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), l = (c) => {
728
- const n = this.depthNode.sample(c).r;
729
- if (t.renderer.logarithmicDepthBuffer === !0) {
730
- const i = Ft(n, this._cameraNear, this._cameraFar);
731
- return nt(i, this._cameraNear, this._cameraFar);
732
- }
733
- return n;
734
- }, f = (c) => this.normalNode !== null ? this.normalNode.sample(c).rgb.normalize() : Lt(c, this.depthNode.value, this._cameraProjectionMatrixInverse), T = (c) => this.beautyNode.sample(c), v = Q(([c]) => w(0.25).mul(bs(c.y, c.x).bitAnd(3))).setLayout({
735
- name: "spatialOffsets",
736
- type: "float",
737
- inputs: [
738
- { name: "position", type: "vec2" }
739
- ]
740
- }), x = Q(([c]) => {
741
- const n = pe(c).mul(w(-0.156583)).add(Ze);
742
- n.mulAssign(Et(pe(c).oneMinus()));
743
- const i = c.x.greaterThanEqual(0).select(n.x, fe.sub(n.x)), p = c.y.greaterThanEqual(0).select(n.y, fe.sub(n.y));
744
- return Y(i, p);
745
- }).setLayout({
746
- name: "GTAOFastAcos",
747
- type: "vec2",
748
- inputs: [
749
- { name: "value", type: "vec2" }
750
- ]
751
- }), V = Q(([c, n, i, p, y, h, A, C, N, u]) => {
752
- const S = this.stepCount.toConst(), M = this.expFactor.toConst(), b = this.thickness.toConst(), j = this.backfaceLighting.toConst(), G = c.select(Y(1, -1), Y(-1, 1)), E = c.select(1, -1), U = ae(0);
753
- return Oe({ start: oe(0), end: S, type: "uint", condition: "<" }, ({ i: P }) => {
754
- const _ = Ge(pe($e(n, w(P).add(h)).div(i)), M).mul(i).toConst(), L = y.mul(W(_, w(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, l(H), this._cameraProjectionMatrixInverse).toConst(), K = ne.sub(p).normalize().toConst(), ue = this.useLinearThickness.select(ne.z.negate().div(this._cameraFar).clamp().mul(100), w(1)), Z = be(ne.sub(ue.mul(C).mul(b)).sub(p));
759
- let F = Y(ie(K, C), ie(Z, C));
760
- F = x(Me(F, -1, 1)), F = Me(vs($e(E, F.negate()).sub(u.sub(Ze)), fe)), F = c.select(F.yx, F.xy);
761
- const me = F.x.toConst(), te = F.y.toConst(), Ce = oe(F.mul(w(r))).toConst(), Be = oe(As(te.sub(me).mul(w(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(Ce);
763
- ge = ge.bitAnd(o.bitNot()), o.assign(o.bitOr(ge));
764
- const Ne = xt(ge);
765
- he(Ne.greaterThan(0), () => {
766
- const dt = T(H);
767
- he(ve(dt).greaterThan(1e-3), () => {
768
- const ut = be(K), ht = Me(ie(N, 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(j), pe(ye));
773
- ye = j.greaterThan(0).and(ie(mt, C).greaterThan(0)).select(Zt, Me(ye)), U.rgb.addAssign(w(Ne).div(w(r)).mul(dt).mul(ht).mul(ye));
774
- });
775
- });
776
- });
777
- }), U;
778
- }), m = Ee("float"), k = Ee("vec3"), R = Ee("vec4"), d = Cs(m, k, R), g = Q(() => {
779
- const c = l(a).toVar();
780
- c.greaterThanEqual(1).discard();
781
- const n = Ie(a, c, this._cameraProjectionMatrixInverse).toVar(), i = f(a).toVar(), p = be(n.xyz.negate()).toVar(), y = v(bt), h = Ns(bt), A = this._temporalDirection.mul(0.02), C = Ms(y.add(this._temporalOffset)).add(_s(a.add(A).mul(2).sub(1))), N = w(0), u = ae(0), S = ae(0), M = this.sliceCount.toConst(), b = this.stepCount.toConst(), j = this.aoIntensity.toConst(), G = this.giIntensity.toConst(), E = this.radius.toConst(), U = w(0).toVar();
782
- he(this.useScreenSpaceSampling, () => {
783
- U.assign(E.mul(this._resolution.x.div(2)).div(w(16)));
784
- }).Else(() => {
785
- U.assign(W(E.mul(this._halfProjScale).div(n.z.negate()), w(b)));
786
- }), U.divAssign(w(b).add(1));
787
- const P = W(1, w(b.sub(1))).mul(U).toConst();
788
- Oe({ start: oe(0), end: M, type: "uint", condition: "<" }, ({ i: ne }) => {
789
- const K = $e(w(ne).add(h).add(this._temporalDirection), fe.div(w(M))).toConst(), ue = ae(Y(ot(K), at(K)), 0).toConst(), Z = ue.xy.mul(w(1).div(this._resolution)).toConst(), F = be(Tt(ue, p)).toConst(), me = Tt(p, F).toConst(), te = i.sub(F.mul(ie(i, F))).toConst(), Ce = be(te).toConst(), Be = Me(ie(Ce, p), -1, 1).toConst(), De = St(ie(te, me)).negate().mul(ks(Be)).toConst();
790
- o.assign(0), u.addAssign(V(vt(!0), U, P, n, Z, C, a, p, i, De)), u.addAssign(V(vt(!1), U, P, n, Z, C, a, p, i, De)), N.addAssign(w(xt(o)).div(w(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 Ne = Ze.sub(De).sub(w(ge).add(0.5).div(w(r)).mul(fe));
793
- S.addAssign(p.mul(ot(Ne)).add(me.mul(at(Ne))));
794
- });
795
- });
796
- }), N.divAssign(w(M)), N.assign(Ge(N.clamp().oneMinus(), j).clamp()), u.divAssign(w(M)), u.mulAssign(G);
797
- const _ = w(7).toConst(), L = ve(u), H = L.greaterThan(_).select(_.div(L), w(1));
798
- return u.mulAssign(H), S.assign(be(S.add(i.mul(1e-4)))), m.assign(N), k.assign(u), R.assign(J(S.mul(0.5).add(0.5), 1)), J(0);
799
- });
800
- return this._material.colorNode = g().context(t.getSharedContext()), this._material.outputNode = d, 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 Te()), 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 = (x) => this.textureNode.sample(x), a = (x) => this.depthNode.sample(x).x, r = (x) => this.normalNode !== null ? this.normalNode.sample(x).rgb.normalize() : Lt(x, this.depthNode.value, this._cameraProjectionMatrixInverse), o = (x) => this.noiseNode.sample(x), l = (x, V, m, k) => {
843
- const R = s(k).toVar(), d = a(k).toVar(), g = r(k).toVar(), c = Ie(k, d, this._cameraProjectionMatrixInverse).toVar(), n = ie(V, g), i = Ge(W(n, 0), this.normalPhi), p = pe(ve(R.rgb).sub(ve(x))), y = W(w(1).sub(p.div(this.lumaPhi)), 0), h = pe(ie(m.sub(c), V)), A = W(w(1).sub(h.div(this.depthPhi)), 0), C = y.mul(A).mul(i).toVar();
844
- return { color: R.mul(C), weight: C };
845
- }, f = Q(([x]) => {
846
- const V = a(x).toVar(), m = r(x).toVar(), k = s(x).toVar(), R = Ee("vec4");
847
- return he(V.greaterThanEqual(1).or(ie(m, m).equal(0)), () => {
848
- R.assign(k);
849
- }).Else(() => {
850
- const d = ae(k.rgb), g = Ie(x, V, this._cameraProjectionMatrixInverse).toConst(), c = Vs(this.noiseNode, 0);
851
- let n = Y(x.x, x.y.oneMinus());
852
- n = n.mul(this._resolution.div(c));
853
- const i = o(n).toVar(), p = at(i.element(this.index.mod(4).mul(2).mul(fe))), y = ot(i.element(this.index.mod(4).mul(2).mul(fe))), h = Y(p, y), A = Is(h.x, h.y.negate(), h.x, h.y), C = w(1).toVar(), N = J(k).toVar();
854
- Oe({ start: At(0), end: At(16), type: "int", condition: "<" }, ({ i: u }) => {
855
- const S = this._sampleVectors.element(u), M = A.mul(S.xy.mul(w(1).add(S.z.mul(this.radius.sub(1))))).div(this._resolution), b = x.add(M), j = l(d, m, g, b);
856
- N.addAssign(j.color), C.addAssign(j.weight);
857
- }), R.assign(N.div(C));
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, l = Math.pow(r / (e - 1), s);
867
- a.push(new Bt(Math.cos(o), Math.sin(o), l));
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 l = 0; l < e; l++) {
875
- const f = o, T = l;
876
- a[(o * e + l) * 4] = (t.noise(f, T) * 0.5 + 0.5) * 255, a[(o * e + l) * 4 + 1] = (t.noise(f + e, T) * 0.5 + 0.5) * 255, a[(o * e + l) * 4 + 2] = (t.noise(f, T + e) * 0.5 + 0.5) * 255, a[(o * e + l) * 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 = (l) => Et(l.div(l.add(1))), a = (l) => {
904
- const f = l.pow2().min(0.9999);
905
- return f.div(f.oneMinus());
906
- }, r = (l) => l.g.add(l.r.add(l.b).mul(0.5));
907
- return Q(() => {
908
- const l = _e(t.size()).toConst(), f = l.sub(1).toConst(), T = _e(Re().mul(Y(l))).toConst(), v = (U, P) => {
909
- const _ = t.load(W(ce(T.add(_e(U, P)), f), _e(0))), L = _.a.saturate().toConst(), H = L.greaterThan(1 / 255).select(_.rgb.max(0).div(L), ae(0));
910
- return { p: s(H).toConst(), a: L };
911
- }, x = v(0, 0), V = v(0, -1), m = v(-1, 0), k = v(1, 0), R = v(0, 1), d = ce(ce(V.p, m.p), ce(k.p, R.p)).toConst(), g = W(W(V.p, m.p), W(k.p, R.p)).toConst(), c = w(0.25 - 1 / 16), n = ce(d, x.p).div(g.mul(4).max(1e-5)), i = ae(1).sub(W(g, x.p)).div(d.mul(4).sub(4)), p = W(n.negate(), i).toConst(), y = W(c.negate(), ce(W(p.r, W(p.g, p.b)), 0)).mul(this.amount).toVar(), h = r(V.p), A = r(m.p), C = r(x.p), N = r(k.p), u = r(R.p), S = h.add(A).add(N).add(u).mul(0.25).sub(C), M = W(W(h, A), W(C, W(N, u))).sub(ce(ce(h, A), ce(C, ce(N, u)))), b = w(1).sub(pe(S).div(M.max(1 / 65536)).saturate().mul(0.5));
912
- y.mulAssign(this.denoise.greaterThan(0.5).select(b, 1));
913
- const j = y.mul(4).add(1).reciprocal().toConst(), G = a(V.p.add(m.p).add(k.p).add(R.p).mul(y).add(x.p).mul(j).max(0)), E = V.a.add(m.a).add(k.a).add(R.a).mul(y).add(x.a).mul(j).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"), l = 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), x = 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(), d = je("near", "float", t), g = je("far", "float", t), c = (G) => Es(r.sample(G).r, d, g), n = Q(() => {
934
- const G = Re(), E = Y(m.getAONode().size()), U = G.mul(E).sub(0.5), P = U.floor(), _ = U.sub(P), L = c(G), H = J(0).toVar(), ne = w(0).toVar();
935
- for (const [K, ue] of [[0, 0], [1, 0], [0, 1], [1, 1]]) {
936
- const Z = P.add(Y(K + 0.5, ue + 0.5)).div(E), F = (K === 1 ? _.x : _.x.oneMinus()).mul(ue === 1 ? _.y : _.y.oneMinus()), me = Os(L.sub(c(Z)).abs().mul(-32)).add(1e-3), te = F.mul(me);
937
- H.addAssign(J(R.sample(Z).rgb, k.sample(Z).r).mul(te)), ne.addAssign(te);
938
- }
939
- return H.div(ne);
940
- }), i = Bn(n(), r, V, t);
941
- i.radius.value = 8, i.depthPhi.value = 0.1, i.lumaPhi.value = 5;
942
- const p = rt(i), y = I(0.5), h = I(0.5), A = p.a.oneMinus().mul(ke(w(1), y, x)).mul(ke(w(1), h, v)).oneMinus(), C = ke(a.rgb, f.rgb, f.a), N = Q(([G, E]) => {
943
- const U = E.mul(2.0404).sub(0.3324), P = E.mul(-4.7951).add(0.6417), _ = E.mul(2.7552).add(0.6903);
944
- return ae(G).max(U.mul(G).add(P).mul(G).add(_).mul(G));
945
- }), u = I(new B.Vector3(0.45, 0.15, 0.05)), S = ke(ae(A), Ge(ae(A), ae(1).sub(u)), T), M = J(
946
- a.rgb.mul(N(S, C)).add(C.mul(p.rgb)),
947
- // indirect diffuse modulated by albedo
948
- a.a
949
- ), b = Yt(M, r, l, t);
950
- return b._resolveMaterial.needsUpdate = !0, { outputNode: zn(b, 0.5), scenePassColor: a, traaPass: b, giPass: m, denoisePass: i, ao: k, gi: R, hairAO: y, eyeAO: h };
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), l = z((n) => n.textToSpeak), f = z((n) => n.visemes), T = z((n) => n.blendshapes), v = z((n) => n.visemeIntensity), x = z((n) => n.currentVisemeIndex), V = z((n) => n.currentBlendshapeIndex), m = z((n) => n.useBlendshapeManager), [k, R] = ee(!1), [d, g] = ee(!1), c = 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 q(() => {
967
- if (c) {
968
- const n = c.speechSynthesis.getVoices();
969
- n && Array.isArray(n) && n.length ? (Pt(n), R(!0)) : c.speechSynthesis.onvoiceschanged = () => {
970
- Pt(c.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
- }, [c]), q(() => {
974
- k && (m ? !!a : !!s) && e && g(!0);
975
- }, [k, s, a, e, m]), q(() => {
976
- if (l) {
977
- const n = new Hs(l);
978
- Sn(n);
979
- }
980
- }, [l]), q(() => {
981
- var n, i;
982
- o && d ? (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 = (p) => {
988
- qt(p);
989
- }, (n = c == null ? void 0 : c.speechSynthesis) == null || n.speak(o, null)) : (i = c == null ? void 0 : c.speechSynthesis) == null || i.cancel();
990
- }, [o]), q(() => {
991
- s && (s.visemeIntensity = v);
992
- }, [v]), q(() => {
993
- if (!m && s && t === de.speaking) {
994
- if (!s.isStarted && s.start(), f.length > 1 && x === 0)
995
- f.forEach((n) => {
996
- const i = parseInt(n.name);
997
- if (!isNaN(i)) {
998
- const p = kt.get(i);
999
- p && s.PlayVisemeAsync(p, n.elapsedTime / 1e4);
1000
- }
1001
- });
1002
- else
1003
- for (let n = x + 1; n < f.length; n++) {
1004
- const i = f[n], p = parseInt(i.name);
1005
- if (!isNaN(p)) {
1006
- const y = kt.get(p);
1007
- y && s.PlayVisemeAsync(y, i.elapsedTime / 1e4);
1008
- }
1009
- }
1010
- bn(f.length - 1);
1011
- }
1012
- }, [t, f, s, m]), q(() => {
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 i = T[n];
1021
- a.PlayBlendShapeAsync(i);
1022
- }
1023
- Tn(T.length - 1);
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);
1024
194
  }
1025
- }, [t, T, a, m]), q(() => {
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((u) => u.cameraPosition), l = se((u) => u.lookAt), f = se((u) => u.movable), T = re((u) => u.targets), v = re((u) => u.showFirstTarget), [x, V] = ee(e || ds()), [m, k] = ee(
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, d] = ee(null), [g, c] = ee(void 0), n = Pe(null), [i, p] = ee(null), y = Pe(null), h = (u) => {
1039
- u.preventDefault(), u.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
- q(() => {
1042
- var u, S, M, b;
1043
- if (f)
1044
- R == null || R.abort(), d(null);
237
+ l(() => {
238
+ var a, v, V, u;
239
+ if (k)
240
+ h == null || h.abort(), U(null);
1045
241
  else {
1046
- const j = new AbortController();
1047
- d(j), (u = n.current) == null || u.addEventListener("wheel", h, { passive: !1, signal: j.signal }), (S = n.current) == null || S.addEventListener("pointerdown", h, { passive: !1, signal: j.signal }), (M = n.current) == null || M.addEventListener("pointermove", h, { passive: !1, signal: j.signal }), (b = n.current) == null || b.addEventListener("click", h, { passive: !1, signal: j.signal });
242
+ const x = new AbortController();
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 });
1048
244
  }
1049
- }, [f]), q(() => {
1050
- if (i && l && o) {
1051
- const u = y.current === i;
1052
- i.setLookAt(o.x, o.y, o.z, l.x, l.y, l.z, u), y.current = i;
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;
1053
249
  }
1054
- }, [i, o, l]), q(() => {
1055
- e && V(e);
1056
- }, [e]), q(() => {
1057
- if (x)
1058
- if (x.type === "FALLBACK") {
1059
- const u = typeof navigator < "u" && /Macintosh|Mac OS X/.test(navigator.userAgent);
1060
- k(
1061
- u ? "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"
1062
258
  /* low */
1063
259
  );
1064
260
  } else
1065
- switch (x.tier) {
261
+ switch (w.tier) {
1066
262
  case 0:
1067
263
  case 1:
1068
- k(
264
+ D(
1069
265
  "low"
1070
266
  /* low */
1071
267
  );
1072
268
  break;
1073
269
  case 2:
1074
- k(
270
+ D(
1075
271
  "medium"
1076
272
  /* medium */
1077
273
  );
1078
274
  break;
1079
275
  case 3:
1080
- k(
276
+ D(
1081
277
  "high"
1082
278
  /* high */
1083
279
  );
1084
280
  break;
1085
281
  default:
1086
- k(
282
+ D(
1087
283
  "low"
1088
284
  /* low */
1089
285
  );
1090
286
  break;
1091
287
  }
1092
- }, [x]), q(() => {
1093
- switch (m && (A.current = m), m) {
288
+ }, [w]), l(() => {
289
+ switch (E && (f.current = E), E) {
1094
290
  case "low":
1095
291
  console.warn("Retorik React-Bodyengine-Three > GPU tier too low, no rendering available"), t(!1);
1096
292
  break;
1097
293
  case "medium":
1098
- c([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);
1099
295
  break;
1100
296
  case "high":
1101
- c([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);
1102
298
  break;
1103
299
  }
1104
- }, [m]);
1105
- const A = Pe(void 0), C = $t(async (u) => {
1106
- const S = new B.WebGPURenderer({
1107
- canvas: u.canvas,
1108
- antialias: !1,
1109
- alpha: !0,
1110
- powerPreference: "high-performance"
1111
- });
1112
- return S.setClearColor(new B.Color("#000000"), 0), S.setPixelRatio(Math.min(devicePixelRatio, 1.5)), S.shadowMap.type = B.PCFShadowMap, await S.init(), S;
1113
- }, []), N = it(() => {
1114
- if (T.length) {
1115
- const u = T[0], S = new B.Vector3(u.position.x - 0.5, u.position.y, u.position.z - 0.1), M = new B.Vector3(u.position.x + 0.5, u.position.y, u.position.z - 0.1);
1116
- return [S, M];
1117
- } else if (o) {
1118
- const u = new B.Vector3(o.x - 0.5, o.y, o.z - 0.1), S = new B.Vector3(o.x + 0.5, o.y, o.z - 0.1);
1119
- return [u, S];
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];
1120
308
  }
1121
309
  return [];
1122
- }, [T, o]);
1123
- return g ? (
310
+ }, [C, s]);
311
+ return o ? (
1124
312
  // "percentage" = PCFShadowMap; shadows={true} would make R3F set the removed PCFSoftShadowMap
1125
- /* @__PURE__ */ D.createElement(Us, { gl: C, 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: Qs, makeDefault: !0, fov: 28 }), /* @__PURE__ */ D.createElement(ms, { ref: p }), v && N.length && /* @__PURE__ */ D.createElement(Ln, { points: N, color: "red" }), /* @__PURE__ */ D.createElement(Qt, { fallback: null }, s)))
1126
- ) : /* @__PURE__ */ D.createElement(D.Fragment, null);
1127
- }, jn = ({ tonemapping: e, processedTier: t, inspector: s = !1 }) => {
1128
- const [a, r] = ee(!1), { gl: o, scene: l, camera: f, size: T } = js(), [v] = ee(new B.Vector3(-3, 2, 2)), [x] = ee(new B.Vector3(0, 1, 0)), [V] = ee(3.5), [m] = ee(-2e-4), [k] = ee(0.57), [R] = ee(0.25), d = Pe(null), g = Pe(null);
1129
- return q(() => {
1130
- o && (o.shadowMap.type = B.PCFShadowMap, o.toneMapping = e, t !== "low" ? l.environmentIntensity = R : l.environmentIntensity = 1);
1131
- }, [o, e]), q(() => {
1132
- l.environmentIntensity = R;
1133
- }, [R]), q(() => {
1134
- if (!s || !o || a) return;
1135
- let c = !1;
1136
- return import("three/addons/inspector/Inspector.js").then(({ Inspector: n }) => {
1137
- c || (o.inspector = new n(), r(!0));
1138
- }).catch((n) => console.warn("Scene: could not load three's Inspector", n)), () => {
1139
- c = !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;
1140
328
  };
1141
- }, [s, o, a]), q(() => {
1142
- if (!o || !l || !f || !t) return;
1143
- l.background = null;
1144
- const c = t === "high", n = c ? Fn(l, f) : On(l, f), { outputNode: i, scenePassColor: p, traaPass: y, giPass: h, ao: A, gi: C, hairAO: N, eyeAO: u } = n, S = new B.RenderPipeline(o);
1145
- if (S.outputNode = i, g.current = S, s && a && o.inspector) {
1146
- const M = () => {
1147
- S.needsUpdate = !0;
1148
- }, b = o.inspector.createParameters(c ? "SSGI + TRAA" : "TRAA");
1149
- if (c) {
1150
- const j = { output: 0, feedback: !1 }, G = { Combined: 0, AO: 1, GI: 2, Direct: 3 };
1151
- b.add(j, "output", G).name("output").onChange((E) => {
1152
- const U = Number(E);
1153
- S.outputNode = U === 1 ? J(ae(A.r), 1) : U === 2 ? J(C.rgb, 1) : U === 3 ? p : i, M();
1154
- }), b.add(h.sliceCount, "value", 1, 4, 1).name("slice count"), b.add(h.stepCount, "value", 1, 32, 1).name("step count"), b.add(h.radius, "value", 0.1, 2).name("radius"), b.add(h.expFactor, "value", 1e-3, 10).name("exp factor"), b.add(h.thickness, "value", 1e-3, 0.1).name("thickness"), b.add(h.backfaceLighting, "value", 0, 1).name("backface lighting"), b.add(h.aoIntensity, "value", 0, 4).name("AO intensity"), b.add(h.giIntensity, "value", 0, 20).name("GI intensity"), b.add(h, "resolutionScale", 0.25, 1).name("SSGI resolution scale"), b.add(N, "value", 0, 1).name("SSGI AO on hair"), b.add(u, "value", 0, 1).name("SSGI AO on eyes"), b.add(j, "feedback").name("SSGI 2nd bounce (TRAA history)").onChange((E) => {
1155
- h.beautyNode = E ? y.getHistoryTextureNode() : p, M();
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();
1156
344
  });
1157
345
  }
1158
- b.add(y, "maxVelocityLength", 4, 128, 1).name("TRAA max velocity").onChange(M), b.add(y, "depthThreshold", 1e-4, 0.01).name("TRAA depth threshold").onChange(M), b.add(y, "edgeDepthDiff", 1e-4, 0.01).name("TRAA edge depth diff").onChange(M), b.add(y, "useSubpixelCorrection").name("TRAA subpixel correction").onChange(M);
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)");
1159
347
  }
1160
348
  return () => {
1161
- S.dispose(), g.current = null;
349
+ v.dispose(), o.current = null;
1162
350
  };
1163
- }, [o, l, f, t, s, a]), q(() => {
1164
- !o || !T || o.setSize(T.width, T.height);
1165
- }, [T]), Ht(({ gl: c, scene: n, camera: i }) => {
1166
- g.current && g.current.render();
1167
- }, 1), /* @__PURE__ */ D.createElement(D.Fragment, null, t !== "low" && o && /* @__PURE__ */ D.createElement(D.Fragment, null, /* @__PURE__ */ D.createElement("directionalLight", { ref: d, color: "white", position: v.toArray(), "target-position": x.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 })));
1168
- }, Gn = ({ character: e, autoLookAt: t }) => {
1169
- const s = O((v) => v.characterState), a = re((v) => v.currentAUs), r = re((v) => v.currentGaze), o = re((v) => v.currentHeadPose), l = re((v) => v.lookAtCamera), f = se((v) => v.cameraPosition), T = re((v) => v.targets);
1170
- return Ht((v, x) => {
1171
- const V = {
1172
- deltaTime: x,
1173
- timestamp: v.clock.oldTime,
1174
- AU: a,
1175
- gaze: r,
1176
- headPose: o,
1177
- characterState: s,
1178
- lookAt: l ? f : void 0,
1179
- 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
1180
368
  };
1181
- e.update(V);
1182
- }), q(() => {
369
+ e.update(P);
370
+ }), l(() => {
1183
371
  if (t)
1184
- switch (s) {
1185
- case de.idle:
1186
- case de.waiting:
1187
- Qe(!1);
372
+ switch (n) {
373
+ case z.idle:
374
+ case z.waiting:
375
+ se(!1);
1188
376
  break;
1189
- case de.listening:
1190
- case de.speaking:
1191
- Qe(!0);
377
+ case z.listening:
378
+ case z.speaking:
379
+ se(!0);
1192
380
  break;
1193
381
  }
1194
382
  else
1195
- Qe(!1);
1196
- }, [s, t]), q(() => {
1197
- Zs(e);
383
+ se(!1);
384
+ }, [n, t]), l(() => {
385
+ We(e);
1198
386
  }, [e]), null;
1199
- }, xo = ({ url: e, type: t, animationsUrl: s, gender: a, speechSynthesis: r, camera: o, onLoadingCompleted: l, autoLookAt: f, breathing: T, disableAnimations: v, debug: x, inspector: V, enableBml: m, animationWeights: k, license: R, detectGpuData: d, environmentPreset: g = "apartment", tonemapping: c = B.NeutralToneMapping, targets: n, useBlendshapeManager: i = !1 }) => {
1200
- const p = O((P) => P.animationsLoaded), y = se((P) => P.defaultPositions), h = se((P) => P.defaultDistances), [A, C] = ee(), [N, u] = ee(null), [S, M] = ee(), [b, j] = ee(!1), G = async (P) => {
1201
- let _ = null;
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) => {
412
+ let N = null;
1202
413
  switch (t) {
1203
- case Se.cc3:
1204
- _ = new ls(), M(Le.cc3);
414
+ case $.cc3:
415
+ N = new De(), u(ne.cc3);
1205
416
  break;
1206
- case Se.avatarsdk:
1207
- _ = new cs(), M(Le.avatarsdk);
417
+ case $.avatarsdk:
418
+ N = new ve(), u(ne.avatarsdk);
1208
419
  break;
1209
- case Se.avaturn:
1210
- _ = new is(), M(Le.avaturn);
420
+ case $.avaturn:
421
+ N = new Re(), u(ne.avaturn);
1211
422
  break;
1212
423
  }
1213
- const L = await _.loadAsync(P).catch((H) => console.warn("Error loading character : ", H));
1214
- if (L) {
1215
- let H = null;
1216
- const ne = {
1217
- mesh: L,
1218
- onAnimationsLoaded: E,
1219
- animationsUrl: s,
1220
- 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",
1221
432
  type: t,
1222
- debug: x,
1223
- enableBmlManager: !!m,
1224
- animationWeights: k,
1225
- useBlendshapeManager: i,
1226
- license: R
433
+ debug: w,
434
+ enableBmlManager: !!E,
435
+ animationWeights: D,
436
+ license: h
1227
437
  };
1228
438
  switch (t) {
1229
- case Se.cc3:
1230
- H = await Ye.fromCharacterCreator(ne);
439
+ case $.cc3:
440
+ B = await ae.fromCharacterCreator(te);
1231
441
  break;
1232
- case Se.avatarsdk:
1233
- H = await Ye.fromAvatarSDK(ne);
442
+ case $.avatarsdk:
443
+ B = await ae.fromAvatarSDK(te);
1234
444
  break;
1235
- case Se.avaturn:
1236
- H = await Ye.fromAvaturn(ne);
445
+ case $.avaturn:
446
+ B = await ae.fromAvaturn(te);
1237
447
  break;
1238
448
  }
1239
- H && u(H);
449
+ B && K() ? B.dispose() : B && v(B);
1240
450
  }
1241
- }, E = () => {
1242
- Ct(!0);
451
+ }, Y = () => {
452
+ ie(!0);
1243
453
  };
1244
- q(() => {
1245
- var P, _;
1246
- N && p && (T === !1 && ((_ = (P = N.animationManager) == null ? void 0 : P.disableBreathing) == null || _.call(P)), b ? (an(N.getAllAnimationNames()), rn(N.getAllAnimations()), setTimeout(() => {
1247
- l == null || l();
1248
- }, 1e3)) : U());
1249
- }, [N, p, b]), q(() => {
1250
- sn(n || []);
1251
- }, [n]), q(() => {
1252
- Ct(!1), A !== void 0 && (A ? G(e) : l == null || l());
1253
- }, [e, A]), q(() => {
1254
- if (b && h && y)
1255
- if (o) {
1256
- const P = wn(o, h, y);
1257
- 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);
1258
480
  } else {
1259
- const P = y.mouth.clone();
1260
- P.setComponent(2, h.farther), Mt(P), _t(y.lowerbelly);
481
+ const S = f.mouth.clone();
482
+ S.setComponent(2, L.farther), le(S), me(f.lowerbelly);
1261
483
  }
1262
- }, [b, o, h, y]), q(() => {
1263
- r && (r.credentials && xn(r.credentials), r.voice && vn(r.voice));
1264
- }, [r]), q(() => {
1265
- An(i);
1266
- }, [i]);
1267
- const U = () => {
1268
- if (N && S) {
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) {
1269
493
  try {
1270
- const P = new B.Box3().setFromObject(N), _ = P.max, L = P.min, H = new B.Vector3((_.x + L.x) / 2, (_.y + L.y) / 2, (_.z + L.z) / 2);
1271
- Xs(H);
1272
- const ne = Math.abs(_.x - L.x), K = Math.abs(_.y - L.y), ue = Math.abs(_.z - L.z);
1273
- $s({
1274
- x: ne,
1275
- y: K,
1276
- z: ue
1277
- });
1278
- const Z = (_.x + L.x) / 2, F = (_.z + L.z) / 2, me = {
1279
- eye: new B.Vector3(Z, _.y - K / 16, F),
1280
- mouth: new B.Vector3(Z, _.y - K / 12, F),
1281
- neck: new B.Vector3(Z, _.y - K / 8, F),
1282
- clavicle: new B.Vector3(Z, _.y - K / 6, F),
1283
- torso: new B.Vector3(Z, _.y - K / 4, F),
1284
- belly: new B.Vector3(Z, _.y - K / 8 * 3, F),
1285
- lowerbelly: new B.Vector3(Z, _.y - K / 32 * 15, F),
1286
- hips: H,
1287
- higherthigh: new B.Vector3(Z, L.y + K / 32 * 15, F),
1288
- thigh: new B.Vector3(Z, L.y + K / 8 * 3, F),
1289
- knee: new B.Vector3(Z, L.y + K / 4, F),
1290
- leg: new B.Vector3(Z, L.y + K / 8, F),
1291
- feet: new B.Vector3(Z, L.y, F)
1292
- }, te = (_.y - (L.y + K / 7 * 2)) / 2 / Math.tan(25 * (Math.PI / 180)), Ce = {
1293
- veryclose: te / 4,
1294
- closer: te / 3,
1295
- close: te / 2.5,
1296
- midclose: te / 2,
1297
- medium: te,
1298
- midfar: te * 2,
1299
- far: te * 2.5,
1300
- farther: te * 3,
1301
- veryfar: te * 4
1302
- };
1303
- Js(me), en(Ce);
1304
- } catch (P) {
1305
- 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);
1306
498
  }
1307
- j(!0);
499
+ ee(!0);
1308
500
  }
1309
501
  };
1310
- return /* @__PURE__ */ D.createElement(Un, { parentGpuTier: d, setIsGpuAvailable: C, tonemapping: c, inspector: V }, A ? /* @__PURE__ */ D.createElement(D.Fragment, null, N && /* @__PURE__ */ D.createElement(Gn, { character: N, autoLookAt: !!f }), N && /* @__PURE__ */ D.createElement(D.Fragment, null, /* @__PURE__ */ D.createElement(ps, { preset: g }), /* @__PURE__ */ D.createElement("primitive", { object: N, castShadow: !0, receiveShadow: !0 }))) : /* @__PURE__ */ D.createElement(D.Fragment, null));
1311
- }, Hn = {
1312
- emotions: [],
1313
- currentTopEmotion: lt.Neutral,
1314
- useTopEmotionOnly: !0,
1315
- autoDecay: !1
1316
- }, Ve = we()(() => Hn), So = (e) => {
1317
- if (Ve.setState({ emotions: e || [] }), e != null && e.length) {
1318
- const t = e.reduce((s, a) => s.value > a.value ? s : a);
1319
- Ve.setState({ currentTopEmotion: t.emotion });
1320
- } else
1321
- Ve.setState({ currentTopEmotion: lt.Neutral });
1322
- }, bo = (e) => {
1323
- Ve.setState({ useTopEmotionOnly: e });
1324
- }, To = (e) => {
1325
- Ve.setState({ autoDecay: e });
1326
- }, vo = (e) => {
1327
- const t = O.getState().FACSManager;
1328
- 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));
1329
503
  };
1330
504
  export {
1331
- xo as Character,
1332
- Mo as CharacterState,
1333
- _o as CreationTool,
1334
- X as Distances,
1335
- Co as Object3D,
1336
- $ as Positions,
1337
- le as Rotations,
1338
- mo as addBlendshape,
1339
- po as addSPPASViseme,
1340
- qt as addViseme,
1341
- ko as bmlTags,
1342
- Po as emotionList,
1343
- Kt as flushBlendshapeData,
1344
- Wt as flushLipSyncData,
1345
- ro as getAnimationsMap,
1346
- eo as getCameraPosition,
1347
- Jn as getCharacterHeight,
1348
- to as getLookAt,
1349
- fo as getVoices,
1350
- nn as lookAtAndKeep,
1351
- co as playAnimationByName,
1352
- vo as playFacialAnimation,
1353
- lo as presets,
1354
- on as releaseLookAt,
1355
- To as setAutoDecay,
1356
- io as setAutoPlay,
1357
- ho as setBlendshapes,
1358
- Mt as setCameraPosition,
1359
- Nt as setCharacterState,
1360
- so as setCurrentAUs,
1361
- no as setCurrentGaze,
1362
- oo as setCurrentHeadPose,
1363
- Sn as setCurrentUtterance,
1364
- So as setEmotions,
1365
- Qe as setLookAtCamera,
1366
- tn as setMovable,
1367
- ao as setShowFirstTarget,
1368
- go as setTextToSpeak,
1369
- bo as setUseTopEmotionOnly,
1370
- yo as setVisemeIntensity,
1371
- uo as setVisemes,
1372
- vn as setVoice,
1373
- 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
1374
546
  };