Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(society): keep the motion of designs and cigar smoke on 3D agent faces (#606)
Ruben Lütke7219c5de9970
diff --git a/jarvis/ui/web/frontend/src/components/society/AgentSymbol.tsx b/jarvis/ui/web/frontend/src/components/society/AgentSymbol.tsxindex d10caae80a..6fbf462950 100644--- a/jarvis/ui/web/frontend/src/components/society/AgentSymbol.tsx+++ b/jarvis/ui/web/frontend/src/components/society/AgentSymbol.tsx@@ -196,6 +196,8 @@ function FigureSymbol(props: SymbolProps) {const effect = skin ? skinEffect(skin) : "none";const eyeY = symbolEyeY(shape);return <ShapeFigure look={look} size={size} shape={shape} fallback={<FlatSymbol {...props} />}+ flow={skin && effect === "flow" ? { colors: skin.colors, angle: skin.angle } : undefined} shine={effect === "shimmer"}+ smoke={(plume, index) => <SmokePuffs c={[0, 0, 0]} size={plume.size} fill={plume.fill} id={`${id}-smoke-${index}`} />}behind={skin && effect === "glow" ? <span aria-hidden className="agent-figure-halo" style={{ background: `radial-gradient(closest-side, ${skinHighlight(skin.colors)}, transparent)` }} /> : undefined}overlay={skin && effect === "sparkle" ? <svg aria-hidden focusable="false" viewBox="0 0 40 44" className="society-agent-symbol"><SkinOverlay id={id} skin={skin} body={() => null} /></svg> : undefined}>{moving && <g className="agent-symbol-gaze"><g data-agent-eyes fill={companionEyeColors(color).eye}><g className="agent-symbol-lids">diff --git a/jarvis/ui/web/frontend/src/components/society/agentSymbol.css b/jarvis/ui/web/frontend/src/components/society/agentSymbol.cssindex 4a766f241a..da4459bb44 100644--- a/jarvis/ui/web/frontend/src/components/society/agentSymbol.css+++ b/jarvis/ui/web/frontend/src/components/society/agentSymbol.css@@ -113,15 +113,24 @@display: inline-block;flex-shrink: 0;}-.society-agent-figure > canvas {+/* The picture and what is blended onto it: flowing colours meet the picture only, never the page behind. */+.society-agent-figure > .agent-figure-picture {position: relative;display: block;width: 100%;height: 100%;+ isolation: isolate;+ -webkit-mask-size: 100% 100%;+ mask-size: 100% 100%;opacity: 0;transition: opacity 0.18s ease-out;}-.society-agent-figure[data-ready="true"] > canvas { opacity: 1; }+.society-agent-figure[data-ready="true"] > .agent-figure-picture { opacity: 1; }+.agent-figure-picture > canvas {+ display: block;+ width: 100%;+ height: 100%;+}.society-agent-figure > svg {position: absolute;inset: 0;@@ -145,7 +154,64 @@to { opacity: 0.5; transform: scale(1.04); }}+/* Effects that move across the body: layers over the still picture, cut to the body's outline by a mask+ of the same picture and moved by transforms only. */+.agent-figure-picture > .agent-figure-flow,+.society-agent-figure > .agent-figure-shine {+ position: absolute;+ inset: 0;+ overflow: hidden;+ pointer-events: none;+ -webkit-mask-size: 100% 100%;+ mask-size: 100% 100%;+ -webkit-mask-repeat: no-repeat;+ mask-repeat: no-repeat;+}++/* A flowing design: the body is drawn white with its light and shade, and the colours are multiplied onto+ it, so they run over a lit volume. One gradient period spans the face; the strip moves by exactly one. */+.agent-figure-picture > .agent-figure-flow { mix-blend-mode: multiply; }+.agent-figure-flow > i {+ position: absolute;+ left: -150%;+ top: -150%;+ width: 400%;+ height: 400%;+}+.agent-figure-flow > i > b {+ position: absolute;+ top: 0;+ bottom: 0;+ left: 0;+ width: 125%;+ background-size: 20% 100%;+ background-repeat: repeat;+ animation: agent-figure-flow 7s linear infinite;+}+@keyframes agent-figure-flow {+ from { transform: translateX(0); }+ to { transform: translateX(-20%); }+}++/* A shimmering design: a soft band of light crosses the body and rests before the next pass. */+.agent-figure-shine > i {+ position: absolute;+ top: -20%;+ bottom: -20%;+ left: -45%;+ width: 38%;+ background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.7), transparent);+ transform: translateX(0) skewX(-22deg);+ animation: agent-figure-shine 3.4s ease-in-out infinite;+}+@keyframes agent-figure-shine {+ 0% { transform: translateX(0) skewX(-22deg); }+ 55%, 100% { transform: translateX(490%) skewX(-22deg); }+}+@media (prefers-reduced-motion: reduce) {- .society-agent-figure > canvas { transition: none; }+ .society-agent-figure > .agent-figure-picture { transition: none; }.society-agent-figure > .agent-figure-halo { animation: none; }+ .agent-figure-flow > i > b { animation: none; }+ .agent-figure-shine > i { animation: none; transform: translateX(230%) skewX(-22deg); opacity: 0.5; }}diff --git a/jarvis/ui/web/frontend/src/components/society/companion/ShapeFigure.tsx b/jarvis/ui/web/frontend/src/components/society/companion/ShapeFigure.tsxindex 48bfef4272..b202a06b86 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/ShapeFigure.tsx+++ b/jarvis/ui/web/frontend/src/components/society/companion/ShapeFigure.tsx@@ -1,5 +1,5 @@import { useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react";-import { figureKey, type FigureLook } from "./figureScene";+import { figureKey, type FigureLook, type FigureSmoke } from "./figureScene";import { FIGURE_BROKEN, figuresSupported, readFigure, watchFigure, watchFigureSupport, type Figure } from "./figureStore";/** True while agent shapes can be drawn as 3D figures here; re-renders when that changes. */@@ -16,6 +16,36 @@ function figurePixels(size: number): number {return Math.max(8, Math.min(MAX_PIXELS, Math.round(size * ratio)));}+/**+ * The body's outline as an image a CSS mask can use: white where the body+ * is, by how much of each pixel it covers. Encoded on the CPU, once per+ * picture, and only for a look whose effect moves across the body. With+ * `grown`, the outline reaches one pixel further, so a layer cut to it+ * fully covers the body's soft edge.+ */+function outlineUrl(figure: Figure, grown: boolean): string | undefined {+ const body = figure.body;+ if (!body || typeof document === "undefined") return undefined;+ const sheet = document.createElement("canvas");+ const side = figure.pixels;+ sheet.width = side; sheet.height = side;+ const context = sheet.getContext("2d", { willReadFrequently: true });+ if (!context) return undefined;+ const pixels = new Uint8ClampedArray(side * side * 4).fill(255);+ for (let y = 0; y < side; y++) for (let x = 0; x < side; x++) {+ let cover = body[y * side + x]!;+ if (grown && cover < 255) {+ for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) {+ const nx = x + dx, ny = y + dy;+ if (nx >= 0 && ny >= 0 && nx < side && ny < side && body[ny * side + nx]! > cover) cover = body[ny * side + nx]!;+ }+ }+ pixels[(y * side + x) * 4 + 3] = cover;+ }+ context.putImageData(new ImageData(pixels, side, side), 0, 0);+ return sheet.toDataURL("image/png");+}+/*** An agent's shape as a 3D figure, `size` pixels wide. The picture is drawn* once by the figure worker and painted into a plain 2D canvas; until it is@@ -23,8 +53,12 @@ function figurePixels(size: number): number {* its way the previous picture stays. `children` is drawn over the eyes, in* the flat symbol's own units (a face with moving eyes). A look that cannot* be drawn shows `fallback` instead.+ *+ * What moves is laid over the still picture as compositor-only layers: the+ * colours of a flowing design (multiplied onto a white body), the shine of a+ * shimmering one, both cut to the body's outline, and the smoke of a cigar.*/-export function ShapeFigure({ look, size, shape, behind, children, overlay, fallback }: {+export function ShapeFigure({ look, size, shape, behind, children, overlay, fallback, flow, shine, smoke }: {look: FigureLook; size: number;/** Shown when this look could not be drawn and no earlier picture is there. */fallback: ReactNode;@@ -34,6 +68,12 @@ export function ShapeFigure({ look, size, shape, behind, children, overlay, fallbehind?: ReactNode;/** Drawn over the picture, unscaled (glints around the figure). */overlay?: ReactNode;+ /** The colours that flow across the body, and their direction as a CSS angle. */+ flow?: { colors: readonly string[]; angle: number };+ /** A shine sweeps across the body. */+ shine?: boolean;+ /** Draws one plume of smoke, in symbol units around its source. */+ smoke?: (plume: FigureSmoke, index: number) => ReactNode;children?: ReactNode;}) {const pixels = figurePixels(size);@@ -48,6 +88,9 @@ export function ShapeFigure({ look, size, shape, behind, children, overlay, fallif (figure && figure !== last) setLast(figure);const shown = figure ?? last;const canvas = useRef<HTMLCanvasElement>(null);+ // The outlines belong to one picture; they are set in the same pass that paints it, before the browser draws.+ const [outline, setOutline] = useState<{ of: Figure; body: string | undefined; whole: string | undefined }>();+ const flowing = !!flow;useLayoutEffect(() => {const node = canvas.current;if (!node || !shown) return;@@ -55,14 +98,33 @@ export function ShapeFigure({ look, size, shape, behind, children, overlay, fall// Painted on the CPU like the pixel creatures: many small GPU canvases can hold the UI thread.const context = node.getContext("2d", { willReadFrequently: true });context?.putImageData(new ImageData(shown.data, shown.pixels, shown.pixels), 0, 0);- }, [shown]);+ // Flowing colours are multiplied over the whole body and its soft edge, then the pair is cut to the picture itself.+ setOutline(current => current?.of === shown ? current+ : { of: shown, body: outlineUrl(shown, flowing), whole: flowing && shown.body ? node.toDataURL("image/png") : undefined });+ }, [shown, flowing]);if (answer === FIGURE_BROKEN && !shown) return <>{fallback}</>;- return <span className="society-agent-figure" data-agent-figure={shape} data-ready={shown ? "true" : undefined} style={{ width: size, height: size }}>+ const masked = (url: string | undefined) => url ? { maskImage: `url(${url})`, WebkitMaskImage: `url(${url})` } : undefined;+ const current = shown && outline?.of === shown ? outline : undefined;+ const cut = masked(current?.body);+ // A flowing body is white until its colours lie over it: show nothing rather than a white figure.+ const ready = !!shown && (!shown.body || !!cut);+ return <span className="society-agent-figure" data-agent-figure={shape} data-ready={ready ? "true" : undefined} style={{ width: size, height: size }}>{behind}- <canvas ref={canvas} aria-hidden />+ <span className="agent-figure-picture" style={flow ? masked(current?.whole) : undefined}>+ <canvas ref={canvas} aria-hidden />+ {cut && flow && <span aria-hidden className="agent-figure-flow" style={cut}>+ <i style={{ transform: `rotate(${flow.angle - 90}deg)` }}>+ <b style={{ backgroundImage: `linear-gradient(90deg, ${[...flow.colors, flow.colors[0]].join(", ")})` }} />+ </i>+ </span>}+ </span>+ {cut && shine && <span aria-hidden className="agent-figure-shine" style={cut}><i /></span>}{shown && children && <svg aria-hidden focusable="false" viewBox={`0 0 ${shown.pixels} ${shown.pixels}`} className="society-agent-symbol" data-expressive="true"><g transform={`matrix(${shown.face.map(value => +value.toFixed(4)).join(" ")})`}>{children}</g></svg>}+ {shown && smoke && shown.smoke.length > 0 && <svg aria-hidden focusable="false" viewBox={`0 0 ${shown.pixels} ${shown.pixels}`} className="society-agent-symbol" data-figure-smoke>+ {shown.smoke.map((plume, index) => <g key={index} transform={`translate(${+plume.x.toFixed(2)} ${+plume.y.toFixed(2)}) scale(${+plume.scale.toFixed(4)})`}>{smoke(plume, index)}</g>)}+ </svg>}{shown && overlay}</span>;}diff --git a/jarvis/ui/web/frontend/src/components/society/companion/figure.worker.ts b/jarvis/ui/web/frontend/src/components/society/companion/figure.worker.tsindex 76e4e2f3e2..3ec45436fc 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/figure.worker.ts+++ b/jarvis/ui/web/frontend/src/components/society/companion/figure.worker.ts@@ -5,8 +5,10 @@* the cheap half of the work. Terminating the worker releases everything.*/import { meshesByName, readGlb, type FigureMesh } from "./figureGlb";-import { shadeFigure, traceFigure, type FigureTrace } from "./figureRender";-import { figureFaceMatrix, figureParts, figureTraceKey, wearsAccessories, type FigureLook } from "./figureScene";+import { figureCover, shadeFigure, traceFigure, type FigureTrace } from "./figureRender";+import {+ bodyEffectMoves, figureFaceMatrix, figureParts, figureSmoke, figureTraceKey, wearsAccessories, type FigureLook, type FigureSmoke,+} from "./figureScene";export interface FigureRequest {id: number;@@ -19,7 +21,12 @@ export interface FigureRequest {}export type FigureResponse =- | { id: number; ok: true; pixels: number; data: ArrayBuffer; face: [number, number, number, number, number, number] }+ | {+ id: number; ok: true; pixels: number; data: ArrayBuffer; face: [number, number, number, number, number, number];+ /** How much of each pixel is body, one byte per pixel: only for a look whose effect moves across the body. */+ body?: ArrayBuffer;+ smoke: FigureSmoke[];+ }| { id: number; ok: false };type Meshes = Map<string, FigureMesh[]>;@@ -70,7 +77,11 @@ async function draw(request: FigureRequest): Promise<FigureResponse> {if (trace) { traces.delete(key); traces.set(key, trace); }else { trace = traceFigure(parts, pixels); remember(key, trace); }const image = shadeFigure(trace, parts);- return { id: request.id, ok: true, pixels, data: image.data.buffer as ArrayBuffer, face: figureFaceMatrix(look, bodies, image.frame) };+ return {+ id: request.id, ok: true, pixels, data: image.data.buffer as ArrayBuffer, face: figureFaceMatrix(look, bodies, image.frame),+ body: bodyEffectMoves(look) ? figureCover(trace, parts.map(part => !!part.body)).buffer : undefined,+ smoke: figureSmoke(look, image.frame),+ };}// One picture at a time, in the order asked.@@ -87,7 +98,7 @@ self.onmessage = (event: MessageEvent<FigureRequest>) => {console.warn("Companion figure unavailable", error);answer = { id: request.id, ok: false };}- if (answer.ok) (self as unknown as { postMessage: (message: FigureResponse, transfer: Transferable[]) => void }).postMessage(answer, [answer.data]);+ if (answer.ok) (self as unknown as { postMessage: (message: FigureResponse, transfer: Transferable[]) => void }).postMessage(answer, answer.body ? [answer.data, answer.body] : [answer.data]);else self.postMessage(answer);});};diff --git a/jarvis/ui/web/frontend/src/components/society/companion/figureRender.test.ts b/jarvis/ui/web/frontend/src/components/society/companion/figureRender.test.tsindex 4389ff793b..effb987b9a 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/figureRender.test.ts+++ b/jarvis/ui/web/frontend/src/components/society/companion/figureRender.test.ts@@ -5,8 +5,8 @@ import { describe, expect, it } from "vitest";import { ACCESSORY_CATALOG, ACCESSORY_ITEMS } from "./accessories";import { COMPANION_SHAPES } from "./appearance";import { meshesByName, readGlb } from "./figureGlb";-import { renderFigure, shadeFigure, traceFigure } from "./figureRender";-import { figureFaceMatrix, figureKey, figureParts, figureTraceKey, type FigureLook } from "./figureScene";+import { figureCover, renderFigure, shadeFigure, traceFigure } from "./figureRender";+import { bodyEffectMoves, EFFECT_FLOW, figureFaceMatrix, figureKey, figureParts, figureSmoke, figureTraceKey, type FigureLook } from "./figureScene";const ASSETS = path.resolve(__dirname, "../../../assets/society/companions");function load(name: string) {@@ -101,6 +101,44 @@ describe("3D profile faces", () => {expect(bottom[2]).toBeGreaterThan(bottom[0]);});+ it("draws a flowing design as a white, lit body and reports where the body is", () => {+ const skin = { colors: ["#22e3a5", "#8a5cf0"], radial: false, angle: 160, effect: EFFECT_FLOW, highlight: "#22e3a5" };+ const flowing = look({ skin, accessories: { head: "top_hat" } });+ expect(bodyEffectMoves(flowing)).toBe(true);+ expect(bodyEffectMoves(look())).toBe(false);+ const parts = figureParts(flowing, bodies, worn);+ const trace = traceFigure(parts, 64);+ const image = shadeFigure(trace, parts);+ const cover = figureCover(trace, parts.map(part => !!part.body));+ const [a, b, c, d, e, f] = figureFaceMatrix(flowing, bodies, image.frame);+ const eyeY = ACCESSORY_CATALOG.shapes.squircle.eyeY;+ const at = (x: number, y: number) => [Math.round(a * x + c * y + e), Math.round(b * x + d * y + f)] as const;+ // Below the eyes: body, drawn without the design's colours (they are laid over it as a moving layer).+ const [bodyX, bodyY] = at(20, eyeY + 6);+ const [red, green, blue] = pixel(image, bodyX, bodyY);+ expect(cover[bodyY * 64 + bodyX]).toBe(255);+ expect(Math.max(red, green, blue) - Math.min(red, green, blue)).toBeLessThan(40);+ // An eye and the hat are not body: the layer must not tint them.+ const [eyeX, eyeYPixel] = at(15.4, eyeY);+ expect(cover[eyeYPixel * 64 + eyeX]).toBeLessThan(128);+ let hat = -1;+ for (let y = 0; y < 64 && hat < 0; y++) for (let x = 0; x < 64; x++) if (pixel(image, x, y)[3] === 255) { hat = y * 64 + x; break; }+ expect(cover[hat]).toBe(0);+ });++ it("places the smoke of a cigar inside the picture", () => {+ const smoking = look({ accessories: { mouth: "cigar" } });+ const image = renderFigure(figureParts(smoking, bodies, worn), 96);+ const plumes = figureSmoke(smoking, image.frame);+ expect(plumes).toHaveLength(1);+ expect(plumes[0]!.x).toBeGreaterThan(48);+ expect(plumes[0]!.x).toBeLessThan(96);+ expect(plumes[0]!.y).toBeGreaterThan(24);+ expect(plumes[0]!.y).toBeLessThan(96);+ expect(plumes[0]!.scale).toBeGreaterThan(0);+ expect(figureSmoke(look(), image.frame)).toHaveLength(0);+ });+it("draws nothing for an empty figure", () => {expect(renderFigure([], 16).data.every(value => value === 0)).toBe(true);});diff --git a/jarvis/ui/web/frontend/src/components/society/companion/figureRender.ts b/jarvis/ui/web/frontend/src/components/society/companion/figureRender.tsindex c31ca9a48d..2bb9f9c515 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/figureRender.ts+++ b/jarvis/ui/web/frontend/src/components/society/companion/figureRender.ts@@ -388,7 +388,6 @@ export function shadeFigure(trace: FigureTrace, coats: readonly FigureCoat[]): Fif (paint.effect === 3) ring(paint.colors, along * 0.9, skin); else ramp(paint.colors, along, skin);cr = skin[0]!; cg = skin[1]!; cb = skin[2]!;if (paint.effect === 1) { const s = specks(bx, by, bz, 7, 0.3) * 2.2; er = s; eg = s; eb = s; }- if (paint.effect === 2) { const band = Math.exp(-(((bx + by * 0.6 + 0.12) * 6) ** 2)) * 0.4; er = band; eg = band; eb = band; }if (paint.effect === 4) { er = paint.highlight[0] * 0.3; eg = paint.highlight[1] * 0.3; eb = paint.highlight[2] * 0.3; }if (paint.effect === 5) { const s = specks(bx, by, bz, 5, 0.18) * 2.2; er = paint.highlight[0] * s; eg = paint.highlight[1] * s; eb = paint.highlight[2] * s; }}@@ -433,6 +432,27 @@ export function shadeFigure(trace: FigureTrace, coats: readonly FigureCoat[]): Freturn { size, data, frame: { k: k / samples, ox: ox / samples, oy: oy / samples, yaw, pitch } };}+/**+ * How much of each pixel shows the chosen parts, 0 to 255: the outline a+ * moving effect is cut to (a shine that sweeps the body must not cross the+ * hat). `chosen` holds one flag per part, in the order the parts were traced.+ */+export function figureCover(trace: FigureTrace, chosen: readonly boolean[]): Uint8ClampedArray<ArrayBuffer> {+ const { size, samples, owner } = trace;+ const width = size * samples;+ const cover = new Uint8ClampedArray(size * size);+ for (let y = 0; y < size; y++) {+ for (let x = 0; x < size; x++) {+ let hits = 0;+ for (let subY = 0; subY < samples; subY++) for (let subX = 0; subX < samples; subX++) {+ if (chosen[owner[(y * samples + subY) * width + x * samples + subX]! - 1]) hits++;+ }+ cover[y * size + x] = Math.round(hits * 255 / (samples * samples));+ }+ }+ return cover;+}+/*** Renders the parts into a square image `size` pixels wide. The figure is* fitted into the square whatever it wears, so a tall hat makes the body adiff --git a/jarvis/ui/web/frontend/src/components/society/companion/figureScene.ts b/jarvis/ui/web/frontend/src/components/society/companion/figureScene.tsindex 319b29773e..0e79ba27a0 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/figureScene.ts+++ b/jarvis/ui/web/frontend/src/components/society/companion/figureScene.ts@@ -22,6 +22,16 @@ export interface FigureLook {}const INK: LinearRgb = [0.0052, 0.0052, 0.007];+/** Indices in SKIN_EFFECTS of the two effects that move across the body. */+export const EFFECT_SHIMMER = 2, EFFECT_FLOW = 3;++/** True when a moving layer is cut to the body's outline, so the picture needs its cover. */+export function bodyEffectMoves(look: FigureLook): boolean {+ return look.skin?.effect === EFFECT_SHIMMER || look.skin?.effect === EFFECT_FLOW;+}++/** A plume of smoke over the picture: where it rises, pixels, and how large one symbol unit is there. */+export interface FigureSmoke { x: number; y: number; scale: number; size: number; fill: string }/** A `#rrggbb` colour in linear light. */export function linearRgb(hex: string): LinearRgb {@@ -57,9 +67,15 @@ export function figureParts(look: FigureLook, bodies: ReadonlyMap<string, Figurecolors: look.skin.colors.map(linearRgb), radial: look.skin.radial, angle: look.skin.angle,effect: look.skin.effect, highlight: linearRgb(look.skin.highlight),};+ // Flowing colours are laid over the picture as a moving layer (ShapeFigure), which+ // multiplies a white body: the picture carries only its light and shade.+ const flowing = paint?.effect === EFFECT_FLOW;for (const mesh of bodies.get(`${look.shape}.Body`) ?? []) {// A soft vinyl sheen lets the light show the volume; a shimmering design is glossier.- parts.push({ mesh, color, finish: "matte", roughness: paint?.effect === 2 ? 0.38 : 0.62, paint, body: true });+ parts.push({+ mesh, color: flowing ? [1, 1, 1] : color, finish: "matte", roughness: paint?.effect === EFFECT_SHIMMER ? 0.38 : 0.62,+ paint: flowing ? undefined : paint, body: true,+ });}const kind = look.eyes === "dots" ? "Dots" : "Lines";const eyes = [0, 1].flatMap(side => bodies.get(`${look.shape}.${kind}.${side}`) ?? []);@@ -112,6 +128,27 @@ export function figureFaceMatrix(look: FigureLook, bodies: ReadonlyMap<string, Freturn [right[0] - origin[0], right[1] - origin[1], down[0] - origin[0], down[1] - origin[1], origin[0], origin[1]];}+/**+ * Where worn items smoke (a cigar), placed like the map companion places its+ * plume: the picture shows the item, the face draws the moving puffs on top.+ */+export function figureSmoke(look: FigureLook, frame: FigureFrame): FigureSmoke[] {+ const meta = ACCESSORY_CATALOG.shapes[look.shape];+ const unit = 1 / (meta.bottom - meta.top);+ const plumes: FigureSmoke[] = [];+ for (const item of wornAccessories(look.accessories)) {+ const [x, y, k] = meta.anchors[item.slot];+ const size = k * (item.scale ?? 1) * unit;+ const depth = slotDepthM(look.shape, item.slot);+ for (const part of item.parts) {+ if (part.t !== "smoke") continue;+ const [px, py] = projectFigure(frame, (x - 20) * unit + part.c[0] * size, (meta.bottom - y) * unit - part.c[1] * size, depth + part.c[2] * size);+ plumes.push({ x: px, y: py, scale: frame.k * size, size: part.size, fill: part.fill });+ }+ }+ return plumes;+}+/** Names what a figure is made of, whatever its colours: equal keys trace alike. */export function figureTraceKey(look: FigureLook, pixels: number): string {return `${look.shape}|${look.blind ? "blind" : look.eyes}|${wornAccessories(look.accessories).map(item => item.id).join(",")}|${pixels}`;diff --git a/jarvis/ui/web/frontend/src/components/society/companion/figureStore.ts b/jarvis/ui/web/frontend/src/components/society/companion/figureStore.tsindex bba4eb5245..a5322912fc 100644--- a/jarvis/ui/web/frontend/src/components/society/companion/figureStore.ts+++ b/jarvis/ui/web/frontend/src/components/society/companion/figureStore.ts@@ -8,7 +8,7 @@import accessoryModels from "@/assets/society/companions/accessories.glb";import companionModels from "@/assets/society/companions/companions.glb";import type { FigureRequest, FigureResponse } from "./figure.worker";-import { figureKey, type FigureLook } from "./figureScene";+import { figureKey, type FigureLook, type FigureSmoke } from "./figureScene";export interface Figure {/** Width and height, device pixels. */@@ -17,6 +17,10 @@ export interface Figure {data: Uint8ClampedArray<ArrayBuffer>;/** SVG matrix from flat symbol units to picture pixels, at the eyes (figureFaceMatrix). */face: [number, number, number, number, number, number];+ /** How much of each pixel is body, one byte per pixel; only where an effect moves across the body. */+ body?: Uint8ClampedArray<ArrayBuffer>;+ /** Where worn items smoke, in picture pixels. */+ smoke: FigureSmoke[];}/** The most picture memory kept, bytes. */@@ -102,12 +106,12 @@ function giveUp(key: string): void {function keep(key: string, figure: Figure): void {pictures.set(key, figure);- pictureBytes += figure.data.byteLength;+ pictureBytes += figure.data.byteLength + (figure.body?.byteLength ?? 0);// Oldest first; a Map keeps insertion order. A face that still shows an evicted picture keeps its own copy.for (const [old, value] of pictures) {if (pictureBytes <= PICTURE_BUDGET || old === key) break;pictures.delete(old);- pictureBytes -= value.data.byteLength;+ pictureBytes -= value.data.byteLength + (value.body?.byteLength ?? 0);}}@@ -119,7 +123,10 @@ function answer(message: FigureResponse): void {if (!message.ok) { giveUp(key); return; }current = undefined;workerFailures = 0;- keep(key, { pixels: message.pixels, data: new Uint8ClampedArray(message.data), face: message.face });+ keep(key, {+ pixels: message.pixels, data: new Uint8ClampedArray(message.data), face: message.face,+ body: message.body && new Uint8ClampedArray(message.body), smoke: message.smoke,+ });const entry = wanted.get(key);wanted.delete(key);entry?.listeners.forEach(listener => listener());