Skip to content

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

fix(gen,video): a diagonal still turns its chest or back and its legs, not only its head

Soohong Kimaa1891174846
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcfbb49..d421bf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## Unreleased
+- **Output change: a diagonal still turns its chest or back and its legs, not only its head** (`STILL_VIEW_TEXT["front_diagonal"]`, `["back_diagonal"]`, read by `still_view_text` and `gen --direction`; an app that draws its own still takes it too). The sentences said the turn, the head and the feet, and a still that turns only its head and shoes, the chest (back) and the legs standing as from the front (straight behind), meets those words. They now say what that angle shows: not a front (back) view with only the head turned, the middle of the chest (back) and of the waist about three quarters of the way across the body toward its far edge, the near shoulder and side seen broad, the far shoulder and arm partly hidden, the legs at the same angle with the far foot set a little higher and partly behind the near leg, and not to follow a reference picture's angle. `STILL_VIEW_TEXT` takes `{other}`, the side opposite `{facing}` (the near side of a front diagonal, the far side of a back one); facing left is the same sentence with the sides swapped. The clip's view sentences (`VIEW_TEXT`, `VIEW_MOTION_TEXT`, `GAIT_HOLD_TEXT`) and the body plan's (`STILL_VIEW_TEXT_ANY_BODY`) are unchanged. The words were chosen by a before-and-after comparison on the still model; its measurements are kept in private evidence and none is recorded here ([video-pipeline](docs/video-pipeline.md#2-clip--sprite-gen-video)).
+- **`tests/video/test_video_pipeline.py`** holds both diagonal still sentences, facing right and left: the chest (back) and hips turn with the head, where the middle of the body sits, the near side broad, the far shoulder, arm and foot on the far side, the reference picture not followed, and facing left the same sentence with the sides swapped. **`tests/gen/test_prompt_freeze.py`** lists the two 2.22.0 sentences (`MEASURED`): the still prompts that hold them are compared with the new sentence in their place, and those prompts and no others differ from 2.22.0.
+
- **Fix: `video-follow` replaces the loop's files only once all of them are written.** The strip, the GIF and the WebP were written over the loop's before the record was, so a run that failed on the record — `follow.follow_loop` given numpy numbers, an int64 of which has no JSON form (`TypeError`) — or on an animation's check left a moved strip beside a record that did not say so. Now the strip, GIF, WebP and record are written and checked in a scratch directory beside the loop (`.follow.*`), each under its own name, and moved over the loop's files after the record is written; a run that fails on the way leaves all four as they were (the strip as cut is still kept as `follow.source.png`, as on a refusal). `follow_loop` reads its regions, `gain`, `freq` and `zeta` as the floats the command line gives, so numpy numbers, or plain ints, write the strip and record that the same numbers as floats write, byte for byte (a caller that passed plain ints finds them recorded as floats, `80.0` where it was `80`). `loop.verify_animation` closes the file it checks. The command's output, its strip, GIF, WebP and record, and `--help` are as before, byte for byte. [docs/video-pipeline.md](docs/video-pipeline.md#6-follow-through--video-follow).
- **`tests/video/test_follow.py`** moves a chest and a smaller head region given as int64, int32, float32, float64 and plain int coordinates, as the rows of an int64 array, and with a float32 `gain`: each writes the strip, GIF, WebP and record the float coordinates write, byte for byte (before this the int64 run failed on the record with the strip already moved). A run made to fail on its record or on its WebP's check, on a loop as cut and on one already followed, leaves the strip, GIF, WebP and record as they were, and nothing beside them but `follow.source.png`.
diff --git a/docs/prompt-assembly.md b/docs/prompt-assembly.md
index e77d8cb..5345b01 100644
--- a/docs/prompt-assembly.md
+++ b/docs/prompt-assembly.md
@@ -16,7 +16,11 @@ and the mid-step redraw. `tests/gen/test_prompt_freeze.py` compares every prompt
with `tests/fixtures/prompts-v2.22.0.json.gz`, drawn from the 2.22.0 tag's source by
`tests/gen/prompt_freeze_table.py`. The notes and warnings printed beside a prompt are not part of
that comparison. A change to these prompts is made only after a before-and-after comparison on the
-app's default clip model shows it is better.
+app's default clip model shows it is better. Such a change is listed in the test (`MEASURED`) with the
+words 2.22.0 sent, and every frozen prompt that holds them is compared with the new words in their
+place: nothing else in it may move. So far: the two diagonal stills' view sentences
+(`STILL_VIEW_TEXT["front_diagonal"]`, `["back_diagonal"]`), compared on the still model
+([video-pipeline](video-pipeline.md#2-clip--sprite-gen-video)).
`--handed` adds its piece and changes nothing else: the prompt is the one without it, with the handed
sentences put in (`tests/gen/test_prompt_assembly.py`).
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 79812d8..de2a3be 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -153,14 +153,33 @@ the viewer and to the right … three-quarter front angle" for the front one). I
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
+picture takes `STILL_VIEW_TEXT` instead (`still_view_text`), which says that the whole body turns
+about 45 degrees, what that angle shows of the chest or back and of the legs (the next paragraph),
+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.
+**What a diagonal still shows of its turn.** Through 2.36.0 the diagonal still sentences said only
+the turn, the head and the feet ("the whole body and head turned about 45 degrees … the feet
+pointing toward the lower right"), and a still that turns only its head and shoes, the chest (back)
+and the legs standing as from the front (straight behind), meets those words. The sentences now say
+what the angle shows: not a front (back) view with only the head turned; the middle of the chest
+(back) and of the waist about three quarters of the way across the body toward its far edge; the
+shoulder and side nearer the viewer seen broad; the far shoulder and arm partly hidden behind the
+body; the legs at the same angle, the far foot set a little higher and partly behind the near leg;
+and not to follow a reference picture's angle. The far side of a front diagonal is the side it
+faces, of a back diagonal the other one, so `STILL_VIEW_TEXT` takes `{other}` (the side opposite
+`{facing}`) beside `{facing}`, and facing left is the same sentence with the two sides swapped. The
+clip's view sentence is unchanged: a clip starts from the still. The body plan's sentences
+(`STILL_VIEW_TEXT_ANY_BODY`) are unchanged too: they count no chest, shoulders or feet and take none
+of these clauses. The words were chosen by a before-and-after comparison on the still model; its
+measurements are kept in private evidence and none is recorded here.
+`tests/gen/test_prompt_freeze.py` holds the old words and the new (`MEASURED`): a further rewording
+fails there until it is compared again ([prompt-assembly](prompt-assembly.md)).
+
A front or back still redrawn from a picture seen from another side has its own still sentence too:
with the clip's one line ("seen from the front, facing the viewer directly"),
a front still redrawn from a side picture could keep part of the picture's turn, the feet frontal
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index b686dfe..03af5c4 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -81,6 +81,12 @@ VIEW_TEXT = {
# less, a three-quarter back view came out as a side view or looking back over the shoulder. A front or
# back still redrawn from a side picture with the clip's one line kept the picture's turn in the head and
# chest, so those two say where the head, chest and feet point and not to follow the picture's angle.
+# The turn, the head and the feet alone leave the chest (or back) and the legs unsaid: a still that turns only
+# its head and shoes meets those words. So the diagonals say what that angle shows: the middle of the chest (or
+# back) about three quarters of the way across toward the far edge, the near shoulder and side seen broad, the
+# far shoulder and arm partly hidden, the legs at the same angle with the far foot higher and behind, and not to
+# follow a reference's angle (docs/video-pipeline.md). `{other}` is the side opposite `{facing}`: the near side
+# of a front diagonal, the far side of a back one.
STILL_VIEW_TEXT = {
"front": (
"seen from the front: the whole body and head turned to face the viewer squarely, the chest, hips and the toes "
@@ -94,19 +100,32 @@ STILL_VIEW_TEXT = {
"character from another angle"
),
"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}"
+ "seen from a three-quarter front angle: the whole body turned about 45 degrees to the {facing}, halfway between "
+ "facing the viewer and facing {facing}, not a front view with only the head turned: the chest and hips turn as far "
+ "as the head, so the middle of the chest and of the waist sits about three quarters of the way across the body "
+ "toward its {facing} edge, the shoulder and the side of the chest on the {other} of the picture, nearer the "
+ "viewer, are seen broad, the shoulder and arm on the {facing} of the picture are partly hidden behind the body and "
+ "the chest looks narrower than from the front, and the legs stand at the same angle, the far foot on the {facing} "
+ "of the picture set a little higher and partly behind the near leg, both toes pointing toward the lower {facing}, "
+ "the face looking the same way as the chest, even when a reference picture shows the character from another angle"
),
"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"
+ "seen from a three-quarter back angle: the whole body turned about 45 degrees away from the viewer toward the upper "
+ "{facing}, halfway between facing away and facing {facing}, not a back view with only the head turned: the back and "
+ "hips turn as far as the head, so the middle of the back and of the waist sits about three quarters of the way "
+ "across the body toward its {other} edge, the shoulder and the side of the body on the {facing} of the picture, "
+ "nearer the viewer, are seen broad, the shoulder and arm on the {other} of the picture are partly hidden behind the "
+ "body and the back looks narrower than from straight behind, and the legs stand at the same angle, the far foot on "
+ "the {other} of the picture set a little higher and partly behind the near leg, the feet pointing diagonally up and "
+ "to the {facing} so the backs of the shoes face the viewer at an angle, the face hidden and not looking back over "
+ "the shoulder, even when a reference picture shows the character from another angle"
),
}
# The same views for a body that is not one biped (`body_plan`): where the body and head point, with no feet
# counted and no chest, hips, shoulders or shoes, so a horse's still is not drawn standing on two feet.
# `{body}` is the character's or every figure's; then what it stands on (`body_plan.still_text`). Not measured.
+# The diagonals here keep their few words and take none of the person's middle-line and leg clauses, which count
+# a chest, shoulders and two feet.
STILL_VIEW_TEXT_ANY_BODY = {
"front": (
"seen from the front: {body} turned to face the viewer squarely, the face centred and looking straight out of "
@@ -138,7 +157,8 @@ def still_view_text(direction: str, facing: str = "right", body_plan: list[Body]
validate_facing(facing)
stands_on = body_mod.still_text(body_plan)
if not stands_on:
- return STILL_VIEW_TEXT.get(direction, VIEW_TEXT[direction]).format(facing=facing)
+ other = "left" if facing == "right" else "right"
+ return STILL_VIEW_TEXT.get(direction, VIEW_TEXT[direction]).format(facing=facing, other=other)
body = "every figure's whole body and head" if body_mod.scene(body_plan) else "the whole body and head"
view = STILL_VIEW_TEXT_ANY_BODY.get(direction, VIEW_TEXT[direction]).format(facing=facing, body=body)
return f"{view}, {stands_on}"
diff --git a/tests/gen/test_prompt_freeze.py b/tests/gen/test_prompt_freeze.py
index 84c3023..2ef1336 100644
--- a/tests/gen/test_prompt_freeze.py
+++ b/tests/gen/test_prompt_freeze.py
@@ -10,6 +10,10 @@ tests draw it again against this tree.
What is compared is the prompt strings only. The notes and warnings a verb prints beside a prompt (`gen`
stderr and `extra.prompt_notes`, `video-prompt` `warnings` and `notes`, `video-set` `prompt_notes`) are not
part of the freeze and may differ.
+
+A sentence changed on purpose since, after a before-and-after comparison on the app's own model, is listed in
+`MEASURED` with the words 2.22.0 sent: a frozen prompt that holds it is compared with the new sentence in its
+place, and nothing else in that prompt, or in any other, may move.
"""
from __future__ import annotations
@@ -20,9 +24,35 @@ from pathlib import Path
import pytest
import prompt_freeze_table as table
+from sprite_gen.video import batch
FIXTURE = Path(__file__).resolve().parents[1] / "fixtures" / "prompts-v2.22.0.json.gz"
GROUPS = ("clip", "video-prompt", "start-still", "still", "video-side")
+# The two diagonal stills' view sentences as 2.22.0 said them: the turn, the head and the feet only, words a still
+# that turns only its head meets. `STILL_VIEW_TEXT` now says what that angle shows of the chest or back and the
+# legs (docs/video-pipeline.md).
+DIAGONAL_STILLS_2_22_0 = {
+ "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"
+ ),
+}
+MEASURED = tuple((was.format(facing=facing), batch.still_view_text(view, facing))
+ for view, was in DIAGONAL_STILLS_2_22_0.items() for facing in ("right", "left"))
+
+
+def _as_measured(prompt: str) -> str:
+ """A frozen prompt with each measured sentence in its new words. `gen` starts the view sentence with a capital,
+ so the first letter is left out of the match."""
+ for was, now in MEASURED:
+ prompt = prompt.replace(was[1:], now[1:])
+ return prompt
@pytest.fixture(scope="module")
@@ -49,9 +79,25 @@ def test_the_table_is_the_one_the_fixture_was_drawn_from(frozen, drawn) -> None:
@pytest.mark.parametrize("group", GROUPS)
def test_every_prompt_string_without_handed_is_2_22_0s_byte_for_byte(group, frozen, drawn) -> None:
names = [name for name in frozen if name.split("/")[0] == group]
- changed = [name for name in names if drawn[name] != frozen[name]]
+ changed = [name for name in names if drawn[name] != _as_measured(frozen[name])]
assert not changed, (f"{len(changed)} of {len(names)} {group} prompts differ from 2.22.0; first:\n"
- + _first_difference(changed[0], frozen[changed[0]], drawn[changed[0]]))
+ + _first_difference(changed[0], _as_measured(frozen[changed[0]]), drawn[changed[0]]))
+
+
+def test_only_the_diagonal_still_sentences_moved(frozen, drawn) -> None:
+ """Each measured sentence is in every still `gen --direction` draws at its view, facing either way (twice in a
+ facing regeneration), and in no clip, `video-prompt`, mid-step redraw or other view; those prompts, and only
+ those, differ from 2.22.0, and the new words say the body and legs turn."""
+ holds = {name for name, prompt in frozen.items() if any(was[1:] in prompt for was, _ in MEASURED)}
+ views = {f"{view}@{facing}" for view in DIAGONAL_STILLS_2_22_0 for facing in ("right", "left")}
+ assert {name.split("/")[2] for name in holds} == views
+ assert all(name.startswith("still/") for name in holds) and len(holds) == 4 * 144
+ assert {name for name in frozen if drawn[name] != frozen[name]} == holds
+ for name in holds:
+ angle = "front" if "/front_diagonal@" in name else "back"
+ said = f"Seen from a three-quarter {angle} angle"
+ assert frozen[name].count(said) == drawn[name].count(f"{said}: the whole body turned about 45 degrees")
+ assert f"not a {angle} view with only the head turned" in drawn[name]
def test_the_default_walk_keeps_its_treadmill_and_screen_sentences(frozen, drawn) -> None:
diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.py
index 17fc224..8426daa 100644
--- a/tests/video/test_video_pipeline.py
+++ b/tests/video/test_video_pipeline.py
@@ -574,12 +574,65 @@ def test_a_diagonal_still_is_told_how_far_to_turn() -> None:
at the image's own angle. A side still 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 "about 45 degrees to the right" in front and "toes 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")
[email protected]("facing", ["right", "left"])
+def test_a_front_diagonal_still_turns_its_body_and_legs_not_only_its_head(facing) -> None:
+ """Regression: the turn, the head and the shoes alone are met by a front-diagonal still that turns only its head,
+ the chest and the legs standing as from the front. The sentence says what that angle shows: the chest and hips
+ turn with the head, the middle of the chest three quarters of the way toward the far edge, the near side broad
+ and the far shoulder and arm partly hidden, the legs at that angle with the far foot higher and behind, and not
+ to follow a reference picture's angle. Turned left, it is the same sentence with the two sides swapped."""
+ other = "left" if facing == "right" else "right"
+ still = batch_mod.still_view_text("front_diagonal", facing)
+ assert still.startswith(f"seen from a three-quarter front angle: the whole body turned about 45 degrees to the {facing},")
+ assert "not a front view with only the head turned: the chest and hips turn as far as the head" in still
+ assert ("the middle of the chest and of the waist sits about three quarters of the way across the body toward its "
+ f"{facing} edge") in still
+ assert f"the shoulder and the side of the chest on the {other} of the picture, nearer the viewer, are seen broad" in still
+ assert f"the shoulder and arm on the {facing} of the picture are partly hidden behind the body" in still
+ assert "the chest looks narrower than from the front" in still
+ assert (f"the legs stand at the same angle, the far foot on the {facing} of the picture set a little higher and "
+ "partly behind the near leg") in still
+ assert f"both toes pointing toward the lower {facing}" in still
+ assert still.endswith("the face looking the same way as the chest, even when a reference picture shows the "
+ "character from another angle")
+ assert "{" not in still and still.count(other) == 1
+ swapped = still.replace(facing, "\0").replace(other, facing).replace("\0", other)
+ assert batch_mod.still_view_text("front_diagonal", other) == swapped
+ # The clip keeps pointing at the image: it starts from the still already drawn at that angle.
+ assert batch_mod.VIEW_TEXT["front_diagonal"] == "seen from a three-quarter front angle, turned exactly as in the image"
+ assert still not in batch_mod.build_prompt("front_diagonal", "walk", "The knight", facing=facing)
+
+
[email protected]("facing", ["right", "left"])
+def test_a_back_diagonal_still_turns_its_back_and_legs_not_only_its_head(facing) -> None:
+ """Regression: the back diagonal said the same few words, which a still seen from straight behind with only its
+ head turned meets. Turned toward the upper right, the far side is the picture's left: the middle of the back
+ sits toward that edge, the far shoulder and arm are partly hidden there and the far foot is set higher there;
+ the near side, toward the way it faces, is seen broad. The face stays hidden and the heels show, as before."""
+ other = "left" if facing == "right" else "right"
+ still = batch_mod.still_view_text("back_diagonal", facing)
+ assert still.startswith("seen from a three-quarter back angle: the whole body turned about 45 degrees away from the "
+ f"viewer toward the upper {facing},")
+ assert "not a back view with only the head turned: the back and hips turn as far as the head" in still
+ assert ("the middle of the back and of the waist sits about three quarters of the way across the body toward its "
+ f"{other} edge") in still
+ assert f"the shoulder and the side of the body on the {facing} of the picture, nearer the viewer, are seen broad" in still
+ assert f"the shoulder and arm on the {other} of the picture are partly hidden behind the body" in still
+ assert f"the far foot on the {other} of the picture set a little higher and partly behind the near leg" in still
+ assert f"the feet pointing diagonally up and to the {facing} so the backs of the shoes face the viewer at an angle" in still
+ assert "the face hidden and not looking back over the shoulder" in still
+ assert still.endswith("even when a reference picture shows the character from another angle") and "{" not in still
+ swapped = still.replace(facing, "\0").replace(other, facing).replace("\0", other)
+ assert batch_mod.still_view_text("back_diagonal", other) == swapped
+ assert batch_mod.VIEW_TEXT["back_diagonal"] == "seen from a three-quarter back angle, turned exactly as in the image"
+
+
def test_a_front_or_back_still_does_not_follow_the_pictures_angle() -> None:
"""A front or back still redrawn from a side picture kept the picture's turn in the head and chest with
the clip's one line, so its view sentence says where the head, chest and feet point and not to follow