Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(video): a horse's still is not drawn on a person's feet — still --body-plan
Soohong Kim8cef4591d0eb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a57358b..ca84b43 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,8 +5,9 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased (v2.32.0) - A horse is not told a person's walk- **Fix: an animal's walk and idle named a person's arms and feet.** The walk and run sentences have named no limb since 2.0.0 ("`video-set` motion templates no longer assume a biped"), but four sentences added later were measured on people and said to every body: the Lite walk calm ("a gentle arm swing close to the body", 2.18.0), the Lite back-diagonal head hold ("only the legs, arms and the ends of the hair move", 2.18.0), the idle ("both feet planted flat", chest, shoulders and arms, 2.9.0) and the front or back walk's mid-step redraw ("one foot … directly under its own hip … the arms swing", 2.18.0). Said of a horse, they walk it on a person's legs or stand it up on two. Not a regression of the 2.0.0 fix: these paths came after it.-- **New `--body-plan` on `video-set` and `video-prompt`** (`build_prompt(body_plan=...)`, `walk_start_prompt(body_plan=...)`, `sprite_gen/video/body_plan.py`): `biped` (default), `quadruped` or `legless`, or one `"<figure>=<plan>"` per figure of a scene (`--body-plan "the man=biped" --body-plan "the horse=quadruped"`). Any body but one biped gets those four sentences without the parts it lacks (`IDLE_TEXT_ANY_BODY`, `LITE_WALK_TEXT_LEGGED` / `LITE_WALK_TEXT_LEGLESS`, `LITE_HEAD_TEXT_ANY_BODY`, `WALK_START_TEXT_ANY_BODY`) and, after the motion sentence or the caller's `--motion`, what it stands on: "It stays on all four legs, as in the image, and never rises onto its hind legs."; a scene says it per figure. A body without legs has no mid-step redraw. `video-set` and `video-prompt --json` record `body_plan`. No body plan, or one biped, keeps every prompt byte for byte (`tests/gen/test_prompt_freeze.py`). The new sentences are not yet measured on clips. [docs/video-pipeline.md](docs/video-pipeline.md#a-body-that-is-not-a-person----body-plan).-- **`tests/video/test_body_plan.py`** draws every walk, run, idle and jump prompt (built-in and `--motion`, every model, `video-prompt`, the mid-step redraw) for a quadruped, a body without legs and a person leading a horse, and finds no arm, hand, wrist, shoulder, chest, hip, knee or counted foot in any; five of them are pinned as snapshots.+- **Fix: the still a front, back or diagonal clip starts from counted a person's feet.** The view sentence a still is drawn with (`still_view_text`, `gen --direction`; an app that draws its own still takes it too) said "the chest, hips and the toes of both feet" (front), "the shoulders, the hips and the heels of both feet" (back), "the face looking the same way as the chest" (front diagonal) and "the backs of the shoes" (back diagonal). The clip starts from that still, so a horse drawn on two feet stands up before the walk begins.+- **New `--body-plan` on `video-set`, `video-prompt` and `gen`** (`build_prompt(body_plan=...)`, `walk_start_prompt(body_plan=...)`, `still_view_text(body_plan=...)`, `gen.still_prompt(body_plan=...)`, `sprite_gen/video/body_plan.py`; on `gen` it needs `--direction`): `biped` (default), `quadruped` or `legless`, or one `"<figure>=<plan>"` per figure of a scene (`--body-plan "the man=biped" --body-plan "the horse=quadruped"`). Any body but one biped gets those four sentences without the parts it lacks (`IDLE_TEXT_ANY_BODY`, `LITE_WALK_TEXT_LEGGED` / `LITE_WALK_TEXT_LEGLESS`, `LITE_HEAD_TEXT_ANY_BODY`, `WALK_START_TEXT_ANY_BODY`) and, after the motion sentence or the caller's `--motion`, what it stands on: "It stays on all four legs, as in the image, and never rises onto its hind legs."; a scene says it per figure. The still's view sentence becomes `STILL_VIEW_TEXT_ANY_BODY` (where the body and head point, no feet, chest, hips, shoulders or shoes) ending in what it stands on (`body_plan.still_text`): "…, standing on all four legs, not rearing onto its hind legs". A body without legs has no mid-step redraw. `video-set`, `video-prompt --json` and `gen`'s `extra.view` record `body_plan`. No body plan, or one biped, keeps every prompt byte for byte (`tests/gen/test_prompt_freeze.py`). The new sentences are not yet measured on clips. [docs/video-pipeline.md](docs/video-pipeline.md#a-body-that-is-not-a-person----body-plan).+- **`tests/video/test_body_plan.py`** draws every walk, run, idle and jump prompt (built-in and `--motion`, every model, `video-prompt`, the mid-step redraw) and every still view sentence (`still_view_text` and `gen.still_prompt`, every view and facing) for a quadruped, a body without legs and a person leading a horse, and finds no arm, hand, wrist, shoulder, chest, hip, knee, shoe, heel, toe or counted foot in any (no foot at all for a body without legs); seven of them are pinned as snapshots.## v2.31.0 - A loop whose foot the set alignment cannot name is told it, one loop at a timediff --git a/SKILL.md b/SKILL.mdindex 397ee8f..f057efd 100644--- a/SKILL.md+++ b/SKILL.md@@ -75,7 +75,7 @@ it never changes the requested direction. Image correction requires explicit opt| `video --direction` | `side`, `front`, `back`, `front_diagonal`, `back_diagonal`; unset by default | `side` opts into facing inspection and a matching prompt requirement; the others skip it. The two diagonals are three-quarter views turned right (`VIEW_TEXT`); a walk or run in one is filmed pinned (`pins_last_frame`). || `video --facing`, `video-set --facing` | `right` (default), `left`; `video-set` also `right,left` | Required side direction. `right,left` films every side and diagonal view both ways, each from its own still (`--base side@left=…`); none is mirrored. || `gen --direction`, `--handed`; `video-prompt` / `video-set --handed` | a view; `"<item>=<left\|right> [part]"` | An item on one of the character's own sides: the still and clip prompts say where it is in each view, and mirroring is refused. |-| `video-prompt` / `video-set --body-plan` | `biped` (default), `quadruped`, `legless`; or `"<figure>=<plan>"` per figure of a scene | What the subject stands on: no clip or redraw prompt names a part it lacks (a horse is not walked on a person's legs or stood up), and a scene says it per figure. |+| `video-prompt` / `video-set` / `gen --direction --body-plan` | `biped` (default), `quadruped`, `legless`; or `"<figure>=<plan>"` per figure of a scene | What the subject stands on: no clip, redraw or still view prompt names a part it lacks (a horse is not walked on a person's legs or stood up), and a scene says it per figure. || `video --facing-fix`, `video-set --facing-fix` | `none` (default), `mirror` | Record the observation; opt into mirroring an observed opposite in a copy. Batch side inspection is enabled by default. |Direction is requested through the generation and motion prompts, which cannot guarantee model compliance.diff --git a/docs/gen.md b/docs/gen.mdindex b7c7e3c..12af456 100644--- a/docs/gen.md+++ b/docs/gen.md@@ -195,6 +195,7 @@ sprite-gen gen \[--layout-guide] # attach a one-slot layout guide (safe box, crown and floor lines); see below[--direction side|front|back|front_diagonal|back_diagonal [--facing right|left]] # add the engine's view sentence[--handed "the black smartwatch=left wrist" ...] # with --direction: where an item on one side is in that view+ [--body-plan quadruped | --body-plan "the horse=quadruped" ...] # with --direction: the view for that body[--report REPORT.json] \[--keep-session] # codex: keep the rollout jsonl instead of deleting it```@@ -217,6 +218,10 @@ Backward-compatible wrapper: `$SPRITE_GEN_ROOT/.venv/bin/python $SPRITE_GEN_ROOT- **`--direction`** adds the view sentence a sprite still is drawn with (`still_view_text`; a side ordiagonal view also takes `--facing`, a front or back view refuses it) and records `extra.view`.+ **`--body-plan`** (with `--direction`; `quadruped`, `legless`, or `"<figure>=<plan>"` per figure of a+ scene) says that view without the feet, chest, hips, shoulders and shoes a person's still is drawn+ with, ending in what the body stands on; see+ [video-pipeline](video-pipeline.md#a-body-that-is-not-a-person----body-plan).**`--handed`** adds, per item, which of the character's own sides it is on and where that side is inthe view; with it, `--facing-fix mirror` is refused and `regen` never mirrors. See[video-pipeline](video-pipeline.md#handedness--an-item-on-one-side).diff --git a/docs/prompt-assembly.md b/docs/prompt-assembly.mdindex 86997f3..167f1d1 100644--- a/docs/prompt-assembly.md+++ b/docs/prompt-assembly.md@@ -28,7 +28,7 @@ sentences put in (`tests/gen/test_prompt_assembly.py`).| Piece | When | Sentence from ||---|---|---|| the caller's text | always | `--prompt` / `--prompt-file` |-| view | `--direction` | `batch.still_view_text` |+| view | `--direction` (with `--body-plan`, the sentence for that body) | `batch.still_view_text` || handed | `--direction --handed` | `handedness.text` || facing | `--ref` with `--facing` | `facing.prompt_suffix` || key background | `--transparent --ref` when `auto` plans a key | `chroma.KEY_BACKGROUND_TEXT` |@@ -55,8 +55,9 @@ the head, a tail, the body, a leg, a shoulder — gets only where it is, and no**A body that is not a person** (`--body-plan`, `video/body_plan.py`): with no body plan, or onebiped, nothing changes. A quadruped, a body without legs or a scene of several figures has the idle,-the Lite walk sentences and the mid-step redraw said without the parts it lacks, and what it stands-on said after the motion paragraph+the Lite walk sentences, the mid-step redraw and the still's view sentence (`gen --direction+--body-plan`) said without the parts it lacks, and what it stands on said after the motion paragraph+or at the end of the view sentence([body plan](video-pipeline.md#a-body-that-is-not-a-person----body-plan)).**A front or back walk's start still** (`batch.walk_start_prompt`): the mid-step redraw sentence,diff --git a/docs/video-pipeline.md b/docs/video-pipeline.mdindex 66c478d..fc1b32d 100644--- a/docs/video-pipeline.md+++ b/docs/video-pipeline.md@@ -255,17 +255,18 @@ films from the base itself. Side and diagonal walks, and every other state, film### A body that is not a person — `--body-plan`-The measured sentences above were measured on people, and four of them name what only a person has:+The measured sentences above were measured on people, and five of them name what only a person has:the Lite walk calm swings the arms (`LITE_WALK_TEXT`), the Lite back-diagonal head hold moves thearms (`LITE_HEAD_TEXT`), the idle plants both feet and settles the chest, shoulders and arms-(`MOTION_TEXT["idle"]`), and the front or back mid-step redraw puts one foot under each hip with the-arms swinging (`WALK_START_TEXT`). Said of a horse, a pig or a dog, they walk it on a person's legs or+(`MOTION_TEXT["idle"]`), the front or back mid-step redraw puts one foot under each hip with the+arms swinging (`WALK_START_TEXT`), and the view sentence the still is drawn with points the chest,+hips and the toes or heels of both feet at the viewer, or the backs of the shoes (`STILL_VIEW_TEXT`). Said of a horse, a pig or a dog, they walk it on a person's legs orstand it up on two. The walk and run sentences themselves name no limb (since 2.0.0's "`video-set`-motion templates no longer assume a biped"); these four came later (idle 2.9.0, the rest 2.18.0) and-were said to every body.+motion templates no longer assume a biped"); these came later and were said to every body.-`video-set --body-plan`, `video-prompt --body-plan` and `build_prompt(body_plan=...)`,-`walk_start_prompt(body_plan=...)` name what the subject stands on (`sprite_gen/video/body_plan.py`):+`video-set --body-plan`, `video-prompt --body-plan`, `gen --direction --body-plan` and+`build_prompt(body_plan=...)`, `walk_start_prompt(body_plan=...)`, `still_view_text(body_plan=...)`,+`gen.still_prompt(body_plan=...)` name what the subject stands on (`sprite_gen/video/body_plan.py`):`biped` (the default), `quadruped` or `legless` for the character, or one `<figure>=<plan>` per figureof a scene (`--body-plan "the man=biped" --body-plan "the horse=quadruped"`). No body plan, or onebiped, keeps every prompt byte for byte. Any other body gets:@@ -276,12 +277,15 @@ biped, keeps every prompt byte for byte. Any other body gets:| idle | `IDLE_TEXT_ANY_BODY`: the same stillness, standing or resting as in the image, no feet counted, no chest, shoulders or arms || Lite walk calm | `LITE_WALK_TEXT_LEGGED` (no arm swing; never trotting or galloping) or, with a figure without legs, `LITE_WALK_TEXT_LEGLESS` (no steps or feet) || Lite back-diagonal head hold | `LITE_HEAD_TEXT_ANY_BODY`: what moves is what it moves on and its loose ends (a tail, a mane, hair) |+| the still's view sentence (`still_view_text`, `gen --direction`) | `STILL_VIEW_TEXT_ANY_BODY` for the front, back and diagonal views (where the body and head point; no feet, chest, hips, shoulders or shoes), the side view's `VIEW_TEXT` as it is, each ending in what it stands on (`body_plan.still_text`): ", standing on all four legs, not rearing onto its hind legs" / ", resting on its base without legs, never growing any" / ", each figure with the body it has: the man on two legs; the horse on all four legs, never rising onto its hind legs" || front or back mid-step redraw | `WALK_START_TEXT_ANY_BODY`: one leg lifted, the others planted, then what it stands on; a body without legs has no step to catch and films from its base (`starts_mid_step` is false, `video-prompt` gives no `start_still`) |Only the biped sentences were measured on clips; the others say no part the body lacks and are notyet measured. `--handed` keeps its own sentences (its arm sentences are for an item on an arm), and an-attack's grip sentence (`HOLD_TEXT["attack"]`) still speaks of hands. `video-set` and `video-prompt---json` record the plan as `body_plan`.+attack's grip sentence (`HOLD_TEXT["attack"]`) still speaks of hands. `video-set`, `video-prompt+--json` and `gen`'s `extra.view` record the plan as `body_plan`. An app that draws the still itself+with `still_view_text` and films with `build_prompt` passes the same `body_plan` to both: the clip+starts from that still.### A clip from a video MCP on your agent — ZCREdiff --git a/sprite_gen/gen/__init__.py b/sprite_gen/gen/__init__.pyindex 9dba236..529499d 100644--- a/sprite_gen/gen/__init__.py+++ b/sprite_gen/gen/__init__.py@@ -45,6 +45,8 @@ from pathlib import Pathfrom typing import Anyfrom sprite_gen.spec.runio import atomic_write_text+from sprite_gen.video import body_plan as body_mod+from sprite_gen.video.body_plan import Bodyfrom . import chroma as chroma_modfrom . import facing as facing_mod@@ -350,6 +352,7 @@ def generate_image(facing_fix: str = "none",view: str | None = None,handed: list[handed_mod.Handed] | None = None,+ body_plan: list[Body] | None = None,model: str | None = None,aspect_ratio: str | None = None,quality: str | None = None,@@ -374,7 +377,7 @@ def generate_image(raise SystemExit("gen: empty prompt; pass --prompt or --prompt-file")if facing is not None:facing_mod.validate(facing, facing_fix)- _check_view(view, facing, facing_fix, handed)+ _check_view(view, facing, facing_fix, handed, body_plan)out = out.expanduser().resolve()refs = [Path(r).expanduser().resolve() for r in (refs or [])]for ref in refs:@@ -397,7 +400,7 @@ def generate_image(# The key is the engine's plan when `auto` stepped down for the refs, so the engine asks for it: a# ref prompt with no key background is answered on white or another light ground, and keying that# takes the outline and light fills with it (2026-10-04). A key the prompt already names stays.- parts = still_prompt(prompt, view=view, facing=facing, handed=handed, refs=bool(refs),+ parts = still_prompt(prompt, view=view, facing=facing, handed=handed, body_plan=body_plan, refs=bool(refs),key=chroma_key if strategy_source == STRATEGY_SOURCE_REFS else None,layout=layout_guide_cell(aspect_ratio) if layout_guide else None)prompt = parts.text@@ -539,7 +542,8 @@ def generate_image(extra={**run.extra, **({"trim_alpha": trim_stats} if trim_stats else {}),**({"facing": facing_report} if facing_report else {}),**({"view": {"direction": view, "facing": facing if view in handed_mod.LATERAL_VIEWS else None,- "handed": [vars(h) for h in handed or []]}} if view else {}),+ "handed": [vars(h) for h in handed or []],+ **({"body_plan": [vars(b) for b in body_plan]} if body_plan else {})}} if view else {}),**({"layout_guide": guide_cell} if guide_cell else {}),**({"prompt_notes": parts.notes} if parts.notes else {})},)@@ -548,11 +552,16 @@ def generate_image(shutil.rmtree(workdir, ignore_errors=True)-def _check_view(view: str | None, facing: str | None, facing_fix: str, handed: list[handed_mod.Handed] | None) -> None:- """Refuse a `--direction` / `--facing` / `--handed` combination that cannot be drawn, before anything runs."""+def _check_view(view: str | None, facing: str | None, facing_fix: str, handed: list[handed_mod.Handed] | None,+ body_plan: list[Body] | None = None) -> None:+ """Refuse a `--direction` / `--facing` / `--handed` / `--body-plan` combination that cannot be drawn, before+ anything runs."""if view is None:if handed:raise SystemExit("gen: --handed needs --direction: where an item shows depends on the view")+ if body_plan:+ raise SystemExit("gen: --body-plan needs --direction: it changes the view sentence, which only "+ "--direction adds")returnhanded_mod.validate_view(view, facing)if view not in handed_mod.LATERAL_VIEWS and facing is not None:@@ -563,24 +572,28 @@ def _check_view(view: str | None, facing: str | None, facing_fix: str, handed: ldef still_prompt(prompt: str, *, view: str | None = None, facing: str | None = None,- handed: list[handed_mod.Handed] | None = None, refs: bool = False, key: str | None = None,+ handed: list[handed_mod.Handed] | None = None, body_plan: list[Body] | None = None,+ refs: bool = False, key: str | None = None,layout: dict[str, Any] | None = None) -> prompt_parts.Prompt:"""The prompt a still is drawn from: the caller's text, then the engine's pieces (`prompt_parts.Prompt.add`;- without `handed`, 2.22.0's prompt to the byte). In order:+ without `handed` or `body_plan`, 2.22.0's prompt to the byte). In order:- `view` (`--direction`): the sentence for drawing the still at that view, turned to `facing` (the side and- diagonal views), then where each `handed` item is in it (`handedness.text`);+ diagonal views; a `body_plan` that is not one biped gets it without the feet, chest, hips, shoulders and+ shoes and with what it stands on, `still_view_text`), then where each `handed` item is in it+ (`handedness.text`);- with `refs` and a `facing`: the turn over the reference (`facing.prompt_suffix`);- `key` (green / magenta, a ref run `auto` planned to key): the key background line, unless the promptnames a key background already;- `layout` (the `--layout-guide` cell): where the guide's lines are."""- parts = prompt_parts.Prompt(prompt)+ figures = body_mod.figures(body_plan)+ parts = prompt_parts.Prompt(prompt, caller=f"{prompt} {figures}" if figures else None)if view is not None:# The view sentences are the video pipeline's (a still is drawn for the clip that starts from it).from sprite_gen.video.batch import still_view_text- text = still_view_text(view, facing or "right")+ text = still_view_text(view, facing or "right", body_plan)parts.add("view", text[0].upper() + text[1:] + ".", facing=facing or prompt_parts.NO_TURN)if handed:parts.add("handed", handed_mod.text(handed, view, facing), sep=" ", handed=handed)@@ -626,6 +639,7 @@ def _run(args: argparse.Namespace) -> int:facing_fix=args.facing_fix,view=getattr(args, "direction", None),handed=handed_mod.parse_all(list(getattr(args, "handed", None) or [])) or None,+ body_plan=body_mod.parse_all(list(getattr(args, "body_plan", None) or [])) or None,model=args.model,aspect_ratio=args.aspect_ratio,quality=args.quality,@@ -755,6 +769,7 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:parser.add_argument("--facing-fix", choices=facing_mod.FIXES, default="none", help="with --ref and --facing: record only (none, default), or opt into mirror / one regen")parser.add_argument("--direction", choices=handed_mod.VIEWS, help="draw the still at this sprite view: the engine's view sentence is added to the prompt (side and diagonal views also take --facing right|left)")parser.add_argument("--handed", action="append", default=[], metavar="ITEM=SIDE [PART]", help="with --direction: an asymmetric item on one of the character's own sides, e.g. 'the black smartwatch=left wrist' (repeatable); the prompt says where it is in this view, and the still is never mirrored")+ parser.add_argument("--body-plan", action="append", default=[], metavar="PLAN | FIGURE=PLAN", help="with --direction: what the character stands on, biped (default), quadruped or legless; a scene of several figures names each, e.g. 'the man=biped' 'the horse=quadruped' (repeatable): the view sentence names no part the body lacks, as video-set --body-plan")parser.add_argument("--trim-alpha", action="store_true", help="with --transparent: crop the published PNG to its opaque bbox so the bottom edge is the foot line (margins reported)")parser.add_argument("--layout-guide",diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.pyindex 3a7a61c..bf41af6 100644--- a/sprite_gen/video/batch.py+++ b/sprite_gen/video/batch.py@@ -104,13 +104,44 @@ STILL_VIEW_TEXT = {"shoulder, and the feet pointing diagonally up and to the {facing} so the backs of the shoes face the viewer at an 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.+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 "+ "the image, not turned toward either side even when a reference picture shows it from another angle"+ ),+ "back": (+ "seen from directly behind: {body} turned fully away from the viewer, the back of the body and of the head "+ "facing straight at the viewer, the face completely hidden and not turned toward either side or looking back, "+ "even when a reference picture shows it from another angle"+ ),+ "front_diagonal": (+ "seen from a three-quarter front angle: {body} turned about 45 degrees to the {facing}, halfway between facing "+ "the viewer and facing {facing}, the face looking the same way as the body and the front of the body pointing "+ "toward the lower {facing}"+ ),+ "back_diagonal": (+ "seen from a three-quarter back angle: {body} 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, and the "+ "body pointing diagonally up and to the {facing} so its back faces 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`)."""+def still_view_text(direction: str, facing: str = "right", body_plan: list[Body] | None = None) -> str:+ """The view sentence for drawing a still seen from `direction` (`STILL_VIEW_TEXT`, else `VIEW_TEXT`); for a+ `body_plan` that is not one biped, `STILL_VIEW_TEXT_ANY_BODY` and what it stands on (`body_plan.still_text`).+ None, or one biped, is the sentence to the byte."""validate_facing(facing)- return STILL_VIEW_TEXT.get(direction, VIEW_TEXT[direction]).format(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)+ 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}"# 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.diff --git a/sprite_gen/video/body_plan.py b/sprite_gen/video/body_plan.pyindex 39b459f..f12ee05 100644--- a/sprite_gen/video/body_plan.py+++ b/sprite_gen/video/body_plan.py@@ -4,7 +4,8 @@The engine's measured walk and idle sentences were measured on people, and some name what only a personhas: the Lite walk's arm swing (`batch.LITE_WALK_TEXT`), the arms in the Lite back-diagonal head hold(`LITE_HEAD_TEXT`), the idle's two feet, chest, shoulders and arms (`MOTION_TEXT["idle"]`), and the front-or back walk's mid-step redraw, one foot under each hip and the arms swinging (`WALK_START_TEXT`). Said of a+or back walk's mid-step redraw, one foot under each hip and the arms swinging (`WALK_START_TEXT`), and the+front, back and diagonal still a clip starts from, both feet, chest, hips and shoes (`STILL_VIEW_TEXT`). Said of ahorse, they walk it on a person's legs or stand it up on two. The caller names the body plan (`parse`,`--body-plan`): one for the character ("quadruped"), or one per figure in a scene ("the man=biped","the horse=quadruped").@@ -15,6 +16,10 @@ horse, they walk it on a person's legs or stand it up on two. The caller names t| quadruped | four legs | it stays on all four legs and never rises onto its hind legs || legless | no legs | it has no legs and never grows any; no mid-step redraw (no step to catch) |+The still a clip starts from is drawn with a view sentence (`batch.still_view_text`, `gen --direction`)+that counts a person's feet and names the chest, hips, shoulders and shoes; a body that is not one biped+gets it without them, ending in what it stands on (`still_text`).+No body, or one biped, is the 2.22.0 prompt to the byte (`tests/gen/test_prompt_freeze.py`). Any otherbody gets the sentences without the parts it lacks and, after the motion sentence, what it stands on(`text`); a scene of several figures says it per figure. Only the biped sentences were measured; the@@ -38,6 +43,12 @@ ONE_TEXT = {"quadruped": "It stays on all four legs, as in the image, and never rises onto its hind legs.","legless": "It has no legs, as in the image, and never grows legs or feet.",}+# One figure, at the end of the view sentence a still is drawn with (`still_text`): the still may be drawn+# from words alone, so it says what the body stands on rather than "as in the image".+STILL_ONE_TEXT = {+ "quadruped": "standing on all four legs, not rearing onto its hind legs",+ "legless": "resting on its base without legs, never growing any",+}@dataclass(frozen=True)@@ -91,6 +102,16 @@ def text(bodies: list[Body] | None) -> str:f"{b.figure} {SCENE_TEXT[b.plan]}" for b in bodies) + "."+def still_text(bodies: list[Body] | None) -> str:+ """What the subject stands on, at the end of a still's view sentence (lower case, no full stop); "" for+ no body or one biped."""+ if not bodies or (not scene(bodies) and bodies[0].plan == "biped"):+ return ""+ if not scene(bodies):+ return STILL_ONE_TEXT[bodies[0].plan]+ return "each figure with the body it has: " + "; ".join(f"{b.figure} {SCENE_TEXT[b.plan]}" for b in bodies)++def figures(bodies: list[Body] | None) -> str:"""The figure names, as the caller wrote them (they are the caller's words in the prompt)."""return " ".join(b.figure for b in bodies or [] if b.figure)diff --git a/tests/video/test_body_plan.py b/tests/video/test_body_plan.pyindex 7d64615..d16412d 100644--- a/tests/video/test_body_plan.py+++ b/tests/video/test_body_plan.py@@ -17,6 +17,8 @@ import reimport pytestfrom PIL import Image, ImageDraw+from sprite_gen import gen+from sprite_gen.gen.base import ProviderRunfrom sprite_gen.video import batch, body_plan as bp, clip_promptLITE, PRO = "grok-imagine-video-1.5-lite", "grok-imagine-video-1.5"@@ -25,8 +27,10 @@ QUADRUPED = bp.parse_all(["quadruped"])LEGLESS = bp.parse_all(["legless"])SCENE = bp.parse_all(["the man=biped", "the horse=quadruped"])# Words that name a part only a person has, or count a person's feet.-PERSON = re.compile(r"\b(arms?|hands?|wrists?|elbows?|shoulders?|chest|hips?|hip-width|knees?|both feet|one foot|the other foot)\b",- re.IGNORECASE)+PERSON = re.compile(r"\b(arms?|hands?|wrists?|elbows?|shoulders?|chest|hips?|hip-width|knees?|both feet|one foot|the other foot|"+ r"shoes?|heels?|toes?)\b", re.IGNORECASE)+# A body without legs has no feet at all, counted or not.+FEET = re.compile(r"\b(feet|foot)\b", re.IGNORECASE)SNAPSHOTS = {'horse/side/walk/lite': (@@ -89,6 +93,18 @@ SNAPSHOTS = {'stay well inside the image. The entire background is one perfectly flat, uniform pure green chroma-''key fill (#00FF00) with no gradient, no texture, no shadow and no ground line.'),+ 'horse/front/still': (+ 'seen from the front: the whole body and head turned to face the viewer squarely, the face centred and '+ 'looking straight out of the image, not turned toward either side even when a reference picture shows it '+ 'from another angle, standing on all four legs, not rearing onto its hind legs'+ ),+ 'scene/back_diagonal/still': (+ 'seen from a three-quarter back angle: every figure\'s whole body and head turned about 45 degrees away from '+ 'the viewer toward the upper right, halfway between facing away and facing right, the face hidden and not '+ 'looking back, and the body pointing diagonally up and to the right so its back faces the viewer at an angle,'+ ' each figure with the body it has: the man on two legs; the horse on all four legs, never rising onto its '+ 'hind legs'+ ),}@@ -116,11 +132,40 @@ def test_no_walk_run_idle_or_jump_prompt_names_a_part_the_body_lacks(body_plan,assert not {name: words for name, words in named.items() if words}+def _every_still(body_plan, character):+ """The view sentence a still is drawn with, at every view and facing: as the app takes it+ (`still_view_text`) and as `gen --direction` adds it to the caller's prompt (`gen.still_prompt`)."""+ for view in batch.VIEW_TEXT:+ for facing in ("right", "left") if view in gen.handed_mod.LATERAL_VIEWS else (None,):+ yield f"still_view_text/{view}/{facing}", batch.still_view_text(view, facing or "right", body_plan=body_plan)+ yield (f"still_prompt/{view}/{facing}",+ gen.still_prompt(f"{character}, pixel art.", view=view, facing=facing, body_plan=body_plan).text)++[email protected]("body_plan, character", [(QUADRUPED, "A brown horse"), (LEGLESS, "A green slime"),+ (SCENE, "A man leading a brown horse by its reins")])+def test_no_still_view_sentence_names_a_part_the_body_lacks(body_plan, character) -> None:+ """The still a clip starts from is drawn with the view sentence; a front still of a horse "with the toes of+ both feet pointing at the viewer" stands it up on two before the clip begins."""+ no = FEET if bp.legless(body_plan) else None+ named = {name: sorted({m.group(0).lower() for m in PERSON.finditer(text)}+ | ({m.group(0).lower() for m in no.finditer(text)} if no else set()))+ for name, text in _every_still(body_plan, character)}+ assert len(named) == 2 * 8+ assert not {name: words for name, words in named.items() if words}+ for name, text in _every_still(body_plan, character):+ assert bp.still_text(body_plan) in text, name++def test_without_a_person_the_v2_31_prompts_did_name_a_persons_parts() -> None:- """What the report was about: a Lite walk, an idle and the front or back redraw of a horse, as 2.31.0 said it."""+ """What the report was about: a Lite walk, an idle and the front or back redraw of a horse, as 2.31.0 said it,+ and the front, back and back-diagonal stills a walk starts from."""assert "arm swing" in batch.build_prompt("side", "walk", "A brown horse", model=LITE)assert "both feet planted flat" in batch.build_prompt("side", "idle", "A brown horse")assert "directly under its own hip" in batch.walk_start_prompt("front", "green")+ assert "the toes of both feet" in batch.still_view_text("front")+ assert "the heels of both feet" in batch.still_view_text("back")+ assert "the backs of the shoes" in batch.still_view_text("back_diagonal")@pytest.mark.parametrize("name", list(SNAPSHOTS))@@ -130,6 +175,8 @@ def test_the_prompts_for_a_horse_and_a_man_leading_one(name) -> None:"scene": (SCENE, "A man leading a brown horse by its reins")}[who]if state == "walk-start":drawn = batch.walk_start_prompt(view, rest[0], body_plan=body_plan)+ elif state == "still":+ drawn = batch.still_view_text(view, body_plan=body_plan)else:drawn = batch.build_prompt(view, state, character, model=LITE if rest == ["lite"] else None, body_plan=body_plan)assert drawn == SNAPSHOTS[name]@@ -146,6 +193,13 @@ def test_one_biped_or_none_keeps_every_prompt_byte_for_byte() -> None:== batch.build_prompt(view, state, "The knight", motion=motion, model=model))for view in batch.WALK_START_TEXT:assert batch.walk_start_prompt(view, "green", body_plan=biped) == batch.walk_start_prompt(view, "green")+ for view, facing in itertools.product(batch.VIEW_TEXT, ("right", "left")):+ plain = batch.still_view_text(view, facing)+ assert batch.still_view_text(view, facing, body_plan=biped) == plain+ assert batch.still_view_text(view, facing, body_plan=[]) == plain+ turned = facing if view in gen.handed_mod.LATERAL_VIEWS else None+ assert (gen.still_prompt("The knight.", view=view, facing=turned, refs=True, body_plan=biped).text+ == gen.still_prompt("The knight.", view=view, facing=turned, refs=True).text)def test_the_body_plan_says_what_it_stands_on_after_the_motion_and_before_the_view() -> None:@@ -221,3 +275,34 @@ def test_video_prompt_takes_the_body_plan() -> None:body_plan=QUADRUPED)assert record["start_still"]["prompt"] == batch.walk_start_prompt("front", "green", body_plan=QUADRUPED)assert record["body_plan"] == [{"plan": "quadruped", "figure": ""}]+++class _Backend:+ name = "openai"+ transparency = "native"++ def __init__(self):+ self.prompts: list[str] = []++ def generate(self, request, workdir):+ self.prompts.append(request.prompt)+ Image.new("RGBA", (32, 32), (120, 60, 40, 255)).save(request.raw)+ return ProviderRun(self.name, 1, model="test-image", extra={})+++def test_gen_direction_takes_the_body_plan(tmp_path, monkeypatch) -> None:+ backend = _Backend()+ monkeypatch.setattr(gen, "_make_provider", lambda *a, **kw: backend)+ result = gen.generate_image("openai", "A brown horse, pixel art.", tmp_path / "out.png", view="back",+ body_plan=QUADRUPED)+ assert backend.prompts == [gen.still_prompt("A brown horse, pixel art.", view="back", body_plan=QUADRUPED).text]+ assert "both feet" not in backend.prompts[0] and bp.still_text(QUADRUPED) in backend.prompts[0]+ assert result.extra["view"]["body_plan"] == [{"plan": "quadruped", "figure": ""}]+ with pytest.raises(SystemExit, match="--body-plan needs --direction"):+ gen.generate_image("openai", "A brown horse.", tmp_path / "x.png", body_plan=QUADRUPED)+ assert len(backend.prompts) == 1+ seen = []+ monkeypatch.setattr(gen, "generate_image", lambda *a, **kw: seen.append(kw) or result)+ assert gen.main(["--provider", "openai", "--prompt", "A man leading a horse.", "--out", str(tmp_path / "s.png"),+ "--direction", "front", "--body-plan", "the man=biped", "--body-plan", "the horse=quadruped"]) == 0+ assert seen[0]["body_plan"] == SCENE