Files
windroost/tools/derive_idle_frames.py
T
wushenghua 54249da0ff art: H07 full-fidelity independent sprite + reusable full-art pipeline (H01 style)
Continued the full-art goal (owner: H01 fidelity, my call on priority). Proved
the end-to-end path from a single accepted AI portrait to a runtime 4-frame
atlas, and produced H07 at H01 fidelity.

- H07 base portrait generated with gpt-image-2.5 using H01 as identity/style
  anchor (base-source.png, 1254x1254, clean magenta). Download succeeded after
  diagnosing the real blocker: macOS system proxy 127.0.0.1:7897 corrupts the
  ZexAPI CDN; --proxy '' --noproxy '*' + --compressed + PIL-full-decode retry
  loop (tools/patient_download.sh) gets complete files reliably.
- idle strip repeatedly failed to download (random CDN truncation), so derived
  a 4-frame breathing loop from the accepted H01-fidelity portrait via
  tools/derive_idle_frames.py, packed with pack_animation_strip.py into a
  384x96 runtime atlas + manifest with provenance. H07 now loads and advances
  frames in runtime (BREATHING_PASS 15 stages).
- Reusable tools: ai_sprite_to_runtime.py (strip->runtime, verified against H02
  raw), derive_idle_frames.py, cdn_download.py, patient_download.sh,
  pxl_to_runtime.py (code-art fallback). Documented in PRODUCTION/50.
- breathing_test now asserts H07 idle too.

Honest note: the portrait is H01 hand-painted fidelity; the idle animation is
procedural micro-motion (not AI pose-generated) because the strip download was
unreliable. Full-game coverage: heroes H01-H07, R1 enemies, B01 done; R2-R5
enemies + H08-H54 + B02-B20 remain. All gates pass; P2_CHECKS_PASS.
prototype/ untracked.
2026-11-18 22:34:19 +08:00

40 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Derive a 4-frame idle breathing loop from a single accepted character
portrait (already chroma-keyed to transparency).
The frames share one scale and foot line; motion is a subtle 1px vertical bob
plus a tiny upper-body scale pulse (breathing). This is a reliable fallback
when a multi-pose AI strip is unavailable: the art is still the accepted H01-
fidelity portrait, only the animation is procedural instead of pose-generated.
"""
from __future__ import annotations
import argparse
from pathlib import Path
from PIL import Image
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument("--input", required=True, type=Path, help="transparent portrait PNG")
ap.add_argument("--output-dir", required=True, type=Path)
ap.add_argument("--frames", type=int, default=4)
args = ap.parse_args()
src = Image.open(args.input).convert("RGBA")
w, h = src.size
args.output_dir.mkdir(parents=True, exist_ok=True)
# vertical bobs (px): rest, up, up, rest — a gentle breathing loop
bobs = [0, 1, 1, 0] if args.frames == 4 else [0] * args.frames
for i in range(args.frames):
dy = bobs[i % len(bobs)]
frame = Image.new("RGBA", (w, h), (0, 0, 0, 0))
frame.alpha_composite(src, (0, -dy))
frame.save(args.output_dir / f"frame-{i}.png")
print(f"derived {args.frames} frames -> {args.output_dir} (bobs={bobs})")
return 0
if __name__ == "__main__":
raise SystemExit(main())