@oxy.so/bloom 23.8.0 → 23.8.1
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/android/src/main/java/so/oxy/bloom/AvatarLoops.kt +293 -0
- package/android/src/main/java/so/oxy/bloom/AvatarSurface.kt +351 -0
- package/android/src/main/java/so/oxy/bloom/BloomPackage.kt +1 -1
- package/docs/agent-avatar.mdx +77 -1
- package/docs/no-nativewind.mdx +3 -1
- package/docs/task-catalog.json +1 -1
- package/docs/task-catalog.mdx +1 -1
- package/docs/theme.mdx +21 -0
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js +267 -111
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/commonjs/agent-avatar/VectorNativeSurface.js +75 -0
- package/lib/commonjs/agent-avatar/VectorNativeSurface.js.map +1 -0
- package/lib/commonjs/agent-avatar/vector-loop.js +161 -0
- package/lib/commonjs/agent-avatar/vector-loop.js.map +1 -0
- package/lib/commonjs/agent-avatar/vector-visibility.js +4 -1
- package/lib/commonjs/agent-avatar/vector-visibility.js.map +1 -1
- package/lib/commonjs/blur/BlurIsland.js +112 -118
- package/lib/commonjs/blur/BlurIsland.js.map +1 -1
- package/lib/commonjs/button/Button.js +12 -22
- package/lib/commonjs/button/Button.js.map +1 -1
- package/lib/commonjs/button/GroupBase.js +35 -50
- package/lib/commonjs/button/GroupBase.js.map +1 -1
- package/lib/commonjs/floating/lens/lens-frame.js +286 -0
- package/lib/commonjs/floating/lens/lens-frame.js.map +1 -0
- package/lib/commonjs/floating/lens/lens-material.js +1 -1
- package/lib/commonjs/page-header/PageHeader.js +24 -15
- package/lib/commonjs/page-header/PageHeader.js.map +1 -1
- package/lib/commonjs/panel-routing/expo-router/StackScene.js +1 -0
- package/lib/commonjs/panel-routing/expo-router/StackScene.js.map +1 -1
- package/lib/commonjs/surface/Surface.js +64 -193
- package/lib/commonjs/surface/Surface.js.map +1 -1
- package/lib/commonjs/tab-bar/TabBarBase.js +18 -15
- package/lib/commonjs/tab-bar/TabBarBase.js.map +1 -1
- package/lib/module/agent-avatar/VectorCharacterAvatar.js +268 -112
- package/lib/module/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/module/agent-avatar/VectorNativeSurface.js +66 -0
- package/lib/module/agent-avatar/VectorNativeSurface.js.map +1 -0
- package/lib/module/agent-avatar/vector-loop.js +150 -0
- package/lib/module/agent-avatar/vector-loop.js.map +1 -0
- package/lib/module/agent-avatar/vector-visibility.js +3 -1
- package/lib/module/agent-avatar/vector-visibility.js.map +1 -1
- package/lib/module/blur/BlurIsland.js +112 -116
- package/lib/module/blur/BlurIsland.js.map +1 -1
- package/lib/module/button/Button.js +13 -23
- package/lib/module/button/Button.js.map +1 -1
- package/lib/module/button/GroupBase.js +37 -52
- package/lib/module/button/GroupBase.js.map +1 -1
- package/lib/module/floating/lens/lens-frame.js +282 -0
- package/lib/module/floating/lens/lens-frame.js.map +1 -0
- package/lib/module/floating/lens/lens-material.js +1 -1
- package/lib/module/page-header/PageHeader.js +24 -15
- package/lib/module/page-header/PageHeader.js.map +1 -1
- package/lib/module/panel-routing/expo-router/StackScene.js +1 -0
- package/lib/module/panel-routing/expo-router/StackScene.js.map +1 -1
- package/lib/module/surface/Surface.js +65 -194
- package/lib/module/surface/Surface.js.map +1 -1
- package/lib/module/tab-bar/TabBarBase.js +18 -15
- package/lib/module/tab-bar/TabBarBase.js.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/VectorNativeSurface.d.ts +75 -0
- package/lib/typescript/commonjs/agent-avatar/VectorNativeSurface.d.ts.map +1 -0
- package/lib/typescript/commonjs/agent-avatar/vector-loop.d.ts +93 -0
- package/lib/typescript/commonjs/agent-avatar/vector-loop.d.ts.map +1 -0
- package/lib/typescript/commonjs/agent-avatar/vector-visibility.d.ts +2 -0
- package/lib/typescript/commonjs/agent-avatar/vector-visibility.d.ts.map +1 -1
- package/lib/typescript/commonjs/blur/BlurIsland.d.ts +1 -1
- package/lib/typescript/commonjs/blur/BlurIsland.d.ts.map +1 -1
- package/lib/typescript/commonjs/button/Button.d.ts.map +1 -1
- package/lib/typescript/commonjs/button/GroupBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/floating/lens/lens-frame.d.ts +52 -0
- package/lib/typescript/commonjs/floating/lens/lens-frame.d.ts.map +1 -0
- package/lib/typescript/commonjs/floating/lens/lens-material.d.ts +1 -1
- package/lib/typescript/commonjs/page-header/PageHeader.d.ts.map +1 -1
- package/lib/typescript/commonjs/panel-routing/expo-router/StackScene.d.ts.map +1 -1
- package/lib/typescript/commonjs/surface/Surface.d.ts.map +1 -1
- package/lib/typescript/commonjs/tab-bar/TabBarBase.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/VectorNativeSurface.d.ts +75 -0
- package/lib/typescript/module/agent-avatar/VectorNativeSurface.d.ts.map +1 -0
- package/lib/typescript/module/agent-avatar/vector-loop.d.ts +93 -0
- package/lib/typescript/module/agent-avatar/vector-loop.d.ts.map +1 -0
- package/lib/typescript/module/agent-avatar/vector-visibility.d.ts +2 -0
- package/lib/typescript/module/agent-avatar/vector-visibility.d.ts.map +1 -1
- package/lib/typescript/module/blur/BlurIsland.d.ts +1 -1
- package/lib/typescript/module/blur/BlurIsland.d.ts.map +1 -1
- package/lib/typescript/module/button/Button.d.ts.map +1 -1
- package/lib/typescript/module/button/GroupBase.d.ts.map +1 -1
- package/lib/typescript/module/floating/lens/lens-frame.d.ts +52 -0
- package/lib/typescript/module/floating/lens/lens-frame.d.ts.map +1 -0
- package/lib/typescript/module/floating/lens/lens-material.d.ts +1 -1
- package/lib/typescript/module/page-header/PageHeader.d.ts.map +1 -1
- package/lib/typescript/module/panel-routing/expo-router/StackScene.d.ts.map +1 -1
- package/lib/typescript/module/surface/Surface.d.ts.map +1 -1
- package/lib/typescript/module/tab-bar/TabBarBase.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent-avatar/VectorCharacterAvatar.tsx +327 -120
- package/src/agent-avatar/VectorNativeSurface.tsx +117 -0
- package/src/agent-avatar/vector-loop.ts +213 -0
- package/src/agent-avatar/vector-visibility.ts +3 -1
- package/src/blur/BlurIsland.tsx +16 -14
- package/src/button/Button.tsx +19 -36
- package/src/button/GroupBase.tsx +42 -56
- package/src/floating/lens/lens-frame.tsx +195 -0
- package/src/floating/lens/lens-material.ts +1 -1
- package/src/page-header/PageHeader.tsx +26 -13
- package/src/panel-routing/expo-router/StackScene.tsx +9 -0
- package/src/surface/Surface.tsx +13 -28
- package/src/tab-bar/TabBarBase.tsx +13 -8
- package/lib/commonjs/floating/lens/lens-button-host.js +0 -218
- package/lib/commonjs/floating/lens/lens-button-host.js.map +0 -1
- package/lib/module/floating/lens/lens-button-host.js +0 -214
- package/lib/module/floating/lens/lens-button-host.js.map +0 -1
- package/lib/typescript/commonjs/floating/lens/lens-button-host.d.ts +0 -34
- package/lib/typescript/commonjs/floating/lens/lens-button-host.d.ts.map +0 -1
- package/lib/typescript/module/floating/lens/lens-button-host.d.ts +0 -34
- package/lib/typescript/module/floating/lens/lens-button-host.d.ts.map +0 -1
- package/src/floating/lens/lens-button-host.tsx +0 -148
|
@@ -27,7 +27,18 @@ import { useStaticPortraits } from "./use-static-portraits.js";
|
|
|
27
27
|
import { useVectorAssetLoader } from "./default-catalog.js";
|
|
28
28
|
import { loadVectorGeometry, paintVectorCharacter, VECTOR_REST_CLIPS, vectorGeometryKey } from "./vector-compose.js";
|
|
29
29
|
import { renderVectorFrame } from "./vector-frame.js";
|
|
30
|
-
import {
|
|
30
|
+
import { releaseVectorLoop, vectorLoop, vectorLoopFrame, vectorLoopIndex, vectorLoopKey, vectorLoopTime, vectorLoopTracks } from "./vector-loop.js";
|
|
31
|
+
import { nativePaint, nativeVectorLoop, VectorNativeSurface, viewBoxNumbers } from "./VectorNativeSurface.js";
|
|
32
|
+
|
|
33
|
+
/** One computed frame: what is drawn, and the pose and motion a later transition starts from. */
|
|
34
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
|
+
/**
|
|
36
|
+
* The rest loops the native surface has, by `vectorLoopKey`: `true` once it said it has one (from
|
|
37
|
+
* memory, from an earlier start, or because it was handed over), `false` once it said it has not.
|
|
38
|
+
* Where there is no native surface (the web) the JS thread replays the remembered frames itself.
|
|
39
|
+
*/
|
|
40
|
+
const nativeLoops = new Map();
|
|
41
|
+
let lastCapture = 0;
|
|
31
42
|
/** Shared browser/native SVG host; loading, composition and projection never start the 3D runtime. */
|
|
32
43
|
export function VectorCharacterAvatar(props) {
|
|
33
44
|
const $ = _c(4);
|
|
@@ -133,6 +144,15 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
133
144
|
latestAsset.current = paintedAsset;
|
|
134
145
|
const [display, setDisplay] = useState(),
|
|
135
146
|
[revision, setRevision] = useState(0);
|
|
147
|
+
/** The clock of the rest loop the native surface plays, if it does; the JS thread draws nothing meanwhile. */
|
|
148
|
+
const [looping, setLooping] = useState();
|
|
149
|
+
const loopSession = useRef(undefined);
|
|
150
|
+
/** The rest loop the native surface is asked about, and the loop handed to it when it has not got it. */
|
|
151
|
+
const [restKey, setRestKey] = useState();
|
|
152
|
+
const [handedLoop, setHandedLoop] = useState();
|
|
153
|
+
const [capture, setCapture] = useState(0);
|
|
154
|
+
const captures = useRef(new Map());
|
|
155
|
+
const drawn = useRef(false);
|
|
136
156
|
const host = useRef(null);
|
|
137
157
|
const svg = useRef(null);
|
|
138
158
|
const observeSnapshot = useContext(AvatarSnapshotObserver);
|
|
@@ -144,8 +164,15 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
144
164
|
uri: 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(new XMLSerializer().serializeToString(element))
|
|
145
165
|
} : null;
|
|
146
166
|
}
|
|
147
|
-
return
|
|
148
|
-
|
|
167
|
+
if (VectorNativeSurface) return drawn.current ? new Promise(resolve => {
|
|
168
|
+
const id = ++lastCapture;
|
|
169
|
+
captures.current.set(id, data => resolve(data ? {
|
|
170
|
+
uri: 'data:image/png;base64,' + data
|
|
171
|
+
} : null));
|
|
172
|
+
setCapture(id);
|
|
173
|
+
}) : null;
|
|
174
|
+
return svg.current ? new Promise(resolve_0 => svg.current.toDataURL(data_0 => resolve_0({
|
|
175
|
+
uri: 'data:image/png;base64,' + data_0
|
|
149
176
|
}))) : null;
|
|
150
177
|
});
|
|
151
178
|
return () => observeSnapshot?.(null);
|
|
@@ -200,6 +227,49 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
200
227
|
cycles.current = props.workingCycles;
|
|
201
228
|
const catalogRef = useRef(catalog);
|
|
202
229
|
catalogRef.current = catalog;
|
|
230
|
+
/**
|
|
231
|
+
* Takes the drawing back from the native surface: the clock moves on by what it played (both read
|
|
232
|
+
* the same monotonic clock), and the surface keeps the frame it got to on screen until the JS
|
|
233
|
+
* thread draws one. Called before anything changes the motion (a gesture, a mood, the pointer) and
|
|
234
|
+
* whenever the frame loop restarts, so the character carries on from where it was.
|
|
235
|
+
*/
|
|
236
|
+
const endLoop = useCallback(() => {
|
|
237
|
+
const session = loopSession.current;
|
|
238
|
+
if (!session) return;
|
|
239
|
+
loopSession.current = undefined;
|
|
240
|
+
const seconds = Math.max(0, (performance.now() - session.epoch) / 1000),
|
|
241
|
+
motion = state.current;
|
|
242
|
+
advanceVectorPlayback(motion, session.asset, seconds);
|
|
243
|
+
advanceVectorMood(motion.mood, latestMood.current, seconds);
|
|
244
|
+
// The pose of that frame, which a gesture blends from: at rest it is the idle clip's pose at the
|
|
245
|
+
// frame's grid time, as the loop drew it.
|
|
246
|
+
motion.lastPose = sampleVectorPose(session.asset, 'idle', vectorLoopTime(session.loop, vectorLoopIndex(session.loop, motion.time)));
|
|
247
|
+
setLooping(undefined);
|
|
248
|
+
setDisplay(shown => shown && {
|
|
249
|
+
...shown,
|
|
250
|
+
time: motion.time
|
|
251
|
+
});
|
|
252
|
+
}, []);
|
|
253
|
+
const onLoop = useCallback(({
|
|
254
|
+
nativeEvent: {
|
|
255
|
+
key,
|
|
256
|
+
ready: ready_0
|
|
257
|
+
}
|
|
258
|
+
}) => {
|
|
259
|
+
nativeLoops.set(key, ready_0);
|
|
260
|
+
if (ready_0) setHandedLoop(handed => handed?.key === key ? undefined : handed);
|
|
261
|
+
// The surface lost a loop it was playing: the JS thread draws it again.
|
|
262
|
+
else if (loopSession.current?.key === key) endLoop();
|
|
263
|
+
}, [endLoop]);
|
|
264
|
+
const onCapture = useCallback(({
|
|
265
|
+
nativeEvent: {
|
|
266
|
+
id: id_0,
|
|
267
|
+
data: data_1
|
|
268
|
+
}
|
|
269
|
+
}) => {
|
|
270
|
+
captures.current.get(id_0)?.(data_1);
|
|
271
|
+
captures.current.delete(id_0);
|
|
272
|
+
}, []);
|
|
203
273
|
/**
|
|
204
274
|
* The character is first loaded at rest (`VECTOR_REST_CLIPS`): its idle tracks and the geometry
|
|
205
275
|
* they draw, which is what an avatar shows almost always (a mood is drawn on the idle clip). Its
|
|
@@ -211,24 +281,27 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
211
281
|
const loadingFull = useRef(null);
|
|
212
282
|
const pendingAction = useRef(null);
|
|
213
283
|
const ensureFull = useCallback(() => {
|
|
214
|
-
const
|
|
215
|
-
if (fullGeometry.current ===
|
|
216
|
-
loadingFull.current =
|
|
284
|
+
const key_0 = vectorGeometryKey(latestResolved.current);
|
|
285
|
+
if (fullGeometry.current === key_0 || loadingFull.current === key_0) return;
|
|
286
|
+
loadingFull.current = key_0;
|
|
217
287
|
void loadVectorGeometry(latestResolved.current, catalogRef.current).then(value_0 => {
|
|
218
|
-
if (vectorGeometryKey(latestResolved.current) !==
|
|
219
|
-
fullGeometry.current =
|
|
220
|
-
loadedGeometry.current =
|
|
288
|
+
if (vectorGeometryKey(latestResolved.current) !== key_0) return;
|
|
289
|
+
fullGeometry.current = key_0;
|
|
290
|
+
loadedGeometry.current = key_0;
|
|
221
291
|
if (value_0.referenceFace) state.current.workLook = vectorWorkLook(value_0);
|
|
292
|
+
// The loop may have been handed over again while this loaded: its clock first.
|
|
293
|
+
endLoop();
|
|
222
294
|
setAsset(value_0);
|
|
223
295
|
const action = pendingAction.current;
|
|
224
296
|
pendingAction.current = null;
|
|
225
297
|
if (action) playVectorAction(state.current, action, action === 'work' ? cycles.current : 1);
|
|
226
298
|
setRevision(revision_0 => revision_0 + 1);
|
|
227
299
|
}, () => {
|
|
228
|
-
if (loadingFull.current ===
|
|
300
|
+
if (loadingFull.current === key_0) loadingFull.current = null;
|
|
229
301
|
});
|
|
230
|
-
}, []);
|
|
302
|
+
}, [endLoop]);
|
|
231
303
|
const play = useCallback(action_0 => {
|
|
304
|
+
endLoop();
|
|
232
305
|
if (action_0 !== 'idle' && fullGeometry.current !== vectorGeometryKey(latestResolved.current)) {
|
|
233
306
|
pendingAction.current = action_0;
|
|
234
307
|
ensureFull();
|
|
@@ -237,7 +310,7 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
237
310
|
pendingAction.current = null;
|
|
238
311
|
playVectorAction(state.current, action_0, action_0 === 'work' ? cycles.current : 1);
|
|
239
312
|
setRevision(value_1 => value_1 + 1);
|
|
240
|
-
}, [ensureFull]);
|
|
313
|
+
}, [ensureFull, endLoop]);
|
|
241
314
|
useEffect(() => {
|
|
242
315
|
let current = true;
|
|
243
316
|
setFailed(false);
|
|
@@ -276,7 +349,7 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
276
349
|
eyewear: resolved.eyewear,
|
|
277
350
|
accessory: resolved.accessory
|
|
278
351
|
},
|
|
279
|
-
available: Object.fromEntries([...AVATAR_SHAPES.map(
|
|
352
|
+
available: Object.fromEntries([...AVATAR_SHAPES.map(id_1 => [`shape:${id_1}`, true]), ...AVATAR_EYES.map(id_2 => [`eyes:${id_2}`, true]), ['eyes:none', true], ...AVATAR_EYEWEAR.map(id_3 => [`eyewear:${id_3}`, true]), ...AVATAR_ACCESSORIES.map(id_4 => [`accessory:${id_4}`, true]), ...AVATAR_COLORS.map(id_5 => [`color:${id_5}`, true])])
|
|
280
353
|
});
|
|
281
354
|
}).catch(() => {
|
|
282
355
|
if (current) {
|
|
@@ -309,11 +382,12 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
309
382
|
}, [props.idleKey, props.reactionKey, props.workingKey, props.entranceKey, play]);
|
|
310
383
|
useEffect(() => {
|
|
311
384
|
if (mood === previous.current.mood) return;
|
|
385
|
+
endLoop();
|
|
312
386
|
setVectorMood(state.current.mood, mood, previous.current.mood);
|
|
313
387
|
previous.current.mood = mood;
|
|
314
388
|
// A still character repaints into the new mood; a running one restarts its frame loop.
|
|
315
389
|
setRevision(value_3 => value_3 + 1);
|
|
316
|
-
}, [mood]);
|
|
390
|
+
}, [mood, endLoop]);
|
|
317
391
|
useEffect(() => {
|
|
318
392
|
if (Platform.OS !== 'web' || typeof IntersectionObserver === 'undefined' || !host.current) return;
|
|
319
393
|
const observer = new IntersectionObserver(([entry]) => setVisible(entry?.isIntersecting ?? false));
|
|
@@ -322,12 +396,15 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
322
396
|
}, []);
|
|
323
397
|
useEffect(() => {
|
|
324
398
|
if (!asset || !visible || !screenVisible) return;
|
|
399
|
+
// The UI thread plays the loop until something changes; then the JS thread takes over again.
|
|
400
|
+
if (looping) return endLoop;
|
|
325
401
|
let last,
|
|
326
402
|
painted = 0,
|
|
403
|
+
paintedIndex = -1,
|
|
327
404
|
disposed = false;
|
|
328
405
|
const stopped = !!paused || !!portrait || reduced;
|
|
329
406
|
const tick = timestamp => {
|
|
330
|
-
if (disposed) return;
|
|
407
|
+
if (disposed || loopSession.current) return;
|
|
331
408
|
// A frame callback that brings no timestamp is read off the page's own clock; with no clock
|
|
332
409
|
// at all there is nothing to advance by, and the frame is not drawn.
|
|
333
410
|
const now = Number.isFinite(timestamp) ? timestamp : typeof performance === 'undefined' ? Number.NaN : performance.now();
|
|
@@ -335,92 +412,126 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
335
412
|
const delta = vectorFrameDelta(now, last);
|
|
336
413
|
last = now;
|
|
337
414
|
const asset_0 = latestAsset.current;
|
|
338
|
-
const
|
|
415
|
+
const motion_0 = state.current;
|
|
339
416
|
if (!stopped) {
|
|
340
|
-
advanceVectorPlayback(
|
|
341
|
-
|
|
417
|
+
advanceVectorPlayback(motion_0, asset_0, delta);
|
|
418
|
+
motion_0.entrance = Math.min(1, motion_0.entrance + delta / 0.25);
|
|
342
419
|
const follow = 1 - Math.exp(-delta * 7);
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
advanceVectorMood(
|
|
347
|
-
} else settleVectorMood(
|
|
348
|
-
|
|
420
|
+
motion_0.yaw += (motion_0.targetYaw - motion_0.yaw) * follow;
|
|
421
|
+
motion_0.pitch += (motion_0.targetPitch - motion_0.pitch) * follow;
|
|
422
|
+
motion_0.lookMix += ((motion_0.pointerActive ? 1 : 0) - motion_0.lookMix) * follow;
|
|
423
|
+
advanceVectorMood(motion_0.mood, latestMood.current, delta);
|
|
424
|
+
} else settleVectorMood(motion_0.mood, latestMood.current);
|
|
425
|
+
// At rest the frame is one of the loop's, drawn once and remembered (`vector-loop.ts`), and
|
|
426
|
+
// each grid frame is painted in turn; otherwise a frame is painted 30 times a second.
|
|
427
|
+
const resting = !stopped && motion_0.action === 'idle' && !motion_0.poseFrom && !motion_0.motionFrom && motion_0.entrance >= 1 && motion_0.yaw === 0 && motion_0.pitch === 0 && !vectorMoodActive(motion_0.mood) && !asset_0.referenceFace && !previewPart;
|
|
428
|
+
const loop = resting ? vectorLoop(latestFrameRecipe.current, asset_0.clips.idle.duration) : undefined;
|
|
429
|
+
const index = loop ? vectorLoopIndex(loop, motion_0.time) : 0;
|
|
430
|
+
const transition = Math.min(1, Math.max(0, (motion_0.clock - motion_0.transitionStarted) / motion_0.transitionDuration));
|
|
431
|
+
const eased = transition * transition * (3 - 2 * transition);
|
|
432
|
+
const feeling = !portrait && vectorMoodActive(motion_0.mood) ? {
|
|
433
|
+
...motion_0.mood
|
|
434
|
+
} : undefined;
|
|
435
|
+
const draw = (action_1, time) => {
|
|
436
|
+
const poseTime = asset_0.referenceFace && action_1 === 'work' ? referenceWorkTime(time) : time;
|
|
437
|
+
const targetPose = sampleVectorPose(asset_0, action_1, poseTime);
|
|
438
|
+
const pose = motion_0.poseFrom && !portrait ? blendVectorPose(motion_0.poseFrom, targetPose, eased) : targetPose;
|
|
439
|
+
const procedural = asset_0.referenceFace ? sampleVectorMotion({
|
|
440
|
+
personalityKey: latestResolved.current.shape,
|
|
441
|
+
time: portrait ? 0 : motion_0.clock,
|
|
442
|
+
state: action_1,
|
|
443
|
+
stateTime: poseTime,
|
|
444
|
+
workLook: motion_0.workLook,
|
|
445
|
+
look: {
|
|
446
|
+
yaw: motion_0.yaw,
|
|
447
|
+
pitch: motion_0.pitch,
|
|
448
|
+
mix: portrait ? 0 : motion_0.lookMix,
|
|
449
|
+
wander: (action_1 === 'work' ? 0.15 : 1) * (1 - motion_0.lookMix)
|
|
450
|
+
},
|
|
451
|
+
transition: motion_0.motionFrom && !portrait ? {
|
|
452
|
+
from: motion_0.motionFrom,
|
|
453
|
+
startedAt: motion_0.transitionStarted,
|
|
454
|
+
duration: motion_0.transitionDuration
|
|
455
|
+
} : undefined
|
|
456
|
+
}) : undefined;
|
|
457
|
+
// The mood goes over the blended motion, never into it: a transition captures the
|
|
458
|
+
// motion without the mood, which carries on through the transition on its own clock.
|
|
459
|
+
const framed = vectorMoodFrame(asset_0, procedural, {
|
|
460
|
+
yaw: portrait ? 0 : motion_0.yaw,
|
|
461
|
+
pitch: portrait ? 0 : motion_0.pitch
|
|
462
|
+
}, feeling);
|
|
463
|
+
const drawing = renderVectorFrame(asset_0, {
|
|
464
|
+
action: action_1,
|
|
465
|
+
time,
|
|
466
|
+
...framed,
|
|
467
|
+
eyesOnly: previewPart === 'eyes',
|
|
468
|
+
pose
|
|
469
|
+
});
|
|
470
|
+
return {
|
|
471
|
+
pose,
|
|
472
|
+
procedural,
|
|
473
|
+
gaze: framed.look ?? framed,
|
|
474
|
+
drawing
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
// Where there is a native surface, a loop it has is played by it, from where the clock is.
|
|
478
|
+
const key_1 = loop && VectorNativeSurface ? vectorLoopKey(loop, JSON.stringify([vectorGeometryKey(latestResolved.current), latestResolved.current.paint]), asset_0.clips.idle, () => vectorLoopFrame(loop, 0, () => draw('idle', vectorLoopTime(loop, 0))).drawing) : undefined;
|
|
479
|
+
if (key_1 !== undefined) {
|
|
480
|
+
setRestKey(key_1);
|
|
481
|
+
// Once a frame is on screen, so the surface is there to play it.
|
|
482
|
+
if (nativeLoops.get(key_1) && motion_0.count > 0) {
|
|
483
|
+
const clock = {
|
|
484
|
+
epoch: performance.now(),
|
|
485
|
+
time: motion_0.time
|
|
486
|
+
};
|
|
487
|
+
loopSession.current = {
|
|
488
|
+
key: key_1,
|
|
489
|
+
loop: loop,
|
|
490
|
+
asset: asset_0,
|
|
491
|
+
...clock
|
|
492
|
+
};
|
|
493
|
+
releaseVectorLoop(loop);
|
|
494
|
+
setLooping(clock);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (loop ? index !== paintedIndex : !painted || stopped || now - painted >= 1000 / 30) {
|
|
349
499
|
painted = painted ? now - (now - painted) % (1000 / 30) : now;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
const feeling = !portrait && vectorMoodActive(motion.mood) ? {
|
|
355
|
-
...motion.mood
|
|
356
|
-
} : undefined;
|
|
357
|
-
const sharedKey = JSON.stringify([latestFrameRecipe.current, action_1, time, motion.clock, motion.yaw, motion.pitch, motion.lookMix, motion.workLook, motion.transitionStarted, motion.transitionDuration, vectorStateIdentity(motion.poseFrom), vectorStateIdentity(motion.motionFrom), feeling?.sadness, feeling?.declineTime, portrait, previewPart]);
|
|
500
|
+
paintedIndex = loop ? index : -1;
|
|
501
|
+
const action_2 = portrait ? 'idle' : motion_0.action,
|
|
502
|
+
time_0 = loop ? vectorLoopTime(loop, index) : portrait ? 0 : motion_0.time;
|
|
503
|
+
const sharedKey = () => JSON.stringify([latestFrameRecipe.current, action_2, time_0, motion_0.clock, motion_0.yaw, motion_0.pitch, motion_0.lookMix, motion_0.workLook, motion_0.transitionStarted, motion_0.transitionDuration, vectorStateIdentity(motion_0.poseFrom), vectorStateIdentity(motion_0.motionFrom), feeling?.sadness, feeling?.declineTime, portrait, previewPart]);
|
|
358
504
|
const {
|
|
359
505
|
pose: pose_0,
|
|
360
506
|
procedural: procedural_0,
|
|
361
507
|
gaze,
|
|
362
508
|
drawing: drawing_0
|
|
363
|
-
} = shareVectorFrame(sharedKey, () =>
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const pose = motion.poseFrom && !portrait ? blendVectorPose(motion.poseFrom, targetPose, eased) : targetPose;
|
|
367
|
-
const procedural = asset_0.referenceFace ? sampleVectorMotion({
|
|
368
|
-
personalityKey: latestResolved.current.shape,
|
|
369
|
-
time: portrait ? 0 : motion.clock,
|
|
370
|
-
state: action_1,
|
|
371
|
-
stateTime: poseTime,
|
|
372
|
-
workLook: motion.workLook,
|
|
373
|
-
look: {
|
|
374
|
-
yaw: motion.yaw,
|
|
375
|
-
pitch: motion.pitch,
|
|
376
|
-
mix: portrait ? 0 : motion.lookMix,
|
|
377
|
-
wander: (action_1 === 'work' ? 0.15 : 1) * (1 - motion.lookMix)
|
|
378
|
-
},
|
|
379
|
-
transition: motion.motionFrom && !portrait ? {
|
|
380
|
-
from: motion.motionFrom,
|
|
381
|
-
startedAt: motion.transitionStarted,
|
|
382
|
-
duration: motion.transitionDuration
|
|
383
|
-
} : undefined
|
|
384
|
-
}) : undefined;
|
|
385
|
-
// The mood goes over the blended motion, never into it: a transition captures the
|
|
386
|
-
// motion without the mood, which carries on through the transition on its own clock.
|
|
387
|
-
const framed = vectorMoodFrame(asset_0, procedural, {
|
|
388
|
-
yaw: portrait ? 0 : motion.yaw,
|
|
389
|
-
pitch: portrait ? 0 : motion.pitch
|
|
390
|
-
}, feeling);
|
|
391
|
-
const drawing = renderVectorFrame(asset_0, {
|
|
392
|
-
action: action_1,
|
|
393
|
-
time,
|
|
394
|
-
...framed,
|
|
395
|
-
eyesOnly: previewPart === 'eyes',
|
|
396
|
-
pose
|
|
397
|
-
});
|
|
398
|
-
return {
|
|
399
|
-
pose,
|
|
400
|
-
procedural,
|
|
401
|
-
gaze: framed.look ?? framed,
|
|
402
|
-
drawing
|
|
403
|
-
};
|
|
404
|
-
});
|
|
405
|
-
motion.lastPose = pose_0;
|
|
406
|
-
motion.lastMotion = procedural_0;
|
|
509
|
+
} = loop ? vectorLoopFrame(loop, index, () => draw(action_2, time_0)) : shareVectorFrame(sharedKey(), () => draw(action_2, time_0));
|
|
510
|
+
motion_0.lastPose = pose_0;
|
|
511
|
+
motion_0.lastMotion = procedural_0;
|
|
407
512
|
if (transition >= 1) {
|
|
408
|
-
|
|
409
|
-
|
|
513
|
+
motion_0.poseFrom = undefined;
|
|
514
|
+
motion_0.motionFrom = undefined;
|
|
410
515
|
}
|
|
411
|
-
|
|
516
|
+
motion_0.count++;
|
|
412
517
|
setDisplay({
|
|
413
518
|
geometry: loadedGeometry.current,
|
|
414
519
|
drawing: drawing_0,
|
|
415
|
-
action:
|
|
416
|
-
time,
|
|
417
|
-
count:
|
|
418
|
-
entrance: stopped ? 1 :
|
|
520
|
+
action: action_2,
|
|
521
|
+
time: time_0,
|
|
522
|
+
count: motion_0.count,
|
|
523
|
+
entrance: stopped ? 1 : motion_0.entrance,
|
|
419
524
|
gazeYaw: gaze.yaw,
|
|
420
525
|
gazePitch: gaze.pitch,
|
|
421
|
-
tracking:
|
|
526
|
+
tracking: motion_0.lookMix
|
|
422
527
|
});
|
|
423
528
|
}
|
|
529
|
+
// A complete loop the native surface said it has not got is handed to it once.
|
|
530
|
+
const tracks = key_1 !== undefined && nativeLoops.get(key_1) === false && vectorLoopTracks(loop);
|
|
531
|
+
if (tracks) setHandedLoop(handed_0 => handed_0?.key === key_1 ? handed_0 : {
|
|
532
|
+
key: key_1,
|
|
533
|
+
loop: nativeVectorLoop(tracks, avatarViewBox(tracks.viewBox))
|
|
534
|
+
});
|
|
424
535
|
};
|
|
425
536
|
if (stopped) tick(typeof performance === 'undefined' ? 0 : performance.now());
|
|
426
537
|
const unsubscribe = stopped ? undefined : subscribeVectorFrame(tick);
|
|
@@ -428,7 +539,7 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
428
539
|
disposed = true;
|
|
429
540
|
unsubscribe?.();
|
|
430
541
|
};
|
|
431
|
-
}, [asset, visible, screenVisible, paused, portrait, reduced, previewPart, revision]);
|
|
542
|
+
}, [asset, visible, screenVisible, paused, portrait, reduced, previewPart, revision, looping, endLoop]);
|
|
432
543
|
useEffect(() => {
|
|
433
544
|
if (paused || portrait || reduced) setRevision(value_4 => value_4 + 1);
|
|
434
545
|
}, [resolved.paint, paused, portrait, reduced]);
|
|
@@ -439,9 +550,37 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
439
550
|
onReady.current?.();
|
|
440
551
|
}
|
|
441
552
|
}, [display]);
|
|
553
|
+
drawn.current = !!display;
|
|
554
|
+
/** The paint a drawn path is shown with: the current paint, when the frame is of the current geometry. */
|
|
555
|
+
const paintOf = path => {
|
|
556
|
+
const part = display?.geometry === loadedGeometry.current ? paintedAsset?.parts[Number(path.id)] : undefined;
|
|
557
|
+
const stroke = part ? part.stroke ?? (part.role === 'panel' ? path.stroke : undefined) : path.stroke;
|
|
558
|
+
return {
|
|
559
|
+
fill: part?.color ?? path.fill,
|
|
560
|
+
stroke,
|
|
561
|
+
strokeWidth: stroke ? part?.strokeWidth ?? path.strokeWidth ?? 1.5 : undefined
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
const nativeFrame = useMemo(() => VectorNativeSurface && display ? {
|
|
565
|
+
revision: display.count,
|
|
566
|
+
viewBox: viewBoxNumbers(avatarViewBox(display.drawing.viewBox)),
|
|
567
|
+
opacity: display.entrance,
|
|
568
|
+
paths: display.drawing.paths.map(path_0 => ({
|
|
569
|
+
d: path_0.d,
|
|
570
|
+
...(path_0.clip !== undefined ? {
|
|
571
|
+
clip: path_0.clip
|
|
572
|
+
} : {}),
|
|
573
|
+
...nativePaint(paintOf(path_0)),
|
|
574
|
+
opacity: path_0.opacity,
|
|
575
|
+
fillOpacity: path_0.fillOpacity
|
|
576
|
+
}))
|
|
577
|
+
} : undefined,
|
|
578
|
+
// `paintOf` reads only `display` and `paintedAsset`.
|
|
579
|
+
[display, paintedAsset]);
|
|
442
580
|
const gaze_0 = (x, y, width, height) => {
|
|
443
581
|
if (!interactive || paused || portrait || reduced) return;
|
|
444
582
|
if (![x, y, width, height].every(Number.isFinite) || width <= 0 || height <= 0) return;
|
|
583
|
+
endLoop();
|
|
445
584
|
state.current.pointerActive = true;
|
|
446
585
|
const limit = asset?.referenceFace ? 0.6 : 0.8;
|
|
447
586
|
state.current.targetYaw = Math.max(-limit, Math.min(limit, (x / width - 0.5) * 1.8));
|
|
@@ -499,40 +638,57 @@ function AnimatedVectorCharacterAvatar(props) {
|
|
|
499
638
|
fontSize: 10
|
|
500
639
|
},
|
|
501
640
|
children: messages.unavailable
|
|
502
|
-
}) : display ? /*#__PURE__*/
|
|
641
|
+
}) : display && VectorNativeSurface ? /*#__PURE__*/_jsx(VectorNativeSurface, {
|
|
642
|
+
style: {
|
|
643
|
+
width: '100%',
|
|
644
|
+
height: '100%'
|
|
645
|
+
},
|
|
646
|
+
pointerEvents: "none",
|
|
647
|
+
accessible: false,
|
|
648
|
+
importantForAccessibility: "no-hide-descendants",
|
|
649
|
+
testID: "bloom-vector-drawing",
|
|
650
|
+
frame: nativeFrame,
|
|
651
|
+
loopKey: restKey,
|
|
652
|
+
loopTracks: handedLoop?.key === restKey ? handedLoop?.loop : undefined,
|
|
653
|
+
loopClock: looping,
|
|
654
|
+
capture: capture,
|
|
655
|
+
onLoop: onLoop,
|
|
656
|
+
onCapture: onCapture
|
|
657
|
+
}) : display ? /*#__PURE__*/_jsx(Svg, {
|
|
503
658
|
ref: svg,
|
|
504
659
|
width: "100%",
|
|
505
660
|
height: "100%",
|
|
506
661
|
viewBox: avatarViewBox(display.drawing.viewBox),
|
|
507
662
|
testID: "bloom-vector-drawing",
|
|
508
663
|
...svgA11yProps(),
|
|
509
|
-
children:
|
|
510
|
-
children:
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
664
|
+
children: /*#__PURE__*/_jsxs(_Fragment, {
|
|
665
|
+
children: [/*#__PURE__*/_jsx(Defs, {
|
|
666
|
+
children: display.drawing.paths.filter(path_1 => path_1.clip !== undefined).map(path_2 => /*#__PURE__*/_jsx(ClipPath, {
|
|
667
|
+
id: `${prefix}-${path_2.id}`,
|
|
668
|
+
clipPathUnits: 'userSpaceOnUse',
|
|
669
|
+
children: /*#__PURE__*/_jsx(Path, {
|
|
670
|
+
d: path_2.clip,
|
|
671
|
+
fillRule: "nonzero",
|
|
672
|
+
clipRule: "nonzero"
|
|
673
|
+
})
|
|
674
|
+
}, path_2.id))
|
|
675
|
+
}), /*#__PURE__*/_jsx(G, {
|
|
676
|
+
opacity: display.entrance,
|
|
677
|
+
children: display.drawing.paths.map(path_3 => {
|
|
678
|
+
const paint = paintOf(path_3);
|
|
679
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
680
|
+
d: path_3.d,
|
|
681
|
+
fill: paint.fill,
|
|
682
|
+
opacity: path_3.opacity,
|
|
683
|
+
fillOpacity: path_3.fillOpacity,
|
|
684
|
+
fillRule: "nonzero",
|
|
685
|
+
stroke: paint.stroke,
|
|
686
|
+
strokeWidth: paint.strokeWidth,
|
|
687
|
+
clipPath: path_3.clip !== undefined ? `url(#${prefix}-${path_3.id})` : undefined
|
|
688
|
+
}, path_3.id);
|
|
517
689
|
})
|
|
518
|
-
}
|
|
519
|
-
})
|
|
520
|
-
opacity: display.entrance,
|
|
521
|
-
children: display.drawing.paths.map(path_1 => {
|
|
522
|
-
const currentPart = display.geometry === loadedGeometry.current ? paintedAsset?.parts[Number(path_1.id)] : undefined;
|
|
523
|
-
const stroke = currentPart ? currentPart.stroke ?? (currentPart.role === 'panel' ? path_1.stroke : undefined) : path_1.stroke;
|
|
524
|
-
return /*#__PURE__*/_jsx(Path, {
|
|
525
|
-
d: path_1.d,
|
|
526
|
-
fill: display.geometry === loadedGeometry.current ? paintedAsset?.parts[Number(path_1.id)]?.color ?? path_1.fill : path_1.fill,
|
|
527
|
-
opacity: path_1.opacity,
|
|
528
|
-
fillOpacity: path_1.fillOpacity,
|
|
529
|
-
fillRule: "nonzero",
|
|
530
|
-
stroke: stroke,
|
|
531
|
-
strokeWidth: stroke ? currentPart?.strokeWidth ?? path_1.strokeWidth ?? 1.5 : undefined,
|
|
532
|
-
clipPath: path_1.clip !== undefined ? `url(#${prefix}-${path_1.id})` : undefined
|
|
533
|
-
}, path_1.id);
|
|
534
|
-
})
|
|
535
|
-
})]
|
|
690
|
+
})]
|
|
691
|
+
})
|
|
536
692
|
}) : null
|
|
537
693
|
});
|
|
538
694
|
}
|