an.ir#

Scene IR — the single source of truth for a scene.

Three layers, per the architectural spec:

  • Narrative (scene.md) — human Markdown with structured fenced blocks.

  • Scene Graph (ir/scene.json) — Pydantic-validated JSON. The SSOT.

  • Render Code — generated per-backend, disposable.

This subpackage owns layer 2 (the Pydantic schema), the Markdown↔JSON sync that keeps layer 1 and layer 2 in lock-step, the validators (schema + semantic), the version migration registry, and the composition combinators that flatten authoring-time DSL to canonical-form actions.

Functions

lower_world(scene, *, extents[, ...])

The scene with every framed shot's placements derived from the world.

set_(target, property, value, *[, at])

Discrete property set at time at (relative to its enclosing scope).

tween(target, property, to, duration, *[, ...])

Animate a property from from_ (or its current value) to to.

sequence(*actions)

Run children one after the other.

parallel(*actions)

Run all children at once.

stagger(lag, *actions)

Start each action lag seconds after the previous one STARTS.

crowd(id, *, ref, count[, kind, store, ...])

count entities of one asset (kind/store/ref) placed in area.

fan_out(action, members, *[, crowd_id])

A copy of action per member, its targets moved from the crowd to the member.

delay(duration)

An empty span that consumes time.

loop(action, count)

Repeat action count times.

flatten(action, *[, start, play_extent])

Walk a composition tree, emitting leaf actions with absolute times.

dialogue_layout(shot, *[, tempo_of])

A LinePlacement for each dialogue line of shot, in order.

validate_schema(doc)

Validate that doc (dict, JSON string, or SceneIR) conforms to the schema.

validate_semantic(scene, *[, ...])

Cross-field semantic checks.

migrate(doc[, target_version, kind])

