/** * Scene Renderer — Composites multiple characters onto a background. * * Matches CAM's rendering behavior: * - 2560×1440 base canvas (characters drawn at world coordinates) * - Character yCoor = rig root anchor (feet land below; adjusted at world-build time) * - Animation interpolation via lerpAngle (shortest-path rotation), not frame snapping * - Camera viewport maps a region of the 2560×1440 world to the output resolution * - Background drawn at 0,0,2560,1440 * * Performance: SceneEngine loads images once, caches rendered stamps per unique state. */ import type { RigData } from '../types.js'; export interface WorldCharacter { id: string; name?: string; xCoor?: number; yCoor?: number; /** Foot / ground contact Y (when yCoor is rig root anchor). */ footY?: number; width?: number; height?: number; zIndex?: number; renderScale?: number; [key: string]: any; } export interface WorldKeyframe { time: number; value: any; easing?: string; } export interface WorldLane { property: string; keyframes: WorldKeyframe[]; } export interface WorldCharacterTrack { characterId: string; lanes: WorldLane[]; } export interface WorldAnimation { id: string; name: string; frames: any[]; } export interface WorldJSON { scene?: { background?: string | null; }; characters?: WorldCharacter[]; objects?: any[]; dialogs?: any[]; timeline?: WorldCharacterTrack[]; variations?: any[]; animations?: Record; filename?: string; } export interface CharacterState { id: string; x: number; y: number; width: number; height: number; hidden: boolean; flipX: boolean; zIndex: number; animationId: string | null; animationProgress: number; variationName: string | null; jointValues?: Record; } export interface CameraState { x: number; y: number; width: number; height: number; } export interface SceneState { time: number; camera: CameraState; characters: CharacterState[]; } export interface SceneRenderReport { time: number; output: string; canvas: { width: number; height: number; }; camera: CameraState; characters: Array<{ id: string; position: { x: number; y: number; }; size: { width: number; height: number; }; hidden: boolean; flipX: boolean; animationId: string | null; variationName: string | null; screenBounds: { x: number; y: number; w: number; h: number; }; }>; quality: { total_characters: number; visible_characters: number; has_camera_move: boolean; has_animation: boolean; has_variation: boolean; has_background: boolean; shot_count: number; }; } export declare function evaluateScene(world: WorldJSON, time: number): SceneState; export declare class SceneEngine { private world; private rigDataMap; private createCanvas; private loadImage; private renderers; private bgCache; private resolvedAnims; private ready; private objectImageLoader; private objectLoadedImages; constructor(world: WorldJSON, rigDataMap: Record); /** Draw a world-level object (prop) onto the canvas */ private drawWorldObject; init(): Promise; /** * Get the interpolated rig data for a character at a given animation progress. * Applies: variation (expression swap) → animation interpolation → flip */ private getInterpolatedRig; /** * Render one frame. * * Matches CAM's approach: * 1. Create a 2560×1440 "world canvas" * 2. Draw background at 0,0,2560,1440 * 3. For each visible character: compute rig at (xCoor, yCoor) using cameraOffset * 4. Apply camera viewport: copy the camera region from world canvas to output canvas */ renderFrame(time: number, outputPath: string, outWidth: number, outHeight: number): Promise; /** * Render one frame and return the raw canvas (no PNG encode, no file write). * Used by video pipeline to pipe raw pixels to ffmpeg. */ renderFrameToCanvas(time: number, outWidth: number, outHeight: number): Promise; } export declare function renderScene(world: WorldJSON, time: number, outputPath: string, rigDataMap: Record, options?: { width?: number; height?: number; }): Promise; export declare function renderSceneKeyFrames(world: WorldJSON, outputDir: string, rigDataMap: Record, options?: { width?: number; height?: number; frameCount?: number; }): Promise; export interface RigBounds { width: number; height: number; aboveRoot: number; belowRoot: number; } /** * Compute the native bounding box of a rig when rendered at renderScale=1.0. * * Returns the total pixel dimensions and how much extends above/below the root * point (feet). This is needed to calculate renderScale for consistent sizing. * * @param rigData - Character rig JSON * @returns RigBounds or null if rig can't be measured */ export declare function computeRigBounds(rigData: RigData): Promise; /** * Compute the renderScale needed to make a rig render at a target height * in world coordinates. * * @param rigData - Character rig JSON * @param targetHeight - Desired total height in world pixels * @returns renderScale value, or 1.0 if bounds can't be computed */ export declare function computeRenderScale(rigData: RigData, targetHeight: number): Promise; /** * Compute renderScale values for a group of characters that should appear * on the same baseline at correct relative sizes. * * @param characters - Array of { id, rigData, targetHeight } * @returns Record keyed by character id */ export declare function computeGroupRenderScales(characters: Array<{ id: string; rigData: RigData; targetHeight: number; }>): Promise>; /** * Compute a camera viewport that fits all characters without clipping. * * Given character positions, heights, and renderScales, returns a camera * that contains all characters with padding. * * @param characters - Array of { xCoor, yCoor, targetHeight, renderScale, bounds } * @param baseCamera - Starting camera { x, y, width, height } (from shot type preset) * @param padding - Extra padding in world pixels (default 80) * @returns Adjusted camera { x, y, width, height } */ export declare function fitCameraToCharacters(characters: Array<{ xCoor: number; yCoor: number; targetHeight: number; renderScale?: number; bounds?: RigBounds | null; }>, baseCamera: CameraState, padding?: number): CameraState; //# sourceMappingURL=sceneRenderer.d.ts.map