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]]
body_frames ¶
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 ¶
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 ¶
One scale for the whole skeleton: the character's leg + torso length over the source's (first frame).
smooth ¶
A centred moving average over 2 * frames + 1 frames (edges padded); K unchanged when too short.
lock_feet ¶
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 ¶
Angles in degrees (T, n) between the limb segments of point sets A and B (T, K, 3).
feet_height ¶
(T,) height of the lowest foot keypoint of P (T, K, 3).
ground_correction ¶
(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.