an.ir.world#
One world, many shots: the scene world’s geometry and its lowering (ADR 0009).
A scene may declare a world (SceneIR.world): members at world positions
with a size, named viewpoints, and a travel. A shot with a viewpoint is a
pinhole camera onto that world; this module turns the two into what the stage
already understands — a stage placement per entity, and plain set/tween
actions for the streams of a travelling view — so the compiler, the shot cache
and the renderers see nothing new. A shot without a viewpoint is untouched,
and a hand stage.at always wins.
The projection, with the stage’s axes extended by depth (x right, y DOWN,
z away from the viewer): a point p seen from a camera at c with basis
(forward, right, down) and focal length f (pixels) lands at
depth = (p − c) · forward sx = f · ((p − c) · right) / depth sy = f · ((p − c) · down) / depth
and an entity of world size S whose art is n pixels tall at stage.scale
1 is drawn at stage.scale = (S / n) · f / depth. That is the multiplane
camera: near things are large and rush past, far things are small and barely
move, and a close-up is the same world seen from nearer.
>>> from an.ir.schema import World, WorldMember, Viewpoint
>>> world = World(members=[
... WorldMember(kind="prop", id="near", store="props", ref="p", at=(1.0, 0.0, 2.0), height=1.0),
... WorldMember(kind="prop", id="far", store="props", ref="p", at=(1.0, 0.0, 20.0), height=1.0),
... ])
>>> box = (-10.0, -20.0, 10.0, 0.0) # 20 px tall art, feet at the origin
>>> eye = resolve_viewpoint(world, Viewpoint(at=(0.0, 0.0, 0.0), focal=1000.0),
... extents={"near": box, "far": box}, width=1280, height=720)
>>> placed = member_placements(world, eye, extents={"near": box, "far": box}, width=1280, height=720)
>>> placed["near"].at, round(placed["near"].scale, 2)
((500.0, 0.0), 25.0)
>>> placed["far"].at, round(placed["far"].scale, 2)
((50.0, 0.0), 2.5)
Module Attributes
|
|
|
|
A hand |
|
A hand placement whose scale differs from the ground plane's by more than this fraction is out of perspective (catalogue A6). |
|
The stage direction of a member's floor line. |
Functions
|
One channel's motion |
|
The lens in pixels: |
|
The |
|
Per framed shot, where each frame stands in the world as the shot opens and as it closes (after the shot's own |
|
Whether lowering would change anything: a world, or a shot with a viewpoint. |
|
The scene with every framed shot's placements derived from the world. |
|
The positioned members of shot |
|
The world member a shot entity becomes (the inverse of |
|
Every member's placement under |
|
Every plane of |
|
The |
|
The camera a viewpoint is, as a |
|
The instances of |
|
How many entities a stream needs by its depth range: one per instance that can be between |
|
The shot's viewpoint as a model: a name is looked up in the world. |
|
The floor |
|
|
Classes
|
A member's floor at one instant ( |
|
The scene as the compiler will see it, the notes to report, and for each framed shot where its lowered entities came from ( |
|
Where one member lands in a framed shot. |
|
A plane at infinity, and why (an#735): what |
|
A resolved viewpoint: where the camera is, which way it looks, its lens. |
|
One thing the lowering did or could not do for one shot, for |
Exceptions
A world or viewpoint that cannot be resolved (an unknown member, a subject whose extent is unknown, a viewpoint name the world does not have, a travel past its budget). |
- an.ir.world.Box#
(x0, y0, x1, y1)in its art’s pixels atstage.scale1, relative to its placement point (a character’s feet).Nonemeans it could not be measured (nothing drawn, or a compile that failed: the lowering’s note says which).- Type:
A member’s native extent
- an.ir.world.Extents#
{member or stream id: Box | None}, measured by the stage (an.stage.world.member_extents()); the IR layer only reads it.
- class an.ir.world.GroundAt(at, along, scale=1.0, lateral=0.0)[source]#
Bases:
objectA member’s floor at one instant (
an.base.GROUND_OVERRIDE), in the coordinates of itsstage.at: the floor point under its placement point (at), the floor line’s unit direction (along), the stage px one world unit along the floor spans there (scale: focal over depth), and where that floor point lies along the floor in the frame the member stands in, in world units from where it stood as the shot opens (lateral). A stage point on the floor is atlateral + (p - at) · along / scaleworld units along it, in the member’s own frame: a foot that keeps that number keeps its place on the floor, however the member, its frame or the camera carry it across the stage.
- an.ir.world.HAND_PLACEMENT_TOLERANCE_PX: float = 2.0#
A hand
stage.atthis far from the world’s placement is “the same” (the cut-continuity tolerance, an#394); farther is a lint warning.
- class an.ir.world.Lowered(scene, notes=list(), origins=dict(), carried=dict())[source]#
Bases:
objectThe scene as the compiler will see it, the notes to report, and for each framed shot where its lowered entities came from (
origins: per lowered entity index, the author’s entity index, orNonefor one the world added), so a finding on a lowered shot can name the author’s line.
- an.ir.world.MEMBER_FLOOR_ALONG: tuple[float, float] = (1.0, 0.0)#
The stage direction of a member’s floor line. Members are billboards that never roll with the camera: an upright figure stands on a level line, so under a rolled camera its floor is level too (the horizon’s tilt would put its downhill foot into the floor). When members roll, this is the horizon’s stage direction.
- an.ir.world.PERSPECTIVE_TOLERANCE: float = 0.15#
A hand placement whose scale differs from the ground plane’s by more than this fraction is out of perspective (catalogue A6).
- class an.ir.world.Placed(id, at, scale, depth, box, in_frame, via, note='')[source]#
Bases:
objectWhere one member lands in a framed shot.
- class an.ir.world.PlaneAtInfinity(member, plane, reason, frame, coupled_frame, ir_path)[source]#
Bases:
objectA plane at infinity, and why (an#735): what
an validatepins to parallax factor 0 and a genre’s far-plate critic judges.member/planename it ("<member>/<plane>", as the travel’s plates list it);reasonis"listed"(farunderworld.travel.plates) or"frame"(it stands inframe, which is, or hangs from,coupled_frame, coupledfar);ir_pathis where a finding about it points: the listing (world/travel/plates/far/<k>) or the world member that puts it in the frame (world/members/<j>).>>> PlaneAtInfinity("set", "sky", "frame", "horizon", "far", "world/members/0").why "in frame 'horizon', under 'far' coupled `far`"
- class an.ir.world.Projection(at, forward, right, down, focal, aim=None)[source]#
Bases:
objectA resolved viewpoint: where the camera is, which way it looks, its lens.
>>> eye = Projection(at=(0.0, 0.0, 0.0), forward=(0.0, 0.0, 1.0), right=(1.0, 0.0, 0.0), down=(0.0, 1.0, 0.0), focal=1000.0) >>> eye.project((2.0, -1.0, 10.0)) (200.0, -100.0, 10.0) >>> eye.project((0.0, 0.0, -1.0)) is None True >>> rolled = Projection((0.0, 0.0, 0.0), *_basis(0.0, 0.0, 90.0), focal=100.0) >>> [round(v, 6) + 0.0 for v in rolled.project((1.0, 0.0, 10.0))] # a point on the right: now at the bottom [0.0, 10.0, 10.0]
- aim: tuple[float, float, float] | None = None#
the centre of the band it frames (not the subject’s footing).
Nonefor a camera given byat. The jump-cut check measures a shot’s size there (an#853).- Type:
The point a subject-framed viewpoint aims at
- project(p)[source]#
(sx, sy, depth): screen pixels from the frame centre, and the depth;Nonefor a point at or behind the camera.
- transformed(pose)[source]#
The same camera carried by a frame whose pose is
pose: this projection is in the frame’s units, the result is in its parent’s (the world’s, for a frame’s world pose).>>> eye = Projection((0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), 100.0) >>> eye.transformed(Pose(at=(0.0, 0.0, 4.0))).at (0.0, 0.0, 4.0) >>> eye.transformed(Pose()) is eye True
- Return type:
- exception an.ir.world.WorldError[source]#
Bases:
ValueErrorA world or viewpoint that cannot be resolved (an unknown member, a subject whose extent is unknown, a viewpoint name the world does not have, a travel past its budget). The IR layer raises it;
an validatereports it as an error and the lowering is then skipped for that scene.
- class an.ir.world.WorldNote(shot, index, severity, kind, entity, message)[source]#
Bases:
objectOne thing the lowering did or could not do for one shot, for
an validate(its severity) andan world show.
- an.ir.world.fit_channel(g, a, b, *, tolerance, min_step)[source]#
One channel’s motion
gon[a, b]as tweens:[(t0, t1, v0, v1, easing)], each a cubic-Bézier easing whose end slopes matchg’s (a Hermite fit: control points(1/3, d0/3, 2/3, 1 − d1/3)), split in two wherever the fit strays more thantolerancefromg— dense where the motion bends (a stream instance near the camera), one segment where it is straight. A segment is never shorter thanmin_step.>>> segs = fit_channel(lambda t: 100.0 / (10.0 - t), 0.0, 9.0, tolerance=1.0, min_step=0.05) >>> segs[0][:2], segs[-1][1], round(segs[-1][3], 1) ((0.0, 4.5), 9.0, 100.0) >>> len(segs) < 8 True
- an.ir.world.focal_length(viewpoint, *, width)[source]#
The lens in pixels:
focalas given, else fromfov(horizontal, degrees;DFLT_FOV_DEGwhen unset) and the frame width. A wider frame at the same field of view is a longer focal, so a world framed once frames the same at any resolution.>>> round(focal_length(Viewpoint(fov=90.0), width=1280)) 640 >>> focal_length(Viewpoint(focal=500.0), width=1280) 500.0
- Return type:
- an.ir.world.frame_moving_members(scene, index, *, film_start=None)[source]#
The positioned members of shot
index’s world that stand in a frame moving relative to the viewpoint’s over the shot (the rulelower_world()samples their motion by), or that areframecarries between frames. A stage floor does not stay under them, so a check measuring against it (skateonsolve.groundor the member’s own floor, an#519) cannot judge them; a world that declaresgroundgives each its own floor and reference point, keyed as the camera sees it (overrides.ground,world_ground_at()). Empty for a shot no world frames; raisesWorldErroras lowering would.>>> frame_moving_members(SceneIR(), 0) frozenset()
- an.ir.world.frame_poses(scene, *, film_starts=None)[source]#
Per framed shot, where each frame stands in the world as the shot opens and as it closes (after the shot’s own
<frame>:at_*actions): whatan world show --framesprints.>>> from an.ir.schema import Frame, FrameMoving, Viewpoint, World >>> scene = SceneIR(world=World(frames={"car": Frame(moving=FrameMoving(speed=10.0))}, ... viewpoints={"v": Viewpoint(at=(0.0, 0.0, 0.0), frame="car")}), ... timeline=[Shot(id="s", duration=2.0, viewpoint="v")]) >>> row = frame_poses(scene)[0] >>> row["viewpoint_frame"], row["frames"][0]["name"], row["frames"][0]["end"]["at"] ('car', 'car', (0.0, 0.0, 20.0))
- an.ir.world.ground_scale(projection, at, *, floor_y, unit)[source]#
The
stage.scaleof a member standing on the horizontal planey = floor_ywhose feet are drawn at screenat(px from the frame centre), orNoneat or above the horizon or when the plane is not below the eye.The single-view relation (catalogue A6): the ray through the pixel meets the floor at depth
t * f, and a member ofunitworld units per native pixel is drawn atunit * f / depth=unit * ray_y / (floor_y - eye_y), so scale grows with the pixel’s distance below the horizon.>>> eye = Projection((0.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), 1000.0) >>> round(ground_scale(eye, (0.0, 100.0), floor_y=1.0, unit=0.01), 3) # feet 100 px below the horizon 1.0 >>> round(ground_scale(eye, (0.0, 200.0), floor_y=1.0, unit=0.01), 3) # nearer: twice the size 2.0 >>> ground_scale(eye, (0.0, -50.0), floor_y=1.0, unit=0.01) is None # above the horizon True
- an.ir.world.has_world(scene)[source]#
Whether lowering would change anything: a world, or a shot with a viewpoint.
>>> has_world(SceneIR()) False
- Return type:
- an.ir.world.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.atwins (a note says when it disagrees with the world; itsscaleis 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.extentsis what the stage measured (an.stage.world.member_extents()),extent_problemswhy some could not be;film_startsis where each shot starts in the film, so stream phase is continuous across cuts (the shot sum by default);plane_geometryis{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);bandsis where a subject’s own rig puts each shot size (Bands, measured byan.stage.world.member_shot_sizes()), andband_problemswhy a subject’s could not be (ashot_sizenote on each shot that frames it).view_foris(member, relative_yaw) -> actions | None(ViewFor, bound to the kinds’ own hook byan.stage.world.member_views()): for each shown member with afacingit 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
WorldErrorfor a viewpoint the world cannot resolve.>>> lower_world(SceneIR(), extents={}).scene.timeline []
- Return type:
- an.ir.world.member_of(entity, **placement)[source]#
The world member a shot entity becomes (the inverse of
entity_of()): its fields as they are, itsstagedropped (a member is placed by each shot’s viewpoint) and itsafterkept, withplacement(at,height, …) where the world stands it. Itsjointsstay with the shot: they tie it to other entities of THAT shot, andentity_of()gives a member none.>>> e = AssetRef(kind="prop", id="lamp", store="props", ref="lamp", ... stage=StagePlacement(at=(1.0, 2.0), after="set/sky")) >>> m = member_of(e, at=(0.0, 0.0, 5.0), height=1.0) >>> m.at, m.after, m.stage ((0.0, 0.0, 5.0), 'set/sky', None)
- Return type:
- an.ir.world.member_placements(world, projection, *, extents, width, height, hide=(), hand=None, extent_problems=None, member_at=None, fixed=None)[source]#
Every member’s placement under
projection:{id: Placed}.Positioned members are projected; attached ones follow their host (an offset in the host’s native units, times the host’s scale); an environment is present with no placement. A member behind the camera is placed nowhere and is not in frame.
handis{id: (at, scale)}for members a shot placed by hand, positioned or attached: that placement stands in for the derived one (its depth stays the world’s), so what is attached to it follows the hand, as the compiler’s own passes do.extent_problemssays why an extent could not be measured, for the note.member_atoverrides a member’satwith where it stands in the viewpoint’s frame (a member in another frame, or moved by an action);fixedis a placement some other pass already settled (a member in motion), which attached members then follow.
- an.ir.world.planes_at_infinity(world, environments)[source]#
Every plane of
worldat infinity (an#735), byan validate’s own rule: listedfarunderworld.travel.plates(in listing order), then each plane of an environment member in a frame coupledfar(in member order). A member’s planes are read from its descriptor inenvironments(the environments store); a listed plane is reported even when its descriptor cannot be read, and a listed path with no/is skipped (malformed: another check’s to report). For a genre’s critic (cutan’s far-plate critic, reeleehq/cutan#177), so the check and the critic share one definition of “far”.>>> from an.ir.schema import Travel >>> w = World(travel=Travel(plates={"far": ["set/sky", "oops"]})) >>> [(p.path, p.reason, p.ir_path) for p in planes_at_infinity(w, {})] [('set/sky', 'listed', 'world/travel/plates/far/0')]
- Return type:
- an.ir.world.pose_look(pose)[source]#
The
(yaw, pitch)in degrees a pose faces.>>> pose_look(Pose()) (0.0, 0.0)
- an.ir.world.resolve_viewpoint(world, viewpoint, *, extents, width, height, member_at=None, bands=None)[source]#
The camera a viewpoint is, as a
Projection, in its own frame’s units.member_atoverrides a subject’satwith where it stands in the VIEWPOINT’s frame (a subject in another frame, at the shot’s start).bandsgives a subject’s own band for a size (its rig’s landmarks,an.genres.EntityKind.shot_sizes); otherwiseSHOT_SIZES’. A band that names its own columns ((top, bottom, left, right), an#769) is framed at its true width and centred on it.Crop policy for a partial size (
medium,close_up; an#769). When a band’s true width is known and fitting it would put the camera so far back that the size is not a jump-cut step (an.ir.schema.JUMP_CUT_SIZE_RATIO) nearer than the next wider size, the camera comes in to that step, but never nearer than the band’s height needs: the sides are cropped rather than the cut becoming a jump cut. A band without columns is fitted at its box’s aspect, as before.A viewpoint with
atis that camera. One with asubjectis computed: on the look direction, at the distance that fillsfillof the frame with the subject’s band (SHOT_SIZES; its rows at its box’s aspect,_band_box()), shifted so the band’s centre lands atsubject_at. With several subjects the band is their union, aimed at their mean depth, and the distance is what the NEAREST subject needs from its own depth, so every subject’s band fits the frame’s height and width.>>> from an.ir.schema import World, WorldMember >>> world = World(members=[WorldMember(kind="prop", id="p", store="props", ref="p", at=(3.0, 0.0, 10.0), height=2.0)]) >>> eye = resolve_viewpoint(world, Viewpoint(subject="p", size="full", focal=900.0), ... extents={"p": (-10.0, -40.0, 10.0, 0.0)}, width=1600, height=900) >>> [round(v, 3) for v in eye.at] # 2 units tall fills 0.9 × 900 px: 2.222 away, centred on the box [3.0, -1.0, 7.778]
- Return type:
- an.ir.world.stream_instances(stream, travel, *, s_min, s_max)[source]#
The instances of
streamwhose position along the travel lies in[s_min, s_max]:[(k, world position)],kthe instance index.Instance
kstands atk × mean spacingplus a seeded jitter that keeps consecutive spacings inside the stream’s range,laneto the right of the direction of travel, at heighty.>>> from an.ir.schema import Stream, Travel >>> t = Travel(speed=10.0) >>> s = Stream(id="pole", ref="pole", height=6.0, every=12.0, lane=2.0) >>> stream_instances(s, t, s_min=0.0, s_max=30.0) [(0, (2.0, 0.0, 0.0)), (1, (2.0, 0.0, 12.0)), (2, (2.0, 0.0, 24.0))]
- an.ir.world.stream_slots(stream, travel)[source]#
How many entities a stream needs by its depth range: one per instance that can be between
nearandfarat once, plus one. Instancekis drawn by slotk mod slots, so an entity is reused for the next instance once this one has passed the camera. A shot takes the larger of this and what its viewpoint shows (_span_slots(), an#516), so the count, and the slot an instance takes, can differ between two shots; nothing relies on it, since each shot compiles alone.>>> stream_slots(Stream(id="pole", ref="pole", height=6.0, every=12.0), Travel(speed=10.0, near=0.5, far=60.0)) 6
- Return type:
- an.ir.world.viewpoint_of(world, viewpoint)[source]#
The shot’s viewpoint as a model: a name is looked up in the world.
>>> viewpoint_of(World(viewpoints={"a": Viewpoint(focal=1.0)}), "a").focal 1.0 >>> viewpoint_of(None, "a") Traceback (most recent call last): ... an.ir.world.WorldError: shot names viewpoint 'a' but the scene has no `world`
- an.ir.world.world_ground_at(spec, t)[source]#
The floor
spec(an entity’soverrides.ground, as the world’s lowering writes it) gives at shot timet: a member’s keys interpolated linearly, held past either end.Nonefor a spec that is not one of the lowering’s two shapes.>>> world_ground_at({"at": [3.0, 120.0], "along": [1.0, 0.0], "scale": 60.0}, 0.5) GroundAt(at=(3.0, 120.0), along=(1.0, 0.0), scale=60.0, lateral=0.0) >>> world_ground_at({"keys": [[0.0, 0.0, 100.0, 1.0, 0.0, 60.0, 0.0], ... [1.0, 0.0, 140.0, 1.0, 0.0, 80.0, 0.5]]}, 0.25) GroundAt(at=(0.0, 110.0), along=(1.0, 0.0), scale=65.0, lateral=0.125) >>> world_ground_at(240, 1.0), world_ground_at("nonsense", 0.0) (None, None)
- an.ir.world.world_ground_mark(shot, entity)[source]#
entity’san.base.GROUND_OVERRIDEmark onshot, orNone. It is read only on a shot lowered from a world (one with aviewpoint): the lowering owns it there (lower_world()writes it under a world that declaresgroundand drops any other), and the compiler refuses it on any other shot, so a hand-written one is never taken for the world’s floor.>>> from an.ir.schema import AssetRef, Shot >>> e = AssetRef(kind="prop", id="p", store="props", ref="r", ... overrides={"ground": {"at": [0, 60], "along": [1, 0]}}) >>> world_ground_mark(Shot(id="s", duration=1.0, viewpoint="v"), e) {'at': [0, 60], 'along': [1, 0]} >>> world_ground_mark(Shot(id="s", duration=1.0), e) is None True