// 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>; const Insert = HandsInsert as unknown as React.FC>; 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 = ( {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 ( {c.label} ); })} ); 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 ``. 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 ( {node} ); }; 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, ), }, { title: "2. Segurando (2 mãos)", refFile: "maos-segurando.png", bg: "#232d4b", renderOur: (w, h) => cropFig(w, h, 100, 250, 128, ), }, { title: "3. Joinha (thumbs_up)", refFile: "joinha.png", bg: "#68623e", renderOur: (w, h) => cropFig(w, h, 122, 212, 130, ), }, { title: "4. Segurando (1 mão)", refFile: "mao-prancheta.png", bg: "#3e4844", renderOur: (w, h) => cropFig(w, h, 118, 224, 132, ), }, { title: "5. Apontando (point)", refFile: "apontando.png", bg: "#6e4e3a", renderOur: (w, h) => cropFig(w, h, 130, 178, 125, ), }, { title: "6. Braços cruzados", refFile: "bracos-cruzados.png", bg: "#8c8275", renderOur: (w, h) => cropFig(w, h, 100, 266, 142, ), }, { title: "7. Insert de mãos", refFile: "insert-maos.png", bg: "#4a3322", renderOur: (w, h) => ( ), }, ]; const cw = 320, ch = 320, pad = 16, topBanner = 52, labelH = 34; const W = items.length * cw, H = topBanner + (ch + labelH) * 2 + 20; const sheet = ( REFERÊNCIA (recortes originais) × NOSSO RESULTADO (SVG puro / rig contínuo sem juntas) {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 ( {it.title} — Ref {refData && } {it.title} — Nosso {it.renderOur(boxW, boxH)} ); })} ); 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"); } }