an.ir.holds#

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

A hold says what carries an item over a span of a shot: a hand (any point of a body), a socket of another body (a figurine’s hand), the ground, a point of the stage, or nothing (it is in flight). These five action kinds change holds, and each one moves the holder the way a hand would, so the change reads as handled rather than teleported:

  • grasp: the holder’s point (by) reaches the item’s grip over reach seconds, takes it at the instant it arrives (the item keeps the pose it has at that instant: no slide, no jump), and retracts to where the shot would have it over retract seconds, carrying it. The item is taken from whatever held it: the ground, a socket, another hand (a hand-over between two hands is the receiver’s grasp).

  • place: the hand that holds the item brings it onto a target over reach seconds (its contact point onto the ground at floor height, its grip into a socket, aligned with the socket’s frame), lets it go there, and retracts empty.

  • release: the hand lets go at at; the item falls under gravity with the velocity it had and lands on the ground at its rest angle, or is tossed onto: ground@x on an arc of height arc.

  • handover: place into another holder’s point (to), or, with meet below 1, both hands reach toward each other and the receiver takes it where they meet.

  • swap: a hand takes the item a holder has (take) and the hand holding another item gives it in its place (give), a beat later.

A reach that cannot arrive is never cheated: the body it hangs from may bend (lean, degrees; the chain’s root turns about its own pivot, the way a figure bends at the hip), and beyond that an validate says how far the hand stays short and where to stand instead.

None of these makes a clip: the solve compile pass reads them (an.stage.hold) and emits the holders’ and the items’ keys.

>>> from an.ir.compose import flatten, sequence, delay
>>> [(f.start, f.end, f.action.kind) for f in flatten(sequence(delay(1.0), grasp("paul/arm_r", "cup")))]
[(1.0, 1.75, 'grasp')]
>>> [(f.start, f.action.kind) for f in flatten(sequence(delay(2.0), release("cup", at=0.5)))]
[(2.5, 'release')]
>>> [(round(f.start, 2), f.action.kind) for f in flatten(swap("nap/hand", take="musket", give="sword", by="stu@hand_r"))]
[(0.0, 'grasp'), (0.25, 'place')]

These kinds are the core’s (ADR 0001’s test: a robot arm putting a box on a shelf needs them without saying character), registered when an.ir loads.

Module Attributes

DFLT_REACH

a deliberate reach at arm's length, about two thirds of a second there and back.

DFLT_RETRACT

How long the hand takes to come back to where the shot has it (s).

DFLT_LEAN_DEG

a figure bent well over at the hip.

DFLT_TOSS_ARC

How high a toss rises above the higher of its two ends (scene px).

DFLT_SWAP_LAG

In a swap, how long after the taking hand starts the giving hand starts (s): it arrives a beat after the socket is empty.

GROUND

The name of the floor in a target (ground, ground@x).

SURFACE

The point name of a body's supporting surface in a target (an#536): crate@surface (below the hand), crate@surface@0.3 (that fraction of the way along it), as on the ground but on the body's top, following it.

HOLD_ACTION_KINDS

The kinds' names.

GESTURE_KINDS

The kinds that move a hand (a reach and a retract), as flattened leaves.

Functions

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

by takes item.

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.

Classes

GraspAction(*[, name, kind, reach, retract, ...])