Migrate a document to target_version (default: its kind's current).

register_migration(kind, from_version, ...)

Decorator: register a migration for one kind in MIGRATIONS.

register_kind(kind)

Register a document kind.

kind_of(doc, *[, kind])

Resolve a document's kind, by explicit name or from its kind tag.

markdown_to_ir(md_text)

Parse the structured Markdown form of a scene into a SceneIR.

ir_to_markdown(scene)

Render a SceneIR back into the structured Markdown form.

sync(project_dir[, scene_file])

Reconcile a scene's markdown and JSON inside a project directory (scene.md and ir/scene.json, or the pair of the scene_file named; a named scene that is not there raises SceneFileError).

pin(point, to, *[, duration])

point held at to.

pull(point, to, *[, over, give])

point drawn toward to (a point, a body point, or a path).

join(joint, *[, at])

Rejoin the joint named joint at at.

unjoin(joint, *[, at])

Let go of the joint named joint at at.

grasp(by, item, *[, reach, retract, lean, ...])

by takes item.

reframe(target, *, to[, at, keep, snap, ...])

target changes to frame to at at seconds into the action.

place(item, onto, *[, by, rotation, reach, ...])

The hand holding item puts it onto a target.

release(item, *[, at, onto, arc, rotation, ...])

Let item go at at (a drop; onto: ground@x to land there; arc > 0 to throw it up first).

handover(item, to, *[, by, meet, reach, ...])

Give item to to.

swap(holder, *, take, give, by[, lag, ...])

by takes take from holder; give goes there in its place.

topple(body, **kw)

body falls over (see ToppleAction for the fields).

Classes

SceneIR(*[, version, compatible_version, ...])

Top-level Scene IR document.

Meta(*[, title, author, duration, fps, ...])

Scene metadata.

AssetRef(*, kind, id, store, ref[, ...])

Reference to an entry in a project store.

Shot(*, id[, renderer, duration, camera, ...])

A single rendered unit.

Dialogue(*, speaker, text[, voice_ref, ...])

One line of spoken dialogue.

Camera(*[, shake, follow, move, keys])

Camera state for a shot: a named move, or explicit keys.

Resolution(*[, width, height])

Pixel dimensions of the rendered output.

World(*[, members, viewpoints, travel, ...])

A scene's world: members at positions, the named viewpoints that are its coverage, and its travel (ADR 0009).

WorldMember(*, kind, id, store, ref[, ...])

An entity of the scene's world: the same reference a shot's entity carries, at a world position with a size (ADR 0009 decision 1).

Attachment(*, to[, at, scale])

A member that goes where another member goes (ADR 0009 decision 1).

Viewpoint(*[, at, look, look_at, vanish, ...])

A pinhole camera onto the world, or a composition that resolves to one (ADR 0009 decision 2).

Frame(*[, parent, at, look, coupling, ...])

A frame of reference: a pose (position and orientation) over film time, relative to its parent (ADR 0009 amendment, an#501).

FrameMoving(*[, direction])

A frame translating at a constant velocity: sugar for a frame whose at grows by direction × speed per second of FILM time.

Travel(*[, direction, speed, near, far, ...])

The viewpoints moving through the world in film time (ADR 0009 decision 4).

Stream(*, id, ref[, kind, store, height, ...])

A row of one prop along a travel's direction (ADR 0009 decision 4).

FlatAction(start, end, action)

A leaf action with its absolute start and end times.

LinePlacement(k, line, start, end, estimated)

One line of a shot and where it plays (shot-local seconds).

ValidationReport([passed, findings])

Result of running one or more validators.

ValidationFinding(severity, ir_path, description)

A single validation issue with a path into the IR.

DocumentKind(name, version_field, ...)

A schema-versioned document kind.

class an.ir.AssetRef(*, kind, id, store, ref, overrides=None, stage=None, library=None, joints=<factory>, **extra_data)[source]#

Bases: _IRModel

Reference to an entry in a project store.

The IR never inlines large assets. Instead it references them by store name + key, so the same character/voice/environment is reusable across scenes. overrides lets a single shot tweak presentation without forking the asset.

>>> AssetRef(kind="character", id="maya", store="characters", ref="maya-v1").id
'maya'
joints: list[JointSpec]#

its parts’ limits, its strings, its pins to other entities; a is relative to the entity. Omitted when empty, so no stored scene changes.

Type:

Joints this entity declares (JointSpec, ADR 0008)

kind: str#

it selected nothing (the compiler skipped it, nothing read the styles store) and the name belonged to the renderer selector. Art direction arrives as a StylePack (#112).

A str in the schema, not a Literal (ADR 0001 decision 2): the values are the REGISTERED entity kinds (an.genres) — the core’s environment, prop and voice, a genre’s character — and an validate checks it against that registry, naming the genre that provides an unregistered one.

Type:

"style" was retired in an#106

library: str | None#

The asset-library version this entry was checked out from (ADR 0005 decision 8): "[<library>:]<asset_id>@<version>", e.g. "cutan:character.alice-reiniger@v003" (grammar: an.library.ids.parse_ref(), a pinned version required: vNNN or sha256:<prefix>, never latest). None — the default, and every document written before the library existed — means the asset is the project’s own. Today the strategy is check-out, so ref still names the project-store key the compiler reads and this field is the pin beside it; live reference resolves it instead, later.

Additive and omit-when-unset, like stage: an unset library leaves no trace in a dump, so no stored scene changes and no schema version moves.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

stage: StagePlacement | None#

Where on the stage this entity stands. None — the default and what every existing document has — means “wherever the layout puts it”, which for characters is the evenly-spaced row the compiler computes.

Additive by construction, and hash-free by construction: the contract hashes the COMPILED document, and an AssetRef never reaches it. So this field can grow without retiring a single ledger row.

class an.ir.Attachment(*, to, at=None, scale=1.0, **extra_data)[source]#

Bases: _IRModel

A member that goes where another member goes (ADR 0009 decision 1).

>>> Attachment(to="paul", at=(8.0, 70.0), scale=0.9).to
'paul'

at is the offset in the HOST’s native units (its art’s pixels at stage.scale 1) and scale the size relative to the host, so the pair is derived from the host’s placement in every framing. Without at the member is added whenever the host is, with no placement of its own: another pass places it (the cut-out genre’s body attachments, from the host’s bones).

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.Camera(*, shake=None, follow=None, move=None, keys=None, **extra_data)[source]#

Bases: _CameraShakes

Camera state for a shot: a named move, or explicit keys.

>>> Camera(move="push_in").move
'push_in'
>>> Camera(keys=[CameraKey(at=0.0), CameraKey(at=2.0, x=-200.0)]).keys[1].x
-200.0

One code path, two front doors — the shape the dialogue [emotion] sugar already uses. A named move desugars to a key list; keys is that list written out. Setting both raises, because a scene that says two things about the same camera has no reading that is not a guess.

keys defaults to None, not [], and that too is load-bearing: the markdown writer dumps the camera with exclude_none=True, which KEEPS empty lists — an empty default would write keys: [] into every camera block it regenerates.

position, target and focal_length were removed in an#109. They were written into every scene.md this package ever generated and read by nothing; a registered migration drops them.

keys: list[CameraKey] | None#

The explicit door. None = use move.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

move: str | None#

A named preset — sugar for keys. The cutout renderer’s vocabulary is an.stage.compile.CAMERA_MOVES; validate and the compiler are pinned to the same table by test, because a move that validates and then raises is the failure _check_renderable exists to prevent.

class an.ir.Dialogue(*, speaker, text, voice_ref=None, start=None, duration=None, emotion=None, emotion_intensity=None, viseme_track=None, word_timings=None, audio_ref=None, viseme_ref=None, leveled=None, spoken=None, pause=None, at=None, direction=None, **extra_data)[source]#

Bases: _IRModel

One line of spoken dialogue.

start and duration are None until the audio pipeline runs (TTS gives us a real duration); the pipeline stamps them then, deriving start from the author’s pause / at (planned_start()).

at: float | None#

Where this line starts, in SHOT seconds, whatever came before it — (at 3.0) in scene.md. start is what the audio pipeline DERIVES from at/pause on every pass; these two are what the author wrote (an#187).

direction: list[str] | None#

How the line is DELIVERED — cues such as ["excited"] or ["sighs", "annoyed"], {excited} in scene.md (an#209). A TTS model that takes inline audio tags (ElevenLabs v3/v4) receives them as [excited] Hi!; others ignore them. Never part of text, so captions and lip-sync alignment never see a cue.

emotion_intensity: float | None#

maya [angry 0.4]: … in scene.md, a typed parameter on the (b-name) emotion. None is full strength, and is omitted from JSON.

Type:

How strongly emotion shows, 0..1 (an#253)

leveled: dict | None#

<the synthesized line’s audio_ref>, “gain_db”: <its voice’s gain>}`` when audio_ref is the leveled audio. None — unleveled — is omitted from JSON.

Type:

Stamped by voice leveling (an#315)

Type:

``{“source”

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

pause: float | None#

Seconds of silence before this line, after the previous line’s speech ends (the shot start, for the first line) — (pause 1.5) in scene.md.

planned_start(cursor)[source]#

Where this line starts, given the previous line ends at cursor.

The one rule the audio pipeline stamps into start and an validate lays lines out by: at if set, else cursor + pause. A start on a line never synthesized (no audio_ref) was authored — the spelling of at before an#187 — and counts as one; a synthesized line’s start is the pipeline’s own stamp, re-derived here.

>>> Dialogue(speaker="a", text="bye", pause=1.5).planned_start(0.8)
2.3
>>> Dialogue(speaker="a", text="bye", at=4.0).planned_start(0.8)
4.0
>>> Dialogue(speaker="a", text="bye").planned_start(0.8)
0.8
Return type:

float

spoken: float | None#

seconds from the line’s start to the end of its AUDIBLE speech — its take’s own trailing silence left out — stamped with duration from the line’s audio. The next line’s pause counts from here (a line with no pause still follows the whole take). None (silent audio, a line its voice’s trim_silence already cut to the tail the author keeps, a line stamped before an#397) counts from the end of duration, as before. Never written to JSON: it is read off the line’s stored audio on every pass (the audio pipeline, and a render that skips synthesis), so scene.json and its fixtures do not change.

Type:

DERIVED (an#397)

word_timings: list[WordTimingIR] | None#

The provider’s word timings, line-relative; None when the provider has none (offline, Rhubarb) or the line was stamped before an#96.

class an.ir.DocumentKind(name, version_field, current_version)[source]#

Bases: object

A schema-versioned document kind.

version_field differs between kinds (version for the scene IR, schema_version for the character descriptor), which is exactly why a migrator cannot simply reach for doc["version"].

version_of(doc)[source]#

The document’s declared version, defaulting to this build’s.

Return type:

str

class an.ir.FlatAction(start, end, action)[source]#

Bases: object

A leaf action with its absolute start and end times.

The flat-form list is the canonical representation passed to renderers and verifiers. Composition nodes (sequence/parallel/delay/loop) do not appear in the flat form — they’re collapsed into time offsets.

class an.ir.Frame(*, parent='world', at=(0.0, 0.0, 0.0), look=(0.0, 0.0, 0.0), coupling='rigid', moving=None, sway=None, sockets=<factory>, **extra_data)[source]#

Bases: _IRModel

A frame of reference: a pose (position and orientation) over film time, relative to its parent (ADR 0009 amendment, an#501).

>>> Frame(moving=FrameMoving(speed=20.0)).parent
'world'
>>> Frame(parent="vehicle", coupling="far").coupling
'far'

at and look ([yaw, pitch, roll], as a viewpoint’s) are the pose in the parent’s units at film time 0; moving adds a constant velocity; a set/tween of <frame>:at_x|at_y|at_z|yaw|pitch|roll in a shot replaces the channel for that shot. coupling: far follows the parent’s rotation and none of its translation: the frame of what is at infinity (a sky, a range of mountains).

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sockets: dict[str, tuple[float, float, float]]#

where a member that reframe``s into it with ``snap: <name> lands (a hand’s palm, a shelf’s slot).

Type:

Named points of this frame, {name: point} in its units

sway: FrameSway | None#

Lean of the members riding in it when it accelerates (off when unset).

class an.ir.FrameMoving(*, direction=(0.0, 0.0, 1.0), speed, **extra_data)[source]#

Bases: _IRModel

A frame translating at a constant velocity: sugar for a frame whose at grows by direction × speed per second of FILM time.

>>> FrameMoving(direction=(0.0, 0.0, 1.0), speed=20.0).speed
20.0
model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.LinePlacement(k, line, start, end, estimated)[source]#

Bases: NamedTuple

One line of a shot and where it plays (shot-local seconds).

A tuple, so for k, line, start, end, estimated in dialogue_layout(shot) reads it as the private layout it replaces did.

end: float#

Alias for field number 3

estimated: bool#

Whether end comes from the offline estimate (the line has no audio yet).

k: int#

The line’s index in shot.dialogue.

line: Any#

Alias for field number 1

start: float#

Alias for field number 2

class an.ir.Meta(*, title='', author='', duration=0.0, fps=30, resolution=<factory>, default_renderer='cutout', notes='', step_hz=None, style_pack=None, default_easing=None, sounds=<factory>, captions=None, closing_transition=None, voice_loudness=None, light=None, **extra_data)[source]#

Bases: _IRModel

Scene metadata.

captions: Captions | None#

Captions from the dialogue’s word timings (Captions, an#175); None — the default — is none, omitted from JSON like style_pack.

closing_transition: Transition | None#

a fade to its color over its duration, on the last shot’s last frames (the film’s length is unchanged, and its final frame is the colour; the sound fades with it). None (or a cut) ends on the last frame as drawn. A dissolve has nothing to dissolve into, so it is refused.

Type:

How the film ENDS (an#389)

default_easing: str | tuple[float, float, float, float] | list[float] | None#

The easing every authored tween that names none is drawn with (an#166) — "linear" for a snappy South Park cadence, an overshooting cubic-Bezier for a bouncy one. Precedence is **tween > this > the built-in "ease_in_out"``** (:meth:`TweenAction.resolved_easing`). ``None — the default and what every existing document has — changes nothing, and is omitted from JSON like style_pack, so no committed scene and no compiled document moves. It reaches authored tweens ONLY: a motion preset writes its own easings, the camera’s named moves supply theirs, and blinks, play clips and swap channels have none to inherit. There is no per-shot override yet — style is a scene’s.

default_renderer: str#

a registered renderer’s name.

Type:

Like Shot.renderer

light: SceneLight | None#

The scene’s one light (SceneLight, catalogue D1); None — the default — declares none, checks nothing, and is omitted from JSON.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sounds: list[SoundCue]#

Sound cues in FILM time — a music bed, an ambience under every shot (SoundCue). Empty, the default, is no sound layer at all.

step_hz: float | None#

Stepped timing for AUTHORED TWEENS, in pose updates per second; None (the default) leaves every tween smooth. At 30 fps, 15 is “on twos” and 10 “on threes” — the character-animation practice Spider-Verse made famous (characters on twos, simulation on ones). The camera is exempt by construction, as are swap channels (already stepped by format), compiled blinks and play clips: only tween curves are resampled — sample-and-hold of the eased curve on a SHOT-wide grid (every tween in a shot shares it; it restarts at a cut), not a retiming into holds and fast transitions. A tween’s own START and END are always pose changes too, so a tween that begins or ends off-grid changes pose on that frame as well as on the grid (a set at an off-grid at likewise lands where it was authored). A shot’s own step_hz overrides this. Must be positive (schema) and <= fps (validate + compile), an#89.

style_pack: str | None#

The StylePack in the project’s styles store this scene is drawn under, by key. None — the default and what every existing document has — leaves every colour exactly where it is, which is why adding this moved no corpus hash (an#112).

A pack changes what the COMPILER decides: the character palette, the leg and pupil colours, the environment presets’ sky and ground — and SVG art whose descriptor tags its colours by role (colour_roles, written by an character new). Untagged art is never inferred (inferring a role from a pixel is what produced an#99’s wrong-tone lid); a rig a pack cannot reach is WARNED about by name at compile.

voice_loudness: VoiceLoudness | None#

One loudness for every voice (VoiceLoudness, an#315); None — the default — levels nothing, and is omitted from JSON.

class an.ir.Resolution(*, width=1920, height=1080, **extra_data)[source]#

Bases: _IRModel

Pixel dimensions of the rendered output.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.SceneIR(*, version='0.3.0', compatible_version='0.3.0', kind='SceneIR', meta=<factory>, assets=<factory>, timeline=<factory>, world=None, **extra_data)[source]#

Bases: _IRModel

Top-level Scene IR document. The SSOT.

A document is portable, diffable, and renderer-agnostic. Persisted as JSON at ir/scene.json inside an an project.

>>> from an.base import SCHEMA_VERSION
>>> doc = SceneIR(meta=Meta(title="Hello"))
>>> doc.version == SCHEMA_VERSION
True
>>> round_tripped = SceneIR.model_validate_json(doc.model_dump_json())
>>> round_tripped.meta.title
'Hello'
model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

world: World | None#

its members at world positions, its named viewpoints and its travel. None — the default, and every document written before it existed — is no world at all: every shot is placed by hand. Omitted from JSON when unset (the stage rule), so no stored scene and no schema version moves.

Type:

The scene’s world (ADR 0009)

class an.ir.Shot(*, id, renderer='cutout', duration=5.0, camera=None, entities=<factory>, actions=<factory>, dialogue=<factory>, narration=<factory>, options=<factory>, step_hz=None, transition=None, sounds=<factory>, policy=None, viewpoint=None, welds=<factory>, joints=<factory>, solve=None, continue_from=None, **extra_data)[source]#

Bases: _IRModel

A single rendered unit. A scene is a sequence of shots.

A shot’s renderer selects the backend that draws it. Every renderer must accept the same Shot fields; renderer-specific options go under options.

continue_from: str | None#

"<shot id>" in this scene, or "<scene file>#<shot id>" in a sibling scene file. Every entity this shot shares with that one opens as that one ends (its transform, swap keys, alpha, and what holds it); this shot’s own opening set/tween wins. Written continue: in the shot block; resolved before compile (an.continuity). None (omitted): opens as staged.

Type:

Open from another shot’s end state (an#542)

joints: list[JointSpec]#

Joints between this shot’s bodies (JointSpec, ADR 0008); the solve compile pass keeps them at every frame. Omitted when empty.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

policy: dict[str, Any] | None#

per aspect, the methods it prefers in order, over the style pack’s (StylePack.policy) and under an author’s request — {"locomotion": ["loco.glide"]}. None: the style’s.

Type:

This shot’s policy (an#348)

renderer: str#

Which RENDERER draws this shot — not art direction. The field was called style until an#106, colliding with the styles store (which holds art direction) and with AssetRef(kind="style"); one word for two meanings is how a scene came to declare a “style” that selected a renderer while the thing that actually styles it went unread. A str in the schema (ADR 0001 decision 2): any name a renderer registered (an.adapters.register_renderer), checked by an validate. cutout stays the persisted default (decision 9).

solve: SolveSettings | None#

mode, gravity and damping over the style pack’s. None (omitted): the defaults.

Type:

How this shot is solved (SolveSettings)

sounds: list[SoundCue]#

Sound cues in SHOT-local time (SoundCue).

step_hz: float | None#

Per-shot override of Meta.step_hz (None = inherit).

transition: Transition | None#

How this shot is entered (Transition); None is a hard cut.

viewpoint: str | Viewpoint | None#

the name of one of world.viewpoints or an inline Viewpoint. None (the default, and every document written before the world existed) means the shot is placed by hand, as it always was. Omitted from JSON when unset, like policy.

Type:

This shot’s viewpoint onto the scene’s world (ADR 0009)

welds: list[Weld]#

Items held by something for a span (Weld); omitted when empty.

class an.ir.Stream(*, id, ref, kind='prop', store='props', height=None, width=None, units_per_px=None, every, lane=0.0, y=0.0, after=None, seed=0, frame=None, **extra_data)[source]#

Bases: _IRModel

A row of one prop along a travel’s direction (ADR 0009 decision 4).

>>> Stream(id="tree", ref="olive_tree", height=4.0, every=(1.0, 3.0), lane=(-3.0, -2.0)).id
'tree'

Instances <id>_<k> stand every world units apart along the direction (a range is seeded-uniform), lane to the right of it (negative: left), at height y; sized like a member. They are positioned in the world once, so every shot sees the same instances in the same places at the same film time.

frame: str | None#

the world.

Type:

The frame the row stands in (document key in); unset

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.Travel(*, direction=(0.0, 0.0, 1.0), speed=None, near=0.5, far=60.0, tolerance_px=1.0, max_actions=20000, streams=<factory>, plates=<factory>, **extra_data)[source]#

Bases: _IRModel

The viewpoints moving through the world in film time (ADR 0009 decision 4).

>>> t = Travel(speed=20.0, streams=[Stream(id="pole", ref="pole", height=6.0, every=12.0, lane=2.0)])
>>> t.direction, t.speed
((0.0, 0.0, 1.0), 20.0)

The vehicle the members and viewpoints ride moves at speed world units per second of FILM time along direction; streams stream past between near and far. plates declares every plane a framed shot’s environment holds as far (at infinity; its parallax factor must be 0) or vehicle (rigid with the camera): {"far": ["set/rear_view"], "vehicle": ["set/cabin"]}. A plane in neither is a validate warning, because a plate with near objects baked in stands still while the streams move.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.ValidationFinding(severity, ir_path, description, location=None)[source]#

Bases: object

A single validation issue with a path into the IR.

location: str | None#

"<file>:<line>" when the thing to fix is an opaque source a shot runs (a Manim scene file, an#279) rather than the IR; None otherwise.

class an.ir.ValidationReport(passed=True, findings=list())[source]#

Bases: object

Result of running one or more validators.

passed is True iff there are no error-severity findings.

class an.ir.Viewpoint(*, at=None, look=(0.0, 0.0, 0.0), look_at=None, vanish=None, fov=None, focal=None, subject=None, size=None, distance=None, subject_at=(0.0, 0.0), hide=<factory>, frame=None, **extra_data)[source]#

Bases: _IRModel

A pinhole camera onto the world, or a composition that resolves to one (ADR 0009 decision 2).

>>> Viewpoint(at=(0.0, 0.0, 0.0), vanish=(0.0, -262.0)).vanish
(0.0, -262.0)
>>> Viewpoint(subject="paul", size="close_up", subject_at=(190.0, 0.0)).size
'close_up'

A camera: at (world), its look as look: [yaw, pitch, roll] in degrees (yaw turns right, pitch looks down, roll turns the picture clockwise), or look_at (a world point), or vanish (where the +z direction lands on screen, in pixels from the frame centre: the road’s vanishing point), and fov (horizontal, degrees) or focal (pixels).

A composition: subject (a member, or a list), size (a SHOT_SIZES name) or distance (world units), and subject_at (where the subject’s band lands on screen, pixels; the centre by default). The camera is computed on the look direction so the band fills the frame as the size says. hide names members this shot leaves out.

frame: str | None#

The frame this camera is mounted in (document key in); its at and look are in that frame’s units. Unset: the world’s default frame.

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.World(*, members=<factory>, viewpoints=<factory>, travel=None, frames=<factory>, ground=None, **extra_data)[source]#

Bases: _IRModel

A scene’s world: members at positions, the named viewpoints that are its coverage, and its travel (ADR 0009).

>>> world = World(members=[
...     WorldMember(kind="character", id="jerry", store="characters", ref="jerry", at=(-0.45, 0.65, 1.6), height=1.75),
...     WorldMember(kind="prop", id="wheel", store="props", ref="wheel", attached=Attachment(to="jerry")),
... ], viewpoints={"two_shot": Viewpoint(at=(0.0, 0.0, 0.0))})
>>> [m.id for m in world.members], sorted(world.viewpoints)
(['jerry', 'wheel'], ['two_shot'])
all_frames()[source]#

The declared frames plus the one a travel with a speed is sugar for (vehicle, moving along the travel’s direction).

>>> World(travel=Travel(speed=4.0)).all_frames()["vehicle"].moving.speed
4.0
Return type:

dict[str, Frame]

default_frame()[source]#

The frame a member or viewpoint is in when it names none: the travel’s vehicle (members ride it) when there is one, else the world.

>>> World().default_frame(), World(travel=Travel(speed=1.0)).default_frame()
('world', 'vehicle')
Return type:

str

frames: dict[str, Frame]#

The frames of reference, {name: Frame}; world is the implicit root and a travel with a speed adds vehicle.

ground: float | None#

the world y (down positive, in the world frame) of a horizontal plane the members stand on (an#519). Lowering projects it under each positioned member, at that member’s depth, as the floor line the support and skate checks measure b: ground against (overrides.ground, an.base.GROUND_OVERRIDE): each frame’s floor as lowered, under where the member stands then, with its place along the floor in the frame it stands in, so a passenger standing still over the world’s floor (its car moving) does not skate. The line is level on the stage (members do not roll with the camera); a member whose hand stage.at wins gets none. Unset: no floor in the world, and ground is the shot’s solve.ground or where the member stands as the shot opens.

Type:

The floor

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class an.ir.WorldMember(*, kind, id, store, ref, overrides=None, stage=None, library=None, joints=<factory>, at=None, height=None, width=None, units_per_px=None, attached=None, after=None, facing=None, frame=None, planes=None, depths=None, **extra_data)[source]#

Bases: AssetRef

An entity of the scene’s world: the same reference a shot’s entity carries, at a world position with a size (ADR 0009 decision 1).

>>> m = WorldMember(kind="character", id="paul", store="characters", ref="paul",
...                 at=(0.45, 0.65, 1.6), height=1.75)
>>> m.at, m.height
((0.45, 0.65, 1.6), 1.75)

at is where the entity’s placement point stands (a character’s feet, a prop’s origin) in world units; exactly one of height/width (its size in world units) or units_per_px (world units per native pixel, for art whose extent cannot be measured) sizes it. A member is attached to another instead of positioned, or it is an environment (present in every framed shot, placed by nothing: plates are per shot). after is the draw anchor a shot’s stage.after would be. A member never carries stage: the viewpoint places it.

depths: dict[str, float] | None#

An environment’s planes at a depth, {plane name: z} in world units from the camera along its look direction (an#503): the parallax factor of a plane is DERIVED from it, z_ref / z with z_ref the depth of the viewpoint’s subject (else of what the shot shows: the character plane), so a plane declares where it is and not how fast it scrolls. A plane with a depth must keep the descriptor’s own depth (1.0) and parallax unset: two spellings of one fact are refused. What is at infinity is a plane in a far frame, not a depth.

facing: float | None#

a yaw in degrees in its own frame, in the convention of a camera’s yaw (0 looks along +z, positive turns toward +x). None (the default) keeps a billboard: the member has no facing for its kind to answer to. Read by an.genres.EntityKind.view_for (an#734, an.genres.API_LEVEL 20), which is handed the camera’s yaw relative to it.

Type:

Where the member faces

frame: str | None#

The frame of reference this member is in (document key in); unset means the world’s default frame (World.default_frame()). An environment’s frame is the default of its planes; planes names the exceptions, {plane name: frame} (one environment can hold a cabin plate and a sky plate).

model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'populate_by_name': True}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

an.ir.crowd(id, *, ref, count, kind='prop', store=None, layout='grid', area=(-480.0, -60.0, 480.0, 240.0), scale=1.0, scale_jitter=0.0, jitter=0.0, seed=0)[source]#

count entities of one asset (kind/store/ref) placed in area.

id: the crowd’s name; member k is <id>_<k> (member_id()) ref: the asset every member draws count: how many (at least 1) kind: the entity kind (prop, or a genre’s, such as character) store: the store the asset lives in (default: the kind’s registered store) layout: grid (rows filled from the back), row or scatter area: (x0, y0, x1, y1) in scene pixels about the stage centre; a

member’s stage point stands inside it

scale: every member’s stage scale scale_jitter: each member’s scale varies by up to this fraction (0.1: ±10%) jitter: each grid or row member moves by up to this fraction of its cell seed: the scatter and the jitters are drawn from it

>>> [m.stage.at for m in crowd("line", ref="dot", count=3, layout="row", area=(0, 0, 300, 100))]
[(50.0, 50.0), (150.0, 50.0), (250.0, 50.0)]
>>> crowd("x", ref="dot", count=0)
Traceback (most recent call last):
...
ValueError: a crowd needs at least one member; got count=0
Return type:

list[AssetRef]

an.ir.delay(duration)[source]#

An empty span that consumes time. Useful inside sequence.

Return type:

DelayAction

an.ir.dialogue_layout(shot, *, tempo_of=None)[source]#

A LinePlacement for each dialogue line of shot, in order.

A line synthesized plays for its duration; one not yet synthesized for the offline voice’s estimate (an.audio.offline_tts.estimate_speech_duration()) divided by its voice’s tempo, tempo_of(line) (an#265: the effect applies under every provider; default 1).

Return type:

Iterator[LinePlacement]

an.ir.fan_out(action, members, *, crowd_id=None)[source]#

A copy of action per member, its targets moved from the crowd to the member.

action: any action, leaf or composite; every target naming the crowd

(army, or a node of it, army/arm_l) is rewritten

members: the crowd’s members (AssetRef s or ids), in order crowd_id: the crowd’s name (default: read off the first member’s id,

army_0 -> army)

Pair it with an.ir.compose.stagger() for a ripple through the ranks, or parallel() for the crowd moving as one.

>>> from an.ir.compose import tween
>>> [a.target for a in fan_out(tween("army/arm_l", "rotation", to=1.0, duration=0.5), ["army_0", "army_1"])]
['army_0/arm_l', 'army_1/arm_l']
Return type:

list[Any]

an.ir.flatten(action, *, start=0.0, play_extent=None)[source]#

Walk a composition tree, emitting leaf actions with absolute times.

A play without duration advances a sequence by play_extent (default default_play_extent()): its natural length, or zero for a looping animation, which runs to the shot end.

Delays are absorbed into the timeline (they don’t appear in the output). Loops are unrolled by simple repetition — appropriate at v0.1; the cutout runtime can re-roll for efficiency later.

Every node is dispatched through its registered kind (ActionKind), so a genre’s kind flattens without an edit here; a node whose kind nobody registered raises, naming the genre that provides it, and an ExtensionAction read before its genre loaded is validated by the registered model on the way through.

Return type:

list[FlatAction]

an.ir.grasp(by, item, *, reach=0.4, retract=0.35, lean=60.0, align=True, carry=None)[source]#

by takes item.

>>> grasp("stu@hand_r", "musket@grip").item
'musket@grip'
Return type:

GraspAction

an.ir.handover(item, to, *, by=None, meet=1.0, reach=0.4, retract=0.35, lean=60.0, align=True)[source]#

Give item to to.

>>> handover("cup", "jo@hand_l", meet=0.5).meet
0.5
Return type:

HandoverAction

an.ir.ir_to_markdown(scene)[source]#

Render a SceneIR back into the structured Markdown form.

>>> from an.ir.schema import SceneIR, Meta, Shot
>>> scene = SceneIR(meta=Meta(title="Demo", duration=5.0),
...                 timeline=[Shot(id="s1", renderer="cutout", duration=5.0)])
>>> md = ir_to_markdown(scene)
>>> "# Demo" in md
True
>>> "## Shot s1 (cutout)" in md
True

This writes the WHOLE document in the writer’s own formatting, and keeps no prose but meta.notes. Updating an existing scene.md goes through merge_markdown(), which keeps the author’s text wherever the content did not change.

Return type:

str

an.ir.join(joint, *, at=0.0)[source]#

Rejoin the joint named joint at at.

>>> join("grip", at=2.0).at
2.0
Return type:

JoinAction

an.ir.kind_of(doc, *, kind=None)[source]#

Resolve a document’s kind, by explicit name or from its kind tag.

Raises ValueError for an unregistered kind rather than guessing — a document whose kind nobody declared has no known version field, so any answer would be a fabrication.

Return type:

DocumentKind

an.ir.loop(action, count)[source]#

Repeat action count times.

Return type:

LoopAction

an.ir.lower_world(scene, *, extents, film_starts=None, fps=None, extent_problems=None, plane_geometry=None, bands=None, band_problems=None, view_for=None)[source]#

The scene with every framed shot’s placements derived from the world.

A shot without a viewpoint is returned as it is. For a framed shot: its listed entities keep their order of appearance among themselves but are drawn in depth order (far first) with the members the frame shows and the shot did not list; environments come first; listed entities that are not members go on top. A listed member’s hand stage.at wins (a note says when it disagrees with the world; its scale is the world’s unless set); one without is filled in. A member the viewpoint hides is left out unless the shot lists it: the listing wins, and a note says so. Under a travel, the streams’ slot entities are added with their motion; a scene already lowered gains nothing from a second pass.

extents is what the stage measured (an.stage.world.member_extents()), extent_problems why some could not be; film_starts is where each shot starts in the film, so stream phase is continuous across cuts (the shot sum by default); plane_geometry is {environment member id: {plane: (offset, box)}}, each plane’s origin on screen (Plane.offset) and its drawn box around it (None: unknown), read by the stage (an.stage.world.plane_geometry()): where a plane at a world depth is anchored and when it is on screen (an#503; the origin and no box for one it does not name); bands is where a subject’s own rig puts each shot size (Bands, measured by an.stage.world.member_shot_sizes()), and band_problems why a subject’s could not be (a shot_size note on each shot that frames it). view_for is (member, relative_yaw) -> actions | None (ViewFor, bound to the kinds’ own hook by an.stage.world.member_views()): for each shown member with a facing it is given the camera’s yaw about the member relative to where it faces (an#734), and what it returns is put at the head of the shot’s actions. None (the default): no member is turned to the camera.

Raises WorldError for a viewpoint the world cannot resolve.

>>> lower_world(SceneIR(), extents={}).scene.timeline
[]
Return type:

Lowered

an.ir.markdown_to_ir(md_text)[source]#

Parse the structured Markdown form of a scene into a SceneIR.

>>> md = '''# Demo
...
... ```yaml meta
... title: Demo
... duration: 5
... ```
...
... ## Shot s1 (cutout)
...
... ```yaml shot
... duration: 5
... ```
...
... ```dialogue
... charlie: hi
... ```
... '''
>>> scene = markdown_to_ir(md)
>>> scene.meta.title
'Demo'
>>> scene.timeline[0].id
's1'
>>> scene.timeline[0].dialogue[0].text
'hi'
Return type:

SceneIR

an.ir.migrate(doc, target_version=None, *, kind=None)[source]#

Migrate a document to target_version (default: its kind’s current).

Walks the migration registry one step at a time, considering only the migrations registered for this document’s kind. Raises ValueError if no path exists between the source and target versions.

>>> from an.base import SCHEMA_VERSION
>>> migrate({"version": SCHEMA_VERSION, "kind": "SceneIR"})["version"] == SCHEMA_VERSION
True
>>> migrate({"version": "0.1.0", "kind": "SceneIR"})["version"] == SCHEMA_VERSION
True
Return type:

dict[str, Any]

an.ir.parallel(*actions)[source]#

Run all children at once. Total duration = max of child durations.

Return type:

ParallelAction

an.ir.pin(point, to, *, duration=None)[source]#

point held at to. to is body[@point] or (x, y).

>>> pin("cup", (10.0, -40.0)).to
(10.0, -40.0)
Return type:

PinAction

an.ir.place(item, onto, *, by=None, rotation=None, reach=0.4, retract=0.35, lean=60.0)[source]#

The hand holding item puts it onto a target.

>>> place("book", "ground@-860").onto
'ground@-860'
Return type:

PlaceAction

an.ir.pull(point, to, *, over=None, give=0.0)[source]#

point drawn toward to (a point, a body point, or a path).

>>> pull("kite", "world@0,-300", over=1.0).give == DFLT_PULL_GIVE
True
Return type:

PullAction

an.ir.reframe(target, *, to, at=0.0, keep='world', snap=None, inherit=None, motion=None, velocity=(0.0, 0.0, 0.0), gravity=9.81)[source]#

target changes to frame to at at seconds into the action.

>>> reframe("cup", to="hand", snap="palm").snap
'palm'
Return type:

ReframeAction

an.ir.register_kind(kind)[source]#

Register a document kind. Returns it, so callers can bind the result.

Return type:

DocumentKind

an.ir.register_migration(kind, from_version, to_version)[source]#

Decorator: register a migration for one kind in MIGRATIONS.

Registered against the throwaway Widget kind from the module docstring, deliberately: this registry is process-wide, so a doctest that registered a step for a REAL kind would leave a second path through the ladder for every test that ran afterwards — which is exactly what happened once, and it presented as one unrelated test failing only in a full run (an#106).

>>> @register_migration("Widget", "1.0", "2.0")
... def _bump(doc):
...     doc["widget_version"] = "2.0"
...     return doc
>>> ("Widget", "1.0", "2.0") in MIGRATIONS
True
Return type:

Callable[[Callable[[dict[str, Any]], dict[str, Any]]], Callable[[dict[str, Any]], dict[str, Any]]]

an.ir.release(item, *, at=0.0, onto=None, arc=0.0, rotation=None, bounce=None)[source]#

Let item go at at (a drop; onto: ground@x to land there; arc > 0 to throw it up first).

>>> release("musket", onto="ground@-620", arc=60).arc
60.0
>>> release("musket", onto="ground@-620").arc   # let fall: no rise
0.0
Return type:

ReleaseAction

an.ir.sequence(*actions)[source]#

Run children one after the other. Total duration = sum of child durations.

Return type:

SequenceAction

an.ir.set_(target, property, value, *, at=0.0)[source]#

Discrete property set at time at (relative to its enclosing scope).

Return type:

SetAction

an.ir.stagger(lag, *actions)[source]#

Start each action lag seconds after the previous one STARTS.

The stagger (Manim’s LaggedStart, previz’s compose, a crowd entering one by one): the children run in parallel, the i-th delayed by i * lag. It is authoring sugar, not a new kind — it builds the parallel of sequence(delay(i * lag), action) it means, so the scene document, scene.md and every renderer see only core kinds. Total duration: the latest child’s end. scene.md holds it verbatim (a kind: parallel entry), so it round-trips. (an.stage.text.reveal_units — an.stage.text.stagger before an#241 — is the text-block preset: a LIST of per-unit actions with holds, not a combinator.)

>>> flat = flatten(stagger(0.25, tween("a", "x", to=1.0, duration=1.0),
...                              tween("b", "x", to=1.0, duration=1.0),
...                              tween("c", "x", to=1.0, duration=1.0)))
>>> [(f.action.target, f.start, f.end) for f in flat]
[('a', 0.0, 1.0), ('b', 0.25, 1.25), ('c', 0.5, 1.5)]
>>> duration_of(stagger(0.5, delay(1.0), delay(1.0)))
1.5
>>> stagger(0.1).children
[]
>>> stagger(-1.0, delay(1.0))
Traceback (most recent call last):
...
ValueError: stagger lag must be >= 0, got -1.0
Return type:

ParallelAction

an.ir.swap(holder, *, take, give, by, lag=0.25, rotation=None, reach=0.4, retract=0.35, lean=60.0, align=True)[source]#

by takes take from holder; give goes there in its place.

>>> swap("nap/hand", take="musket", give="sword", by="stu@hand_r").give
'sword'
Return type:

SwapAction

an.ir.sync(project_dir, scene_file='scene.md')[source]#

Reconcile a scene’s markdown and JSON inside a project directory (scene.md and ir/scene.json, or the pair of the scene_file named; a named scene that is not there raises SceneFileError).

The side _scene_side() picks is written over the other: Markdown is the human SSOT, but pipeline stages (audio, lip-sync) write rich state into the JSON that the Markdown cannot represent, so a newer JSON is merged into the Markdown (an#275: the author’s text kept) rather than overwritten, and a tie that disagrees is warned about (SyncTieWarning). After a write over an existing file the two mtimes are equalised, so the next sync does not flip.

Return type:

SyncResult

an.ir.topple(body, **kw)[source]#

body falls over (see ToppleAction for the fields).

>>> topple("cam", toward="right", push=1.0).push
1.0
Return type:

ToppleAction

an.ir.tween(target, property, to, duration, *, from_=None, easing=INHERIT)[source]#

Animate a property from from_ (or its current value) to to.

easing left out inherits the scene’s meta.default_easing (else "ease_in_out"); naming one — "ease_in_out" included — pins it.

>>> "easing" in tween("a", "x", to=1.0, duration=1.0).model_fields_set
False
>>> tween("a", "x", to=1.0, duration=1.0, easing="linear").easing
'linear'
Return type:

TweenAction

an.ir.unjoin(joint, *, at=0.0)[source]#

Let go of the joint named joint at at.

>>> unjoin("grip").joint
'grip'
Return type:

UnjoinAction

an.ir.validate_schema(doc)[source]#

Validate that doc (dict, JSON string, or SceneIR) conforms to the schema.

>>> validate_schema({"meta": {"title": "x"}, "timeline": []}).passed
True
>>> r = validate_schema({"meta": {"title": "x"}, "timeline": [{"id": "s", "duration": "not-a-number"}]})
>>> r.passed
False
Return type:

ValidationReport

an.ir.validate_semantic(scene, *, available_voices=None, available_characters=None, available_props=None, available_environments=None, available_sounds=None, available_library_lock=None, available_styles=None, available_recordings=None, available_scenes=None, only=None, fps=None)[source]#

Cross-field semantic checks. Pass live stores in for cross-store checks.

Both available_voices and available_characters accept any mapping; available_props is the same thing for kind="prop" entities (an#108), and available_environments lets the flat-pan warning read a stage’s planes (an#111) — without it a prop’s swaps are reported as having no descriptor, which is validate refusing what compile accepts. Voices are consulted via __contains__ only; characters additionally via __getitem__ (the swap-reference and play checks read descriptor dicts, an#87 / an#7). Pass None to skip those checks — and know that skipping them is what it sounds like: a play or a swap the compiler will refuse passes silently without the store (the CLI, an validate, always passes it).

available_styles is the project’s styles store: a check reads the StylePack the scene names (meta.style_pack) from ctx.stores["styles"] (a style’s policy, an#348).

available_library_lock is the project’s asset-library lockfile (mall["library_lock"]): with it, every scene library: pin is checked against the lockfile (warning on disagreement) and every pinned check-out against its library version (info when it has been edited).

available_scenes is the project’s scenes store (mall["scenes"]): its project folder is where a continue: <scene file>#<shot> reads the sibling scene file from (an#542). Without it, such a continuation is an error naming the missing folder.

The checks are a REGISTRY (an.genres.registry.register_check()): the core’s own register below, a genre’s when it is loaded (the cut-out genre’s play, expression, turn and view checks), and they run in stages — scene, then shot once per shot, then finish — each by its order. An action or entity kind no loaded genre registered is one error naming the genre that provides it; checks that would trip over it skip that shot rather than crash.

only runs just the registered checks of those names (what an render does after synthesis, post_synthesis_findings()), plus the ones in ALWAYS_RUN_CHECKS, which report on whichever checks ran; fps is the one the film is assembled at when it is not the scene’s (an render --fps), which decides how long a dissolve’s overlap is.

Return type:

ValidationReport

Modules

assets

Where a third-party asset came from, and what its licence obliges.

camera

Camera semantics: the named moves, and the one resolver that expands them.

compose

Composition combinators for authoring action trees, plus a flattener.

dialogue

Where each dialogue line of a shot will play (an#767): the layout an validate and the genres' checks share.

events

The visible events a compiled shot records, by name: what a sound cue's event may say (an#804).

frames

Frames of reference: a tree of named poses over film time (ADR 0009 amendment, an#501).

holds

Holding things: grasp, place, release, handover and swap (an#502, catalogue A4).

joints

The constraint layer's verbs: pin, pull, join and unjoin (ADR 0008, an#512).

schema

Pydantic v2 models for the Scene IR.

validate

Schema and semantic validation for SceneIR documents.

world

One world, many shots: the scene world's geometry and its lowering (ADR 0009).

world_from_shot

World members from a shot placed by hand (an#514): the projection inverted.