Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): a front or back walk walks naturally instead of being told how each step goes
Soohong Kim88cfea6b5ed6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0b42033..de8ca24 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,8 +2,9 @@All notable public changes to `sprite-gen` are recorded here. Versions track the `version:` field in `SKILL.md` and `pyproject.toml`.-## v2.15.0 - A slow walk, or one that drifts toward the camera, still finds its loop+## v2.15.0 - A front walk walks naturally, and a slow or drifting walk still finds its loop+- A walk seen from the front or from behind now says only that it walks naturally, which way it faces and that it stays in place (`VIEW_MOTION_TEXT`): "walks naturally in place, facing the viewer, as if on a treadmill, without coming any closer". The 2.13 sentence spelled out the steps, and some takes marched in place with the knees lifted to the waist and the arms held stiff. On one character, two clips per sentence on the API: the 2.13 sentence marched in one of two; "walks naturally" swung the arms, kept the knees low and kept facing the viewer in both. How a character walks is the caller's to say, so the default stays generic. The front run keeps its sentence. [docs/video-pipeline.md](docs/video-pipeline.md).- When `video-loop --anchor motion-auto` finds no walk or run cycle, it now looks once more (`sprite_gen/video/gait_fallback.py`). A front walk asked to stay in place sometimes comes toward the camera, and the body grows through the clip, so the same pose never matches itself in size: when a straight-line fit of the subject's height changes by 3 % or more over the clip, every frame is scaled back to the first frame's height about its foot point, and the search, the cells and the seam gate all read the scaled-back frames. A calm walk in long clothing can also take longer than half the clip per cycle, the most the first search confirms: the second search allows up to 60 % of the clip and at most 2 s (43 frames of a 3 s clip at 24 fps, where the first stops at 36).- Only a failed search reaches this, so a clip that looped before is cut exactly as before, and every gate, the seam limit included, is unchanged. An explicit `--max-len` stays the ceiling. The report records what was tried in `gait_fallback`; when the second search fails too, the error still starts with `video-loop: no periodic cycle found` and says what was tried.- Measured on six stored 3 s front walks that had failed with `no periodic cycle found`: four loop now. Three takes of a kimono that hides the legs walked a 27 to 39 frame cycle (one clip grew 3.9 %, two grew 11 % and 16 %), and a front horse walk grew 6.4 % with a 42 frame cycle. One of the other two still shows no repeat; the other finds a 38 frame candidate that the seam gate refuses. On the walk clips we have kept, the median height change is 0.5 % and nine in ten stay under 2.7 %. Method: [docs/loop-review.md](docs/loop-review.md).diff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex dc609d6..4a244d1 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -101,6 +101,18 @@ three-quarter angle kept that angle in about half the clips (6 of 10) with the oand in 5 of 10 with one that said to walk "toward the way its body faces in the image", andotherwise mostly turned to a side view: no sentence tried held a three-quarter view.+Since 2.15.0 the walk says less. Spelling the steps out ("each one lifting and landing straight+forward and back under the body") made some takes march in place, knees lifted to the waist and+arms held stiff, so a front or back walk now says only that it walks naturally, which way it+faces and that it stays in place: "walks naturally in place, facing the viewer, as if on a+treadmill, without coming any closer" (and "facing away from the viewer … without moving any+farther away"). On one character, 480p 3 s on the API, two clips per sentence: the 2.13+sentence lifted the knees to the waist in one of two; "walks naturally" swung the arms, kept the+knees low and kept facing the viewer in both; a third sentence that asked for low heel-to-toe+steps and a loose arm swing kept the feet low but shuffled. Two clips each is a small sample:+the default is generic on purpose, because how a character walks (high steps, a stroll, a+march) is the caller's to say. The front run keeps its sentence.+An attack is one timed strike, not a repeat. `MOTION_TEXT["attack"]` asks for one attack: a windup(about 0.5 s), one strike in front (about 0.25 s), a held impact pose (about 0.3 s) and a recoveryto the exact starting stance (about 0.5 s), then `HOLD_TEXT["attack"]`:diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.pyindex 9011a26..d500dcb 100644--- a/sprite_gen/video/batch.py+++ b/sprite_gen/video/batch.py@@ -94,23 +94,18 @@ MOTION_TEXT = {}# A walk seen from the front or from behind, and a run seen from the front, in place of the body-neutral# sentences above. Asked for "an even left-right or front-back rhythm", a walk that faces the viewer-# stepped sideways, crossed its feet or turned the body to the side in most of the takes. These say which-# way the steps go and that the body does not turn. A walk also asks for small, calm steps: without them a-# front walk still crossed its feet or kicked sideways in about a quarter of the takes. A side view keeps-# MOTION_TEXT, and so does a run seen from behind, which was not measured. "as if on a treadmill" keeps-# the treadmill a comparison: said as a place, it was sometimes drawn under the feet.+# stepped sideways, crossed its feet or turned the body to the side in most of the takes. The walk says+# only that it walks naturally, which way it faces and that it stays in place: the 2.13 sentence spelled out+# the steps ("each one lifting and landing straight forward and back") and some takes marched in place,+# knees up to the waist and arms stiff, while "walks naturally" swung the arms and kept the knees low. How a+# character walks is the caller's to say; the engine's default stays generic. The run keeps saying which way+# its strides go and that the body does not turn. A side view keeps MOTION_TEXT, and so does a run seen+# from behind, which was not measured. "as if on a treadmill" keeps the treadmill a comparison: said as a+# place, it was sometimes drawn under the feet.VIEW_MOTION_TEXT = {- ("walk", "front"): (- "walks in place toward the viewer, as if on a treadmill, without coming any closer: a calm, natural walk cycle "- "for this body type with small, even steps, each one lifting and landing straight forward and back under the "- "body, with clear repeating ground contacts. It never turns to the side, never steps sideways, never kicks a "- "leg out to the side and never crosses its feet."- ),+ ("walk", "front"): "walks naturally in place, facing the viewer, as if on a treadmill, without coming any closer.",("walk", "back"): (- "walks in place away from the viewer, as if on a treadmill, without moving any farther away: a calm, natural "- "walk cycle for this body type with small, even steps, each one lifting and landing straight forward and back "- "under the body, with clear repeating ground contacts. It never turns to the side, never steps sideways, never "- "kicks a leg out to the side and never crosses its feet."+ "walks naturally in place, facing away from the viewer, as if on a treadmill, without moving any farther away."),("run", "front"): ("runs in place toward the viewer, as if on a treadmill, without coming any closer: a fast run cycle for this "diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.pyindex 5dcba2b..0c54ca1 100644--- a/tests/video/test_video_pipeline.py+++ b/tests/video/test_video_pipeline.py@@ -488,25 +488,27 @@ def test_prompt_uses_state_and_view_and_optional_character() -> None:def test_front_and_back_gaits_say_which_way_the_steps_go() -> None:for state, direction, opening in (- ("walk", "front", "walks in place toward the viewer"),- ("walk", "back", "walks in place away from the viewer"),+ ("walk", "front", "walks naturally in place, facing the viewer"),+ ("walk", "back", "walks naturally in place, facing away from the viewer"),("run", "front", "runs in place toward the viewer"),):sentence = batch_mod.VIEW_MOTION_TEXT[(state, direction)]p = batch_mod.build_prompt(direction, state, None)assert p == batch_mod.COMMON_TEXT.format(motion=sentence, view=batch_mod.VIEW_TEXT[direction])assert f"{opening}, as if on a treadmill" in p- assert "It never turns to the side, never steps sideways" in p and "never crosses its feet." in passert "left-right" not in p and "on a treadmill:" not in p- # A walk asks for small, calm steps that do not kick out; a run is fast and keeps its stride.- assert ("small, even steps" in p and "never kicks a leg out to the side" in p) == (state == "walk")+ # A walk says only that it walks naturally: how the steps go is the caller's to say. The run+ # keeps naming its strides and that the body does not turn.+ if state == "walk":+ assert sentence.startswith(opening) and sentence.count(".") == 1+ assert ("It never turns to the side, never steps sideways" in p) == (state == "run")# A side view, a run from behind and every other front or back state keep the state's own sentence.assert batch_mod.MOTION_TEXT["walk"] in batch_mod.build_prompt("side", "walk", None)assert batch_mod.MOTION_TEXT["run"] in batch_mod.build_prompt("side", "run", None)assert batch_mod.MOTION_TEXT["run"] in batch_mod.build_prompt("back", "run", None)assert batch_mod.MOTION_TEXT["idle"] in batch_mod.build_prompt("back", "idle", None)named = batch_mod.build_prompt("back", "walk", "The armored knight")- assert named.startswith("2D game sprite animation. The armored knight walks in place away from the viewer")+ assert named.startswith("2D game sprite animation. The armored knight walks naturally in place, facing away from the viewer")def test_motion_templates_do_not_assume_a_body_plan() -> None: