Overview
TheMotionLib class provides functionality for loading, managing, and sampling motion data for character animation. It supports loading motions from files or from MotionFrames objects, and provides methods for sampling and interpolating motion frames.
Classes
LoopMode
An enumeration that defines how motions should loop.Clamp the motion time to the end of the motion. Motion stays at final frame after completion.
Wrap the motion time back to the beginning. Motion loops continuously.
MotionLib
Main class for managing motion libraries.Initialization
Constructor
The kinematic character model associated with the motions.
The device (CPU or GPU) on which to store motion data.
Whether to load and store contact information for each frame.
Class Methods
from_file
Load a motion library from a motion file.Path to the motion file (.yaml for config with multiple motions, or direct motion file).
The kinematic character model.
Device for storing motion data.
Whether to load contact information.
A new MotionLib instance loaded from the file.
from_frames
Create a motion library from MotionFrames.Motion frames containing root_pos, root_rot, and joint_rot tensors.
The kinematic character model.
Device for storing motion data.
Loop mode for the motion (CLAMP or WRAP).
Frames per second of the motion.
Whether to include contact information.
A new MotionLib instance created from the frames.
Methods
num_motions
Get the number of motions in the library.The number of motions stored in the library.
get_total_length
Get the total length of all motions combined.Total duration of all motions in seconds.
sample_motions
Randomly sample motion IDs from the library.Number of motion IDs to sample.
Optional weights for sampling. If None, uses default motion weights.
Tensor of shape (n,) containing sampled motion IDs.
sample_time
Sample random times within motions.Tensor of motion IDs to sample times for.
Optional time to truncate from the end of each motion.
Tensor of sampled times (in seconds) within each motion.
calc_motion_frame
Calculate interpolated motion frames at specific times.Tensor of motion IDs.
Tensor of times (in seconds) within each motion.
Tuple containing:
root_pos(torch.Tensor): Root positions (shape: […, 3])root_rot(torch.Tensor): Root rotations as quaternions (shape: […, 4])root_vel(torch.Tensor): Root velocities (shape: […, 3])root_ang_vel(torch.Tensor): Root angular velocities (shape: […, 3])joint_rot(torch.Tensor): Joint rotations as quaternions (shape: […, num_joints-1, 4])dof_vel(torch.Tensor): DOF velocities (shape: […, dof_size])contacts(torch.Tensor, optional): Contact information if contact_info=True
get_motion_length
Get the length of specific motions.Tensor of motion IDs.
Tensor of motion lengths in seconds.
get_motion_num_frames
Get the number of frames in specific motions.Tensor of motion IDs.
Tensor of frame counts.
get_motion_loop_mode
Get the loop mode values for specific motions.Tensor of motion IDs.
Tensor of loop mode values (0 for CLAMP, 1 for WRAP).
get_motion_loop_mode_enum
Get the loop mode enum for a specific motion.Single motion ID.
LoopMode enum value (CLAMP or WRAP).
get_motion_fps
Get the frames per second of a specific motion.Single motion ID.
Frames per second of the motion.
calc_motion_phase
Calculate the phase (0.0 to 1.0) within a motion at given times.Tensor of motion IDs.
Tensor of times within motions.
Tensor of phase values between 0.0 and 1.0.
get_motion_names
Get the list of motion names.List of motion names loaded from files.
get_frames_for_id
Get all frames for a specific motion.Motion ID to retrieve frames for.
Whether to compute forward kinematics for body positions and rotations.
MotionFrames object containing the motion data.
joint_rot_to_dof
Convert joint rotations to DOF values.Joint rotations as quaternions.
DOF values for the joints.
clone
Create a deep copy of the motion library on a different device.Target device for the cloned library.
Cloned MotionLib instance on the specified device.
Usage Examples
Loading from File
Sampling Motions
Creating from MotionFrames
Working with Motion Metadata
Helper Functions
extract_pose_data
Extract components from a motion frame.Motion frame tensor containing root position, root rotation (exp map), and joint DOFs.
Tuple containing:
root_pos(torch.Tensor): Root position (first 3 elements)root_rot(torch.Tensor): Root rotation as exp map (elements 3-6)joint_dof(torch.Tensor): Joint DOFs (remaining elements)
calc_phase
Calculate motion phase based on time and loop mode.Times within motions.
Length of motions.
Loop mode values (0 for CLAMP, 1 for WRAP).
Phase values between 0.0 and 1.0.