Skip to content

hylo.codeagents.motion_retarget

Package: hylo-code-agents · Core contracts

motion_retarget

Retargeting math shared by every target character (pure numpy, no Hylo imports): the MuJoCo worker (motion_sim) uses it for robots, the Blender script (motion_blender) for rigged characters; both load this file by path, Hylo code imports it as hylo.codeagents.motion_retarget.

Skeleton points are arrays (..., K, 3) indexed by idx (keypoint name -> column), metres, z up, facing +x.

  • body_frames: the pelvis and chest frames of a skeleton (forward, left, up columns).
  • proportional_targets: source keypoints -> target points with a character's proportions: the root path scaled by the leg-length ratio, each limb segment along the source's direction with the character's own length, hips and shoulders placed as on the character, turned with the source's pelvis and chest.
  • lock_feet / smooth: clean-ups of the source before the fit (no sliding while a foot is down; video noise).
  • segment_angles: limb direction error between two skeletons (a scale-free retargeting error).
  • ground_correction: a per-frame height offset that keeps the lowest foot point on the floor while the source's feet are down, and never below it.

LIMBS module-attribute

LIMBS = [('LeftLeg', 'LeftShin'), ('LeftShin', 'LeftFoot'), ('LeftFoot', 'LeftToeBase'), ('RightLeg', 'RightShin'), ('RightShin', 'RightFoot'), ('RightFoot', 'RightToeBase'), ('LeftArm', 'LeftForeArm'), ('LeftForeArm', 'LeftHand'), ('RightArm', 'RightForeArm'), ('RightForeArm', 'RightHand')]

TREE module-attribute

TREE = [('LeftLeg', 'Hips', 'pelvis'), ('RightLeg', 'Hips', 'pelvis'), ('Chest', 'Hips', 'dir'), ('Head', 'Chest', 'chest'), ('LeftArm', 'Chest', 'chest'), ('RightArm', 'Chest', 'chest'), *[(c, p, 'dir') for p, c in LIMBS]]

FEET module-attribute

FEET = ('LeftFoot', 'LeftToeBase', 'RightFoot', 'RightToeBase')

Index module-attribute

Index = Mapping[str, int]

unit

unit(v: ndarray) -> np.ndarray

v / |v| along the last axis (zero-safe).

body_frames

body_frames(P: ndarray, idx: Index) -> tuple[np.ndarray, np.ndarray]

Pelvis and chest frames (..., 3, 3) of points P (..., K, 3); columns forward, left, up. Pelvis: left = right -> left hip, up = hips -> chest; chest: left = right -> left shoulder, up = chest -> mid-shoulders.

leg_length

leg_length(P: ndarray, idx: Index) -> float

Mean hip-knee-ankle length of both legs of P (K, 3) or (T, K, 3) (the median over frames).

proportional_targets

proportional_targets(K: ndarray, idx: Index, rest: Mapping[str, ndarray]) -> tuple[np.ndarray, float]

Source keypoints K (T, K, 3) -> (target points with the character's proportions, root scale). rest: keypoint -> the character's rest position (facing +x), for every keypoint in idx.

uniform_scale

uniform_scale(K: ndarray, idx: Index, rest: Mapping[str, ndarray]) -> float

One scale for the whole skeleton: the character's leg + torso length over the source's (first frame).

smooth

smooth(K: ndarray, frames: int) -> np.ndarray

A centred moving average over 2 * frames + 1 frames (edges padded); K unchanged when too short.

lock_feet

lock_feet(K: ndarray, idx: Index, tol: float = 0.025) -> np.ndarray

While a foot keypoint stays near the ground (within tol of its low height), hold its horizontal position at the run's mean, eased over 3 frames at each end: removes the source's foot sliding.

segment_angles

segment_angles(A: ndarray, B: ndarray, idx: Index) -> np.ndarray

Angles in degrees (T, n) between the limb segments of point sets A and B (T, K, 3).

feet_height

feet_height(P: ndarray, idx: Index) -> np.ndarray

(T,) height of the lowest foot keypoint of P (T, K, 3).

ground_correction

ground_correction(low: ndarray, src_feet: ndarray, scale: float) -> np.ndarray

(T,) height offsets: the lowest foot point (low) on the floor whenever the source's feet (src_feet, at target scale) are near the ground, interpolated in between (jumps keep their flight), never below the floor.