Skip to content

hylo.codeagents.motion_ops

Package: hylo-code-agents · Core contracts

motion_ops

Motion data and edits for the motion studio (pure numpy): one keypoint skeleton, converters from the motion tools and edits on joint trajectories.

Skeleton: 17 keypoints (NAMES, SOMA joint names), metres, z up, ground z = 0. canonical puts a motion on the ground, at the origin, facing +x at its first frame, so edits can align clips by root position and heading. Edits (concat, blend, loop, mirror, retime, trim, hold, keyframe) work on positions: clips are aligned (the next clip starts where and facing where the last one ended) and cross-faded over a short window.

NAMES module-attribute

NAMES = ['Hips', 'Chest', 'Head', 'LeftLeg', 'LeftShin', 'LeftFoot', 'LeftToeBase', 'RightLeg', 'RightShin', 'RightFoot', 'RightToeBase', 'LeftArm', 'LeftForeArm', 'LeftHand', 'RightArm', 'RightForeArm', 'RightHand']

PARENTS module-attribute

PARENTS = [-1, 0, 1, 0, 3, 4, 5, 0, 7, 8, 9, 1, 11, 12, 1, 14, 15]

IDX module-attribute

IDX = {n: i for i, n in enumerate(NAMES)}

FEET module-attribute

FEET = [IDX[n] for n in ('LeftFoot', 'LeftToeBase', 'RightFoot', 'RightToeBase')]

MEDIAPIPE module-attribute

MEDIAPIPE = {'Hips': (23, 24), 'LeftLeg': (23,), 'LeftShin': (25,), 'LeftFoot': (27,), 'LeftToeBase': (31,), 'RightLeg': (24,), 'RightShin': (26,), 'RightFoot': (28,), 'RightToeBase': (32,), 'LeftArm': (11,), 'LeftForeArm': (13,), 'LeftHand': (15,), 'RightArm': (12,), 'RightForeArm': (14,), 'RightHand': (16,), 'Head': (7, 8)}

CHEST_FRACTION module-attribute

CHEST_FRACTION = 0.47

EDITS module-attribute

EDITS = {'concat': concat, 'blend': blend, 'loop': loop, 'mirror': mirror, 'retime': retime, 'trim': trim, 'hold': hold, 'keyframe': keyframe}

Motion dataclass

Motion(joints: ndarray, fps: float = 30.0, source: str = '', meta: dict[str, Any] = dict())

A skeleton motion: joints (T, 17, 3) in NAMES order, at fps. source says where it came from.

joints instance-attribute

joints: ndarray

fps class-attribute instance-attribute

fps: float = 30.0

source class-attribute instance-attribute

source: str = ''

meta class-attribute instance-attribute

meta: dict[str, Any] = field(default_factory=dict)

frames property

frames: int

seconds property

seconds: float

names property

names: list[str]

joint

joint(name: str) -> np.ndarray

(T, 3) trajectory of one keypoint.

pose

pose(t: float) -> 'Motion'

The frame at time t (seconds) as a one-frame motion.

summary

summary() -> dict[str, Any]

from_soma

from_soma(joints: ndarray, names: Sequence[str], fps: float, source: str = 'text_motion') -> Motion

from_mediapipe

from_mediapipe(joints_world: ndarray, valid: ndarray, fps: float, source: str = 'video') -> Motion

MediaPipe Pose world keypoints (T, 33, 3; z up) -> the skeleton; frames without a person are interpolated.

level

level(m: Motion) -> Motion

Remove a sideways tilt of the ground (a camera roll the pose estimator did not know): the standing heights of the left and right foot keypoints should match.

heading

heading(J: ndarray) -> np.ndarray

Yaw (rad) per frame of the hips' forward direction (left hip - right hip, turned -90 deg about z).

canonical

canonical(m: Motion) -> Motion

Ground at z = 0 (low percentile of the feet), first root at x = y = 0, facing +x at the first frame.

concat

concat(*motions: Motion, blend: float = 0.3) -> Motion

Play clips one after another; each starts where (and facing where) the previous ended, cross-faded over blend seconds (the overlap shortens the result by that much per join).

blend

blend(a: Motion, b: Motion, seconds: float = 0.5) -> Motion

A smooth transition from a into b over seconds (same as concat with a longer cross-fade).

loop

loop(m: Motion, times: int = 2, blend: float = 0.25) -> Motion

Repeat a clip times times; each repeat continues from where the previous one ended.

mirror

mirror(m: Motion) -> Motion

Swap left and right (mirror across the vertical plane along the initial heading).

retime

retime(m: Motion, speed: float | None = None, seconds: float | None = None) -> Motion

Play faster (speed > 1) or slower, or stretch to a duration in seconds.

trim

trim(m: Motion, start: float = 0.0, end: float | None = None) -> Motion

The part between start and end (seconds; end None = to the end).

hold

hold(pose: Motion, seconds: float = 1.0) -> Motion

Stand still in a pose (the last frame of pose) for seconds.

keyframe

keyframe(m: Motion, pose: Motion, at: float, width: float = 0.8, root: bool = False) -> Motion

Constrain m to pass through pose at time at (seconds): the body offset (relative to the root and heading, so the pose is matched where the motion is at that time) is added with a smooth bump of width seconds on each side, full at at; from at on it is held when at is the last frame. root: also match the pelvis height.