Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

feat(video): two three-quarter views, a walk heading down or up to the right as in an isometric game

Soohong Kimc5b49db967d5
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index d03801d..2d889a4 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -122,6 +122,25 @@ and said "toward the viewer" and "without coming any closer" in one clause). On
480p 3 s on the API: the front run kept facing in 2 of 2, the side run ran in 2 of 2, the back
run kept facing away in the one clip whose frames passed; the side walk walked in 2 of 2.
+Since 2.17.0 there are two three-quarter views, `front_diagonal` and `back_diagonal`: turned to the
+right, the way an isometric game's character walks down and up to the right (turned over, they face
+left). A walk or run in one says where it heads on the screen in those words: "walks naturally in
+place, as if on a treadmill, heading diagonally away from the viewer toward the upper right, like a
+character walking up and to the right in an isometric game, without moving across the screen. It
+keeps the exact three-quarter back angle of the image the whole time: its back stays turned toward
+the viewer at that angle and its face stays hidden. It never turns into a side view." (and "toward
+the viewer and to the right … three-quarter front angle" for the front one). It is filmed pinned to
+its first frame (`PINNED_GAIT_VIEWS`, `pins_last_frame`) with the return sentence, and cut as any
+walk (`--anchor motion-auto`). The clip's view sentence points at the image ("seen from a
+three-quarter back angle, turned exactly as in the image"); a still drawn at a diagonal from another
+picture takes `STILL_VIEW_TEXT` instead (`still_view_text`), which says the whole body and head turn
+about 45 degrees and which way the feet point — told less, a three-quarter back view came out as a
+side view or looking back over the shoulder. Measured on the API, 480p 3 s, pinned, five humanoid
+characters twice each, judged on frame sheets: the front and the back diagonal walk kept their angle
+in 10 of 10 each; "toward the way its body faces in the image" kept the front one in 4 to 5 of 5 and,
+on another character, the back one in 0 of 2. Idle and attack keep their angle in a diagonal (4 of
+4). A diagonal run is weaker: 2 of 4 kept the angle, the others turned toward a side view.
+
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 recovery
to the exact starting stance (about 0.5 s), then `HOLD_TEXT["attack"]`:
diff --git a/sprite_gen/gen/video.py b/sprite_gen/gen/video.py
index f64f033..18e0871 100644
--- a/sprite_gen/gen/video.py
+++ b/sprite_gen/gen/video.py
@@ -291,8 +291,8 @@ class VideoResult:
def _validate(request: VideoRequest) -> None:
validate_facing(request.facing, request.facing_fix)
- if request.direction not in (None, "side", "front", "back"):
- raise SystemExit("video: --direction must be side, front or back")
+ if request.direction not in (None, "side", "front", "back", "front_diagonal", "back_diagonal"):
+ raise SystemExit("video: --direction must be side, front, back, front_diagonal or back_diagonal")
if request.facing_fix not in facing_mod.FIXES:
raise SystemExit("video: --facing-fix must be mirror or none")
if request.direction == "side" and request.mode != MODE_IMAGE_TO_VIDEO:
@@ -696,7 +696,7 @@ def _add_prompt_and_report(parser: argparse.ArgumentParser) -> None:
def add_arguments(parser: argparse.ArgumentParser) -> None:
- parser.add_argument("--direction", choices=("side", "front", "back"), help="sprite view; side opts into facing inspection before video generation")
+ parser.add_argument("--direction", choices=("side", "front", "back", "front_diagonal", "back_diagonal"), help="sprite view; side opts into facing inspection before video generation")
parser.add_argument("--facing", choices=FACINGS, default="right", help="with --direction side: required direction (default right)")
parser.add_argument("--facing-fix", choices=facing_mod.FIXES, default="none", help="with --direction side: record only (none, default), or opt into mirror")
parser.add_argument("--image", type=Path, help="the still to animate / the first frame (PNG/JPEG/WebP)")
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index e1016f7..b45d928 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -60,7 +60,34 @@ VIEW_TEXT = {
"side": "seen from the exact side, facing {facing}",
"front": "seen from the front, facing the viewer directly",
"back": "seen from directly behind, facing away from the viewer",
+ # Three-quarter views, as an isometric game's character walks down and up to the right. The clip
+ # starts from a still already drawn at that angle, so the clip's view sentence points at the image.
+ "front_diagonal": "seen from a three-quarter front angle, turned exactly as in the image",
+ "back_diagonal": "seen from a three-quarter back angle, turned exactly as in the image",
}
+# The view sentence for drawing a still at a view, where it differs from the clip's: a diagonal still is
+# often redrawn from a front or side picture, so "turned exactly as in the image" would keep the picture's
+# angle. It says how far the body turns, that the head turns with it and which way the feet point; said
+# less, a three-quarter back view came out as a side view or looking back over the shoulder.
+STILL_VIEW_TEXT = {
+ "front_diagonal": (
+ "seen from a three-quarter front angle: the whole body and head turned about 45 degrees to the {facing}, halfway "
+ "between facing the viewer and facing {facing}, the face looking the same way as the chest and the feet pointing "
+ "toward the lower {facing}"
+ ),
+ "back_diagonal": (
+ "seen from a three-quarter back angle: the whole body and head turned about 45 degrees away from the viewer toward "
+ "the upper {facing}, halfway between facing away and facing {facing}, the face hidden and not looking back over the "
+ "shoulder, and the feet pointing diagonally up and to the {facing} so the backs of the shoes face the viewer at an angle"
+ ),
+}
+DIAGONAL_VIEWS = frozenset({"front_diagonal", "back_diagonal"})
+
+
+def still_view_text(direction: str, facing: str = "right") -> str:
+ """The view sentence for drawing a still seen from `direction` (`STILL_VIEW_TEXT`, else `VIEW_TEXT`)."""
+ validate_facing(facing)
+ return STILL_VIEW_TEXT.get(direction, VIEW_TEXT[direction]).format(facing=facing)
# What stays put while an attack moves, said once: after the built-in attack sentence and after a
# caller's own motion paragraph alike. A request interpreter writes its motion before the still
# exists, so it cannot know where the other hand's shield or lantern is drawn; the engine holds it.
@@ -82,6 +109,14 @@ GAIT_HOLD_TEXT = {
"the whole time."
),
"side": "It stays in place as if on a treadmill, without moving across the screen, and keeps facing {facing} the whole time.",
+ "front_diagonal": (
+ "It stays in place as if on a treadmill, without moving across the screen, and keeps the exact three-quarter front "
+ "angle of the image the whole time, never turning into a side view."
+ ),
+ "back_diagonal": (
+ "It stays in place as if on a treadmill, without moving across the screen, and keeps the exact three-quarter back "
+ "angle of the image the whole time, its face hidden, never turning into a side view."
+ ),
}
MOTION_TEXT = {
# A side-view full body asked for "a subtle weight sway" and an evenly paced loop steps in place
@@ -122,7 +157,41 @@ VIEW_MOTION_TEXT = {
("run", "back"): (
"runs naturally in place, facing away from the viewer, as if on a treadmill, without moving any farther away."
),
+ # A diagonal says where the character is heading on the screen, the way an isometric game reads, and that it
+ # keeps the image's angle. Asked only to walk "toward the way its body faces in the image", a three-quarter
+ # back walk turned to a side view in 2 of 2 clips; named as a heading up and to the right, in 10 of 10 it
+ # kept the angle (2026-10-02, five people twice each, pinned).
+ ("walk", "front_diagonal"): (
+ "walks naturally in place, as if on a treadmill, heading diagonally toward the viewer and to the right, like a "
+ "character walking down and to the right in an isometric game, without moving across the screen. It keeps the "
+ "exact three-quarter front angle of the image the whole time and never turns into a side view."
+ ),
+ ("walk", "back_diagonal"): (
+ "walks naturally in place, as if on a treadmill, heading diagonally away from the viewer toward the upper right, "
+ "like a character walking up and to the right in an isometric game, without moving across the screen. It keeps "
+ "the exact three-quarter back angle of the image the whole time: its back stays turned toward the viewer at that "
+ "angle and its face stays hidden. It never turns into a side view."
+ ),
+ ("run", "front_diagonal"): (
+ "runs naturally in place, as if on a treadmill, heading diagonally toward the viewer and to the right, like a "
+ "character running down and to the right in an isometric game, without moving across the screen. It keeps the "
+ "exact three-quarter front angle of the image the whole time and never turns into a side view."
+ ),
+ ("run", "back_diagonal"): (
+ "runs naturally in place, as if on a treadmill, heading diagonally away from the viewer toward the upper right, "
+ "like a character running up and to the right in an isometric game, without moving across the screen. It keeps "
+ "the exact three-quarter back angle of the image the whole time: its back stays turned toward the viewer at that "
+ "angle and its face stays hidden. It never turns into a side view."
+ ),
}
+# Views a walk or run is filmed pinned to its first frame in (`video --last-frame`), with the pinned template:
+# a diagonal walk ended where it began, and its angle with it. Cut as any walk (`video-loop --anchor motion-auto`).
+PINNED_GAIT_VIEWS = DIAGONAL_VIEWS
+
+
+def pins_last_frame(state: str, direction: str) -> bool:
+ """Whether the clip of (state, direction) is filmed ending on its first frame."""
+ return state in PIN_LAST_FRAME_STATES or (state in GAIT_STATES and direction in PINNED_GAIT_VIEWS)
COMMON_TEXT = (
"2D game sprite animation. The character {motion} The character is {view}. Stays centered in the frame and does "
"not move across the screen; the body and hair always stay fully inside the frame with margin. Camera completely "
@@ -176,13 +245,14 @@ def build_prompt(direction: str, state: str, character: str | None, facing: str
`pinned` says the clip is pinned to end on its first frame (`video --last-frame`): it then asks
for the return to the first pose instead of an evenly paced repeat (`PINNED_LOOP_TEXT`). None
- leaves it to the state (`PINNED_LOOP_STATES`); a caller that pins a walk or run says True.
+ leaves it to the state and view (`PINNED_LOOP_STATES`, a walk or run in `PINNED_GAIT_VIEWS`);
+ a caller that pins any other walk or run says True.
"""
validate_facing(facing)
view = VIEW_TEXT.get(direction, f"seen from the {direction}").format(facing=facing)
if state in ACTION_TEXT_STATES:
template = ACTION_COMMON_TEXT
- elif (state in PINNED_LOOP_STATES) if pinned is None else pinned:
+ elif (state in PINNED_LOOP_STATES or (state in GAIT_STATES and direction in PINNED_GAIT_VIEWS)) if pinned is None else pinned:
template = PINNED_LOOP_TEXT
else:
template = COMMON_TEXT
@@ -301,7 +371,7 @@ def run_item(
attempts: list[int] = []
for attempt in range(1 + len(RETRY_BACKOFF_SECONDS)):
_staggered_start(gap)
- pin = {"last_frame": canvas_png} if state in PIN_LAST_FRAME_STATES else {}
+ pin = {"last_frame": canvas_png} if pins_last_frame(state, direction) else {}
rc = video_runner(canvas_png, prompt, clip, clip_report, duration=duration, resolution=resolution, log=item_dir / "clip.log", **pin)
attempts.append(rc)
if rc == 0 and clip.exists():
@@ -311,7 +381,7 @@ def run_item(
time.sleep(RETRY_BACKOFF_SECONDS[attempt])
continue
break
- result["clip"] = {"attempts": attempts, "duration": duration, "last_frame": state in PIN_LAST_FRAME_STATES}
+ result["clip"] = {"attempts": attempts, "duration": duration, "last_frame": pins_last_frame(state, direction)}
if attempts[-1] != 0 or not clip.exists():
raise SystemExit(f"clip generation failed after {len(attempts)} attempt(s); see {item_dir / 'clip.log'}")
diff --git a/tests/video/test_batch_bases.py b/tests/video/test_batch_bases.py
index e29fb31..d0bec5c 100644
--- a/tests/video/test_batch_bases.py
+++ b/tests/video/test_batch_bases.py
@@ -23,7 +23,7 @@ def test_unknown_direction_is_refused_by_name(key, tmp_path):
with pytest.raises(SystemExit) as exc:
batch._parse_bases([f"{key}={tmp_path / 's.png'}"])
message = str(exc.value)
- assert repr(key) in message and "back, front, side" in message
+ assert repr(key) in message and "back, back_diagonal, front, front_diagonal, side" in message
def test_missing_equals_still_refused():
diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.py
index fd54b59..dafecf1 100644
--- a/tests/video/test_video_pipeline.py
+++ b/tests/video/test_video_pipeline.py
@@ -537,6 +537,48 @@ def test_pinned_picks_the_return_sentence_for_any_state() -> None:
assert batch_mod.build_prompt("side", "attack", None, pinned=False) == batch_mod.build_prompt("side", "attack", None)
+def test_a_diagonal_walk_is_pinned_and_named_as_an_isometric_heading() -> None:
+ """The two three-quarter views (2.17.0): a walk or run says where it heads on the screen, as an
+ isometric game reads, keeps the image's angle, and is filmed pinned to its first frame with the
+ return sentence. Any other state in a diagonal is the state's own sentence at that view."""
+ for direction, heading in (("front_diagonal", "heading diagonally toward the viewer and to the right"),
+ ("back_diagonal", "heading diagonally away from the viewer toward the upper right")):
+ for state in ("walk", "run"):
+ sentence = batch_mod.VIEW_MOTION_TEXT[(state, direction)]
+ p = batch_mod.build_prompt(direction, state, None)
+ assert p == batch_mod.PINNED_LOOP_TEXT.format(motion=sentence, view=batch_mod.VIEW_TEXT[direction])
+ assert heading in sentence and "never turns into a side view" in sentence
+ assert batch_mod.pins_last_frame(state, direction)
+ assert "turned exactly as in the image" in batch_mod.VIEW_TEXT[direction]
+ idle = batch_mod.build_prompt(direction, "idle", None)
+ assert batch_mod.MOTION_TEXT["idle"] in idle and batch_mod.VIEW_TEXT[direction] in idle
+ assert not batch_mod.pins_last_frame("jump", direction)
+ for direction in ("front", "back", "side"):
+ assert not batch_mod.pins_last_frame("walk", direction)
+ assert batch_mod.pins_last_frame("attack", "side") and batch_mod.pins_last_frame("idle", "front")
+
+
+def test_a_diagonal_still_is_told_how_far_to_turn() -> None:
+ """A still at a diagonal is often redrawn from a front or side picture, so its view sentence says the
+ turn (45 degrees), that the head turns with the body and where the feet point, instead of pointing
+ at the image's own angle. Every other view draws with the clip's view sentence."""
+ front = batch_mod.still_view_text("front_diagonal")
+ back = batch_mod.still_view_text("back_diagonal")
+ assert "about 45 degrees to the right" in front and "feet pointing toward the lower right" in front
+ assert "away from the viewer toward the upper right" in back and "not looking back over the" in back
+ assert "turned exactly as in the image" not in front + back
+ assert batch_mod.still_view_text("side", "left") == batch_mod.VIEW_TEXT["side"].format(facing="left")
+ assert batch_mod.still_view_text("front") == batch_mod.VIEW_TEXT["front"]
+
+
+def test_a_callers_diagonal_gait_keeps_the_angle() -> None:
+ sneak = "The knight sneaks along on tiptoe, setting each foot down slowly."
+ for direction, angle in (("front_diagonal", "three-quarter front"), ("back_diagonal", "three-quarter back")):
+ p = batch_mod.build_prompt(direction, "walk", "The knight", motion=sneak)
+ assert f"keeps the exact {angle} angle of the image the whole time" in p
+ assert "The last frame returns to the exact pose of the first frame" in p
+
+
def test_motion_templates_do_not_assume_a_body_plan() -> None:
# the templates were first written for a biped; a quadruped or a legless blob must not
# be prompted into a contradiction (2026-09-09 generalization run)