Cartoon: rig, movimento e lip sync dos personagens
- cartoon/src/rig.ts, motion.ts e lipsync.ts: esqueleto do personagem, curvas de movimento e sincronia labial no estilo Cartoon (Remotion) - CharacterFigure/CharacterCard/Shot/overlays e spec atualizados - Painel: estúdio de personagens e montagem cartoon ajustados - Documentação em doc/cartoon/animacao.md e personagens.md; skill atualizada Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
"exports": {
|
||||
"./character": "./src/character.ts",
|
||||
"./figure": "./src/CharacterFigure.tsx",
|
||||
"./spec": "./src/spec.ts"
|
||||
"./spec": "./src/spec.ts",
|
||||
"./motion": "./src/motion.ts",
|
||||
"./rig": "./src/rig.ts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import React from "react";
|
||||
import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
|
||||
import { CharacterFigure } from "./CharacterFigure";
|
||||
import { TagLabel } from "./overlays";
|
||||
import { Grain, TagLabel } from "./overlays";
|
||||
import { loadFonts } from "./theme";
|
||||
import type { CharacterLook, Expression, Pose } from "./character";
|
||||
import type { IconId } from "./spec";
|
||||
@@ -13,25 +13,36 @@ loadFonts();
|
||||
export type CardProps = {
|
||||
width: number; height: number;
|
||||
background?: string;
|
||||
/** "face": enquadra só a cabeça (conferir expressões de perto). */
|
||||
framing?: "full" | "face";
|
||||
figures: { look: CharacterLook; expression?: Expression; pose?: Pose; item?: IconId; label?: string }[];
|
||||
};
|
||||
|
||||
export function CharacterCard({ figures, background = "#2a2e45" }: CardProps) {
|
||||
export function CharacterCard({ figures, background = "#2a2e45", framing = "full" }: CardProps) {
|
||||
const frame = useCurrentFrame();
|
||||
const { fps } = useVideoConfig();
|
||||
const n = Math.max(1, figures.length);
|
||||
return (
|
||||
<AbsoluteFill style={{ background, containerType: "size" }}>
|
||||
<div style={{ position: "absolute", inset: "8% 2% 4%", display: "grid", gridTemplateColumns: `repeat(${n}, 1fr)`, alignItems: "end" }}>
|
||||
<div style={{ position: "absolute", inset: "8% 2% 4%", display: "grid", gridTemplateColumns: `repeat(${n}, minmax(0, 1fr))`, alignItems: "end" }}>
|
||||
{figures.map((f, i) => (
|
||||
<div key={i} style={{ position: "relative", height: "100%", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "flex-end" }}>
|
||||
{f.label && <div style={{ marginBottom: "4%" }}><TagLabel text={f.label} size={n > 3 ? 2.2 : 3.4} /></div>}
|
||||
<div style={{ width: "90%", aspectRatio: "200 / 440", maxHeight: "86%" }}>
|
||||
<CharacterFigure look={f.look} expression={f.expression} pose={f.pose} item={f.item} t={frame / fps} />
|
||||
</div>
|
||||
{framing === "face" ? (
|
||||
<div style={{ width: "92%", aspectRatio: "1 / 1", overflow: "hidden", position: "relative" }}>
|
||||
<div style={{ position: "absolute", left: "-60%", top: "-64%", width: "220%", aspectRatio: "200 / 440" }}>
|
||||
<CharacterFigure look={f.look} expression={f.expression} pose={f.pose} item={f.item} t={frame / fps} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ width: "90%", aspectRatio: "200 / 440", maxHeight: "86%" }}>
|
||||
<CharacterFigure look={f.look} expression={f.expression} pose={f.pose} item={f.item} t={frame / fps} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<Grain />
|
||||
</AbsoluteFill>
|
||||
);
|
||||
}
|
||||
|
||||
+299
-138
@@ -1,78 +1,100 @@
|
||||
// Desenho do personagem a partir das peças (character.ts). SVG puro, sem Remotion: o painel usa o mesmo
|
||||
// componente na prévia ao vivo da aba Personagens. viewBox 200×440 com os pés em (100, 440).
|
||||
// `t` (segundos) só move detalhes vivos: respiração, piscar, braço acenando.
|
||||
import React from "react";
|
||||
// Desenho do personagem a partir do RIG (rig.ts): rosto e corpo por parâmetros contínuos, braços e pernas em
|
||||
// dois segmentos (ombro/cotovelo, quadril/joelho). SVG puro, sem Remotion: o painel usa o mesmo componente.
|
||||
// viewBox 200×440, pés em (100, 440). O movimento (andar, pular, falar…) vem de motion.ts como `state`; sem ele,
|
||||
// usa a expressão/pose pedida com a "vida" (piscar, respirar). Posição, giro e espelho ficam por conta de quem
|
||||
// desenha a cena (Shot.tsx).
|
||||
import React, { useId } from "react";
|
||||
import { Icon } from "./icons";
|
||||
import type { IconId } from "./spec";
|
||||
import { DEFAULT_LOOK, type CharacterLook, type Expression, type Pose } from "./character";
|
||||
import { DEFAULT_LOOK, type CharacterLook } from "./character";
|
||||
import { evaluate, type ActorState } from "./motion";
|
||||
import type { BodyParams, FaceParams, Limb } from "./rig";
|
||||
|
||||
const INK = "#15161f";
|
||||
|
||||
/** Ângulo dos braços por pose (graus; 0 = para baixo). Direito negativo = para fora; esquerdo positivo = para fora. */
|
||||
const ARMS: Record<Pose, [number, number]> = {
|
||||
stand: [-8, 8], point: [-95, 8], wave: [-150, 8], hold: [-38, 8], arms_up: [-160, 160], shrug: [-55, 55], think: [150, 8],
|
||||
};
|
||||
|
||||
function shade(hex: string, k: number): string {
|
||||
const n = parseInt(hex.slice(1), 16);
|
||||
const c = (v: number) => Math.max(0, Math.min(255, Math.round(v * k))).toString(16).padStart(2, "0");
|
||||
return `#${c((n >> 16) & 255)}${c((n >> 8) & 255)}${c(n & 255)}`;
|
||||
}
|
||||
/** Ponta de um segmento: ângulo de tela em graus (0 = para baixo). */
|
||||
const tip = (x: number, y: number, deg: number, len: number) => {
|
||||
const r = (deg * Math.PI) / 180;
|
||||
return { x: x - Math.sin(r) * len, y: y + Math.cos(r) * len };
|
||||
};
|
||||
|
||||
function Mouth({ expression }: { expression: Expression }) {
|
||||
const common = { stroke: INK, strokeWidth: 4.5, fill: "none", strokeLinecap: "round" as const };
|
||||
switch (expression) {
|
||||
case "happy": return <path d="M84 131 Q100 150 116 131 Q100 140 84 131 Z" fill={INK} />;
|
||||
case "sad": return <path d="M87 141 Q100 129 113 141" {...common} />;
|
||||
case "worried": return <path d="M86 139 Q93 133 100 139 Q107 145 114 139" {...common} />;
|
||||
case "angry": return <path d="M87 139 L113 136" {...common} strokeWidth={6} />;
|
||||
case "surprised": return <ellipse cx={100} cy={139} rx={8} ry={10} fill={INK} />;
|
||||
case "scared": return <ellipse cx={100} cy={140} rx={10} ry={7} fill={INK} />;
|
||||
default: return <path d="M88 136 Q100 140 112 136" {...common} />;
|
||||
function Segment({ x, y, deg, len, w, fill }: { x: number; y: number; deg: number; len: number; w: number; fill: string }) {
|
||||
return <rect x={x - w / 2} y={y - w / 2} width={w} height={len + w / 2} rx={w / 2} fill={fill} transform={`rotate(${deg} ${x} ${y})`} />;
|
||||
}
|
||||
|
||||
function Mouth({ f, uid }: { f: FaceParams; uid: string }) {
|
||||
const w = 32 * f.mouthWidth * (1 - f.mouthRound * 0.35);
|
||||
const cy = 137 - f.smile * 6;
|
||||
if (f.mouthOpen < 0.06 && f.mouthRound < 0.3) {
|
||||
return <path d={`M${100 - w / 2} ${cy} Q100 ${137 + f.smile * 12} ${100 + w / 2} ${cy}`} stroke={INK} strokeWidth={5} fill="none" strokeLinecap="round" />;
|
||||
}
|
||||
}
|
||||
|
||||
function Brows({ expression, thick, color }: { expression: Expression; thick: boolean; color: string }) {
|
||||
// Inclinação da sobrancelha esquerda (a direita espelha): + sobe por dentro (triste/preocupado), − desce (bravo).
|
||||
const tilt = { neutral: 0, happy: -6, sad: 16, worried: 14, angry: -18, surprised: 0, scared: 18 }[expression];
|
||||
const lift = expression === "surprised" || expression === "scared" ? -7 : expression === "happy" ? -3 : 0;
|
||||
const w = thick ? 7 : 4.5;
|
||||
return (
|
||||
<g stroke={color} strokeWidth={w} strokeLinecap="round">
|
||||
<line x1={71} y1={89 + lift} x2={92} y2={89 + lift} transform={`rotate(${tilt} 92 ${89 + lift})`} />
|
||||
<line x1={108} y1={89 + lift} x2={129} y2={89 + lift} transform={`rotate(${-tilt} 108 ${89 + lift})`} />
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function Eyes({ expression, t }: { expression: Expression; t: number }) {
|
||||
const big = expression === "surprised" || expression === "scared";
|
||||
const r = big ? 12.5 : 10.5;
|
||||
const pupil = expression === "scared" ? 3.4 : big ? 5.5 : 5;
|
||||
const blink = (t % 3.7) < 0.12 && !big ? 0.12 : 1;
|
||||
const squint = expression === "angry" ? 0.7 : expression === "happy" ? 0.8 : 1;
|
||||
const open = Math.max(f.mouthOpen, f.mouthRound * 0.25);
|
||||
// A curva quadrática só chega à metade do ponto de controle: os controles ficam no dobro da abertura desejada.
|
||||
const up = cy + f.smile * 2 - open * 8 - f.mouthRound * 6;
|
||||
const low = cy + open * 46 * (1 + f.mouthRound * 0.3) + f.smile * 12;
|
||||
const d = `M${100 - w / 2} ${cy} Q100 ${up} ${100 + w / 2} ${cy} Q100 ${low} ${100 - w / 2} ${cy} Z`;
|
||||
return (
|
||||
<g>
|
||||
{[82, 118].map((x) => (
|
||||
<g key={x} transform={`translate(${x} 108) scale(1 ${blink * squint})`}>
|
||||
<circle r={r} fill="#ffffff" />
|
||||
<circle r={pupil} cx={expression === "worried" ? -1.5 : 0} cy={expression === "sad" ? 2 : 0} fill={INK} />
|
||||
</g>
|
||||
))}
|
||||
<defs><clipPath id={`m${uid}`}><path d={d} /></clipPath></defs>
|
||||
<path d={d} fill={INK} />
|
||||
<g clipPath={`url(#m${uid})`}>
|
||||
{f.teeth && open > 0.12 && <rect x={60} y={Math.min(up, cy) - 10} width={80} height={(cy - Math.min(up, cy)) + 10 + (low - cy) * 0.16} fill="#f7f7f2" />}
|
||||
{open > 0.4 && <ellipse cx={100} cy={cy + (low - cy) * 0.5} rx={w * 0.3} ry={(low - cy) * 0.16} fill="#d9534f" />}
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function Glasses({ kind }: { kind: CharacterLook["glasses"] }) {
|
||||
if (kind === "none") return null;
|
||||
const lens = kind === "sun" ? INK : "none";
|
||||
function Eyes({ f, lid, skin, uid }: { f: FaceParams; lid: number; skin: string; uid: string }) {
|
||||
const big = Math.max(f.eyeL, f.eyeR);
|
||||
const r = 10.5 + Math.max(0, big - 1) * 7;
|
||||
const cover = Math.max(0, Math.min(0.85, lid));
|
||||
const eye = (x: number, open: number) => {
|
||||
// Olho de riso: fechado em arco para cima quando quase fechado e sorrindo.
|
||||
if (open < 0.3 && f.smile > 0.55) return <path key={x} d={`M${x - 10} 110 Q${x} 98 ${x + 10} 110`} stroke={INK} strokeWidth={4.5} fill="none" strokeLinecap="round" />;
|
||||
if (open < 0.14) return <path key={x} d={`M${x - 10} 108 Q${x} 113 ${x + 10} 108`} stroke={INK} strokeWidth={4} fill="none" strokeLinecap="round" />;
|
||||
return (
|
||||
<g key={x} transform={`translate(${x} 108) scale(1 ${Math.min(1.2, open)})`}>
|
||||
<defs><clipPath id={`e${uid}${x}`}><circle r={r} /></clipPath></defs>
|
||||
<circle r={r} fill="#ffffff" />
|
||||
<circle r={Math.max(2.2, 5 * f.pupil)} cx={f.gazeX * 4} cy={f.gazeY * 3 + cover * 3} fill={INK} />
|
||||
<circle r={1.6} cx={f.gazeX * 4 + 1.8} cy={f.gazeY * 3 - 1.8 + cover * 3} fill="#ffffff" opacity={0.85} />
|
||||
{cover > 0.02 && (
|
||||
<g clipPath={`url(#e${uid}${x})`}>
|
||||
<rect x={-r - 1} y={-r - 1} width={2 * r + 2} height={2 * r * cover + 1} fill={skin} />
|
||||
<path d={`M${-r} ${-r + 2 * r * cover} Q0 ${-r + 2 * r * cover + 3} ${r} ${-r + 2 * r * cover}`} stroke={shade(skin, 0.6)} strokeWidth={2.6} fill="none" />
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
};
|
||||
return <g>{eye(82, f.eyeL)}{eye(118, f.eyeR)}</g>;
|
||||
}
|
||||
|
||||
function Brows({ f, thick, color }: { f: FaceParams; thick: boolean; color: string }) {
|
||||
return (
|
||||
<g stroke={INK} strokeWidth={4} fill={lens}>
|
||||
{kind === "square"
|
||||
? <><rect x={67} y={95} width={30} height={25} rx={5} /><rect x={103} y={95} width={30} height={25} rx={5} /></>
|
||||
: <><circle cx={82} cy={108} r={15} /><circle cx={118} cy={108} r={15} /></>}
|
||||
<line x1={97} y1={107} x2={103} y2={107} />
|
||||
<line x1={55} y1={104} x2={67} y2={106} /><line x1={133} y1={106} x2={145} y2={104} />
|
||||
<g stroke={color} strokeWidth={thick ? 7 : 4.5} strokeLinecap="round">
|
||||
<line x1={71} y1={89 + f.browL.y} x2={92} y2={89 + f.browL.y} transform={`rotate(${-f.browL.tilt} 92 ${89 + f.browL.y})`} />
|
||||
<line x1={108} y1={89 + f.browR.y} x2={129} y2={89 + f.browR.y} transform={`rotate(${f.browR.tilt} 108 ${89 + f.browR.y})`} />
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function Extras({ f, t }: { f: FaceParams; t: number }) {
|
||||
return (
|
||||
<g>
|
||||
{f.blush > 0.02 && <><ellipse cx={72} cy={124} rx={11} ry={6} fill="#ff6b8b" opacity={0.55 * f.blush} /><ellipse cx={128} cy={124} rx={11} ry={6} fill="#ff6b8b" opacity={0.55 * f.blush} /></>}
|
||||
{f.sweat && <path d="M146 74 Q152 86 146 92 Q140 86 146 74 Z" fill="#8fd3ff" stroke="#3a8fd0" strokeWidth={1.5} />}
|
||||
{f.tears && [78, 122].map((x, i) => {
|
||||
const k = ((t * 1.4 + i * 0.5) % 1);
|
||||
return <path key={x} d={`M${x} ${116 + k * 26} q4 6 0 9 q-4 -3 0 -9 Z`} fill="#8fd3ff" opacity={1 - k * 0.6} />;
|
||||
})}
|
||||
{f.anger && <g stroke="#e8463d" strokeWidth={4} strokeLinecap="round" fill="none"><path d="M128 62 q6 4 12 0" /><path d="M128 74 q6 -4 12 0" /><path d="M128 62 q-4 6 0 12" /><path d="M140 62 q4 6 0 12" /></g>}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
@@ -81,15 +103,57 @@ function Beard({ style, color }: { style: CharacterLook["beard"]["style"]; color
|
||||
switch (style) {
|
||||
case "full": return <path d="M56 108 Q58 168 100 172 Q142 168 144 108 Q138 128 124 126 Q100 122 76 126 Q62 128 56 108 Z" fill={color} />;
|
||||
case "stubble": return <path d="M60 116 Q64 162 100 166 Q136 162 140 116 Q130 132 100 128 Q70 132 60 116 Z" fill={color} opacity={0.35} />;
|
||||
case "goatee": return <path d="M88 146 Q100 166 112 146 Q100 152 88 146 Z" fill={color} />;
|
||||
case "mustache": return <path d="M82 128 Q100 120 118 128 Q110 134 100 130 Q90 134 82 128 Z" fill={color} />;
|
||||
case "goatee": return <path d="M88 150 Q100 168 112 150 Q100 156 88 150 Z" fill={color} />;
|
||||
case "mustache": return <path d="M76 134 Q80 117 100 121 Q120 117 124 134 Q113 128 100 131 Q87 128 76 134 Z" fill={color} />;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
function HairBack({ look }: { look: CharacterLook }) {
|
||||
if (look.hair.style !== "long") return null;
|
||||
return <path d="M50 100 Q48 40 100 38 Q152 40 150 100 L156 190 Q100 205 44 190 Z" fill={look.hair.color} />;
|
||||
function Nose({ kind, skin }: { kind: NonNullable<CharacterLook["nose"]>; skin: string }) {
|
||||
const dark = shade(skin, 0.72);
|
||||
switch (kind) {
|
||||
case "curve": return <path d="M97 110 Q86 123 95 128 Q101 131 105 126" stroke={dark} strokeWidth={3.6} fill="none" strokeLinecap="round" />;
|
||||
case "round": return <><circle cx={100} cy={121} r={9} fill={shade(skin, 0.9)} /><circle cx={97} cy={118} r={2.5} fill="#ffffff" opacity={0.35} /></>;
|
||||
case "long": return <path d="M99 104 L104 126 Q100 131 94 127" stroke={dark} strokeWidth={3.4} fill="none" strokeLinecap="round" strokeLinejoin="round" />;
|
||||
case "wide": return <><ellipse cx={100} cy={123} rx={11} ry={7} fill={shade(skin, 0.9)} /><circle cx={95} cy={125} r={2} fill={dark} /><circle cx={105} cy={125} r={2} fill={dark} /></>;
|
||||
default: return <ellipse cx={100} cy={123} rx={6} ry={4.5} fill={shade(skin, 0.86)} />;
|
||||
}
|
||||
}
|
||||
|
||||
function Wrinkles({ k, skin }: { k: number; skin: string }) {
|
||||
if (k <= 0.05) return null;
|
||||
const c = shade(skin, 0.78);
|
||||
return (
|
||||
<g stroke={c} strokeWidth={3} fill="none" strokeLinecap="round" opacity={Math.min(1, 0.5 + k * 0.5)}>
|
||||
<path d="M80 72 Q100 66 120 72" />
|
||||
{k > 0.35 && <path d="M84 80 Q100 75 116 80" />}
|
||||
{k > 0.5 && <><path d="M62 104 l-6 -3 M62 110 l-7 0" /><path d="M138 104 l6 -3 M138 110 l7 0" /></>}
|
||||
{k > 0.4 && <><path d="M76 128 Q72 138 76 146" /><path d="M124 128 Q128 138 124 146" /></>}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
/** Formato da cabeça (centro (100,106)). */
|
||||
function headPath(shape: CharacterLook["head"]): string {
|
||||
switch (shape) {
|
||||
case "oval": return "M100 54 C126 54 143 76 143 106 C143 140 124 160 100 160 C76 160 57 140 57 106 C57 76 74 54 100 54 Z";
|
||||
case "square": return "M100 56 C130 56 147 72 147 100 L146 128 C144 150 126 158 100 158 C74 158 56 150 54 128 L53 100 C53 72 70 56 100 56 Z";
|
||||
case "wide": return "M100 58 C124 58 140 74 143 98 C148 124 140 154 100 158 C60 154 52 124 57 98 C60 74 76 58 100 58 Z";
|
||||
default: return "M100 56 C126 56 147 78 147 106 C147 134 126 156 100 156 C74 156 53 134 53 106 C53 78 74 56 100 56 Z";
|
||||
}
|
||||
}
|
||||
|
||||
function Glasses({ kind }: { kind: CharacterLook["glasses"] }) {
|
||||
if (kind === "none") return null;
|
||||
return (
|
||||
<g stroke={INK} strokeWidth={4} fill={kind === "sun" ? INK : "none"}>
|
||||
{kind === "square"
|
||||
? <><rect x={67} y={95} width={30} height={25} rx={5} /><rect x={103} y={95} width={30} height={25} rx={5} /></>
|
||||
: <><circle cx={82} cy={108} r={15} /><circle cx={118} cy={108} r={15} /></>}
|
||||
<line x1={97} y1={107} x2={103} y2={107} />
|
||||
<line x1={55} y1={104} x2={67} y2={106} /><line x1={133} y1={106} x2={145} y2={104} />
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function HairFront({ look }: { look: CharacterLook }) {
|
||||
@@ -107,92 +171,189 @@ function HairFront({ look }: { look: CharacterLook }) {
|
||||
}
|
||||
}
|
||||
|
||||
function Torso({ look, w }: { look: CharacterLook; w: number }) {
|
||||
const { top } = look;
|
||||
const x0 = 100 - 36 * w;
|
||||
const x1 = 100 + 36 * w;
|
||||
const bottomY = top.style === "dress" ? 345 : 290;
|
||||
const flare = top.style === "dress" ? 14 : 0;
|
||||
const body = `M${x0} 172 Q${x0} 158 ${x0 + 14} 156 L${x1 - 14} 156 Q${x1} 158 ${x1} 172 L${x1 + flare} ${bottomY} L${x0 - flare} ${bottomY} Z`;
|
||||
const accent = top.accent ?? shade(top.color, 1.3);
|
||||
/** Cabeça inteira no sistema antigo (centro ~ (100,106)); `turn` desloca o rosto para fingir 3/4, `nod` sobe/desce. */
|
||||
function Head({ look, f, b, t, uid }: { look: CharacterLook; f: FaceParams; b: BodyParams; t: number; uid: string }) {
|
||||
const fx = b.headTurn * 9;
|
||||
const fy = b.headNod * 6;
|
||||
const browColor = look.hair.style === "bald" || look.hair.style === "cap" ? look.beard.color : look.hair.color;
|
||||
return (
|
||||
<g>
|
||||
{top.style === "hoodie" && <path d={`M${x0 + 6} 160 Q100 132 ${x1 - 6} 160 Z`} fill={shade(top.color, 0.8)} />}
|
||||
<path d={body} fill={top.color} />
|
||||
{top.style === "uniform" && <rect x={x0} y={248} width={x1 - x0} height={11} fill={accent} />}
|
||||
{top.style === "shirt" && top.accent && <rect x={x0} y={252} width={x1 - x0} height={9} fill={accent} />}
|
||||
{top.style === "jacket" && <><path d={`M100 158 L100 ${bottomY}`} stroke={shade(top.color, 0.6)} strokeWidth={4} /><path d="M86 158 L100 186 L114 158 Z" fill={accent} /></>}
|
||||
{top.style === "hoodie" && <rect x={84} y={240} width={32} height={22} rx={6} fill={shade(top.color, 0.85)} />}
|
||||
{top.style === "dress" && [0, 1, 2, 3].map((i) => <circle key={i} cx={84 + (i % 2) * 32} cy={196 + Math.floor(i / 2) * 70} r={3.5} fill="#ffffff" opacity={0.5} />)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
function Legs({ look, w }: { look: CharacterLook; w: number }) {
|
||||
const { bottom } = look;
|
||||
const gap = 10 * w;
|
||||
const legW = 20 * w;
|
||||
const left = 100 - gap - legW;
|
||||
const right = 100 + gap;
|
||||
const skinTop = look.top.style === "dress" ? 345 : bottom.style === "shorts" ? 330 : bottom.style === "skirt" ? 345 : 440;
|
||||
return (
|
||||
<g>
|
||||
<rect x={left} y={286} width={legW} height={140} rx={6} fill={look.skin} />
|
||||
<rect x={right} y={286} width={legW} height={140} rx={6} fill={look.skin} />
|
||||
{look.top.style !== "dress" && bottom.style === "pants" && <><rect x={left} y={284} width={legW} height={142} rx={4} fill={bottom.color} /><rect x={right} y={284} width={legW} height={142} rx={4} fill={bottom.color} /></>}
|
||||
{look.top.style !== "dress" && bottom.style === "shorts" && <path d={`M${left - 2} 284 L${right + legW + 2} 284 L${right + legW + 2} ${skinTop} L${left - 2} ${skinTop} Z`} fill={bottom.color} />}
|
||||
{look.top.style !== "dress" && bottom.style === "skirt" && <path d={`M${left + 2} 284 L${right + legW - 2} 284 L${right + legW + 12} ${skinTop} L${left - 12} ${skinTop} Z`} fill={bottom.color} />}
|
||||
<rect x={left - 4} y={422} width={legW + 10} height={16} rx={7} fill={look.shoes} />
|
||||
<rect x={right - 6} y={422} width={legW + 10} height={16} rx={7} fill={look.shoes} />
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
export function CharacterFigure({ look = DEFAULT_LOOK, expression = "neutral", pose = "stand", item, t = 0 }: {
|
||||
look?: CharacterLook; expression?: Expression; pose?: Pose; item?: IconId; t?: number;
|
||||
}) {
|
||||
const w = look.build === "slim" ? 0.86 : look.build === "heavy" ? 1.22 : 1;
|
||||
const breathe = Math.sin(t * 2.2) * 1.6;
|
||||
const [r0, l0] = ARMS[pose];
|
||||
const swing = pose === "wave" ? Math.sin(t * 9) * 14 : Math.sin(t * 1.4) * 2.5;
|
||||
const rAngle = r0 + swing;
|
||||
const lAngle = l0 - (pose === "wave" ? 0 : swing);
|
||||
const shoulderY = 168;
|
||||
const sx = 34 * w;
|
||||
const sleeve = look.top.style === "dress" ? look.skin : look.top.color;
|
||||
const arm = (side: 1 | -1, angle: number, holds?: IconId) => (
|
||||
<g transform={`rotate(${angle} ${100 + side * sx} ${shoulderY})`}>
|
||||
<rect x={100 + side * sx - 9} y={shoulderY - 6} width={18} height={104} rx={9} fill={sleeve} />
|
||||
<circle cx={100 + side * sx} cy={shoulderY + 102} r={11} fill={look.skin} />
|
||||
{holds && (
|
||||
<g transform={`translate(${100 + side * sx - 26} ${shoulderY + 96}) rotate(${-angle} 26 26)`}>
|
||||
<svg x={0} y={0} width={52} height={52} viewBox="0 0 100 100" overflow="visible"><Icon id={holds} /></svg>
|
||||
{[53, 147].map((x, i) => (
|
||||
<g key={x} transform={`translate(${x + b.headTurn * 7} 112) scale(${1 - (i === 0 ? Math.max(0, b.headTurn) : -Math.min(0, b.headTurn)) * 0.5} 1)`}>
|
||||
<ellipse rx={9} ry={12} fill={shade(look.skin, 0.94)} />
|
||||
<path d={i === 0 ? "M3 -6 Q-4 0 3 6" : "M-3 -6 Q4 0 -3 6"} stroke={shade(look.skin, 0.72)} strokeWidth={2.4} fill="none" strokeLinecap="round" />
|
||||
</g>
|
||||
))}
|
||||
<defs><clipPath id={`h${uid}`}><path d={headPath(look.head)} /></clipPath></defs>
|
||||
<path d={headPath(look.head)} fill={look.skin} />
|
||||
{/* Sombra suave do lado de baixo/direito e brilho na testa: volume de ilustração. */}
|
||||
<g clipPath={`url(#h${uid})`}>
|
||||
<ellipse cx={128} cy={140} rx={44} ry={34} fill={shade(look.skin, 0.86)} opacity={0.55} />
|
||||
<ellipse cx={86} cy={72} rx={22} ry={12} fill="#ffffff" opacity={0.12} />
|
||||
</g>
|
||||
<g transform={`translate(${fx} ${fy})`}>
|
||||
<Wrinkles k={look.wrinkles ?? 0} skin={look.skin} />
|
||||
<Beard style={look.beard.style} color={look.beard.color} />
|
||||
<Extras f={f} t={t} />
|
||||
<Eyes f={f} lid={(look.lids ?? 0) + f.lid} skin={look.skin} uid={uid} />
|
||||
{look.nose && <Nose kind={look.nose} skin={look.skin} />}
|
||||
<Brows f={f} thick={look.brows === "thick"} color={browColor} />
|
||||
<Glasses kind={look.glasses} />
|
||||
<Mouth f={f} uid={uid} />
|
||||
</g>
|
||||
<g transform={`translate(${fx * 0.4} 0)`}><HairFront look={look} /></g>
|
||||
{look.accessories?.includes("helmet") && (
|
||||
<g transform={`translate(${fx * 0.4} 0)`}>
|
||||
<path d="M50 92 Q50 42 100 42 Q150 42 150 92 Z" fill={look.accessoryColor ?? "#f2c230"} />
|
||||
<rect x={42} y={88} width={116} height={10} rx={5} fill={shade(look.accessoryColor ?? "#f2c230", 0.85)} />
|
||||
<path d="M100 44 L100 90" stroke={shade(look.accessoryColor ?? "#f2c230", 0.85)} strokeWidth={6} />
|
||||
</g>
|
||||
)}
|
||||
{look.accessories?.includes("headset") && (
|
||||
<g><path d="M52 100 Q52 44 100 44 Q148 44 148 100" stroke={INK} strokeWidth={6} fill="none" /><rect x={142} y={96} width={14} height={26} rx={6} fill={INK} /><path d="M150 120 Q140 142 116 140" stroke={INK} strokeWidth={3} fill="none" /></g>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
/** Acessórios por cima da roupa (combináveis). Capacete e fone são desenhados na cabeça. */
|
||||
function Accessories({ look, x0, x1, top, bottom, hipY }: { look: CharacterLook; x0: number; x1: number; top: number; bottom: number; hipY: number }) {
|
||||
const acc = look.accessories ?? [];
|
||||
const c = look.accessoryColor;
|
||||
return (
|
||||
<g>
|
||||
{acc.includes("vest") && <>
|
||||
<path d={`M${x0 + 2} ${top + 8} L${x0 + 30} ${top + 4} L${x0 + 30} ${bottom} L${x0 + 2} ${bottom} Z`} fill={c ?? "#ff8a2a"} />
|
||||
<path d={`M${x1 - 2} ${top + 8} L${x1 - 30} ${top + 4} L${x1 - 30} ${bottom} L${x1 - 2} ${bottom} Z`} fill={c ?? "#ff8a2a"} />
|
||||
<rect x={x0 + 2} y={hipY - 70} width={x1 - x0 - 4} height={8} fill="#d9dde3" opacity={0.95} />
|
||||
<rect x={x0 + 2} y={hipY - 40} width={x1 - x0 - 4} height={8} fill="#d9dde3" opacity={0.95} />
|
||||
</>}
|
||||
{acc.includes("apron") && <path d={`M${x0 + 10} ${top + 30} L${x1 - 10} ${top + 30} L${x1 - 4} ${hipY + 70} L${x0 + 4} ${hipY + 70} Z`} fill={c ?? "#e9ecef"} />}
|
||||
{acc.includes("tie") && <><path d={`M95 ${top + 4} L105 ${top + 4} L102 ${top + 14} L98 ${top + 14} Z`} fill={c ?? "#2b3a67"} /><path d={`M98 ${top + 14} L102 ${top + 14} L108 ${top + 80} L100 ${top + 92} L92 ${top + 80} Z`} fill={c ?? "#2b3a67"} /></>}
|
||||
{acc.includes("scarf") && <><rect x={82} y={top - 6} width={36} height={16} rx={7} fill={c ?? "#c8443a"} /><rect x={104} y={top + 6} width={12} height={40} rx={5} fill={c ?? "#c8443a"} /></>}
|
||||
{acc.includes("whistle") && <><path d={`M86 ${top + 4} L100 ${top + 52} L114 ${top + 4}`} stroke="#e8463d" strokeWidth={2.5} fill="none" /><rect x={94} y={top + 50} width={14} height={9} rx={4} fill="#c0c4cc" /></>}
|
||||
{acc.includes("chain") && <path d={`M84 ${top + 4} Q100 ${top + 48} 116 ${top + 4}`} stroke="#d4a63a" strokeWidth={3.5} fill="none" strokeDasharray="4 2" />}
|
||||
{acc.includes("badge") && <rect x={x0 + 14} y={top + 26} width={18} height={12} rx={2} fill={c ?? "#d4a63a"} />}
|
||||
{acc.includes("towel") && <path d={`M${x1 - 26} ${top - 4} Q${x1 - 6} ${top - 6} ${x1 - 4} ${top + 12} L${x1 - 10} ${hipY - 20} L${x1 - 34} ${hipY - 24} L${x1 - 36} ${top + 6} Z`} fill={c ?? "#efe6d2"} stroke={shade(c ?? "#efe6d2", 0.85)} strokeWidth={2} />}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
export function CharacterFigure({ look = DEFAULT_LOOK, expression, pose, item, t = 0, state }: {
|
||||
look?: CharacterLook; expression?: string; pose?: string; item?: IconId; t?: number;
|
||||
/** Estado calculado pela linha do tempo (motion.ts). Sem ele: expressão/pose pedidas + piscar/respirar. */
|
||||
state?: Pick<ActorState, "face" | "body" | "emote">;
|
||||
}) {
|
||||
const uid = useId().replace(/:/g, "");
|
||||
const st = state ?? evaluate({ x: 0, expression, pose }, t, 3600, 1);
|
||||
const f = st.face;
|
||||
const b = st.body;
|
||||
const w = look.build === "slim" ? 0.86 : look.build === "heavy" ? 1.22 : 1;
|
||||
const breathe = Math.sin(t * 2.2) * 1.4;
|
||||
|
||||
// Quadril desce ao sentar; coxas abrem e encurtam (perspectiva), canelas voltam para baixo.
|
||||
const hipY = 290 + b.crouch * 62;
|
||||
const legW = 20 * w;
|
||||
const pants = look.top.style === "dress" || look.bottom.style !== "pants" ? look.skin : look.bottom.color;
|
||||
const leg = (s: 1 | -1, l: Limb) => {
|
||||
const hx = 100 + s * 20 * w;
|
||||
const thighDeg = -s * (l.raise + b.crouch * 55);
|
||||
const knee = tip(hx, hipY, thighDeg, 72 * (1 - 0.72 * b.crouch));
|
||||
const shinDeg = thighDeg + s * (l.bend + b.crouch * 55);
|
||||
const foot = tip(knee.x, knee.y, shinDeg, 68);
|
||||
const shorts = look.bottom.style === "shorts" && look.top.style !== "dress";
|
||||
return (
|
||||
<g key={s}>
|
||||
<Segment x={hx} y={hipY} deg={thighDeg} len={72 * (1 - 0.72 * b.crouch)} w={legW} fill={shorts ? look.bottom.color : pants} />
|
||||
<Segment x={knee.x} y={knee.y} deg={shinDeg} len={68} w={legW * 0.95} fill={pants} />
|
||||
<rect x={foot.x - legW * 0.5 - (s < 0 ? 6 : 0)} y={foot.y - 8} width={legW + 10} height={16} rx={7} fill={look.shoes} />
|
||||
</g>
|
||||
);
|
||||
};
|
||||
|
||||
const sx = 34 * w;
|
||||
const shY = hipY - 122;
|
||||
const longSleeve = ["jacket", "hoodie", "uniform"].includes(look.top.style);
|
||||
const sleeve = look.top.style === "dress" ? look.skin : look.top.color;
|
||||
const arm = (s: 1 | -1, l: Limb, holds?: IconId) => {
|
||||
const x = 100 + s * sx;
|
||||
const upperDeg = -s * l.raise;
|
||||
const elbow = tip(x, shY, upperDeg, 54);
|
||||
const foreDeg = upperDeg + s * l.bend;
|
||||
const hand = tip(elbow.x, elbow.y, foreDeg, 50);
|
||||
return (
|
||||
<g key={s}>
|
||||
<Segment x={x} y={shY} deg={upperDeg} len={54} w={18} fill={sleeve} />
|
||||
<Segment x={elbow.x} y={elbow.y} deg={foreDeg} len={50} w={16} fill={longSleeve ? sleeve : look.skin} />
|
||||
<circle cx={hand.x} cy={hand.y} r={11} fill={look.skin} />
|
||||
<ellipse cx={hand.x - s * 8} cy={hand.y - 6} rx={4.5} ry={7} fill={shade(look.skin, 0.94)} transform={`rotate(${-s * 25} ${hand.x - s * 8} ${hand.y - 6})`} />
|
||||
{s < 0 && look.accessories?.includes("watch") && <rect x={hand.x - 9} y={hand.y - 22} width={18} height={8} rx={3} fill="#d4a63a" />}
|
||||
{holds && <svg x={hand.x - 26} y={hand.y - 30} width={52} height={52} viewBox="0 0 100 100" overflow="visible"><Icon id={holds} /></svg>}
|
||||
</g>
|
||||
);
|
||||
};
|
||||
// Mão perto do rosto (pensar, tapar a boca, mão na testa) é desenhada por cima da cabeça.
|
||||
const handOnFace = b.armR.raise < 45 && b.armR.bend > 135;
|
||||
|
||||
const top = look.top;
|
||||
const x0 = 100 - 36 * w;
|
||||
const x1 = 100 + 36 * w;
|
||||
const torsoTop = hipY - 134;
|
||||
const torsoBottom = top.style === "dress" ? hipY + 55 : hipY;
|
||||
const flare = top.style === "dress" ? 14 : 0;
|
||||
const accent = top.accent ?? shade(top.color, 1.3);
|
||||
const belly = !!look.belly;
|
||||
const torsoPath = `M${x0} ${torsoTop + 16} Q${x0} ${torsoTop + 2} ${x0 + 14} ${torsoTop} L${x1 - 14} ${torsoTop} Q${x1} ${torsoTop + 2} ${x1} ${torsoTop + 16} L${x1 + flare} ${torsoBottom} L${x0 - flare} ${torsoBottom} Z`;
|
||||
const holdItem = b.armR.raise > 20 || b.armR.bend > 40 ? item : undefined;
|
||||
|
||||
return (
|
||||
<svg viewBox="0 0 200 440" width="100%" height="100%" overflow="visible">
|
||||
<g transform={`translate(100 440) scale(${look.height}) translate(-100 -440) translate(0 ${breathe * 0.3})`}>
|
||||
<HairBack look={look} />
|
||||
<Legs look={look} w={w} />
|
||||
{arm(-1, lAngle)}
|
||||
<Torso look={look} w={w} />
|
||||
{pose !== "think" && arm(1, rAngle, pose === "hold" || pose === "point" ? item : undefined)}
|
||||
<rect x={90} y={146} width={20} height={16} fill={shade(look.skin, 0.9)} />
|
||||
<g transform={`translate(0 ${breathe * 0.4})`}>
|
||||
<ellipse cx={53} cy={112} rx={8} ry={11} fill={shade(look.skin, 0.92)} />
|
||||
<ellipse cx={147} cy={112} rx={8} ry={11} fill={shade(look.skin, 0.92)} />
|
||||
<ellipse cx={100} cy={106} rx={47} ry={50} fill={look.skin} />
|
||||
<Beard style={look.beard.style} color={look.beard.color} />
|
||||
<Eyes expression={expression} t={t} />
|
||||
<Brows expression={expression} thick={look.brows === "thick"} color={look.hair.style === "bald" || look.hair.style === "cap" ? look.beard.color : look.hair.color} />
|
||||
<Glasses kind={look.glasses} />
|
||||
<Mouth expression={expression} />
|
||||
<HairFront look={look} />
|
||||
<g transform={`translate(100 440) scale(${look.height}) translate(-100 -440)`}>
|
||||
{look.hair.style === "long" && (
|
||||
<g transform={`rotate(${b.lean} 100 ${hipY})`}>
|
||||
<path d={`M50 ${torsoTop - 34} Q48 ${torsoTop - 94} 100 ${torsoTop - 96} Q152 ${torsoTop - 94} 150 ${torsoTop - 34} L156 ${torsoTop + 56} Q100 ${torsoTop + 71} 44 ${torsoTop + 56} Z`} fill={look.hair.color} />
|
||||
</g>
|
||||
)}
|
||||
{leg(-1, b.legL)}
|
||||
{leg(1, b.legR)}
|
||||
{look.bottom.style === "skirt" && look.top.style !== "dress" && (
|
||||
<path d={`M${100 - 30 * w} ${hipY - 6} L${100 + 30 * w} ${hipY - 6} L${100 + 42 * w} ${hipY + 52} L${100 - 42 * w} ${hipY + 52} Z`} fill={look.bottom.color} />
|
||||
)}
|
||||
<g transform={`rotate(${b.lean} 100 ${hipY}) translate(0 ${breathe * 0.3})`}>
|
||||
{arm(-1, b.armL)}
|
||||
<g>
|
||||
{top.style === "hoodie" && <path d={`M${x0 + 6} ${torsoTop + 4} Q100 ${torsoTop - 24} ${x1 - 6} ${torsoTop + 4} Z`} fill={shade(top.color, 0.8)} />}
|
||||
<defs><clipPath id={`t${uid}`}><path d={torsoPath} /></clipPath></defs>
|
||||
<path d={torsoPath} fill={top.color} />
|
||||
{belly && <ellipse cx={100} cy={hipY - 44} rx={44 * w} ry={40} fill={top.color} />}
|
||||
<g clipPath={`url(#t${uid})`}>
|
||||
<rect x={100 + 14 * w} y={torsoTop} width={40 * w} height={torsoBottom - torsoTop + 2} fill="#000000" opacity={0.1} />
|
||||
</g>
|
||||
{/* Volume da barriga: curva de baixo mais escura e brilho em cima, sem "mancha". */}
|
||||
{belly && <><path d={`M${100 - 38 * w} ${hipY - 22} Q100 ${hipY + 4} ${100 + 38 * w} ${hipY - 22}`} stroke={shade(top.color, 0.72)} strokeWidth={4} fill="none" strokeLinecap="round" />
|
||||
<ellipse cx={100 - 14 * w} cy={hipY - 62} rx={16 * w} ry={10} fill="#ffffff" opacity={0.035} /></>}
|
||||
{(top.style === "shirt" || top.style === "uniform") && <path d={`M88 ${torsoTop} L100 ${torsoTop + 16} L112 ${torsoTop} Z`} fill={shade(top.color, 0.78)} />}
|
||||
{(top.style === "jacket" || top.style === "hoodie") && <path d={`M100 ${torsoTop + 6} L100 ${torsoBottom}`} stroke={shade(top.color, 0.65)} strokeWidth={3} />}
|
||||
{top.style === "uniform" && <rect x={x0} y={hipY - 42} width={x1 - x0} height={11} fill={accent} />}
|
||||
{top.style === "shirt" && top.accent && <rect x={x0} y={hipY - 38} width={x1 - x0} height={9} fill={accent} />}
|
||||
{top.style === "jacket" && <><path d={`M100 ${torsoTop + 2} L100 ${torsoBottom}`} stroke={shade(top.color, 0.6)} strokeWidth={4} /><path d={`M86 ${torsoTop + 2} L100 ${torsoTop + 30} L114 ${torsoTop + 2} Z`} fill={accent} /></>}
|
||||
{top.style === "hoodie" && <rect x={84} y={hipY - 50} width={32} height={22} rx={6} fill={shade(top.color, 0.85)} />}
|
||||
{top.style === "dress" && [0, 1, 2, 3].map((i) => <circle key={i} cx={84 + (i % 2) * 32} cy={torsoTop + 40 + Math.floor(i / 2) * 70} r={3.5} fill="#ffffff" opacity={0.5} />)}
|
||||
<Accessories look={look} x0={x0} x1={x1} top={torsoTop} bottom={torsoBottom} hipY={hipY} />
|
||||
</g>
|
||||
{!handOnFace && arm(1, b.armR, holdItem)}
|
||||
<rect x={90} y={torsoTop - 12} width={20} height={16} fill={shade(look.skin, 0.9)} />
|
||||
<g transform={`translate(0 ${torsoTop - 156 + breathe * 0.4}) rotate(${b.headTilt} 100 150)`}>
|
||||
<Head look={look} f={f} b={b} t={t} uid={uid} />
|
||||
{st.emote && (
|
||||
<g transform={`translate(150 30) scale(${0.4 + 0.6 * st.emote.k})`} opacity={st.emote.k}>
|
||||
<circle r={24} fill="#ffffff" stroke={INK} strokeWidth={3} />
|
||||
<text y={10} textAnchor="middle" fontSize={30} fontWeight={800} fill={st.emote.text === "!" || st.emote.text === "💢" ? "#e8463d" : INK}>{st.emote.text}</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
{handOnFace && arm(1, b.armR)}
|
||||
</g>
|
||||
{/* Pensando: a mão vai ao queixo, por cima da barba. */}
|
||||
{pose === "think" && arm(1, rAngle)}
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
+19
-8
@@ -4,9 +4,10 @@ import React from "react";
|
||||
import { AbsoluteFill, useCurrentFrame, useVideoConfig } from "remotion";
|
||||
import { CrowdFigure, PersonFigure } from "./actors";
|
||||
import { Icon } from "./icons";
|
||||
import { Captions, CrossOut, Hud, Rings, TagLabel, TextLayer, pop, shake } from "./overlays";
|
||||
import { Captions, CrossOut, Grain, Hud, Rings, TagLabel, TextLayer, pop, shake } from "./overlays";
|
||||
import { SceneBackground } from "./scenes";
|
||||
import { CharacterFigure } from "./CharacterFigure";
|
||||
import { evaluate } from "./motion";
|
||||
import { LightLayer } from "./places";
|
||||
import type { ShotSpec } from "./spec";
|
||||
import { loadFonts } from "./theme";
|
||||
@@ -35,16 +36,25 @@ export function Shot(spec: ShotSpec) {
|
||||
);
|
||||
}
|
||||
if (a.character) {
|
||||
// Personagem da biblioteca: mesmo visual em toda cena; muda expressão, pose e objeto na mão.
|
||||
const ch = height * 0.36 * (a.scale ?? 1);
|
||||
// Personagem da biblioteca: mesmo visual em toda cena. Expressão, pose, andar, pular, falar… saem da
|
||||
// linha do tempo (motion.ts), com a boca na fala (palavras + volume do áudio).
|
||||
const t = frame / fps;
|
||||
const st = evaluate({ x: a.x, expression: a.expression, pose: a.pose, face: a.face, body: a.body, flip: a.flip, timeline: a.timeline },
|
||||
t, spec.durationS, spec.seed + i * 13, { words: spec.words ?? [], env: spec.audioEnv });
|
||||
// Meio corpo / de perto: o personagem cresce e os pés saem do quadro (cabeça perto do terço de cima).
|
||||
const zoom = a.framing === "close" ? 2.9 : a.framing === "medium" ? 1.9 : 1;
|
||||
const ch = height * 0.36 * (a.scale ?? 1) * zoom;
|
||||
const cw = (ch * 200) / 440;
|
||||
const baseY = a.framing === "close" ? 1.15 : a.framing === "medium" ? 0.98 : a.y;
|
||||
const label = a.label ?? a.character.name;
|
||||
const showLabel = label && Math.abs(st.rot) < 30;
|
||||
return (
|
||||
<div key={i} style={{ position: "absolute", left: a.x * width - cw / 2, top: a.y * height - ch, width: cw, height: ch,
|
||||
opacity: Math.min(1, k * 1.5), transform: `translateY(${(1 - k) * 10}%) scaleX(${a.flip ? -1 : 1})` }}>
|
||||
<CharacterFigure look={a.character.look} expression={a.expression} pose={a.pose} item={a.item} t={frame / fps} />
|
||||
{label && (
|
||||
<div style={{ position: "absolute", left: "50%", top: "-15%", transform: `translateX(-50%) scaleX(${a.flip ? -1 : 1})`, textAlign: "center" }}>
|
||||
<div key={i} style={{ position: "absolute", left: (st.x + st.dx) * width - cw / 2, top: (baseY + st.dy) * height - ch, width: cw, height: ch,
|
||||
opacity: Math.min(1, k * 1.5), transformOrigin: "50% 100%",
|
||||
transform: `translateY(${(1 - k) * 10}%) rotate(${st.rot}deg) scale(${(st.flip ? -1 : 1) * st.sx}, ${st.sy})` }}>
|
||||
<CharacterFigure look={a.character.look} item={a.item} t={t} state={st} />
|
||||
{showLabel && (
|
||||
<div style={{ position: "absolute", left: zoom > 1 ? "8%" : "50%", top: zoom > 1 ? "22%" : "-15%", transform: `translateX(-50%) scaleX(${st.flip ? -1 : 1})`, textAlign: "center" }}>
|
||||
<TagLabel text={label} />
|
||||
{a.character.caption && <div style={{ marginTop: "0.6cqw" }}><TagLabel text={a.character.caption} tone="ok" size={2.4} /></div>}
|
||||
</div>
|
||||
@@ -80,6 +90,7 @@ export function Shot(spec: ShotSpec) {
|
||||
<LightLayer light={spec.light} palette={spec.palette} />
|
||||
{(spec.texts ?? []).map((t, i) => <TextLayer key={i} t={t} frame={frame} fps={fps} />)}
|
||||
</AbsoluteFill>
|
||||
{(spec.grain ?? 0.11) > 0 && <Grain opacity={spec.grain ?? 0.11} seed={spec.seed} />}
|
||||
{spec.hud && <Hud hud={spec.hud} frame={frame} fps={fps} />}
|
||||
{spec.words?.length ? <Captions words={spec.words} frame={frame} fps={fps} /> : null}
|
||||
</AbsoluteFill>
|
||||
|
||||
@@ -9,11 +9,18 @@ export const GLASSES = ["none", "round", "square", "sun"] as const;
|
||||
export const BROWS = ["thin", "thick"] as const;
|
||||
export const TOP_STYLES = ["shirt", "jacket", "hoodie", "dress", "uniform"] as const;
|
||||
export const BOTTOM_STYLES = ["pants", "shorts", "skirt"] as const;
|
||||
export const EXPRESSIONS = ["neutral", "happy", "sad", "worried", "angry", "surprised", "scared"] as const;
|
||||
export const POSES = ["stand", "point", "wave", "hold", "arms_up", "shrug", "think"] as const;
|
||||
export const HEAD_SHAPES = ["round", "oval", "square", "wide"] as const;
|
||||
export const NOSES = ["button", "curve", "round", "long", "wide"] as const;
|
||||
/** Acessórios desenhados por cima da roupa (combináveis). */
|
||||
export const ACCESSORIES = ["towel", "whistle", "tie", "vest", "helmet", "watch", "badge", "apron", "scarf", "headset", "chain"] as const;
|
||||
export type Accessory = (typeof ACCESSORIES)[number];
|
||||
// Expressões e poses são ATALHOS do rig (rig.ts): parâmetros contínuos que dá para ajustar e misturar.
|
||||
import { EXPRESSION_NAMES, POSE_NAMES, type ExpressionName, type PoseName } from "./rig";
|
||||
|
||||
export type Expression = (typeof EXPRESSIONS)[number];
|
||||
export type Pose = (typeof POSES)[number];
|
||||
export const EXPRESSIONS = EXPRESSION_NAMES;
|
||||
export const POSES = POSE_NAMES;
|
||||
export type Expression = ExpressionName;
|
||||
export type Pose = PoseName;
|
||||
|
||||
export type CharacterLook = {
|
||||
build: (typeof BUILDS)[number];
|
||||
@@ -27,6 +34,18 @@ export type CharacterLook = {
|
||||
top: { style: (typeof TOP_STYLES)[number]; color: string; accent?: string };
|
||||
bottom: { style: (typeof BOTTOM_STYLES)[number]; color: string };
|
||||
shoes: string;
|
||||
/** Detalhe de ilustração (opcionais; sem eles o personagem sai no traço simples). */
|
||||
head?: (typeof HEAD_SHAPES)[number];
|
||||
nose?: (typeof NOSES)[number];
|
||||
/** Pálpebra de cima de base (0 olho aberto … 0,6 meio caído, olhar cansado/esperto). */
|
||||
lids?: number;
|
||||
/** Rugas (0 nenhuma … 1 muitas: testa e canto dos olhos). */
|
||||
wrinkles?: number;
|
||||
/** Barriga saliente (o "forte" de barriga). */
|
||||
belly?: boolean;
|
||||
accessories?: Accessory[];
|
||||
/** Cor dos acessórios principais (toalha, gravata, colete, capacete…). */
|
||||
accessoryColor?: string;
|
||||
};
|
||||
|
||||
/** Ficha do personagem na biblioteca. `kind: "3d"` aponta para a pessoa articulada da Godot (godot/kits). */
|
||||
@@ -73,8 +92,14 @@ export function validateLook(look: unknown): string[] {
|
||||
if (!one(BROWS, l.brows)) errors.push(`brows: ${BROWS.join("|")}`);
|
||||
if (!one(TOP_STYLES, l.top?.style)) errors.push(`top.style: ${TOP_STYLES.join("|")}`);
|
||||
if (!one(BOTTOM_STYLES, l.bottom?.style)) errors.push(`bottom.style: ${BOTTOM_STYLES.join("|")}`);
|
||||
if (l.head !== undefined && !one(HEAD_SHAPES, l.head)) errors.push(`head: ${HEAD_SHAPES.join("|")}`);
|
||||
if (l.nose !== undefined && !one(NOSES, l.nose)) errors.push(`nose: ${NOSES.join("|")}`);
|
||||
if (l.lids !== undefined && !(typeof l.lids === "number" && l.lids >= 0 && l.lids <= 0.8)) errors.push("lids entre 0 e 0,8");
|
||||
if (l.wrinkles !== undefined && !(typeof l.wrinkles === "number" && l.wrinkles >= 0 && l.wrinkles <= 1)) errors.push("wrinkles entre 0 e 1");
|
||||
if (l.accessories !== undefined && (!Array.isArray(l.accessories) || l.accessories.some((a) => !one(ACCESSORIES, a)))) errors.push(`accessories: ${ACCESSORIES.join("|")}`);
|
||||
if (l.accessoryColor !== undefined && !HEX.test(l.accessoryColor)) errors.push("accessoryColor: cor #rrggbb");
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const isExpression = (v: unknown): v is Expression => one(EXPRESSIONS, v);
|
||||
export const isPose = (v: unknown): v is Pose => one(POSES, v);
|
||||
export const isExpression = (v: unknown): v is Expression => typeof v === "string" && (EXPRESSIONS as string[]).includes(v);
|
||||
export const isPose = (v: unknown): v is Pose => typeof v === "string" && (POSES as string[]).includes(v);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Boca acompanhando a fala SEM perder a expressão. O formato vem das letras da palavra que está sendo dita
|
||||
// (tempos de cada palavra da transcrição): "a" abre, "e/i" esticam, "o/u" arredondam, "m/b/p" fecham, "f/v"
|
||||
// mostram os dentes; vogal dura mais que consoante e as letras vizinhas se misturam (coarticulação). Se houver
|
||||
// o volume do áudio quadro a quadro (`env`), ele fecha a boca nas pausas e abre mais nas sílabas fortes.
|
||||
// A expressão continua por cima: os cantos (sorriso/tristeza), as sobrancelhas e os olhos são dela.
|
||||
import type { FaceParams } from "./rig";
|
||||
|
||||
export type Viseme = { open: number; wide: number; round: number; teeth: boolean };
|
||||
export type SpokenWord = { text: string; startS: number; endS: number };
|
||||
|
||||
const CLOSED: Viseme = { open: 0, wide: 0, round: 0, teeth: false };
|
||||
const V: Record<string, Viseme> = {
|
||||
a: { open: 0.85, wide: 0.3, round: 0, teeth: false },
|
||||
e: { open: 0.55, wide: 0.65, round: 0, teeth: true },
|
||||
i: { open: 0.3, wide: 0.95, round: 0, teeth: true },
|
||||
o: { open: 0.65, wide: 0, round: 0.75, teeth: false },
|
||||
u: { open: 0.35, wide: 0, round: 1, teeth: false },
|
||||
mbp: { open: 0, wide: 0.1, round: 0, teeth: false },
|
||||
fv: { open: 0.12, wide: 0.2, round: 0, teeth: true },
|
||||
cons: { open: 0.3, wide: 0.3, round: 0, teeth: true },
|
||||
};
|
||||
|
||||
function visemeOf(ch: string): Viseme {
|
||||
if ("aáàâã".includes(ch)) return V.a;
|
||||
if ("eéê".includes(ch)) return V.e;
|
||||
if ("iíy".includes(ch)) return V.i;
|
||||
if ("oóôõ".includes(ch)) return V.o;
|
||||
if ("uúü".includes(ch)) return V.u;
|
||||
if ("mbp".includes(ch)) return V.mbp;
|
||||
if ("fv".includes(ch)) return V.fv;
|
||||
return V.cons;
|
||||
}
|
||||
const isVowel = (ch: string) => /[aáàâãeéêiíyoóôõuúü]/.test(ch);
|
||||
|
||||
function mix(a: Viseme, b: Viseme, k: number): Viseme {
|
||||
return { open: a.open + (b.open - a.open) * k, wide: a.wide + (b.wide - a.wide) * k, round: a.round + (b.round - a.round) * k, teeth: k < 0.5 ? a.teeth : b.teeth };
|
||||
}
|
||||
|
||||
/** Formato da boca no instante `t` (segundos do trecho) para as palavras dadas; fechada fora das palavras. */
|
||||
export function visemeAt(words: SpokenWord[], t: number, env?: { values: number[]; fps: number }): Viseme {
|
||||
const w = words.find((x) => t >= x.startS && t < x.endS);
|
||||
if (!w) {
|
||||
// Fim de palavra: fecha em ~60 ms em vez de bater a boca.
|
||||
const prev = [...words].reverse().find((x) => x.endS <= t);
|
||||
return prev && t - prev.endS < 0.06 ? mix(V.cons, CLOSED, (t - prev.endS) / 0.06) : CLOSED;
|
||||
}
|
||||
const letters = [...w.text.toLowerCase().replace(/(ch|lh|nh|qu)/g, "c").replace(/[^a-záàâãéêíóôõúüçy]/g, "")];
|
||||
if (!letters.length) return CLOSED;
|
||||
// Vogal pesa o dobro da consoante no tempo da palavra.
|
||||
const weights = letters.map((ch) => (isVowel(ch) ? 1.7 : 0.8));
|
||||
const total = weights.reduce((a, b) => a + b, 0);
|
||||
let pos = ((t - w.startS) / Math.max(0.04, w.endS - w.startS)) * total;
|
||||
let i = 0;
|
||||
while (i < letters.length - 1 && pos > weights[i]) { pos -= weights[i]; i++; }
|
||||
const frac = Math.min(1, pos / weights[i]);
|
||||
const cur = visemeOf(letters[i]);
|
||||
const next = i + 1 < letters.length ? visemeOf(letters[i + 1]) : CLOSED;
|
||||
// Coarticulação: a 2ª metade da letra já caminha para a próxima.
|
||||
let v = frac > 0.5 ? mix(cur, next, (frac - 0.5) * 0.9) : cur;
|
||||
if (env?.values.length) {
|
||||
const a = env.values[Math.min(env.values.length - 1, Math.max(0, Math.floor(t * env.fps)))] ?? 0;
|
||||
const k = Math.max(0, Math.min(1.15, (a - 0.03) / 0.3));
|
||||
v = { ...v, open: v.open * (0.25 + 0.75 * Math.min(1, k)) * (k < 0.05 ? 0.2 : 1) };
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/** Ênfase (0–1) no instante: o volume perto do pico levanta um pouco as sobrancelhas. */
|
||||
export function emphasisAt(t: number, env?: { values: number[]; fps: number }): number {
|
||||
if (!env?.values.length) return 0;
|
||||
const a = env.values[Math.min(env.values.length - 1, Math.max(0, Math.floor(t * env.fps)))] ?? 0;
|
||||
return Math.max(0, Math.min(1, (a - 0.45) / 0.4));
|
||||
}
|
||||
|
||||
/** Põe a fala na boca mantendo a expressão (cantos, sobrancelhas, olhos). `k` = quanto da fala entra (0–1). */
|
||||
export function speak(face: FaceParams, v: Viseme, k = 1, emphasis = 0): FaceParams {
|
||||
const open = Math.max(face.mouthOpen * 0.35, v.open * 0.9);
|
||||
return {
|
||||
...face,
|
||||
mouthOpen: face.mouthOpen + (open - face.mouthOpen) * k,
|
||||
mouthWidth: face.mouthWidth * (1 + (v.wide * 0.22 - v.round * 0.45) * k),
|
||||
mouthRound: face.mouthRound + (v.round - face.mouthRound) * k,
|
||||
teeth: k > 0.5 ? v.teeth && v.open > 0.1 : face.teeth,
|
||||
browL: { ...face.browL, y: face.browL.y - emphasis * 3 * k },
|
||||
browR: { ...face.browR, y: face.browR.y - emphasis * 3 * k },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// Movimento do personagem: uma LINHA DO TEMPO de ações que se combinam (não animações prontas). Cada ação tem
|
||||
// início (segundos `at`, fração do trecho `atP` ou a palavra da narração `cue`) e duração; o estado em cada
|
||||
// quadro sai de aplicar as ações em ordem sobre a expressão/pose de base, mais a "vida" (piscar, respirar).
|
||||
// Ações permanentes mudam o estado dali em diante (express, pose, walk, sit, fall, turn, look); as momentâneas
|
||||
// voltam ao fim (nod, shake_head, tremble, bounce, wave, jump, talk, emote).
|
||||
import { emphasisAt, speak, visemeAt, type SpokenWord } from "./lipsync";
|
||||
import { blendBody, blendFace, bodyOf, faceOf, withBody, withFace, type BodyParams, type BodyPatch, type FaceParams, type FacePatch } from "./rig";
|
||||
|
||||
export const ACTIONS = ["express", "pose", "walk", "run", "enter", "exit", "jump", "nod", "shake_head", "tremble", "bounce", "fall",
|
||||
"sit", "stand_up", "turn", "talk", "look", "emote", "wave"] as const;
|
||||
export type ActionKind = (typeof ACTIONS)[number];
|
||||
|
||||
export type Action = {
|
||||
do: ActionKind;
|
||||
/** Início: segundos, fração do trecho (0–1) ou a 1ª palavra da narração que começa com `cue`. */
|
||||
at?: number; atP?: number; cue?: string;
|
||||
dur?: number;
|
||||
/** talk: termina no fim desta palavra da narração (a fala vai de `cue` até `cueEnd`). */
|
||||
cueEnd?: string;
|
||||
expression?: string; face?: FacePatch;
|
||||
pose?: string; body?: BodyPatch;
|
||||
/** walk/run/enter: x de destino (fração). */
|
||||
to?: number;
|
||||
/** look: para onde; fall: para que lado. */
|
||||
dir?: "left" | "right" | "up" | "down";
|
||||
/** nod/shake_head/bounce/wave: repetições. jump: altura (fração da altura do quadro). */
|
||||
times?: number; height?: number;
|
||||
/** emote: símbolo sobre a cabeça ("!", "?", "…", "♥", "zzz", "💢"). talk: o texto falado (sem tempos de palavra, é
|
||||
* repartido pela duração). */
|
||||
text?: string;
|
||||
};
|
||||
|
||||
export type ActorInput = {
|
||||
x: number; expression?: string; pose?: string; face?: FacePatch; body?: BodyPatch; flip?: boolean; timeline?: Action[];
|
||||
};
|
||||
|
||||
export type ActorState = {
|
||||
face: FaceParams; body: BodyParams;
|
||||
x: number; dy: number; dx: number; rot: number; sx: number; sy: number; flip: boolean;
|
||||
emote: { text: string; k: number } | null;
|
||||
};
|
||||
|
||||
const DEFAULT_DUR: Record<ActionKind, number> = {
|
||||
express: 0.25, pose: 0.35, walk: 1.6, run: 0.9, enter: 1.2, exit: 1.2, jump: 0.8, nod: 0.7, shake_head: 0.8, tremble: 1, bounce: 0.8,
|
||||
fall: 0.6, sit: 0.5, stand_up: 0.5, turn: 0.3, talk: 1.5, look: 0.3, emote: 1.2, wave: 1.2,
|
||||
};
|
||||
|
||||
const clamp01 = (v: number) => Math.max(0, Math.min(1, v));
|
||||
const ease = (p: number) => (p < 0.5 ? 2 * p * p : 1 - (-2 * p + 2) ** 2 / 2);
|
||||
/** Passa um pouco do alvo e volta (dá vida às poses). */
|
||||
const easeBack = (p: number) => { const c = 1.4; return 1 + (c + 1) * (p - 1) ** 3 + c * (p - 1) ** 2; };
|
||||
const norm = (s: string) => s.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]/g, "");
|
||||
|
||||
/** Início da ação em segundos (cue = palavra falada; sem a palavra, cai para atP/at/0). */
|
||||
export function startOf(a: Action, durationS: number, words: { text: string; startS: number }[] = []): number {
|
||||
if (a.cue) {
|
||||
const c = norm(a.cue);
|
||||
const w = words.find((x) => norm(x.text).startsWith(c));
|
||||
if (w) return w.startS;
|
||||
}
|
||||
if (a.atP !== undefined) return a.atP * durationS;
|
||||
return a.at ?? 0;
|
||||
}
|
||||
|
||||
/** Piscar em intervalos variados (2,4–4,6 s), determinístico pela semente. */
|
||||
function blinkAt(t: number, seed: number): number {
|
||||
let s = 0.6 + (seed % 7) * 0.13;
|
||||
let k = 1;
|
||||
while (s < t + 0.2) {
|
||||
const d = t - s;
|
||||
if (d >= 0 && d < 0.13) k = Math.min(k, Math.abs(d - 0.065) / 0.065);
|
||||
s += 2.4 + ((Math.sin(s * 12.9898 + seed) + 1) / 2) * 2.2;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
/** Fala do trecho: palavras com tempo (narração) e, se houver, o volume do áudio quadro a quadro. */
|
||||
export type Speech = { words: SpokenWord[]; env?: { values: number[]; fps: number } };
|
||||
|
||||
/** Fim da fala: o fim da palavra `cueEnd` (depois do início), senão início + dur. */
|
||||
function endOf(a: Action, s: number, words: SpokenWord[]): number | null {
|
||||
if (!a.cueEnd) return null;
|
||||
const c = norm(a.cueEnd);
|
||||
const w = words.find((x) => x.startS >= s - 0.01 && norm(x.text).startsWith(c));
|
||||
return w ? w.endS : null;
|
||||
}
|
||||
|
||||
export function evaluate(actor: ActorInput, t: number, durationS: number, seed = 1, speech: Speech = { words: [] }): ActorState {
|
||||
const words = speech.words;
|
||||
const st: ActorState = {
|
||||
face: faceOf(actor.expression, actor.face), body: bodyOf(actor.pose, actor.body),
|
||||
x: actor.x, dy: 0, dx: 0, rot: 0, sx: 1, sy: 1, flip: !!actor.flip, emote: null,
|
||||
};
|
||||
const timeline = (actor.timeline ?? []).map((a) => ({ a, s: startOf(a, durationS, words) })).sort((p, q) => p.s - q.s);
|
||||
for (const { a, s } of timeline) {
|
||||
if (t < s) break;
|
||||
const end = a.do === "talk" ? endOf(a, s, words) : null;
|
||||
const d = Math.max(0.05, end !== null ? end - s : a.dur ?? DEFAULT_DUR[a.do]);
|
||||
const p = clamp01((t - s) / d);
|
||||
const active = t - s < d;
|
||||
const env = active ? Math.min(1, (t - s) / 0.15, (s + d - t) / 0.15) : 0; // entra e sai suave (momentâneas)
|
||||
switch (a.do) {
|
||||
case "express": {
|
||||
const target = a.expression ? faceOf(a.expression, a.face) : withFace(st.face, a.face);
|
||||
st.face = blendFace(st.face, target, ease(p));
|
||||
break;
|
||||
}
|
||||
case "pose": {
|
||||
const target = a.pose ? bodyOf(a.pose, a.body) : withBody(st.body, a.body);
|
||||
st.body = blendBody(st.body, target, clamp01(easeBack(p)));
|
||||
break;
|
||||
}
|
||||
case "walk": case "run": case "enter": case "exit": {
|
||||
const from = a.do === "enter" ? (a.to ?? st.x) < 0.5 ? -0.25 : 1.25 : st.x;
|
||||
const to = a.do === "exit" ? (st.x < 0.5 ? -0.3 : 1.3) : a.to ?? st.x;
|
||||
const run = a.do === "run";
|
||||
st.x = from + (to - from) * (run ? p : ease(p));
|
||||
if (to !== from) st.flip = to < from;
|
||||
if (active) {
|
||||
const phase = (t - s) * Math.PI * 2 * (run ? 3.2 : 2.1);
|
||||
const amp = run ? 1.6 : 1;
|
||||
const sw = Math.sin(phase);
|
||||
st.body = withBody(st.body, {
|
||||
armL: { raise: 8 + sw * 20 * amp, bend: run ? 85 : 15 }, armR: { raise: 8 - sw * 20 * amp, bend: run ? 85 : 15 },
|
||||
legL: { raise: 3 + Math.max(0, sw) * 6, bend: Math.max(0, sw) * 38 * amp }, legR: { raise: 3 + Math.max(0, -sw) * 6, bend: Math.max(0, -sw) * 38 * amp },
|
||||
lean: (to < from ? -1 : 1) * (run ? 8 : 3),
|
||||
});
|
||||
st.dy -= Math.abs(Math.sin(phase)) * (run ? 0.012 : 0.006);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "jump": {
|
||||
if (!active) break;
|
||||
const h = a.height ?? 0.08;
|
||||
if (p < 0.15) { st.sy *= 1 - 0.1 * (p / 0.15); st.sx *= 1 + 0.06 * (p / 0.15); st.body = withBody(st.body, { crouch: 0.35 * (p / 0.15) }); }
|
||||
else if (p < 0.85) {
|
||||
const q = (p - 0.15) / 0.7;
|
||||
st.dy -= h * 4 * q * (1 - q);
|
||||
st.sy *= 1.07; st.sx *= 0.95;
|
||||
st.body = withBody(st.body, { arms: { raise: 120, bend: -10 }, legs: { raise: 6, bend: 30 } });
|
||||
} else { const q = (p - 0.85) / 0.15; st.sy *= 1 - 0.08 * (1 - q); st.sx *= 1 + 0.05 * (1 - q); }
|
||||
break;
|
||||
}
|
||||
case "nod": st.body = withBody(st.body, { headNod: st.body.headNod + Math.sin(p * Math.PI * 2 * (a.times ?? 2)) * 0.6 * env }); break;
|
||||
case "shake_head": st.body = withBody(st.body, { headTurn: st.body.headTurn + Math.sin(p * Math.PI * 2 * (a.times ?? 2)) * 0.7 * env }); break;
|
||||
case "tremble": if (active) { st.dx += Math.sin(t * 77.7) * 0.004 * env; st.dy += Math.cos(t * 91.3) * 0.002 * env; } break;
|
||||
case "bounce": st.dy -= Math.abs(Math.sin(p * Math.PI * (a.times ?? 2))) * 0.02 * env; break;
|
||||
case "fall": {
|
||||
const side = a.dir === "right" ? 1 : -1;
|
||||
st.rot = side * 88 * ease(p);
|
||||
st.dy += 0.02 * ease(p);
|
||||
st.face = blendFace(st.face, faceOf("shocked"), Math.min(1, p * 3));
|
||||
break;
|
||||
}
|
||||
case "sit": st.body = blendBody(st.body, withBody(st.body, { crouch: 1, arms: { raise: 14, bend: 40 } }), ease(p)); break;
|
||||
case "stand_up": st.body = blendBody(st.body, withBody(st.body, { crouch: 0 }), ease(p)); break;
|
||||
case "turn": {
|
||||
const flipped = !st.flip;
|
||||
if (p >= 0.5) st.flip = flipped;
|
||||
if (active) st.sx *= Math.max(0.15, Math.abs(Math.cos(p * Math.PI)));
|
||||
break;
|
||||
}
|
||||
case "talk": {
|
||||
if (!active) break;
|
||||
// Palavras da narração dentro da fala; sem elas, o texto da ação repartido pela duração (vogal pesa mais).
|
||||
let spoken = words.filter((w) => w.endS > s && w.startS < s + d);
|
||||
if (!spoken.length && a.text) {
|
||||
const list = a.text.split(/\s+/).filter(Boolean);
|
||||
const total = list.reduce((n, w) => n + w.length + 1, 0);
|
||||
let c = s;
|
||||
spoken = list.map((w) => { const len = (d * (w.length + 1)) / total; const out = { text: w, startS: c, endS: c + len * 0.88 }; c += len; return out; });
|
||||
}
|
||||
if (spoken.length) {
|
||||
st.face = speak(st.face, visemeAt(spoken, t, speech.env), Math.min(1, (t - s) / 0.08, (s + d - t) / 0.08 + 0.2), emphasisAt(t, speech.env));
|
||||
} else {
|
||||
const flap = Math.abs(Math.sin((t - s) * Math.PI * 2 * 4.3 + seed)) * (0.6 + 0.4 * Math.sin((t - s) * 9.1 + seed));
|
||||
st.face = { ...st.face, mouthOpen: Math.max(st.face.mouthOpen, (0.12 + 0.5 * flap) * env), teeth: st.face.teeth || flap > 0.6 };
|
||||
}
|
||||
// Quem fala mexe a cabeça de leve e acompanha as sílabas fortes.
|
||||
st.body = withBody(st.body, { headTilt: st.body.headTilt + Math.sin((t - s) * 5.3) * 2 * env, headNod: st.body.headNod + emphasisAt(t, speech.env) * 0.25 });
|
||||
break;
|
||||
}
|
||||
case "look": {
|
||||
const gx = a.dir === "left" ? -0.9 : a.dir === "right" ? 0.9 : 0;
|
||||
const gy = a.dir === "up" ? -0.8 : a.dir === "down" ? 0.8 : 0;
|
||||
const k = ease(p);
|
||||
st.face = { ...st.face, gazeX: st.face.gazeX + (gx - st.face.gazeX) * k, gazeY: st.face.gazeY + (gy - st.face.gazeY) * k };
|
||||
st.body = withBody(st.body, { headTurn: st.body.headTurn + (gx * 0.5 - st.body.headTurn) * k, headNod: st.body.headNod + (gy * -0.4 - st.body.headNod) * k });
|
||||
break;
|
||||
}
|
||||
case "emote": if (active) st.emote = { text: a.text ?? "!", k: env }; break;
|
||||
case "wave": if (active) st.body = withBody(st.body, { armR: { raise: 140 * Math.min(1, env * 1.5), bend: -25 + Math.sin(p * Math.PI * 2 * (a.times ?? 3)) * 30 } }); break;
|
||||
}
|
||||
}
|
||||
// Vida: piscar (a não ser de olhos quase fechados), respirar e um balanço leve de cabeça.
|
||||
const blink = blinkAt(t, seed);
|
||||
if (blink < 1) st.face = { ...st.face, eyeL: st.face.eyeL * Math.max(0.08, blink), eyeR: st.face.eyeR * Math.max(0.08, blink) };
|
||||
st.body = withBody(st.body, { headTilt: st.body.headTilt + Math.sin(t * 0.9 + seed) * 1.2 });
|
||||
return st;
|
||||
}
|
||||
|
||||
/** Confere uma linha do tempo (lista de problemas; vazia = ok). */
|
||||
export function validateTimeline(timeline: unknown): string[] {
|
||||
if (timeline === undefined) return [];
|
||||
if (!Array.isArray(timeline) || timeline.length > 40) return ["timeline: lista de até 40 ações"];
|
||||
const errors: string[] = [];
|
||||
timeline.forEach((a: Partial<Action>, i) => {
|
||||
if (!a || !ACTIONS.includes(a.do as ActionKind)) errors.push(`timeline[${i}].do: ${ACTIONS.join(", ")}`);
|
||||
for (const k of ["at", "atP", "dur", "to", "times", "height"] as const) {
|
||||
if (a[k] !== undefined && (typeof a[k] !== "number" || !Number.isFinite(a[k]))) errors.push(`timeline[${i}].${k}: número`);
|
||||
}
|
||||
if (a.atP !== undefined && !(a.atP >= 0 && a.atP <= 1)) errors.push(`timeline[${i}].atP entre 0 e 1`);
|
||||
if (a.dur !== undefined && !(a.dur > 0 && a.dur <= 30)) errors.push(`timeline[${i}].dur entre 0 e 30 s`);
|
||||
});
|
||||
return errors;
|
||||
}
|
||||
@@ -130,3 +130,16 @@ export function Captions({ words, frame, fps, y = 0.665 }: { words: Word[]; fram
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Textura de papel/granulado por cima de tudo: tira a cara de "vetor de computador" (acabamento de ilustração). */
|
||||
export function Grain({ opacity = 0.11, seed = 3 }: { opacity?: number; seed?: number }) {
|
||||
return (
|
||||
<svg width="100%" height="100%" style={{ position: "absolute", inset: 0, mixBlendMode: "overlay", opacity, pointerEvents: "none" }}>
|
||||
<filter id={`grain${seed}`}>
|
||||
<feTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves={2} seed={seed} stitchTiles="stitch" />
|
||||
<feColorMatrix type="saturate" values="0" />
|
||||
</filter>
|
||||
<rect width="100%" height="100%" filter={`url(#grain${seed})`} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
// Rig do personagem: o rosto e o corpo são PARÂMETROS contínuos, não desenhos prontos. Uma expressão ou uma
|
||||
// pose é só um conjunto de valores; dá para misturar (blend), ajustar um valor ("sorriso 0,3 a mais") e criar
|
||||
// novas sem mexer no desenho. Ângulos em graus; "para fora" positivo nos dois lados (o desenho espelha).
|
||||
|
||||
export type FaceParams = {
|
||||
/** Sobrancelha: y (px; negativo sobe) e tilt (graus; positivo = ponta de dentro sobe, como triste/preocupado). */
|
||||
browL: { y: number; tilt: number };
|
||||
browR: { y: number; tilt: number };
|
||||
/** Abertura dos olhos (0 fechado · 1 normal · 1,35 arregalado). */
|
||||
eyeL: number;
|
||||
eyeR: number;
|
||||
/** Tamanho da pupila (0,4 pavor · 1 normal · 1,3 encantado). */
|
||||
pupil: number;
|
||||
/** Direção do olhar (-1…1). */
|
||||
gazeX: number;
|
||||
gazeY: number;
|
||||
/** Boca: abertura 0…1, sorriso -1 (triste) … 1 (feliz), largura 0,5…1,4, dentes à mostra. */
|
||||
mouthOpen: number;
|
||||
smile: number;
|
||||
mouthWidth: number;
|
||||
/** Arredondamento dos lábios (0 normal … 1 bico de "o/u"): vem da fala (lipsync.ts). */
|
||||
mouthRound: number;
|
||||
/** Pálpebra de cima somada à de base do personagem (−0,5 arregala … 0,6 quase fecha). */
|
||||
lid: number;
|
||||
teeth: boolean;
|
||||
/** Extras: rubor 0…1, gota de suor, lágrimas, veia de raiva. */
|
||||
blush: number;
|
||||
sweat: boolean;
|
||||
tears: boolean;
|
||||
anger: boolean;
|
||||
};
|
||||
|
||||
export type Limb = {
|
||||
/** Abertura a partir do corpo (0 = para baixo; 90 = horizontal para fora; 180 = para cima). */
|
||||
raise: number;
|
||||
/** Dobra do cotovelo/joelho (positivo = antebraço/canela para dentro, na frente do corpo). */
|
||||
bend: number;
|
||||
};
|
||||
|
||||
export type BodyParams = {
|
||||
/** Inclinação do tronco (graus; positivo = para a direita de quem olha). */
|
||||
lean: number;
|
||||
/** Cabeça: inclinação (graus), virada (-1…1, finge 3/4) e aceno (-1 olha para cima … 1 para baixo). */
|
||||
headTilt: number;
|
||||
headTurn: number;
|
||||
headNod: number;
|
||||
armL: Limb;
|
||||
armR: Limb;
|
||||
legL: Limb;
|
||||
legR: Limb;
|
||||
/** Agachar/sentar: 0 em pé … 1 sentado (quadril desce, coxa encurta em perspectiva). */
|
||||
crouch: number;
|
||||
};
|
||||
|
||||
export const NEUTRAL_FACE: FaceParams = {
|
||||
browL: { y: 0, tilt: 0 }, browR: { y: 0, tilt: 0 }, eyeL: 1, eyeR: 1, pupil: 1, gazeX: 0, gazeY: 0,
|
||||
mouthOpen: 0, smile: 0.1, mouthWidth: 1, mouthRound: 0, lid: 0, teeth: false, blush: 0, sweat: false, tears: false, anger: false,
|
||||
};
|
||||
|
||||
export const NEUTRAL_BODY: BodyParams = {
|
||||
lean: 0, headTilt: 0, headTurn: 0, headNod: 0,
|
||||
armL: { raise: 8, bend: 6 }, armR: { raise: 8, bend: 6 }, legL: { raise: 2, bend: 0 }, legR: { raise: 2, bend: 0 }, crouch: 0,
|
||||
};
|
||||
|
||||
type FacePatch = Partial<Omit<FaceParams, "browL" | "browR">> & { browL?: Partial<FaceParams["browL"]>; browR?: Partial<FaceParams["browR"]>; brows?: Partial<FaceParams["browL"]>; eyes?: number };
|
||||
type BodyPatch = Partial<Omit<BodyParams, "armL" | "armR" | "legL" | "legR">> & { armL?: Partial<Limb>; armR?: Partial<Limb>; legL?: Partial<Limb>; legR?: Partial<Limb>; arms?: Partial<Limb>; legs?: Partial<Limb> };
|
||||
|
||||
/** Aplica um ajuste parcial (aceita `brows`/`eyes`/`arms`/`legs` para os dois lados de uma vez). */
|
||||
export function withFace(base: FaceParams, p: FacePatch = {}): FaceParams {
|
||||
const { brows, eyes, browL, browR, ...rest } = p;
|
||||
return {
|
||||
...base, ...rest,
|
||||
browL: { ...base.browL, ...brows, ...browL }, browR: { ...base.browR, ...brows, ...browR },
|
||||
eyeL: rest.eyeL ?? eyes ?? base.eyeL, eyeR: rest.eyeR ?? eyes ?? base.eyeR,
|
||||
};
|
||||
}
|
||||
export function withBody(base: BodyParams, p: BodyPatch = {}): BodyParams {
|
||||
const { arms, legs, armL, armR, legL, legR, ...rest } = p;
|
||||
return {
|
||||
...base, ...rest,
|
||||
armL: { ...base.armL, ...arms, ...armL }, armR: { ...base.armR, ...arms, ...armR },
|
||||
legL: { ...base.legL, ...legs, ...legL }, legR: { ...base.legR, ...legs, ...legR },
|
||||
};
|
||||
}
|
||||
|
||||
/** Expressões prontas = atalhos de parâmetros (dá para ajustar qualquer valor por cima com `face`). */
|
||||
export const EXPRESSION_PRESETS = {
|
||||
neutral: {},
|
||||
smile: { smile: 0.7, eyes: 0.9 },
|
||||
happy: { smile: 0.9, mouthOpen: 0.3, teeth: true, eyes: 0.85, brows: { y: -3 } },
|
||||
laugh: { smile: 1, mouthOpen: 0.75, teeth: true, eyes: 0.18, brows: { y: -5 }, blush: 0.4 },
|
||||
proud: { smile: 0.6, lid: 0.35, brows: { y: -2 } },
|
||||
sad: { smile: -0.7, brows: { tilt: 16 }, eyes: 0.8, gazeY: 0.5 },
|
||||
cry: { smile: -0.9, mouthOpen: 0.35, brows: { tilt: 20 }, eyes: 0.4, tears: true },
|
||||
worried: { smile: -0.3, brows: { tilt: 14, y: -2 }, eyes: 1.05, sweat: true },
|
||||
angry: { smile: -0.4, brows: { tilt: -18, y: 3 }, lid: 0.25, mouthWidth: 0.9 },
|
||||
furious: { smile: -0.6, mouthOpen: 0.6, teeth: true, brows: { tilt: -24, y: 4 }, lid: 0.3, anger: true },
|
||||
surprised: { mouthOpen: 0.6, mouthWidth: 0.55, smile: 0, brows: { y: -8 }, eyes: 1.25, pupil: 0.8, lid: -0.5 },
|
||||
scared: { mouthOpen: 0.5, mouthWidth: 0.9, smile: -0.5, teeth: true, brows: { tilt: 18, y: -6 }, eyes: 1.3, pupil: 0.55, sweat: true, lid: -0.5 },
|
||||
shocked: { mouthOpen: 0.95, mouthWidth: 0.6, smile: 0, brows: { y: -10 }, eyes: 1.35, pupil: 0.45, lid: -0.5 },
|
||||
suspicious: { smile: -0.1, mouthWidth: 0.8, browL: { y: -6, tilt: 0 }, browR: { y: 4, tilt: -10 }, lid: 0.45, gazeX: 0.6 },
|
||||
smirk: { smile: 0.45, mouthWidth: 0.8, browL: { y: -5 }, lid: 0.3, gazeX: -0.3 },
|
||||
confused: { smile: -0.2, mouthWidth: 0.75, browL: { y: -7 }, browR: { tilt: -8 }, gazeY: -0.6, gazeX: 0.4 },
|
||||
disgusted: { smile: -0.7, mouthWidth: 1.1, brows: { tilt: -10, y: 2 }, lid: 0.35 },
|
||||
sleepy: { lid: 0.6, brows: { y: 3 }, mouthOpen: 0.1, smile: 0 },
|
||||
determined: { smile: 0.1, mouthWidth: 0.85, brows: { tilt: -10, y: 2 }, lid: 0.2 },
|
||||
embarrassed: { smile: 0.3, blush: 1, gazeY: 0.6, gazeX: -0.4, eyes: 0.8, sweat: true },
|
||||
} satisfies Record<string, FacePatch>;
|
||||
|
||||
/** Poses prontas = atalhos de ângulos (ajustáveis por cima com `body`). */
|
||||
export const POSE_PRESETS = {
|
||||
stand: {},
|
||||
point: { armR: { raise: 92, bend: 0 } },
|
||||
wave: { armR: { raise: 140, bend: -25 } },
|
||||
hold: { armR: { raise: 28, bend: 75 } },
|
||||
arms_up: { arms: { raise: 158, bend: -10 } },
|
||||
celebrate: { arms: { raise: 150, bend: -30 }, headNod: -0.4 },
|
||||
shrug: { arms: { raise: 38, bend: 100 }, headTilt: 7 },
|
||||
think: { armR: { raise: 18, bend: 150 }, headTilt: -6 },
|
||||
hands_on_hips: { arms: { raise: 42, bend: 105 } },
|
||||
cross_arms: { arms: { raise: 22, bend: 128 } },
|
||||
facepalm: { armR: { raise: 26, bend: 158 }, headNod: 0.5, headTilt: 5 },
|
||||
cover_mouth: { armR: { raise: 16, bend: 168 } },
|
||||
defend: { arms: { raise: 62, bend: 118 }, lean: -4 },
|
||||
reach: { armR: { raise: 70, bend: -10 }, lean: 6 },
|
||||
sit: { crouch: 1, arms: { raise: 14, bend: 40 } },
|
||||
kneel: { crouch: 0.6, arms: { raise: 10, bend: 20 } },
|
||||
lean_in: { lean: 8, headTilt: 6 },
|
||||
} satisfies Record<string, BodyPatch>;
|
||||
|
||||
export type ExpressionName = keyof typeof EXPRESSION_PRESETS;
|
||||
export type PoseName = keyof typeof POSE_PRESETS;
|
||||
export const EXPRESSION_NAMES = Object.keys(EXPRESSION_PRESETS) as ExpressionName[];
|
||||
export const POSE_NAMES = Object.keys(POSE_PRESETS) as PoseName[];
|
||||
|
||||
export const faceOf = (name: string | undefined, patch?: FacePatch): FaceParams =>
|
||||
withFace(withFace(NEUTRAL_FACE, (EXPRESSION_PRESETS as Record<string, FacePatch>)[name ?? "neutral"] ?? {}), patch);
|
||||
export const bodyOf = (name: string | undefined, patch?: BodyPatch): BodyParams =>
|
||||
withBody(withBody(NEUTRAL_BODY, (POSE_PRESETS as Record<string, BodyPatch>)[name ?? "stand"] ?? {}), patch);
|
||||
|
||||
const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
|
||||
const limb = (a: Limb, b: Limb, k: number): Limb => ({ raise: lerp(a.raise, b.raise, k), bend: lerp(a.bend, b.bend, k) });
|
||||
|
||||
/** Mistura duas expressões (k = 0 → a, 1 → b). Os "liga/desliga" trocam na metade. */
|
||||
export function blendFace(a: FaceParams, b: FaceParams, k: number): FaceParams {
|
||||
const pick = <T,>(x: T, y: T) => (k < 0.5 ? x : y);
|
||||
return {
|
||||
browL: { y: lerp(a.browL.y, b.browL.y, k), tilt: lerp(a.browL.tilt, b.browL.tilt, k) },
|
||||
browR: { y: lerp(a.browR.y, b.browR.y, k), tilt: lerp(a.browR.tilt, b.browR.tilt, k) },
|
||||
eyeL: lerp(a.eyeL, b.eyeL, k), eyeR: lerp(a.eyeR, b.eyeR, k), pupil: lerp(a.pupil, b.pupil, k),
|
||||
gazeX: lerp(a.gazeX, b.gazeX, k), gazeY: lerp(a.gazeY, b.gazeY, k),
|
||||
mouthOpen: lerp(a.mouthOpen, b.mouthOpen, k), smile: lerp(a.smile, b.smile, k), mouthWidth: lerp(a.mouthWidth, b.mouthWidth, k), mouthRound: lerp(a.mouthRound, b.mouthRound, k), lid: lerp(a.lid, b.lid, k),
|
||||
teeth: pick(a.teeth, b.teeth), blush: lerp(a.blush, b.blush, k), sweat: pick(a.sweat, b.sweat), tears: pick(a.tears, b.tears), anger: pick(a.anger, b.anger),
|
||||
};
|
||||
}
|
||||
export function blendBody(a: BodyParams, b: BodyParams, k: number): BodyParams {
|
||||
return {
|
||||
lean: lerp(a.lean, b.lean, k), headTilt: lerp(a.headTilt, b.headTilt, k), headTurn: lerp(a.headTurn, b.headTurn, k), headNod: lerp(a.headNod, b.headNod, k),
|
||||
armL: limb(a.armL, b.armL, k), armR: limb(a.armR, b.armR, k), legL: limb(a.legL, b.legL, k), legR: limb(a.legR, b.legR, k), crouch: lerp(a.crouch, b.crouch, k),
|
||||
};
|
||||
}
|
||||
|
||||
export type { FacePatch, BodyPatch };
|
||||
+23
-2
@@ -3,6 +3,8 @@
|
||||
// do quadro (0 = esquerda/topo, 1 = direita/base). Tempos em segundos, a partir do início do trecho.
|
||||
|
||||
import { EXPRESSIONS, POSES, validateLook, type CharacterLook, type Expression, type Pose } from "./character";
|
||||
import { validateTimeline, type Action } from "./motion";
|
||||
import type { BodyPatch, FacePatch } from "./rig";
|
||||
import { ELEMENTS, GROUNDS, PALETTES, type PaletteId, type Place } from "./places";
|
||||
|
||||
/** "place" = lugar montado por peças (ver places.tsx); os demais são fundos prontos da 1ª versão. */
|
||||
@@ -27,6 +29,13 @@ export type Person = {
|
||||
item?: IconId;
|
||||
/** Olha para a esquerda (espelha o desenho). */
|
||||
flip?: boolean;
|
||||
/** Enquadramento: corpo inteiro (padrão), meio corpo ou de perto (rosto grande, como ilustração de destaque). */
|
||||
framing?: "full" | "medium" | "close";
|
||||
/** Ajuste fino por cima da expressão/pose (ex.: { smile: 0.3, browL: { y: -6 } } ou { armR: { raise: 60 } }). */
|
||||
face?: FacePatch;
|
||||
body?: BodyPatch;
|
||||
/** Movimento: ações com início (at/atP/cue) — andar, pular, falar, trocar de expressão… (motion.ts). */
|
||||
timeline?: Action[];
|
||||
/** Cor da roupa (hex). */
|
||||
outfit?: string;
|
||||
hair?: "short" | "bun" | "none";
|
||||
@@ -78,6 +87,8 @@ export type ShotSpec = {
|
||||
palette?: PaletteId;
|
||||
/** Lugar montado por peças (scene.kind "place"). */
|
||||
place?: Place;
|
||||
/** Textura de papel por cima (0 desliga; padrão 0,11). */
|
||||
grain?: number;
|
||||
/** Luz por cima: foco do teto ("spot") ou vinheta. */
|
||||
light?: (typeof LIGHTS)[number];
|
||||
/** push = zoom no fim do trecho (1 = parado); panX = deslocamento horizontal da câmera (fração). */
|
||||
@@ -86,8 +97,10 @@ export type ShotSpec = {
|
||||
actors?: Actor[];
|
||||
props?: Prop[];
|
||||
texts?: TextItem[];
|
||||
/** Legenda palavra por palavra (tempos da narração). Vazio = sem legenda. */
|
||||
/** Legenda palavra por palavra (tempos da narração). Vazio = sem legenda. A boca de quem "fala" usa os mesmos tempos. */
|
||||
words?: Word[];
|
||||
/** Volume do áudio do trecho quadro a quadro (0–1): fecha a boca nas pausas e abre nas sílabas fortes. */
|
||||
audioEnv?: { fps: number; values: number[] };
|
||||
card?: { title: string; subtitle?: string; footer?: string };
|
||||
};
|
||||
|
||||
@@ -129,8 +142,15 @@ export function validateSpec(spec: unknown): string[] {
|
||||
} else if (a.kind === "person" && a.expression !== undefined && !EXPRESSIONS.includes(a.expression)) errors.push(`actors[${i}]: expressão (${EXPRESSIONS.join(", ")})`);
|
||||
else if (a.kind === "person" && a.pose !== undefined && !POSES.includes(a.pose)) errors.push(`actors[${i}]: pose (${POSES.join(", ")})`);
|
||||
else if (a.kind === "person" && a.item !== undefined && !ICONS.includes(a.item)) errors.push(`actors[${i}]: item "${a.item}" não existe`);
|
||||
else if (a.kind === "person") {
|
||||
for (const e of validateTimeline(a.timeline)) errors.push(`actors[${i}].${e}`);
|
||||
for (const [j, act] of (a.timeline ?? []).entries()) {
|
||||
if (act.expression !== undefined && !EXPRESSIONS.includes(act.expression as Expression)) errors.push(`actors[${i}].timeline[${j}]: expressão "${act.expression}" não existe`);
|
||||
if (act.pose !== undefined && !POSES.includes(act.pose as Pose)) errors.push(`actors[${i}].timeline[${j}]: pose "${act.pose}" não existe`);
|
||||
}
|
||||
}
|
||||
else if (a.kind === "crowd" && (!finite(a.count) || a.count < 1 || a.count > 40 || !frac(a.y))) errors.push(`actors[${i}]: crowd inválida`);
|
||||
else if (a.kind !== "person" && a.kind !== "crowd") errors.push(`actors[${i}]: kind inválido`);
|
||||
else if ((a as { kind: string }).kind !== "crowd") errors.push(`actors[${i}]: kind inválido`);
|
||||
}
|
||||
for (const [i, p] of (s.props ?? []).entries()) {
|
||||
if (!ICONS.includes(p.icon)) errors.push(`props[${i}]: ícone "${p.icon}" não existe (${ICONS.join(", ")})`);
|
||||
@@ -142,6 +162,7 @@ export function validateSpec(spec: unknown): string[] {
|
||||
if (typeof t.text !== "string" || !t.text.trim()) errors.push(`texts[${i}]: texto vazio`);
|
||||
if (!frac(t.x) || !frac(t.y)) errors.push(`texts[${i}]: x/y fora do quadro`);
|
||||
}
|
||||
if (s.audioEnv !== undefined && (!finite(s.audioEnv.fps) || !Array.isArray(s.audioEnv.values) || s.audioEnv.values.length > 36000)) errors.push("audioEnv: { fps, values[] } (até 36 mil valores)");
|
||||
for (const [i, w] of (s.words ?? []).entries()) {
|
||||
if (typeof w.text !== "string" || !finite(w.startS) || !finite(w.endS) || w.endS < w.startS) errors.push(`words[${i}]: inválida`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { visemeAt, speak } from "../src/lipsync";
|
||||
import { evaluate, startOf, validateTimeline } from "../src/motion";
|
||||
import { EXPRESSION_NAMES, blendFace, faceOf } from "../src/rig";
|
||||
|
||||
const words = [
|
||||
{ text: "Mamãe", startS: 0.2, endS: 0.7 },
|
||||
{ text: "não", startS: 0.8, endS: 1.2 },
|
||||
{ text: "ouviu", startS: 1.3, endS: 1.8 },
|
||||
];
|
||||
|
||||
describe("rig: expressões como parâmetros", () => {
|
||||
it("toda expressão pronta vira parâmetros válidos e se mistura com outra", () => {
|
||||
for (const name of EXPRESSION_NAMES) assert.ok(Number.isFinite(faceOf(name).smile), name);
|
||||
const half = blendFace(faceOf("sad"), faceOf("happy"), 0.5);
|
||||
assert.ok(half.smile > faceOf("sad").smile && half.smile < faceOf("happy").smile);
|
||||
});
|
||||
it("ajuste fino por cima de uma expressão", () => {
|
||||
assert.equal(faceOf("neutral", { smile: 0.8, browL: { y: -6 } }).browL.y, -6);
|
||||
});
|
||||
});
|
||||
|
||||
describe("linha do tempo", () => {
|
||||
it("cue = palavra falada; atP = fração do trecho", () => {
|
||||
assert.equal(startOf({ do: "nod", cue: "nao" }, 4, words), 0.8);
|
||||
assert.equal(startOf({ do: "nod", atP: 0.5 }, 4, words), 2);
|
||||
assert.equal(startOf({ do: "nod", cue: "inexistente", at: 1 }, 4, words), 1);
|
||||
});
|
||||
it("andar chega ao destino e vira para o lado certo; é determinístico", () => {
|
||||
const actor = { x: 0.7, timeline: [{ do: "walk" as const, at: 0, to: 0.3, dur: 1 }] };
|
||||
const end = evaluate(actor, 2, 4);
|
||||
assert.ok(Math.abs(end.x - 0.3) < 1e-9);
|
||||
assert.equal(end.flip, true);
|
||||
assert.deepEqual(evaluate(actor, 0.5, 4), evaluate(actor, 0.5, 4));
|
||||
});
|
||||
it("trocar expressão é suave e permanente", () => {
|
||||
const actor = { x: 0.5, timeline: [{ do: "express" as const, at: 1, expression: "happy", dur: 0.4 }] };
|
||||
const mid = evaluate(actor, 1.2, 4).face.smile;
|
||||
assert.ok(mid > faceOf("neutral").smile && mid < faceOf("happy").smile);
|
||||
assert.ok(Math.abs(evaluate(actor, 3, 4).face.smile - faceOf("happy").smile) < 1e-9);
|
||||
});
|
||||
it("pular sobe e volta ao chão", () => {
|
||||
const actor = { x: 0.5, timeline: [{ do: "jump" as const, at: 0, dur: 1 }] };
|
||||
assert.ok(evaluate(actor, 0.5, 4).dy < -0.05);
|
||||
assert.equal(evaluate(actor, 2, 4).dy, 0);
|
||||
});
|
||||
it("valida a linha do tempo", () => {
|
||||
assert.deepEqual(validateTimeline([{ do: "walk", to: 0.3 }]), []);
|
||||
assert.match(validateTimeline([{ do: "voar" }]).join(), /do:/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fala: boca pelas letras, expressão mantida", () => {
|
||||
it("m fecha, a abre, o arredonda; fora das palavras fica fechada", () => {
|
||||
assert.equal(visemeAt(words, 0.21).open, 0); // "M" do começo
|
||||
assert.ok(visemeAt([{ text: "aaa", startS: 0, endS: 1 }], 0.5).open > 0.7);
|
||||
assert.ok(visemeAt([{ text: "oo", startS: 0, endS: 1 }], 0.5).round > 0.6);
|
||||
assert.equal(visemeAt(words, 3).open, 0);
|
||||
});
|
||||
it("falando bravo continua bravo (sobrancelhas e cantos da boca)", () => {
|
||||
const angry = faceOf("angry");
|
||||
const talking = speak(angry, visemeAt([{ text: "aaa", startS: 0, endS: 1 }], 0.5));
|
||||
assert.equal(talking.browL.tilt, angry.browL.tilt);
|
||||
assert.equal(talking.smile, angry.smile);
|
||||
assert.ok(talking.mouthOpen > 0.5);
|
||||
});
|
||||
it("a ação falar vai da palavra de início até o fim da palavra final", () => {
|
||||
const actor = { x: 0.5, timeline: [{ do: "talk" as const, cue: "mamae", cueEnd: "ouviu" }] };
|
||||
assert.ok(evaluate(actor, 0.45, 4, 1, { words }).face.mouthOpen > 0.2);
|
||||
assert.ok(evaluate(actor, 2.5, 4, 1, { words }).face.mouthOpen < 0.05);
|
||||
});
|
||||
it("com o volume do áudio, a boca fecha na pausa", () => {
|
||||
const env = { fps: 10, values: Array.from({ length: 20 }, (_, i) => (i === 5 ? 0 : 0.9)) };
|
||||
const loud = visemeAt([{ text: "aaaaaaaaaa", startS: 0, endS: 2 }], 0.25, env).open;
|
||||
const pause = visemeAt([{ text: "aaaaaaaaaa", startS: 0, endS: 2 }], 0.55, env).open;
|
||||
assert.ok(loud > 0.5 && pause < 0.2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user