Files

243 lines
12 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Folha de conferência do personagem, SEM Remotion: renderiza o mesmo componente do projeto (CharacterFigure / HandsInsert)
// em várias poses/expressões/objetos e grava out/sheet-full.png, out/sheet-close.png e out/referencia-vs-resultado.png.
//
// npm install
// npx tsx render-sheet.tsx → out/sheet-full.svg + .png (e out/referencia-vs-resultado.png)
// npx tsx render-sheet.tsx close → só o close (rosto + tronco + mãos), como no vídeo
// npx tsx render-sheet.tsx compare → folha referência × resultado lado a lado
import fs from "node:fs";
import path from "node:path";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { CharacterFigure, HandsInsert } from "./src/CharacterFigure";
import type { CharacterLook } from "./src/character";
import type { IconId } from "./src/spec";
// Personagens de teste (genéricos; não são da série de referência).
const OLD: CharacterLook = {
build: "average", height: 0.95, skin: "#e0a77a", hair: { style: "bald", color: "#9a9aa2" }, beard: { style: "mustache", color: "#8e8e96" },
glasses: "square", brows: "thick", top: { style: "jacket", color: "#4f7a4a", accent: "#e9ecef" }, bottom: { style: "pants", color: "#2c3346" },
shoes: "#2a2a30", head: "wide", nose: "curve", lids: 0.45, wrinkles: 0.6, accessories: ["towel"],
};
const COACH: CharacterLook = {
build: "heavy", height: 0.98, skin: "#d9a27a", hair: { style: "short", color: "#5a4a3a" }, beard: { style: "mustache", color: "#4a3a2a" },
glasses: "none", brows: "thick", top: { style: "jacket", color: "#22335e", accent: "#e8b13a" }, bottom: { style: "pants", color: "#22335e" },
shoes: "#f2f2f2", head: "round", nose: "round", lids: 0.15, wrinkles: 0.3, belly: true, accessories: ["whistle"],
};
const NOAH: CharacterLook = {
build: "slim", height: 0.96, skin: "#c98a5e", hair: { style: "long", color: "#e2e2e8" }, beard: { style: "long", color: "#eeeef2" },
glasses: "none", brows: "thick", top: { style: "robe", color: "#a8865a", accent: "#6b4a2a" }, bottom: { style: "pants", color: "#5a4a3a" },
shoes: "#6b4a2a", footwear: "sandals", head: "oval", nose: "long", lids: 0.5, wrinkles: 0.85,
};
const WORKER: CharacterLook = {
build: "average", height: 0.98, skin: "#dfa678", hair: { style: "short", color: "#4e3829" }, beard: { style: "full", color: "#78604c" },
glasses: "none", brows: "thick", top: { style: "shirt", color: "#6e6545" }, bottom: { style: "pants", color: "#34465e" },
shoes: "#423127", head: "round", nose: "curve", lids: 0.35, wrinkles: 0.25,
};
const MECHANIC: CharacterLook = {
build: "average", height: 0.97, skin: "#e2a878", hair: { style: "short", color: "#4a3525" }, beard: { style: "mustache", color: "#4a3525" },
glasses: "none", brows: "thick", top: { style: "shirt", color: "#687a52" }, bottom: { style: "pants", color: "#3b4c5e" },
shoes: "#4a372b", head: "round", nose: "round", lids: 0.2, wrinkles: 0.2,
};
type Cell = { look: CharacterLook; label: string; expression?: string; pose?: string; item?: IconId; gesture?: "thumbs_up" };
const CELLS: Cell[] = [
{ look: OLD, label: "stand / relaxed", pose: "stand", expression: "smile" },
{ look: OLD, label: "hold book (2 mãos)", pose: "hold", item: "book", expression: "smile" },
{ look: COACH, label: "thumbs up", pose: "thumbs_up", gesture: "thumbs_up", expression: "happy" },
{ look: COACH, label: "hold ruler (1 mão)", pose: "hold", item: "ruler", expression: "laugh" },
{ look: OLD, label: "point", pose: "point", expression: "surprised" },
{ look: OLD, label: "wave", pose: "wave", expression: "happy" },
{ look: COACH, label: "cross_arms", pose: "cross_arms", expression: "suspicious" },
{ look: OLD, label: "think", pose: "think", expression: "confused" },
{ look: OLD, label: "cover_mouth", pose: "cover_mouth", expression: "shocked" },
{ look: NOAH, label: "hold hammer", pose: "hold", item: "hammer", expression: "determined" },
{ look: NOAH, label: "hold olive", pose: "hold", item: "olive", expression: "smile" },
{ look: NOAH, label: "celebrate", pose: "celebrate", expression: "laugh" },
{ look: MECHANIC, label: "point (manga curta)", pose: "point", expression: "happy" },
{ look: WORKER, label: "cross_arms (manga curta)", pose: "cross_arms", expression: "sad" },
{ look: MECHANIC, label: "hands_on_hips", pose: "hands_on_hips", expression: "proud" },
{ look: WORKER, label: "hold phone", pose: "hold", item: "phone", expression: "neutral" },
{ look: OLD, label: "shrug", pose: "shrug", expression: "confused" },
{ look: WORKER, label: "facepalm", pose: "facepalm", expression: "sad" },
];
const Fig = CharacterFigure as unknown as React.FC<Record<string, unknown>>;
const Insert = HandsInsert as unknown as React.FC<Record<string, unknown>>;
function renderPoseSheet(mode: "full" | "close") {
const cw = 360, ch = mode === "close" ? 580 : 760, cols = 6;
const rows = Math.ceil(CELLS.length / cols);
const W = cw * cols, H = ch * rows;
const sheet = (
<svg xmlns="http://www.w3.org/2000/svg" viewBox={`0 0 ${W} ${H}`} width={W} height={H}>
<rect width={W} height={H} fill="#8f9bb3" />
{CELLS.map((c, i) => {
const x = (i % cols) * cw, y = Math.floor(i / cols) * ch;
const fw = mode === "close" ? 400 : 330, fh = fw * 2.2;
const fx = x + (cw - fw) / 2, fy = mode === "close" ? y - 42 : y + ch - fh - 10;
const cid = `cell${mode}${i}`;
return (
<g key={i}>
<defs>
<clipPath id={cid}>
<rect x={x + 4} y={y + 4} width={cw - 8} height={ch - 8} rx={14} />
</clipPath>
</defs>
<rect x={x + 4} y={y + 4} width={cw - 8} height={ch - 8} rx={14} fill={i % 2 ? "#a3adc2" : "#97a3ba"} />
<g clipPath={`url(#${cid})`}>
<svg x={fx} y={fy} width={fw} height={fh} viewBox="0 0 200 440" overflow="hidden">
<Fig look={c.look} expression={c.expression} pose={c.pose} item={c.item} gesture={c.gesture} t={0.6} />
</svg>
</g>
<text x={x + 16} y={y + 34} fontSize={22} fontFamily="Arial" fontWeight={700} fill="#1b1d26">{c.label}</text>
</g>
);
})}
</svg>
);
return { svg: renderToStaticMarkup(sheet), W };
}
function renderCompareSheet() {
const refDir = path.resolve("..", "referencia", "recortes");
const loadRef = (name: string) => {
const p = path.join(refDir, name);
if (!fs.existsSync(p)) return "";
return `data:image/png;base64,${fs.readFileSync(p).toString("base64")}`;
};
// Enquadra nosso SVG (viewBox 0 0 200 440) na mesma janela de recorte usando um `<g transform="translate(...) scale(...)">`.
const cropFig = (boxW: number, boxH: number, cx: number, cy: number, span: number, node: React.ReactNode) => {
const k = boxW / span;
const tx = boxW / 2 - cx * k;
const ty = boxH / 2 - cy * k;
return (
<g transform={`translate(${tx} ${ty}) scale(${k})`}>
<svg width={200} height={440} viewBox="0 0 200 440" overflow="visible">{node}</svg>
</g>
);
};
const items: {
title: string;
refFile: string;
bg: string;
renderOur: (w: number, h: number) => React.ReactNode;
}[] = [
{
title: "1. Rosto (close)",
refFile: "rosto-close.png",
bg: "#1e2742",
renderOur: (w, h) => cropFig(w, h, 100, 148, 138, <Fig look={OLD} expression="smile" pose="stand" t={0.6} />),
},
{
title: "2. Segurando (2 mãos)",
refFile: "maos-segurando.png",
bg: "#232d4b",
renderOur: (w, h) => cropFig(w, h, 100, 250, 128, <Fig look={OLD} expression="smile" pose="hold" item="book" t={0.6} />),
},
{
title: "3. Joinha (thumbs_up)",
refFile: "joinha.png",
bg: "#68623e",
renderOur: (w, h) => cropFig(w, h, 122, 212, 130, <Fig look={COACH} expression="happy" pose="thumbs_up" gesture="thumbs_up" t={0.6} />),
},
{
title: "4. Segurando (1 mão)",
refFile: "mao-prancheta.png",
bg: "#3e4844",
renderOur: (w, h) => cropFig(w, h, 118, 224, 132, <Fig look={COACH} expression="happy" pose="hold" item="ruler" t={0.6} />),
},
{
title: "5. Apontando (point)",
refFile: "apontando.png",
bg: "#6e4e3a",
renderOur: (w, h) => cropFig(w, h, 130, 178, 125, <Fig look={MECHANIC} expression="happy" pose="point" t={0.6} />),
},
{
title: "6. Braços cruzados",
refFile: "bracos-cruzados.png",
bg: "#8c8275",
renderOur: (w, h) => cropFig(w, h, 100, 266, 142, <Fig look={WORKER} expression="sad" pose="cross_arms" t={0.6} />),
},
{
title: "7. Insert de mãos",
refFile: "insert-maos.png",
bg: "#4a3322",
renderOur: (w, h) => (
<g transform={`translate(${-w * 0.12} ${-h * 0.14}) scale(${(w * 1.24) / 1080})`}>
<svg width={1080} height={1080} viewBox="0 0 1080 1080" overflow="visible">
<Insert look={OLD} item="book" t={0.6} />
</svg>
</g>
),
},
];
const cw = 320, ch = 320, pad = 16, topBanner = 52, labelH = 34;
const W = items.length * cw, H = topBanner + (ch + labelH) * 2 + 20;
const sheet = (
<svg xmlns="http://www.w3.org/2000/svg" viewBox={`0 0 ${W} ${H}`} width={W} height={H}>
<rect width={W} height={H} fill="#181c26" />
<text x={20} y={36} fontSize={24} fontFamily="Arial" fontWeight={700} fill="#f2c230">
REFERÊNCIA (recortes originais) × NOSSO RESULTADO (SVG puro / rig contínuo sem juntas)
</text>
{items.map((it, i) => {
const x = i * cw;
const yRef = topBanner + labelH;
const yOur = yRef + ch + labelH;
const boxW = cw - pad, boxH = ch - pad;
const refData = loadRef(it.refFile);
return (
<g key={i}>
<text x={x + 12} y={yRef - 10} fontSize={18} fontFamily="Arial" fontWeight={700} fill="#d5dce8">{it.title} — Ref</text>
<defs>
<clipPath id={`cref${i}`}><rect x={x + 8} y={yRef} width={boxW} height={boxH} rx={12} /></clipPath>
<clipPath id={`cour${i}`}><rect x={x + 8} y={yOur} width={boxW} height={boxH} rx={12} /></clipPath>
</defs>
<g clipPath={`url(#cref${i})`}>
<rect x={x + 8} y={yRef} width={boxW} height={boxH} fill="#2a3040" />
{refData && <image href={refData} x={x + 8} y={yRef} width={boxW} height={boxH} preserveAspectRatio="xMidYMid slice" />}
</g>
<text x={x + 12} y={yOur - 10} fontSize={18} fontFamily="Arial" fontWeight={700} fill="#7be08a">{it.title} — Nosso</text>
<g clipPath={`url(#cour${i})`}>
<g transform={`translate(${x + 8} ${yOur})`}>
<rect width={boxW} height={boxH} fill={it.bg} />
{it.renderOur(boxW, boxH)}
</g>
</g>
</g>
);
})}
</svg>
);
return { svg: renderToStaticMarkup(sheet), W };
}
fs.mkdirSync("out", { recursive: true });
const arg = process.argv[2] ?? "full";
const { Resvg } = await import("@resvg/resvg-js").catch(() => ({ Resvg: null as unknown as typeof import("@resvg/resvg-js").Resvg }));
if (arg === "compare") {
const { svg, W } = renderCompareSheet();
fs.writeFileSync("out/referencia-vs-resultado.svg", svg);
if (Resvg) {
fs.writeFileSync("out/referencia-vs-resultado.png", new Resvg(svg, { fitTo: { mode: "width", value: W } }).render().asPng());
console.log("out/referencia-vs-resultado.png");
}
} else {
const mode = arg === "close" ? "close" : "full";
const { svg, W } = renderPoseSheet(mode);
fs.writeFileSync(`out/sheet-${mode}.svg`, svg);
console.log(`out/sheet-${mode}.svg`);
if (Resvg) {
fs.writeFileSync(`out/sheet-${mode}.png`, new Resvg(svg, { fitTo: { mode: "width", value: W } }).render().asPng());
console.log(`out/sheet-${mode}.png`);
}
const cmp = renderCompareSheet();
fs.writeFileSync("out/referencia-vs-resultado.svg", cmp.svg);
if (Resvg) {
fs.writeFileSync("out/referencia-vs-resultado.png", new Resvg(cmp.svg, { fitTo: { mode: "width", value: cmp.W } }).render().asPng());
console.log("out/referencia-vs-resultado.png");
}
}