an.ir.frames#
Frames of reference: a tree of named poses over film time (ADR 0009 amendment, an#501).
A frame is a rigid pose (a position and an orientation) as a function of
film time, relative to a parent frame; world is the root. Every element of
the scene’s world (a member, a viewpoint, a stream, a plane) is in exactly one
frame, with a local pose in that frame’s units. Its world pose is the
composition of the poses up the chain, and what a viewpoint sees is the
pinhole projection of world poses into the viewpoint’s own frame (the
projection itself is an.ir.world.Projection). The multiplane camera,
the moving panorama, the process shot and the camera rig are all the same
tree with a different shape: what stands still in one frame is scenery in
another, and the eye is attached to whichever frame the shot is in.
Orientation uses the viewpoint’s convention: look: [yaw, pitch, roll]
degrees, the frame’s local axes being (right, down, forward) — so a frame
with look zero is the world’s axes (x right, y DOWN, z away
from the viewer).
A far frame follows its parent’s rotation and none of its translation: what is at infinity turns with the camera and never moves with it.
This module is pure geometry on tuples; it imports the schema’s Frame
and the easing function, nothing else. It is an extraction candidate: previz
(an#257) is the TypeScript twin of the same vocabulary.
>>> from an.ir.schema import Frame, FrameMoving
>>> tree = FrameTree({
... "car": Frame(moving=FrameMoving(speed=20.0)),
... "seat": Frame(parent="car", at=(0.45, 0.65, 1.6)),
... "horizon": Frame(parent="car", coupling="far"),
... })
>>> tree.world_pose("seat", 2.0).at # 2 s on: the seat is 40 m down the road
(0.45, 0.65, 41.6)
>>> tree.world_pose("horizon", 2.0).at # at infinity: never translates
(0.0, 0.0, 0.0)
Module Attributes
a frame's local axes in its parent's coordinates. |
|
The channels of a frame an ordinary |
Functions
|
|
|
The lagging track |
|
|
Classes
|
The frames of a scene and the world pose of anything in one of them. |
|
A rigid pose: where a frame's origin is ( |
|
The |
|
One |
Exceptions
A frame tree that cannot be built or evaluated (an unknown frame). |
- an.ir.frames.Axes#
a frame’s local axes in its parent’s coordinates.
- Type:
(right, down, forward)
alias of
tuple[tuple[float,float,float],tuple[float,float,float],tuple[float,float,float]]
- an.ir.frames.FRAME_PROPERTIES: tuple[str, ...] = ('at_x', 'at_y', 'at_z', 'yaw', 'pitch', 'roll')#
The channels of a frame an ordinary
set/tweenmay target (<frame>:at_x): its position in its parent’s units, its orientation in degrees.
- exception an.ir.frames.FrameError[source]#
Bases:
ValueErrorA frame tree that cannot be built or evaluated (an unknown frame).
- class an.ir.frames.FrameTree(frames, *, tracks=None)[source]#
Bases:
objectThe frames of a scene and the world pose of anything in one of them.
tracksare the shot’sset/tweenactions on frame channels ({frame: {channel: Track}}, shot time): a track REPLACES the channel’s declared value for that shot, the way a pose value replaces a property.movingaddsdirection × speed × film timeto the position on top. Poses are evaluated at a shot timetwithfilm_startthe shot’s start in the film, so a moving frame keeps its phase across a cut.>>> from an.ir.schema import Frame, FrameMoving >>> tree = FrameTree({"car": Frame(moving=FrameMoving(speed=10.0))}) >>> tree.world_pose("car", 1.0, film_start=4.0).at (0.0, 0.0, 50.0) >>> tree.relative_pose("world", "car", 1.0).at # the world seen from the car: it comes at us (0.0, 0.0, -10.0) >>> FrameTree({"a": Frame(parent="b"), "b": Frame(parent="a")}) Traceback (most recent call last): ... an.ir.frames.FrameError: frames form a cycle through 'a'
- acceleration(name, t, *, film_start=0.0, dt=0.01, within=None)[source]#
The world acceleration of
name’s origin at shot timet(second difference of stepdt, units/s²): zero for a frame at rest or at a constant speed.within=(lo, hi)keeps the three samples inside that window (a shot): near an end the stencil slides inward (a one-sided difference), and a window narrower than2·dtshrinks the step to half of it, so a motion that starts at the window’s edge is not read as an impulse.A step of the frame (
jump_times()) is a cut, not an acceleration: a stencil that would span one slides to the nearest centre that stays whole, and where none does the answer is zero.>>> from an.ir.schema import Frame, FrameMoving >>> tree = FrameTree({"car": Frame(moving=FrameMoving(speed=20.0))}) >>> [round(v, 3) + 0.0 for v in tree.acceleration("car", 1.0)] [0.0, 0.0, 0.0] >>> track = Track([TrackEvent(0.0, 1.0, to=10.0, from_=0.0, easing="ease_out")]) >>> braking = FrameTree({"car": Frame()}, tracks={"car": {"at_z": track}}) >>> [round(v, 1) + 0.0 for v in braking.acceleration("car", 0.5)] # 20 m/s to 0 in a second [0.0, 0.0, -20.0] >>> [round(v, 1) + 0.0 for v in braking.acceleration("car", 0.0, dt=0.04, within=(0.0, 1.0))] [0.0, 0.0, -20.0]
- constant_motion(name)[source]#
(unit direction, speed)whennameis a frame of the world that does nothing but translate at a constant velocity from the origin (avehicle), elseNone: the case a straight travel’s streams are solved for in closed form.
- is_static(name, to, duration, *, film_start=0.0, samples=33)[source]#
Whether
namestands still intothrough a shot ofdurationseconds: the same frame, two frames that move together, or two still ones. Sampled (and at every action’s start and end), exactly equal within_SAME_POSE_EPS.>>> from an.ir.schema import Frame, FrameMoving >>> tree = FrameTree({"car": Frame(moving=FrameMoving(speed=5.0)), "seat": Frame(parent="car", at=(1.0, 0.0, 0.0))}) >>> tree.is_static("seat", "car", 2.0), tree.is_static("world", "car", 2.0) (True, False)
- Return type:
- is_still(name)[source]#
Whether
nameand every frame above it are fixed for any shot: nothing moves them and no action animates them.- Return type:
- jump_times(name)[source]#
The shot times at which a channel of
nameor of a frame above it steps (an instant, not a motion), sorted: aset, and a tween that starts from an explicitfrom_(it snaps there first).>>> tree = FrameTree({"car": Frame()}, tracks={"car": {"at_z": Track([TrackEvent(1.0, 1.0, to=5.0)])}}) >>> tree.jump_times("car") [1.0]
- local_pose(name, t, *, film_start=0.0)[source]#
name’s pose in its parent’s units at shot timet.- Return type:
- relative_pose(name, to, t, *, film_start=0.0)[source]#
name’s pose expressed into’s coordinates: what takes a point innameto the same point into.- Return type:
- class an.ir.frames.Pose(at=(0.0, 0.0, 0.0), axes=None)[source]#
Bases:
objectA rigid pose: where a frame’s origin is (
at) and how its axes lie (axes,Nonefor the parent’s), both in the parent’s coordinates.>>> Pose(at=(1.0, 0.0, 0.0)).apply((0.0, 0.0, 5.0)) (1.0, 0.0, 5.0) >>> turned = Pose(axes=_axes(90.0, 0.0, 0.0)) # turned right by 90 degrees >>> [round(v, 6) + 0.0 for v in turned.apply((0.0, 0.0, 1.0))] [1.0, 0.0, 0.0] >>> [round(v, 6) + 0.0 for v in turned.unapply(turned.apply((2.0, 3.0, 4.0)))] [2.0, 3.0, 4.0]
- compose(child)[source]#
self ∘ child: the child’s pose seen from this pose’s parent.>>> Pose(at=(10.0, 0.0, 0.0)).compose(Pose(at=(1.0, 0.0, 0.0))).at (11.0, 0.0, 0.0)
- Return type:
- class an.ir.frames.Track(events)[source]#
Bases:
objectThe
set/tweenactions on one channel of a frame, as a function of shot time: it holds the base value until the first event, a set steps, a tween ramps from itsfrom_(the value the channel has when it starts, if unset) and holds its end.>>> track = Track([TrackEvent(1.0, 3.0, to=10.0, easing=None)]) >>> track.value(0.0, 4.0), track.value(2.0, 4.0), track.value(5.0, 4.0) (4.0, 7.0, 10.0)
- class an.ir.frames.TrackEvent(start, end, to, from_=None, easing=None)[source]#
Bases:
objectOne
set(start == end) ortweenof a channel, in shot time.
- an.ir.frames.lag_filter(values, *, lag, dt)[source]#
valuesseen through a first-order filter of time constantlag(s), sampled everydt: it starts on the first value and closes1 - exp(-dt/lag)of the gap each step (Cinemachine’s damping: the time it takes to catch up).lag <= 0returns them as they are.dtis one step for all, or one per step (len(values) - 1of them) for a grid that is not uniform — a stepped shot’s frames and steps interleaved (an#626). Each step is the exact response of the filter to the input held at the step’s END value over it, so a grid refined bylag_resample()lands on the same values.>>> out = lag_filter([0.0] + [100.0] * 30, lag=0.5, dt=0.1) >>> round(out[5], 1) # 0.5 s after the step: 1 - 1/e of it 63.2 >>> lag_filter([0.0, 100.0, 100.0], lag=0.5, dt=[0.1, 0.1]) == out[:3] True >>> lag_filter([0.0, 1.0], lag=0.5, dt=0.0) Traceback (most recent call last): ... ValueError: lag_filter: the sample step `dt` must be positive (got 0.0).
- an.ir.frames.lag_resample(times, values, filtered, at, *, lag)[source]#
The lagging track
lag_filter()made overtimes(its inputvalues, its outputfiltered), read at the instantsat(an#626).At a grid instant, the filtered value itself. Between
times[k]andtimes[k+1], the filter’s own trajectory there: fromfiltered[k]towardvalues[k+1](the input it holds over that step), closing1 - exp(-(t - times[k])/lag)of the gap — which reachesfiltered[k+1]at the step’s end, so refining the grid moves nothing on it. Before the first instant, the first value; after the last, the last (the filter’s output is not defined beyond its input).>>> times, values = [0.0, 0.1, 0.2], [0.0, 100.0, 100.0] >>> lagged = lag_filter(values, lag=0.5, dt=0.1) >>> lag_resample(times, values, lagged, [0.0, 0.1, 0.2], lag=0.5) == lagged True >>> round(lag_resample(times, values, lagged, [0.05], lag=0.5)[0], 3) 9.516
- an.ir.frames.look_basis(yaw, pitch, roll)[source]#
(forward, right, down)for a look ofyaw(turn right),pitch(look down) androll(the PICTURE turns clockwise: what was on the right moves to the bottom), in degrees.>>> [tuple(round(v, 6) + 0.0 for v in axis) for axis in look_basis(0.0, 0.0, 0.0)] [(0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0)] >>> [round(v, 6) + 0.0 for v in look_basis(90.0, 0.0, 0.0)[0]] [1.0, 0.0, 0.0]