by (a body's point: a hand) reaches item's grip and takes it.

PlaceAction(*[, name, kind, by, rotation, ...])

The hand holding item puts it onto a target and lets it go.

ReleaseAction(*[, name, kind, at, onto, ...])

The hand holding item lets it go at at: it falls (never rising) onto the ground, onto: ground@x nudged to land there, or tossed up first when arc (px above the hand) is positive; it lands one end first, tips onto its side at rotation (default: the side of it it falls nearest to) and bounces a little (bounce: the coefficient of restitution, default an.stage.rigid.DFLT_BOUNCE; 0 lands dead).

HandoverAction(*[, name, kind, by, meet, ...])

The hand holding item gives it to to (a hand, or a socket).

SwapAction(*[, name, kind, lag, rotation, ...])

by takes take from holder and the hand holding give puts that there, lag seconds later: a grasp and a place.

an.ir.holds.DFLT_LEAN_DEG: float = 60.0#

a figure bent well over at the hip. 0 never bends.

Type:

How far the body a hand hangs from may turn to reach (degrees)

an.ir.holds.DFLT_REACH: float = 0.4#

a deliberate reach at arm’s length, about two thirds of a second there and back.

Type:

How long a hand takes to reach what it takes or where it puts it (s)

an.ir.holds.DFLT_RETRACT: float = 0.35#

How long the hand takes to come back to where the shot has it (s).

an.ir.holds.DFLT_SWAP_LAG: float = 0.25#

In a swap, how long after the taking hand starts the giving hand starts (s): it arrives a beat after the socket is empty.

an.ir.holds.DFLT_TOSS_ARC: float = 0.0#

How high a toss rises above the higher of its two ends (scene px). 0: it is let fall, never thrown up (a let-go item does not rise; a positive arc is a throw).

an.ir.holds.GESTURE_KINDS: tuple[str, ...] = ('grasp', 'place', 'handover')#

The kinds that move a hand (a reach and a retract), as flattened leaves.

an.ir.holds.GROUND: str = 'ground'#

The name of the floor in a target (ground, ground@x).

class an.ir.holds.GraspAction(*, name=None, kind='grasp', by, item, reach=0.4, retract=0.35, lean=60.0, align=True, carry=None, **extra_data)[source]#

Bases: ExtensionAction

by (a body’s point: a hand) reaches item’s grip and takes it.

item is an entity id, with @<point> the grip (a bone of its rig, or u,v a fraction of its drawing); unset: its grip bone, else its stage point. by with no @ is the far end of the body (an arm’s hand). The item is held from start + reach on, and over the retract it turns to how the hand holds things (align): drawn as it is, upright along the hand’s part, the way a socket holds it; align: false keeps the angle it was taken at. carry (degrees) turns the aligned item by that much from how the hand holds it, about the grip, mirrored with the hand: a long musket carried at carry: -60 points up and clears the floor a hand near the ground would sink it through (an#864). It needs align.

>>> GraspAction(by="stu@hand_r", item="musket").reach == DFLT_REACH
True
>>> GraspAction(by="stu@hand_r", item="musket", carry=-60).carry
-60.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].

an.ir.holds.HOLD_ACTION_KINDS: tuple[str, ...] = ('grasp', 'place', 'release', 'handover', 'swap')#

The kinds’ names.

class an.ir.holds.HandoverAction(*, name=None, kind='handover', item, to, by=None, meet=1.0, reach=0.4, retract=0.35, lean=60.0, align=True, **extra_data)[source]#

Bases: ExtensionAction

The hand holding item gives it to to (a hand, or a socket).

meet is where the two meet, as a fraction of the way from the giver’s hand to the receiver’s: 1 (the default) puts it into the receiver’s point, which does not move (a figurine’s hand, a waiting hand); below 1 both hands reach and the receiver takes it where they meet (and turns it as a grasp does, align).

>>> HandoverAction(item="sword", to="nap/arm_r/weapon").meet
1.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.holds.PlaceAction(*, name=None, kind='place', item, onto, by=None, rotation=None, reach=0.4, retract=0.35, lean=60.0, **extra_data)[source]#

Bases: ExtensionAction

The hand holding item puts it onto a target and lets it go.

onto is ground (straight down, at floor height), ground@x (at stage x), a body’s point (a socket: the item’s grip goes there, its frame aligned with the socket’s), a body’s surface (crate@surface, or crate@surface@f at that fraction along it: lying on its top as on the ground, held by that body from then on, an#536) or world@x,y (hung on a point). item@<point> names the item’s point that touches the target (default: its grip on a socket, its lowest point on the ground). rotation: the item’s rotation where it rests (radians, the stage’s; on a surface, relative to the surface, whose tilt is added; default: the angle it last rested at, else the nearest quarter turn; in a socket, the socket’s own). In a socket it is the angle the item comes to rest at (a musket aimed at someone, a sabre raised), held relative to the socket from then on, so it turns with it.

>>> PlaceAction(item="musket", onto="nap/arm_r/weapon").by is None
True
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.holds.ReleaseAction(*, name=None, kind='release', item, at=0.0, onto=None, arc=0.0, rotation=None, bounce=None, **extra_data)[source]#

Bases: ExtensionAction

The hand holding item lets it go at at: it falls (never rising) onto the ground, onto: ground@x nudged to land there, or tossed up first when arc (px above the hand) is positive; it lands one end first, tips onto its side at rotation (default: the side of it it falls nearest to) and bounces a little (bounce: the coefficient of restitution, default an.stage.rigid.DFLT_BOUNCE; 0 lands dead).

>>> ReleaseAction(item="cup", at=1.0).onto is None
True
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.holds.SURFACE: str = 'surface'#

The point name of a body’s supporting surface in a target (an#536): crate@surface (below the hand), crate@surface@0.3 (that fraction of the way along it), as on the ground but on the body’s top, following it.

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

Bases: ExtensionAction

by takes take from holder and the hand holding give puts that there, lag seconds later: a grasp and a place. rotation is the place’s: the angle give comes to rest at in the holder (radians, the stage’s; default: the holder’s own).

>>> SwapAction(holder="nap/hand", take="musket", give="sword", by="stu@hand_r").lag == DFLT_SWAP_LAG
True
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.holds.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.holds.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.holds.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.holds.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.holds.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