- Mãos com formas e rotações próprias, membros articulados (limbs) e animais. - Elementos de cenário separados (natureza, construções, interiores) e testes de lugares. - Personagens reaproveitáveis de Noé e a Arca (Noé, esposa, Sem, Cam e Jafé) e a fonte Barlow Semi Condensed. - História noe-e-a-arca: pauta, bíblia, roteiro do ep. 1, tomadas Cartoon e montagem. - Montagem: narração mais corrida (tira silêncios longos) e cabeçalho com o número do vídeo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
563 lines
35 KiB
TypeScript
563 lines
35 KiB
TypeScript
// Lugares montados por PEÇAS (não há cenário pronto): paleta + céu/hora + chão + peças posicionadas por
|
||
// profundidade (z: 0 = frente, 1 = fundo). Parque de dia, cemitério na névoa, quarto à noite, bunker com foco
|
||
// de luz… tudo sai da mesma gramática. Espaço de desenho 1080×1920; chão começa em `horizon` (fração da altura).
|
||
//
|
||
// Regras de acabamento (valem para toda peça, ver elements/paint.ts): sombreado em 2 tons com a luz vindo da
|
||
// esquerda; 3 planos com perspectiva atmosférica (o fundo puxa para a cor do céu/parede, a frente escurece);
|
||
// sombra de contato no chão sob cada objeto. Tudo por mistura de cor — nada de blur por quadro.
|
||
import React from "react";
|
||
import { rng } from "./random";
|
||
import type { ShotSpec } from "./spec";
|
||
import { makePaint, mix, palette, type Pal, type PaletteId } from "./elements/paint";
|
||
import { NATURE, type Draw } from "./elements/nature";
|
||
import { BUILT, FRONT_PART } from "./elements/built";
|
||
import { INDOOR } from "./elements/indoor";
|
||
|
||
export { PALETTES, palette, type PaletteId } from "./elements/paint";
|
||
export const GROUNDS = ["grass", "street", "dirt", "floor", "sand", "water", "none"] as const;
|
||
export const ELEMENTS = ["tree", "deadtree", "pine", "bush", "rock", "mountain", "cloud", "bench", "lamp", "gravestone", "cross", "fence",
|
||
"house", "building", "car", "sign", "door", "window", "table", "bed", "shelf", "crate", "tent", "fire",
|
||
"ark", "ark_frame", "scaffold", "planks", "rainbow", "waves", "palm", "outcrop",
|
||
"cabinet", "locker", "frame", "pendant", "desklamp", "desk", "clothesline", "wall", "facade", "shopfront"] as const;
|
||
/** Tempo por cima da cena (chuva caindo; tempestade = chuva forte + relâmpago + céu mais escuro). */
|
||
export const WEATHERS = ["none", "rain", "storm"] as const;
|
||
export type ElementKind = (typeof ELEMENTS)[number];
|
||
/** Fonte de luz posicionada (`spec.lightSource`): luminária, janela ou sol. */
|
||
export const LIGHT_SOURCES = ["lamp", "window", "sun"] as const;
|
||
|
||
export type Place = {
|
||
ground: (typeof GROUNDS)[number];
|
||
/** Interno: parede no lugar do céu (quarto, bunker, loja). */
|
||
indoor?: boolean;
|
||
/** Linha do horizonte / pé da parede (fração da altura; padrão 0,56 fora e 0,62 dentro). */
|
||
horizon?: number;
|
||
fog?: boolean;
|
||
weather?: (typeof WEATHERS)[number];
|
||
/** Água cobrindo o lugar: altura da superfície (fração da altura do quadro, 0 = topo) do início ao fim do trecho.
|
||
* Ex.: { from: 0.8, to: 0.5 } = a água sobe. O que não boia fica embaixo dela. */
|
||
flood?: { from: number; to: number };
|
||
elements: {
|
||
kind: ElementKind; x: number; z?: number; scale?: number; flip?: boolean; color?: string;
|
||
/** Sobe a peça (fração da altura do quadro): arca em cima do monte. */
|
||
lift?: number;
|
||
/** Boia na água (com `flood`, acompanha a superfície e balança). */
|
||
float?: boolean;
|
||
/** Tem gente DENTRO (arca, carro): a parte da frente da peça é desenhada por cima dos personagens. */
|
||
occupied?: boolean;
|
||
}[];
|
||
};
|
||
|
||
const W = 1080;
|
||
const H = 1920;
|
||
const DRAW: Record<string, Draw> = { ...NATURE, ...BUILT, ...INDOOR };
|
||
|
||
/** Peças presas na parede do fundo quando o lugar é interno (o z delas é ignorado). */
|
||
const WALL_MOUNTED = new Set<ElementKind>(["window", "frame", "door"]);
|
||
/** Peças penduradas no teto: a origem é o topo do quadro. */
|
||
const CEILING = new Set<ElementKind>(["pendant"]);
|
||
/** Objetos de mesa: sobem sozinhos para cima da mesa/escrivaninha mais próxima (se não tiver `lift`). */
|
||
const ON_TOP = new Set<ElementKind>(["desklamp"]);
|
||
/** Altura do tampo (unidades da peça) das superfícies que recebem objetos de mesa. */
|
||
const SURFACE_TOP: Partial<Record<ElementKind, number>> = { desk: 330, table: 304 };
|
||
/** Só as peças assimétricas espelham; nas simétricas o `flip` trocaria só o lado da sombra (a luz é sempre da esquerda). */
|
||
const FLIPPABLE = new Set<ElementKind>(["deadtree", "palm", "car", "bed", "desklamp", "waves", "clothesline", "outcrop"]);
|
||
/** Meia largura da base de cada peça (unidades da peça) para a sombra de contato; 0 = sem sombra. */
|
||
const FOOT: Partial<Record<ElementKind, number>> = {
|
||
tree: 130, deadtree: 90, pine: 190, bush: 220, rock: 130, bench: 270, lamp: 60, gravestone: 125, cross: 60, fence: 470,
|
||
house: 420, building: 280, car: 390, sign: 40, table: 290, bed: 400, shelf: 230, crate: 170, tent: 350, fire: 130,
|
||
ark: 380, ark_frame: 380, scaffold: 140, planks: 185, palm: 80, outcrop: 340, cabinet: 185, locker: 330, desk: 340,
|
||
wall: 730, facade: 560, shopfront: 460, desklamp: 90, clothesline: 0,
|
||
};
|
||
|
||
const isNight = (id: PaletteId | undefined) => (id ?? "night") === "night";
|
||
|
||
/** Zoom do fundo pelo enquadramento: em meio corpo/de perto a câmera está mais perto, o fundo cresce junto. */
|
||
function backgroundZoom(spec: ShotSpec): number {
|
||
const framings = (spec.actors ?? []).flatMap((a) => (a.kind === "person" && a.framing ? [a.framing] : []));
|
||
if (framings.includes("close")) return 1.32;
|
||
if (framings.includes("medium")) return 1.16;
|
||
return 1;
|
||
}
|
||
|
||
type El = Place["elements"][number] & { i: number; z: number };
|
||
type Placed = { e: El; x: number; y: number; s: number; zEff: number; flip: boolean };
|
||
type Layout = { horizon: number; indoor: boolean; zoom: number; items: Placed[] };
|
||
|
||
/** Onde cada peça fica (base, escala, profundidade efetiva). A camada de luz usa a mesma conta. */
|
||
export function layoutPlace(spec: ShotSpec): Layout {
|
||
const place = spec.place!;
|
||
const indoor = !!place.indoor;
|
||
const horizon = (place.horizon ?? (indoor ? 0.62 : 0.56)) * H;
|
||
const near = indoor ? H * 0.8 : H * 0.72;
|
||
const items: Placed[] = place.elements.map((raw, i) => {
|
||
const e: El = { ...raw, i, z: raw.z ?? 0.3 };
|
||
const wall = indoor && WALL_MOUNTED.has(e.kind);
|
||
const zEff = wall ? 1 : e.z;
|
||
const depth = 1 - zEff * (indoor ? 0.35 : 0.62);
|
||
const s = (e.scale ?? 1) * depth * 1.15;
|
||
let y: number;
|
||
if (CEILING.has(e.kind)) y = 0;
|
||
else if (e.kind === "cloud") y = horizon * (0.15 + 0.5 * e.z);
|
||
else y = horizon + (1 - zEff) * (near - horizon);
|
||
y -= (e.lift ?? 0) * H;
|
||
return { e, x: e.x * W, y, s, zEff, flip: !!e.flip && FLIPPABLE.has(e.kind) };
|
||
});
|
||
// Objeto de mesa perto de uma mesa (mesma profundidade, dentro do tampo) vai para cima dela.
|
||
for (const it of items) {
|
||
if (!ON_TOP.has(it.e.kind) || it.e.lift !== undefined) continue;
|
||
const surface = items.find((o) => SURFACE_TOP[o.e.kind] && Math.abs(o.e.z - it.e.z) <= 0.25 && Math.abs(o.x - it.x) < (FOOT[o.e.kind] ?? 0) * o.s);
|
||
if (!surface) continue;
|
||
it.y = surface.y - SURFACE_TOP[surface.e.kind]! * surface.s;
|
||
it.s = surface.s * (it.e.scale ?? 1) * 0.9;
|
||
it.zEff = surface.zEff - 0.001;
|
||
}
|
||
items.sort((a, b) => b.zEff - a.zEff || a.e.i - b.e.i);
|
||
return { horizon, indoor, zoom: backgroundZoom(spec), items };
|
||
}
|
||
|
||
/** Sol/lua no céu (sempre do lado esquerdo: é de lá que vem a luz das peças). */
|
||
export function sunOf(id: PaletteId | undefined, horizon: number): { x: number; y: number; r: number } | null {
|
||
switch (id ?? "night") {
|
||
case "day": return { x: W * 0.2, y: H * 0.2, r: 66 };
|
||
case "sepia": return { x: W * 0.2, y: H * 0.19, r: 70 };
|
||
case "dusk": return { x: W * 0.2, y: horizon - H * 0.13, r: 96 };
|
||
case "night": return { x: W * 0.22, y: H * 0.15, r: 44 };
|
||
default: return null;
|
||
}
|
||
}
|
||
|
||
/** Altura da superfície da água no instante (fração da altura; null = sem enchente). */
|
||
export function floodLevel(place: Place | undefined, progress: number): number | null {
|
||
if (!place?.flood) return null;
|
||
const p = Math.max(0, Math.min(1, progress));
|
||
const k = p < 0.5 ? 2 * p * p : 1 - (-2 * p + 2) ** 2 / 2;
|
||
return place.flood.from + (place.flood.to - place.flood.from) * k;
|
||
}
|
||
|
||
/** Uma peça no lugar: sombra de contato + desenho com a tinta da profundidade dela. */
|
||
function PlacedElement({ it, pal, spec, hazeColor, y, rot = 0, part }: { it: Placed; pal: Pal; spec: ShotSpec; hazeColor: string; y?: number; rot?: number; part?: "front" }) {
|
||
const { e } = it;
|
||
const place = spec.place!;
|
||
const indoor = !!place.indoor;
|
||
const z = it.zEff;
|
||
const sky = e.kind === "cloud" || e.kind === "rainbow";
|
||
const haze = sky ? 0.12 : indoor ? z * 0.22 : Math.min(0.85, Math.pow(z, 1.8) * 0.66 + (place.fog ? 0.04 + z * 0.16 : 0));
|
||
const front = !sky && z < 0.25 ? (0.25 - z) * 0.5 : 0;
|
||
const p = makePaint(pal, rng(spec.seed + e.i * 17), { haze, hazeColor, front, indoor, night: isNight(spec.palette) });
|
||
const draw = part === "front" ? FRONT_PART[e.kind] : DRAW[e.kind];
|
||
if (!draw) return null;
|
||
const foot = (CEILING.has(e.kind) || (indoor && WALL_MOUNTED.has(e.kind)) || e.float || (e.lift ?? 0) > 0.02) ? 0 : FOOT[e.kind] ?? 0;
|
||
const s = it.s;
|
||
return (
|
||
<g transform={`translate(${it.x} ${y ?? it.y}) rotate(${rot}) scale(${it.flip ? -s : s} ${s})`}>
|
||
{foot > 0 && part !== "front" && <ellipse cx={foot * 0.1} cy={4} rx={foot * 1.12} ry={Math.min(46, Math.max(16, foot * 0.11))} fill="url(#cShadow)" opacity={1 - z * 0.5} />}
|
||
{draw(p, e.color)}
|
||
</g>
|
||
);
|
||
}
|
||
|
||
/** Céu com degradê rico, sol/lua com halo (ou parede do interior). Não muda com o quadro. */
|
||
function SkyLayer({ spec, horizon }: { spec: ShotSpec; horizon: number }) {
|
||
const pal = palette(spec.palette);
|
||
const place = spec.place!;
|
||
if (place.indoor) {
|
||
const wallTop = mix(pal.wall, pal.ink, 0.42);
|
||
return <g>
|
||
<defs>
|
||
<linearGradient id="placeWall" x1="0" y1="0" x2="0" y2="1">
|
||
<stop offset="0" stopColor={wallTop} /><stop offset="0.45" stopColor={mix(pal.wall, pal.ink, 0.12)} /><stop offset="1" stopColor={pal.wall} />
|
||
</linearGradient>
|
||
<linearGradient id="placeCorner" x1="0" y1="0" x2="1" y2="0">
|
||
<stop offset="0" stopColor={pal.shade} stopOpacity={0.4} /><stop offset="0.16" stopColor={pal.shade} stopOpacity={0} />
|
||
<stop offset="0.84" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.45} />
|
||
</linearGradient>
|
||
</defs>
|
||
<rect width={W} height={H} fill="url(#placeWall)" />
|
||
</g>;
|
||
}
|
||
const sun = sunOf(spec.palette, horizon);
|
||
const night = isNight(spec.palette);
|
||
return <g>
|
||
<defs>
|
||
<linearGradient id="placeSky" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="0" y2={horizon}>
|
||
<stop offset="0" stopColor={pal.sky[0]} /><stop offset="0.55" stopColor={pal.sky[1]} /><stop offset="1" stopColor={pal.sky[2]} />
|
||
</linearGradient>
|
||
{sun && <radialGradient id="placeHalo" gradientUnits="userSpaceOnUse" cx={sun.x} cy={sun.y} r={sun.r * 4.2}>
|
||
<stop offset="0" stopColor={pal.halo} stopOpacity={night ? 0.35 : 0.75} /><stop offset="0.35" stopColor={pal.halo} stopOpacity={night ? 0.12 : 0.3} />
|
||
<stop offset="1" stopColor={pal.halo} stopOpacity={0} />
|
||
</radialGradient>}
|
||
</defs>
|
||
<rect width={W} height={H} fill="url(#placeSky)" />
|
||
{sun && <>
|
||
<circle cx={sun.x} cy={sun.y} r={sun.r * 4.2} fill="url(#placeHalo)" />
|
||
<circle cx={sun.x} cy={sun.y} r={sun.r} fill={pal.sun} />
|
||
{night
|
||
? <><circle cx={sun.x + 12} cy={sun.y - 8} r={9} fill={mix(pal.sun, "#b0a890", 0.4)} /><circle cx={sun.x - 14} cy={sun.y + 12} r={6} fill={mix(pal.sun, "#b0a890", 0.4)} /></>
|
||
: <circle cx={sun.x - sun.r * 0.25} cy={sun.y - sun.r * 0.25} r={sun.r * 0.55} fill="#ffffff" opacity={0.35} />}
|
||
</>}
|
||
</g>;
|
||
}
|
||
|
||
/** Chão (degradê + textura) e, ao fundo, a silhueta distante (morros ou cidade). */
|
||
function GroundLayer({ spec, horizon, hazeColor }: { spec: ShotSpec; horizon: number; hazeColor: string }) {
|
||
const place = spec.place!;
|
||
const pal = palette(spec.palette);
|
||
const rand = rng(spec.seed + 29);
|
||
const out: React.ReactNode[] = [];
|
||
const g = place.ground === "none" ? null : pal.ground[place.ground];
|
||
const span = H - horizon;
|
||
if (place.indoor) {
|
||
// Parede: lambri (meia-parede) ou listras, conforme a semente; rodapé no pé da parede.
|
||
const wall = pal.wall;
|
||
if (spec.seed % 2 === 0) {
|
||
const top = horizon - H * 0.17;
|
||
out.push(<rect key="dado" x={0} y={top} width={W} height={horizon - top} fill={mix(wall, pal.ink, 0.16)} />);
|
||
out.push(<path key="dadoP" d={Array.from({ length: 8 }, (_, i) => `M${i * 150 + 40} ${top + 30} L${i * 150 + 40} ${horizon - 40} L${i * 150 + 150} ${horizon - 40}`).join(" ")}
|
||
stroke={mix(wall, pal.ink, 0.3)} strokeWidth={6} fill="none" />);
|
||
out.push(<rect key="rail" x={0} y={top - 16} width={W} height={18} fill={mix(wall, pal.light, 0.22)} />);
|
||
out.push(<rect key="railS" x={0} y={top + 2} width={W} height={6} fill={mix(wall, pal.ink, 0.35)} />);
|
||
} else {
|
||
out.push(<path key="stripes" d={Array.from({ length: 12 }, (_, i) => `M${i * 96 + 30} 0 L${i * 96 + 30} ${horizon}`).join(" ")} stroke={mix(wall, pal.ink, 0.1)} strokeWidth={26} />);
|
||
}
|
||
out.push(<rect key="corner" x={0} y={0} width={W} height={horizon} fill="url(#placeCorner)" />);
|
||
} else if (place.ground === "grass" || place.ground === "dirt" || place.ground === "sand") {
|
||
// Morros distantes em 2 camadas, bem apagados (plano de fundo).
|
||
const ridge = (h: number, amp: number, seed: number) => {
|
||
const r = rng(seed);
|
||
let d = `M0 ${horizon + 2} L0 ${horizon - h}`;
|
||
for (let x = 0; x <= W + 180; x += 180) d += ` Q${x + 90} ${horizon - h - amp * (0.4 + r())} ${x + 180} ${horizon - h + (r() - 0.5) * amp * 0.5}`;
|
||
return d + ` L${W} ${horizon + 2} Z`;
|
||
};
|
||
out.push(<path key="r1" d={ridge(H * 0.075, H * 0.05, spec.seed + 3)} fill={mix(pal.far, hazeColor, 0.55)} />);
|
||
out.push(<path key="r2" d={ridge(H * 0.03, H * 0.03, spec.seed + 7)} fill={mix(g ?? pal.far, hazeColor, 0.45)} />);
|
||
} else if (place.ground === "street") {
|
||
// Cidade ao longe: blocos apagados com algumas janelas.
|
||
let x = -20;
|
||
const blocks: React.ReactNode[] = [];
|
||
while (x < W) {
|
||
const w = 90 + rand() * 120;
|
||
const h = H * (0.05 + rand() * 0.09);
|
||
blocks.push(<rect key={x} x={x} y={horizon - h} width={w} height={h + 2} fill={mix(pal.far, hazeColor, 0.5 + rand() * 0.15)} />);
|
||
x += w - 6;
|
||
}
|
||
out.push(<g key="city">{blocks}</g>);
|
||
}
|
||
if (g) {
|
||
out.push(<rect key="ground" x={0} y={horizon} width={W} height={span} fill="url(#placeGround)" />);
|
||
if (place.ground === "floor") {
|
||
// Tábuas em perspectiva: linhas que fogem para o ponto de fuga, juntas desencontradas, tom alternado.
|
||
const vpY = horizon - H * 0.3;
|
||
const k = (H - vpY) / (horizon - vpY);
|
||
const at = (xh: number, y: number) => W / 2 + (xh - W / 2) * ((y - vpY) / (horizon - vpY));
|
||
const n = 16;
|
||
const step = W / 9;
|
||
let seams = "";
|
||
for (let i = -n; i <= n; i++) {
|
||
const xh = W / 2 + i * step * 0.5;
|
||
if (Math.abs(i) % 2 === 1) {
|
||
const x2 = W / 2 + (i + 1) * step * 0.5;
|
||
out.push(<polygon key={`pl${i}`} points={`${xh},${horizon} ${x2},${horizon} ${W / 2 + (x2 - W / 2) * k},${H} ${W / 2 + (xh - W / 2) * k},${H}`} fill={mix(g, pal.ink, 0.06)} />);
|
||
}
|
||
seams += `M${xh} ${horizon} L${W / 2 + (xh - W / 2) * k} ${H} `;
|
||
for (let j = 0; j < 3; j++) {
|
||
const y = horizon + span * Math.pow(rand(), 1.4);
|
||
const xa = at(xh, y);
|
||
const xb = at(xh + step * 0.5, y);
|
||
seams += `M${xa} ${y} L${xb} ${y} `;
|
||
}
|
||
}
|
||
out.push(<path key="seams" d={seams} stroke={mix(g, pal.ink, 0.32)} strokeWidth={4} fill="none" />);
|
||
out.push(<rect key="base" x={0} y={horizon - 34} width={W} height={36} fill={mix(pal.wall, pal.ink, 0.38)} />);
|
||
out.push(<rect key="baseT" x={0} y={horizon - 34} width={W} height={7} fill={mix(pal.wall, pal.light, 0.15)} />);
|
||
out.push(<rect key="ao" x={0} y={horizon} width={W} height={26} fill={pal.ink} opacity={0.18} />);
|
||
} else if (place.ground === "street") {
|
||
const walk = horizon + span * 0.16;
|
||
const walkC = mix(mix("#d2c8b4", g, 0.3), hazeColor, 0.15);
|
||
out.push(<rect key="walk" x={0} y={horizon} width={W} height={walk - horizon} fill={walkC} />);
|
||
out.push(<path key="tiles" d={Array.from({ length: 14 }, (_, i) => { const x = -120 + i * 110; return `M${x} ${horizon} L${W / 2 + (x - W / 2) * 1.25} ${walk}`; }).join(" ") + ` M0 ${(horizon + walk) / 2} L${W} ${(horizon + walk) / 2}`}
|
||
stroke={mix(walkC, pal.ink, 0.18)} strokeWidth={3} fill="none" />);
|
||
out.push(<rect key="curb" x={0} y={walk} width={W} height={18} fill={mix(walkC, pal.light, 0.25)} />);
|
||
out.push(<rect key="curbS" x={0} y={walk + 18} width={W} height={20} fill={mix(g, pal.ink, 0.35)} />);
|
||
const lane = walk + (H - walk) * 0.42;
|
||
out.push(<path key="lane" d={Array.from({ length: 7 }, (_, i) => `M${i * 190 - 60} ${lane} l120 0`).join(" ")} stroke="#f2ecd8" strokeWidth={12} opacity={0.55} />);
|
||
} else if (place.ground === "grass" || place.ground === "dirt" || place.ground === "sand") {
|
||
// Faixas na perspectiva + tufos/pedrinhas/ondulações, maiores perto da câmera.
|
||
for (let b = 1; b < 6; b++) {
|
||
const y0 = horizon + span * Math.pow(b / 6, 1.7);
|
||
const y1 = horizon + span * Math.pow((b + 0.45) / 6, 1.7);
|
||
out.push(<rect key={`band${b}`} x={0} y={y0} width={W} height={y1 - y0} fill={b % 2 ? mix(g, pal.light, 0.06) : mix(g, pal.ink, 0.05)} opacity={0.45} />);
|
||
}
|
||
let marks = "";
|
||
for (let i = 0; i < 46; i++) {
|
||
const t = Math.pow(rand(), 0.8);
|
||
const y = horizon + span * t;
|
||
const x = rand() * W;
|
||
const s = 6 + t * 26;
|
||
if (place.ground === "grass") marks += `M${x - s} ${y} L${x - s * 0.3} ${y - s * 1.4} L${x} ${y} L${x + s * 0.4} ${y - s * 1.6} L${x + s} ${y} `;
|
||
else if (place.ground === "sand") marks += `M${x - s * 3} ${y} Q${x} ${y - s * 0.6} ${x + s * 3} ${y} `;
|
||
else marks += `M${x - s * 0.6} ${y} a${s * 0.6} ${s * 0.28} 0 1 0 ${s * 1.2} 0 a${s * 0.6} ${s * 0.28} 0 1 0 ${-s * 1.2} 0 `;
|
||
}
|
||
out.push(<path key="marks" d={marks} fill={place.ground === "dirt" ? mix(g, pal.ink, 0.14) : "none"}
|
||
stroke={place.ground === "grass" ? mix(g, pal.ink, 0.25) : place.ground === "sand" ? mix(g, pal.light, 0.35) : "none"} strokeWidth={place.ground === "sand" ? 5 : 4} strokeLinejoin="round" />);
|
||
}
|
||
}
|
||
return <g>{out}</g>;
|
||
}
|
||
|
||
export function PlaceBackground({ spec, frame, progress = 0 }: { spec: ShotSpec; frame: number; progress?: number }) {
|
||
const place = spec.place!;
|
||
const pal = palette(spec.palette);
|
||
const layout = React.useMemo(() => layoutPlace(spec), [spec]);
|
||
const { horizon, zoom } = layout;
|
||
const hazeColor = place.indoor ? pal.wall : mix(mix(pal.sky[2], pal.sky[1], 0.25), "#c8ccd6", place.fog ? 0.45 : 0);
|
||
const level = floodLevel(place, progress);
|
||
const waterY = level === null ? null : level * H;
|
||
const storm = place.weather === "storm";
|
||
const ground = place.ground === "none" ? null : pal.ground[place.ground];
|
||
// Tudo que não muda com o quadro é desenhado uma vez só (céu, chão, peças paradas).
|
||
const sky = React.useMemo(() => <SkyLayer spec={spec} horizon={horizon} />, [spec, horizon]);
|
||
const floating = (it: Placed) => !!it.e.float && waterY !== null;
|
||
const staticBack = React.useMemo(() => (
|
||
<g>
|
||
<GroundLayer spec={spec} horizon={horizon} hazeColor={hazeColor} />
|
||
{layout.items.filter((it) => !(it.e.float && place.flood)).map((it) => <PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor} />)}
|
||
</g>
|
||
), [spec, layout]); // eslint-disable-line react-hooks/exhaustive-deps
|
||
const rand = rng(spec.seed + 13);
|
||
const stars = !place.indoor && isNight(spec.palette)
|
||
? Array.from({ length: 60 }, () => ({ x: rand() * W, y: rand() * horizon * 0.8, r: 1 + rand() * 2, p: rand() * 6 })) : [];
|
||
const zoomT = zoom === 1 ? undefined : `translate(${W / 2} ${horizon}) scale(${zoom}) translate(${-W / 2} ${-horizon})`;
|
||
return (
|
||
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice">
|
||
<defs>
|
||
<linearGradient id="placeFog" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#ffffff" stopOpacity={0} />
|
||
<stop offset="0.3" stopColor="#d8dce6" stopOpacity={0.3} /><stop offset="1" stopColor="#d8dce6" stopOpacity={0.06} /></linearGradient>
|
||
<radialGradient id="cShadow"><stop offset="0" stopColor={pal.ink} stopOpacity={0.5} /><stop offset="0.6" stopColor={pal.ink} stopOpacity={0.28} /><stop offset="1" stopColor={pal.ink} stopOpacity={0} /></radialGradient>
|
||
{ground && <linearGradient id="placeGround" x1="0" y1="0" x2="0" y2="1">
|
||
{place.indoor
|
||
? <><stop offset="0" stopColor={mix(ground, pal.ink, 0.3)} /><stop offset="0.18" stopColor={ground} /><stop offset="1" stopColor={mix(ground, pal.ink, 0.32)} /></>
|
||
: <><stop offset="0" stopColor={mix(ground, hazeColor, 0.35)} /><stop offset="0.3" stopColor={ground} /><stop offset="1" stopColor={mix(ground, pal.ink, 0.22)} /></>}
|
||
</linearGradient>}
|
||
<linearGradient id="placeWater" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={mix(pal.ground.water, "#ffffff", 0.12)} /><stop offset="1" stopColor={mix(pal.ground.water, pal.ink, 0.35)} /></linearGradient>
|
||
</defs>
|
||
{sky}
|
||
{stars.map((s, i) => <circle key={i} cx={s.x} cy={s.y} r={s.r} fill="#fff" opacity={0.3 + 0.3 * Math.sin(frame / 12 + s.p)} />)}
|
||
<g transform={zoomT}>
|
||
{staticBack}
|
||
{waterY !== null && (
|
||
<g>
|
||
<rect x={0} y={waterY} width={W} height={H - waterY} fill="url(#placeWater)" />
|
||
<path d={`M0 ${waterY} ${Array.from({ length: 10 }, (_, i) => `Q${i * 108 + 54} ${waterY - 22 + Math.sin(frame / 9 + i) * 8} ${(i + 1) * 108} ${waterY}`).join(" ")}`}
|
||
stroke="#ffffff" strokeWidth={7} fill="none" opacity={0.55} />
|
||
</g>
|
||
)}
|
||
{place.ground === "water" && waterY === null && Array.from({ length: 6 }, (_, i) => (
|
||
<path key={`w${i}`} d={`M${((i * 197 + frame * 2) % (W + 200)) - 100} ${horizon + 60 + i * ((H - horizon) / 6)} q30 -16 60 0 q30 16 60 0`} stroke="#ffffff" strokeWidth={5} fill="none" opacity={0.35} />
|
||
))}
|
||
{layout.items.filter(floating).map((it) => (
|
||
// Boia: a quilha fica um pouco abaixo da superfície e a peça balança com a água.
|
||
<PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor}
|
||
y={waterY! + H * 0.035 + Math.sin(frame / 14 + it.e.i) * 9} rot={Math.sin(frame / 22 + it.e.i) * (storm ? 3.5 : 1.6)} />
|
||
))}
|
||
{waterY !== null && <rect x={0} y={waterY + H * 0.03} width={W} height={H} fill={pal.ground.water} opacity={0.35} />}
|
||
</g>
|
||
{place.fog && <rect x={0} y={horizon - H * 0.18} width={W} height={H - horizon + H * 0.18} fill="url(#placeFog)" />}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
type LightSpot = { kind: "lamp" | "window" | "sun" | "glow"; x: number; y: number; w?: number; h?: number; spread?: number; fixture?: boolean };
|
||
|
||
/** Fonte de luz do trecho: a escolhida no spec, ou deduzida das peças (luminária > janela > sol). */
|
||
export function resolveLight(spec: ShotSpec | undefined, light: ShotSpec["light"]): LightSpot | null {
|
||
if (light === "none") return null;
|
||
const src = spec?.lightSource;
|
||
if (src) {
|
||
const dy = src.kind === "lamp" ? 0.2 : src.kind === "window" ? 0.32 : 0.2;
|
||
return { kind: src.kind, x: src.x * W, y: (src.y ?? dy) * H, w: W * 0.3, h: H * 0.18 };
|
||
}
|
||
const place = spec?.scene.kind === "place" ? spec.place : undefined;
|
||
const layout = place ? layoutPlace(spec!) : null;
|
||
const toScreen = (x: number, y: number) => layout && layout.zoom !== 1
|
||
? { x: W / 2 + (x - W / 2) * layout.zoom, y: layout.horizon + (y - layout.horizon) * layout.zoom } : { x, y };
|
||
const pendant = layout?.items.find((it) => it.e.kind === "pendant");
|
||
if (pendant && (light === "spot" || light === undefined)) {
|
||
const z = layout!.zoom;
|
||
const b = toScreen(pendant.x, pendant.y + 376 * pendant.s);
|
||
return { kind: "lamp", x: b.x, y: b.y, spread: 130 * pendant.s * z };
|
||
}
|
||
// Luminária de mesa acesa: brilho quente em volta da cúpula, o resto do lugar no escuro.
|
||
const desk = layout?.items.find((it) => it.e.kind === "desklamp");
|
||
if (desk && light === undefined) {
|
||
const k = desk.flip ? -1 : 1;
|
||
const a = toScreen(desk.x + k * 40 * desk.s, desk.y - 130 * desk.s);
|
||
return { kind: "glow", x: a.x, y: a.y, spread: 420 * desk.s * layout!.zoom };
|
||
}
|
||
if (light === "spot") return { kind: "lamp", x: W / 2, y: H * 0.045, spread: W * 0.07, fixture: true };
|
||
if (light !== undefined || !place || !layout) return null;
|
||
if (place.indoor) {
|
||
const win = layout.items.find((it) => it.e.kind === "window");
|
||
if (!win) return null;
|
||
const a = toScreen(win.x - 186 * win.s, win.y - 616 * win.s);
|
||
const b = toScreen(win.x + 186 * win.s, win.y - 244 * win.s);
|
||
return { kind: "window", x: (a.x + b.x) / 2, y: (a.y + b.y) / 2, w: b.x - a.x, h: b.y - a.y };
|
||
}
|
||
const sun = sunOf(spec!.palette, layout.horizon);
|
||
if (!sun || isNight(spec!.palette)) return null;
|
||
return { kind: "sun", x: sun.x, y: sun.y };
|
||
}
|
||
|
||
/**
|
||
* Luz por cima de tudo (inclusive dos personagens). Fonte POSICIONADA: luminária (cone + poça no chão), janela
|
||
* (raios em diagonal + manchas no piso) ou sol (brilho quente). Contraste quente (luz) × frio (sombra).
|
||
* `light: "vignette"` escurece as bordas; `"none"` desliga; sem `light`, a fonte sai das peças do lugar.
|
||
*/
|
||
export function LightLayer({ light, palette: id, spec }: { light: ShotSpec["light"]; palette?: PaletteId; spec?: ShotSpec }) {
|
||
const pal = palette(id ?? spec?.palette);
|
||
const src = resolveLight(spec, light);
|
||
const vignette = light === "vignette";
|
||
if (!src && !vignette) return null;
|
||
const indoor = !!spec?.place?.indoor;
|
||
const horizon = spec?.place ? (spec.place.horizon ?? (indoor ? 0.62 : 0.56)) * H : H * 0.6;
|
||
const night = isNight(id ?? spec?.palette);
|
||
const warm = night && src?.kind === "window" ? "#a8c0ff" : pal.light;
|
||
const layers: React.ReactNode[] = [];
|
||
const defs: React.ReactNode[] = [];
|
||
if (src?.kind === "lamp") {
|
||
const floorY = indoor || !spec?.place ? Math.max(src.y + H * 0.3, horizon + (H - horizon) * 0.55) : H * 0.84;
|
||
const sw = src.spread ?? W * 0.08;
|
||
const spread = (floorY - src.y) * 0.42 + sw;
|
||
defs.push(<linearGradient key="c" id="lgCone" gradientUnits="userSpaceOnUse" x1="0" y1={src.y} x2="0" y2={floorY}>
|
||
<stop offset="0" stopColor={warm} stopOpacity={0.42} /><stop offset="1" stopColor={warm} stopOpacity={0.06} /></linearGradient>);
|
||
defs.push(<radialGradient key="p" id="lgPool"><stop offset="0" stopColor={warm} stopOpacity={0.4} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
|
||
defs.push(<radialGradient key="d" id="lgDark" gradientUnits="userSpaceOnUse" cx={src.x} cy={(src.y + floorY) / 2} r={H * 0.62}>
|
||
<stop offset="0.3" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.62} /></radialGradient>);
|
||
layers.push(<rect key="dark" width={W} height={H} fill="url(#lgDark)" />);
|
||
layers.push(<polygon key="cone" points={`${src.x - sw * 0.92},${src.y} ${src.x + sw * 0.92},${src.y} ${src.x + spread},${floorY} ${src.x - spread},${floorY}`} fill="url(#lgCone)" />);
|
||
layers.push(<ellipse key="pool" cx={src.x} cy={floorY} rx={spread * 1.15} ry={spread * 0.2} fill="url(#lgPool)" />);
|
||
if (src.fixture) {
|
||
layers.push(<path key="fx" d={`M${src.x - sw} ${src.y} Q${src.x - sw * 0.9} ${src.y - 60} ${src.x} ${src.y - 64} Q${src.x + sw * 0.9} ${src.y - 60} ${src.x + sw} ${src.y} Z`} fill={mix(pal.ink, "#4a5270", 0.5)} />);
|
||
layers.push(<ellipse key="fxl" cx={src.x} cy={src.y} rx={sw} ry={12} fill={warm} />);
|
||
}
|
||
} else if (src?.kind === "window") {
|
||
const ww = src.w ?? W * 0.3;
|
||
const wh = src.h ?? H * 0.18;
|
||
const x0 = src.x - ww / 2;
|
||
const y0 = src.y - wh / 2;
|
||
const dir = src.x < W / 2 ? 1 : -1;
|
||
const vx = dir * W * 0.78;
|
||
const vy = H * 0.55;
|
||
const pane = (a: number, b: number) => {
|
||
// Retângulo da vidraça arrastado na direção dos raios (contorno convexo).
|
||
const xa = x0 + ww * a;
|
||
const xb = x0 + ww * b;
|
||
const [l, r] = dir > 0 ? [xa, xb] : [xb, xa];
|
||
return `${l},${y0} ${r},${y0} ${r + vx},${y0 + vy} ${r + vx},${y0 + wh + vy} ${l + vx},${y0 + wh + vy} ${l},${y0 + wh}`;
|
||
};
|
||
defs.push(<linearGradient key="b" id="lgBeam" gradientUnits="userSpaceOnUse" x1={src.x} y1={src.y} x2={src.x + vx} y2={src.y + vy}>
|
||
<stop offset="0" stopColor={warm} stopOpacity={night ? 0.16 : 0.34} /><stop offset="1" stopColor={warm} stopOpacity={0} /></linearGradient>);
|
||
defs.push(<radialGradient key="g" id="lgGlow" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={W * 0.75}>
|
||
<stop offset="0" stopColor={warm} stopOpacity={night ? 0.12 : 0.24} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
|
||
defs.push(<linearGradient key="k" id="lgCool" x1={dir > 0 ? 1 : 0} y1="0" x2={dir > 0 ? 0 : 1} y2="0">
|
||
<stop offset="0" stopColor={pal.shade} stopOpacity={0.4} /><stop offset="0.6" stopColor={pal.shade} stopOpacity={0} /></linearGradient>);
|
||
layers.push(<rect key="cool" width={W} height={H} fill="url(#lgCool)" />);
|
||
layers.push(<rect key="glow" width={W} height={H} fill="url(#lgGlow)" />);
|
||
layers.push(<polygon key="b1" points={pane(0, 0.47)} fill="url(#lgBeam)" />);
|
||
layers.push(<polygon key="b2" points={pane(0.53, 1)} fill="url(#lgBeam)" />);
|
||
// Manchas da janela no piso, inclinadas no sentido dos raios.
|
||
const fy = horizon + (H - horizon) * 0.3;
|
||
const fh = (H - horizon) * 0.2;
|
||
const cx = src.x + dir * W * 0.38;
|
||
const sk = dir * fh * 0.9;
|
||
for (const [a, b] of [[-0.62, -0.03], [0.03, 0.62]]) {
|
||
const xa = cx + ww * a;
|
||
const xb = cx + ww * b;
|
||
layers.push(<polygon key={`f${a}`} points={`${xa},${fy} ${xb},${fy} ${xb + sk},${fy + fh} ${xa + sk},${fy + fh}`} fill={warm} opacity={night ? 0.08 : 0.2} />);
|
||
}
|
||
} else if (src?.kind === "glow") {
|
||
const r = Math.max(W * 0.35, src.spread ?? W * 0.4);
|
||
defs.push(<radialGradient key="g" id="lgGlow" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={r}>
|
||
<stop offset="0" stopColor={warm} stopOpacity={0.38} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
|
||
defs.push(<radialGradient key="d" id="lgDark" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={H * 0.7}>
|
||
<stop offset="0.25" stopColor={pal.shade} stopOpacity={0} /><stop offset="1" stopColor={pal.shade} stopOpacity={0.6} /></radialGradient>);
|
||
layers.push(<rect key="dark" width={W} height={H} fill="url(#lgDark)" />);
|
||
layers.push(<rect key="glow" width={W} height={H} fill="url(#lgGlow)" />);
|
||
} else if (src?.kind === "sun") {
|
||
defs.push(<radialGradient key="s" id="lgSun" gradientUnits="userSpaceOnUse" cx={src.x} cy={src.y} r={W * 1.05}>
|
||
<stop offset="0" stopColor={warm} stopOpacity={0.26} /><stop offset="0.5" stopColor={warm} stopOpacity={0.06} /><stop offset="1" stopColor={warm} stopOpacity={0} /></radialGradient>);
|
||
defs.push(<linearGradient key="k" id="lgCool" x1="1" y1="1" x2="0.3" y2="0.4">
|
||
<stop offset="0" stopColor={pal.shade} stopOpacity={0.3} /><stop offset="1" stopColor={pal.shade} stopOpacity={0} /></linearGradient>);
|
||
layers.push(<rect key="cool" width={W} height={H} fill="url(#lgCool)" />);
|
||
layers.push(<rect key="sun" width={W} height={H} fill="url(#lgSun)" />);
|
||
}
|
||
if (vignette) {
|
||
defs.push(<radialGradient key="v" id="lgVig" cx="0.5" cy="0.45" r="0.75"><stop offset="0.55" stopColor="#000" stopOpacity={0} /><stop offset="1" stopColor="#000" stopOpacity={0.55} /></radialGradient>);
|
||
layers.push(<rect key="vig" width={W} height={H} fill="url(#lgVig)" />);
|
||
}
|
||
return (
|
||
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
|
||
<defs>{defs}</defs>
|
||
{layers}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
/** Chuva por cima de tudo (inclusive dos personagens); tempestade escurece, chove mais e relampeja. */
|
||
export function WeatherLayer({ spec, frame }: { spec: ShotSpec; frame: number }) {
|
||
const weather = spec.place?.weather ?? "none";
|
||
if (weather === "none") return null;
|
||
const storm = weather === "storm";
|
||
const rand = rng(spec.seed + 101);
|
||
const drops = Array.from({ length: storm ? 230 : 130 }, () => ({ x: rand() * (W + 300), y: rand() * H, v: 38 + rand() * 26, l: 40 + rand() * 50 }));
|
||
// Relâmpago: um clarão curto a cada 2,5 s, com fase que depende da semente.
|
||
const cycle = 75;
|
||
const ph = (frame + (spec.seed % cycle)) % cycle;
|
||
const flash = storm && ph < 5 ? (ph < 2 ? 0.55 : 0.25) : 0;
|
||
return (
|
||
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
|
||
{storm && <rect width={W} height={H} fill="#0a1020" opacity={0.22} />}
|
||
<g stroke="#d6e4f5" strokeWidth={storm ? 3.4 : 2.6} strokeLinecap="round" opacity={storm ? 0.6 : 0.5}>
|
||
{drops.map((d, i) => {
|
||
const y = ((d.y + frame * d.v) % (H + 120)) - 60;
|
||
const x = ((((d.x - frame * d.v * 0.22) % (W + 300)) + W + 300) % (W + 300)) - 150;
|
||
return <line key={i} x1={x} y1={y} x2={x - d.l * 0.22} y2={y + d.l} />;
|
||
})}
|
||
</g>
|
||
{flash > 0 && <>
|
||
<rect width={W} height={H} fill="#eaf2ff" opacity={flash} />
|
||
<path d={`M${W * 0.7} 0 L${W * 0.64} ${H * 0.14} L${W * 0.69} ${H * 0.14} L${W * 0.6} ${H * 0.3}`} stroke="#ffffff" strokeWidth={9} fill="none" strokeLinejoin="round" />
|
||
</>}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Por cima dos personagens: a parte da frente das peças ocupadas (casco da arca, lataria do carro), na mesma
|
||
* posição da peça no fundo — quem está "dentro" aparece da cintura para cima.
|
||
*/
|
||
export function PlaceForeground({ spec, frame, progress = 0 }: { spec: ShotSpec; frame: number; progress?: number }) {
|
||
const place = spec.place;
|
||
const layout = React.useMemo(() => (place ? layoutPlace(spec) : null), [spec, place]);
|
||
if (!place || !layout || !place.elements.some((e) => e.occupied && FRONT_PART[e.kind])) return null;
|
||
const pal = palette(spec.palette);
|
||
const hazeColor = place.indoor ? pal.wall : mix(mix(pal.sky[2], pal.sky[1], 0.25), "#c8ccd6", place.fog ? 0.45 : 0);
|
||
const level = floodLevel(place, progress);
|
||
const waterY = level === null ? null : level * H;
|
||
const storm = place.weather === "storm";
|
||
const { horizon, zoom } = layout;
|
||
const zoomT = zoom === 1 ? undefined : `translate(${W / 2} ${horizon}) scale(${zoom}) translate(${-W / 2} ${-horizon})`;
|
||
return (
|
||
<svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
|
||
<g transform={zoomT}>
|
||
{layout.items.filter((it) => it.e.occupied && FRONT_PART[it.e.kind]).map((it) => {
|
||
const floating = !!it.e.float && waterY !== null;
|
||
return <PlacedElement key={it.e.i} it={it} pal={pal} spec={spec} hazeColor={hazeColor} part="front"
|
||
y={floating ? waterY! + H * 0.035 + Math.sin(frame / 14 + it.e.i) * 9 : undefined}
|
||
rot={floating ? Math.sin(frame / 22 + it.e.i) * (storm ? 3.5 : 1.6) : 0} />;
|
||
})}
|
||
{waterY !== null && place.elements.some((e) => e.occupied && e.float) && <rect x={0} y={waterY + H * 0.03} width={W} height={H} fill={pal.ground.water} opacity={0.35} />}
|
||
</g>
|
||
</svg>
|
||
);
|
||
}
|