Cartoon: mãos, membros e cenários novos; elenco de Noé e a Arca
- 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>
This commit is contained in:
+513
-93
@@ -1,142 +1,562 @@
|
||||
// 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 const PALETTES = ["night", "sepia", "day", "dusk", "gray"] as const;
|
||||
export type PaletteId = (typeof PALETTES)[number];
|
||||
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"] as const;
|
||||
"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 (fração da altura; padrão 0,56). */
|
||||
/** Linha do horizonte / pé da parede (fração da altura; padrão 0,56 fora e 0,62 dentro). */
|
||||
horizon?: number;
|
||||
fog?: boolean;
|
||||
elements: { kind: ElementKind; x: number; z?: number; scale?: number; flip?: boolean; color?: string }[];
|
||||
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;
|
||||
}[];
|
||||
};
|
||||
|
||||
type Pal = { sky: [string, string]; wall: string; ground: Record<string, string>; far: string; near: string; ink: string; leaf: string; trunk: string; stone: string; light: string };
|
||||
const P: Record<PaletteId, Pal> = {
|
||||
night: { sky: ["#0b0e22", "#1c2147"], wall: "#2a2f4a", far: "#2a2d57", near: "#3b3f74", ink: "#0c0d1a", leaf: "#24445a", trunk: "#2b2338", stone: "#5a5f86", light: "#ffc94a",
|
||||
ground: { grass: "#1d2e3a", street: "#1a1d38", dirt: "#2a2433", floor: "#22243a", sand: "#4a4560", water: "#152a4a" } },
|
||||
sepia: { sky: ["#c9ad83", "#e8d6ae"], wall: "#7d6a55", far: "#a88f6e", near: "#6e5843", ink: "#2a2018", leaf: "#7b7a45", trunk: "#5a4330", stone: "#9b9387", light: "#ffd98a",
|
||||
ground: { grass: "#8b8a52", street: "#6a5a4a", dirt: "#7a5a3c", floor: "#5e4c3c", sand: "#d2b886", water: "#6f8a8a" } },
|
||||
day: { sky: ["#5aa9e6", "#cfeaf8"], wall: "#e9dcc5", far: "#9cc3d9", near: "#d98a5c", ink: "#22252e", leaf: "#4caf50", trunk: "#7a5232", stone: "#a9adb5", light: "#fff3b0",
|
||||
ground: { grass: "#78c25a", street: "#8a8f99", dirt: "#b88a5a", floor: "#c9a77c", sand: "#f0d79a", water: "#3f9ad8" } },
|
||||
dusk: { sky: ["#2a2c5c", "#e8946a"], wall: "#4a3a52", far: "#4c3f6e", near: "#6a4a62", ink: "#140f1c", leaf: "#2f4a3f", trunk: "#3a2a2a", stone: "#7a7090", light: "#ffcf7a",
|
||||
ground: { grass: "#3a4a3a", street: "#3a3348", dirt: "#4a3530", floor: "#3c3040", sand: "#a87d6a", water: "#4a5a8a" } },
|
||||
gray: { sky: ["#6f7680", "#b4b9bf"], wall: "#565b63", far: "#8a9098", near: "#5c6168", ink: "#1b1d21", leaf: "#5a6b55", trunk: "#4a4038", stone: "#9aa0a8", light: "#f2e6c8",
|
||||
ground: { grass: "#5f6e55", street: "#4a4f57", dirt: "#5e5246", floor: "#45484f", sand: "#a8a08a", water: "#5a6f80" } },
|
||||
};
|
||||
export const palette = (id: PaletteId | undefined): Pal => P[id ?? "night"] ?? P.night;
|
||||
|
||||
const W = 1080;
|
||||
const H = 1920;
|
||||
const DRAW: Record<string, Draw> = { ...NATURE, ...BUILT, ...INDOOR };
|
||||
|
||||
function mix(a: string, b: string, k: number): string {
|
||||
const pa = parseInt(a.slice(1), 16);
|
||||
const pb = parseInt(b.slice(1), 16);
|
||||
const ch = (s: number) => Math.round(((pa >> s) & 255) * (1 - k) + ((pb >> s) & 255) * k);
|
||||
return `#${[16, 8, 0].map((s) => ch(s).toString(16).padStart(2, "0")).join("")}`;
|
||||
/** 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;
|
||||
}
|
||||
|
||||
/** Uma peça desenhada com a base em (0,0), altura de referência ~300 px. */
|
||||
function Element({ kind, pal, color, seed }: { kind: ElementKind; pal: Pal; color?: string; seed: number }) {
|
||||
const r = rng(seed);
|
||||
switch (kind) {
|
||||
case "tree": return <g><rect x={-14} y={-150} width={28} height={150} fill={pal.trunk} /><circle cx={0} cy={-210} r={95} fill={color ?? pal.leaf} /><circle cx={-60} cy={-170} r={60} fill={color ?? pal.leaf} /><circle cx={62} cy={-175} r={62} fill={color ?? pal.leaf} /></g>;
|
||||
case "pine": return <g><rect x={-12} y={-60} width={24} height={60} fill={pal.trunk} /><polygon points="0,-330 -90,-60 90,-60" fill={color ?? pal.leaf} /></g>;
|
||||
case "deadtree": return <g stroke={color ?? pal.trunk} strokeLinecap="round" fill="none"><path d="M0 0 L0 -220" strokeWidth={26} /><path d="M0 -120 L-70 -200 M-40 -160 L-80 -150 M0 -170 L60 -250 M30 -210 L80 -215 M0 -220 L-20 -280" strokeWidth={12} /></g>;
|
||||
case "bush": return <g fill={color ?? pal.leaf}><circle cx={-40} cy={-35} r={42} /><circle cx={10} cy={-50} r={52} /><circle cx={55} cy={-30} r={38} /></g>;
|
||||
case "rock": return <path d="M-70 0 Q-80 -50 -30 -70 Q20 -90 60 -50 Q85 -20 70 0 Z" fill={color ?? pal.stone} />;
|
||||
case "mountain": return <g><polygon points="-520,0 0,-520 520,0" fill={color ?? pal.far} /><polygon points="-110,-410 0,-520 110,-410 50,-430 0,-400 -50,-430" fill="#ffffff" opacity={0.6} /></g>;
|
||||
case "cloud": return <g fill={color ?? "#ffffff"} opacity={0.85}><ellipse cx={0} cy={-40} rx={110} ry={40} /><circle cx={-40} cy={-70} r={45} /><circle cx={30} cy={-80} r={55} /></g>;
|
||||
case "bench": return <g fill={color ?? "#8a5a3a"}><rect x={-110} y={-70} width={220} height={16} rx={4} /><rect x={-110} y={-120} width={220} height={14} rx={4} /><rect x={-95} y={-70} width={12} height={70} fill={pal.ink} /><rect x={83} y={-70} width={12} height={70} fill={pal.ink} /></g>;
|
||||
case "lamp": return <g><rect x={-7} y={-420} width={14} height={420} fill={pal.ink} /><rect x={-36} y={-440} width={72} height={26} rx={8} fill={pal.ink} /><ellipse cx={0} cy={-408} rx={26} ry={8} fill={pal.light} /><path d="M-24 -408 L-140 0 L140 0 L24 -408 Z" fill={pal.light} opacity={0.08} /></g>;
|
||||
case "gravestone": return <g><path d="M-55 0 L-55 -130 Q-55 -185 0 -185 Q55 -185 55 -130 L55 0 Z" fill={color ?? pal.stone} /><rect x={-28} y={-120} width={56} height={6} rx={3} fill={pal.ink} opacity={0.35} /><rect x={-22} y={-100} width={44} height={6} rx={3} fill={pal.ink} opacity={0.35} /></g>;
|
||||
case "cross": return <g fill={color ?? pal.stone}><rect x={-12} y={-200} width={24} height={200} /><rect x={-60} y={-160} width={120} height={22} /></g>;
|
||||
case "fence": return <g fill={color ?? pal.ink}>{Array.from({ length: 9 }, (_, i) => <rect key={i} x={-200 + i * 50} y={-130} width={14} height={130} />)}<rect x={-210} y={-110} width={430} height={10} /><rect x={-210} y={-50} width={430} height={10} /></g>;
|
||||
case "house": return <g><polygon points="-150,-180 0,-290 150,-180" fill={pal.ink} opacity={0.6} /><rect x={-140} y={-180} width={280} height={180} fill={color ?? pal.near} /><rect x={-110} y={-140} width={50} height={50} rx={4} fill={pal.light} opacity={r() > 0.5 ? 1 : 0.15} /><rect x={60} y={-140} width={50} height={50} rx={4} fill={pal.light} opacity={r() > 0.5 ? 1 : 0.15} /><rect x={-25} y={-100} width={50} height={100} fill={pal.ink} opacity={0.7} /></g>;
|
||||
case "building": {
|
||||
const floors = 4 + Math.floor(r() * 4);
|
||||
return <g><rect x={-120} y={-floors * 80} width={240} height={floors * 80} fill={color ?? pal.far} />{Array.from({ length: floors * 3 }, (_, i) => <rect key={i} x={-95 + (i % 3) * 70} y={-floors * 80 + 20 + Math.floor(i / 3) * 80} width={44} height={40} fill={pal.light} opacity={r() > 0.7 ? 0.9 : 0.12} />)}</g>;
|
||||
}
|
||||
case "car": return <g><path d="M-150 -40 L-150 -90 Q-140 -110 -100 -112 L-60 -160 L70 -160 L110 -112 L150 -100 L150 -40 Z" fill={color ?? "#c8443a"} /><rect x={-50} y={-150} width={50} height={36} fill="#cfe3f3" opacity={0.85} /><rect x={8} y={-150} width={52} height={36} fill="#cfe3f3" opacity={0.85} /><circle cx={-90} cy={-35} r={32} fill={pal.ink} /><circle cx={95} cy={-35} r={32} fill={pal.ink} /></g>;
|
||||
case "sign": return <g><rect x={-6} y={-220} width={12} height={220} fill={pal.ink} /><rect x={-90} y={-260} width={180} height={70} rx={8} fill={color ?? "#2f6d3a"} stroke="#ffffff" strokeWidth={5} /></g>;
|
||||
case "door": return <g><rect x={-80} y={-330} width={160} height={330} rx={4} fill={color ?? "#4a2f22"} /><rect x={-60} y={-305} width={120} height={130} rx={3} fill="#000000" opacity={0.15} /><rect x={-60} y={-155} width={120} height={130} rx={3} fill="#000000" opacity={0.15} /><circle cx={52} cy={-165} r={9} fill="#e6c27a" /></g>;
|
||||
case "window": return <g><rect x={-120} y={-260} width={240} height={200} rx={6} fill={pal.ink} /><rect x={-108} y={-248} width={216} height={176} fill={color ?? mix(pal.sky[0], pal.sky[1], 0.5)} /><rect x={-4} y={-248} width={8} height={176} fill={pal.ink} /><rect x={-108} y={-164} width={216} height={8} fill={pal.ink} /></g>;
|
||||
case "table": return <g fill={color ?? "#7a5232"}><rect x={-140} y={-130} width={280} height={20} rx={4} /><rect x={-120} y={-110} width={18} height={110} /><rect x={102} y={-110} width={18} height={110} /></g>;
|
||||
case "bed": return <g><rect x={-170} y={-90} width={340} height={60} rx={10} fill={color ?? "#5a6aa8"} /><rect x={-170} y={-150} width={24} height={150} fill={pal.trunk} /><rect x={-140} y={-120} width={90} height={34} rx={12} fill="#eeeeee" /><rect x={146} y={-110} width={24} height={110} fill={pal.trunk} /></g>;
|
||||
case "shelf": return <g><rect x={-120} y={-360} width={240} height={360} fill={color ?? pal.trunk} />{[0, 1, 2, 3].map((i) => <g key={i}><rect x={-108} y={-340 + i * 88} width={216} height={70} fill="#000000" opacity={0.25} />{[0, 1, 2, 3, 4].map((j) => <rect key={j} x={-100 + j * 42} y={-330 + i * 88 + (r() * 14)} width={30} height={56 - (r() * 14)} rx={3} fill={["#e8463d", "#f2c230", "#4fb0e8", "#5cc48a", "#e8e8ee"][(i + j) % 5]} />)}</g>)}</g>;
|
||||
case "crate": return <g><rect x={-70} y={-140} width={140} height={140} fill={color ?? "#a0743f"} /><path d="M-70 -140 L70 0 M70 -140 L-70 0" stroke="#6e4e28" strokeWidth={10} /><rect x={-70} y={-140} width={140} height={140} fill="none" stroke="#6e4e28" strokeWidth={10} /></g>;
|
||||
case "tent": return <g><polygon points="-170,0 0,-220 170,0" fill={color ?? "#d9773a"} /><polygon points="-40,0 0,-120 40,0" fill={pal.ink} opacity={0.6} /></g>;
|
||||
case "fire": return <g><rect x={-60} y={-18} width={120} height={18} rx={6} fill={pal.trunk} /><path d="M-40 -18 Q-50 -80 -10 -120 Q-5 -80 20 -70 Q30 -110 10 -150 Q70 -100 45 -18 Z" fill="#ff8a2a" /><path d="M-15 -18 Q-20 -60 5 -80 Q10 -50 25 -45 Q30 -30 20 -18 Z" fill="#ffd34a" /></g>;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
export function PlaceBackground({ spec, frame }: { spec: ShotSpec; frame: number }) {
|
||||
/** 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 horizon = (place.horizon ?? 0.56) * H;
|
||||
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];
|
||||
const elements = [...place.elements].map((e, i) => ({ ...e, i, z: e.z ?? 0.3 })).sort((a, b) => b.z - a.z);
|
||||
// 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 && (spec.palette ?? "night") === "night"
|
||||
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="placeSky" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={pal.sky[0]} /><stop offset="1" stopColor={pal.sky[1]} /></linearGradient>
|
||||
<linearGradient id="placeFog" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#ffffff" stopOpacity={0} /><stop offset="1" stopColor="#d8dce6" stopOpacity={0.35} /></linearGradient>
|
||||
<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>
|
||||
<rect width={W} height={H} fill={place.indoor ? pal.wall : "url(#placeSky)"} />
|
||||
{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)} />)}
|
||||
{!place.indoor && (spec.palette ?? "night") === "night" && <circle cx={W * 0.78} cy={H * 0.12} r={40} fill="#f4ecc8" />}
|
||||
{!place.indoor && (spec.palette === "day" || spec.palette === "sepia") && <circle cx={W * 0.8} cy={H * 0.1} r={60} fill={pal.light} opacity={0.9} />}
|
||||
{place.indoor && <rect x={0} y={horizon - 18} width={W} height={18} fill={pal.ink} opacity={0.25} />}
|
||||
{ground && <rect x={0} y={horizon} width={W} height={H - horizon} fill={ground} />}
|
||||
{place.ground === "street" && Array.from({ length: 8 }, (_, i) => <rect key={i} x={i * 150 - 40} y={horizon + (H - horizon) * 0.32} width={90} height={9} rx={4} fill="#ffffff" opacity={0.25} />)}
|
||||
{elements.map((e) => {
|
||||
// Profundidade: mais ao fundo = mais perto do horizonte, menor e mais apagado (névoa/atmosfera).
|
||||
const baseY = e.kind === "cloud" ? horizon * (0.15 + 0.5 * e.z) : horizon + (1 - e.z) * (H * 0.72 - horizon);
|
||||
const scale = (e.scale ?? 1) * (1 - e.z * 0.62) * 1.15;
|
||||
const fade = e.kind === "cloud" ? 0 : e.z * (place.fog ? 0.7 : 0.35);
|
||||
return (
|
||||
<g key={e.i} transform={`translate(${e.x * W} ${baseY}) scale(${e.flip ? -scale : scale} ${scale})`} opacity={1 - fade * 0.3}>
|
||||
<Element kind={e.kind} pal={pal} color={e.color ?? (fade > 0.05 && e.kind !== "fire" ? undefined : undefined)} seed={spec.seed + e.i * 17} />
|
||||
<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.fog && <rect x={0} y={horizon - H * 0.15} width={W} height={H * 0.5} fill="url(#placeFog)" />}
|
||||
)}
|
||||
{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>
|
||||
);
|
||||
}
|
||||
|
||||
/** Foco de luz vindo do teto (bunker, interrogatório) ou vinheta de anoitecer, por cima de tudo. */
|
||||
export function LightLayer({ light, palette: id }: { light: ShotSpec["light"]; palette?: PaletteId }) {
|
||||
if (!light || light === "none") return null;
|
||||
const pal = palette(id);
|
||||
if (light === "vignette") {
|
||||
return <div style={{ position: "absolute", inset: 0, background: "radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%)" }} />;
|
||||
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>
|
||||
<linearGradient id="spot" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor={pal.light} stopOpacity={0.32} /><stop offset="1" stopColor={pal.light} stopOpacity={0.05} /></linearGradient>
|
||||
<radialGradient id="spotDark" cx="0.5" cy="0.55" r="0.65"><stop offset="0.35" stopColor="#000" stopOpacity={0} /><stop offset="1" stopColor="#000" stopOpacity={0.6} /></radialGradient>
|
||||
</defs>
|
||||
<rect width={W} height={H} fill="url(#spotDark)" />
|
||||
<polygon points={`${W * 0.44},${H * 0.03} ${W * 0.56},${H * 0.03} ${W * 0.86},${H * 0.75} ${W * 0.14},${H * 0.75}`} fill="url(#spot)" />
|
||||
<rect x={W * 0.42} y={H * 0.025} width={W * 0.16} height={14} rx={6} fill="#d9d9d9" />
|
||||
<ellipse cx={W / 2} cy={H * 0.75} rx={W * 0.36} ry={34} fill={pal.light} opacity={0.12} />
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user