Overview
TheMotionSampler class provides an interface for sampling motion sequences from a motion library. It handles motion data extraction, temporal sampling, and batching for training motion generation models.
Class Definition
Constructor
Configuration dictionary for the motion sampler.
Configuration Keys
Device to use for tensors (‘cuda’ or ‘cpu’)
Path to the character model XML file
Path to motion library file or MotionLib instance
Attributes
Device for tensor operations
Length of motion sequences to sample (set after initialization)
Frames per second for motion sampling (set after initialization)
Kinematic character model for the motion data
Motion library containing all motion clips
Path or instance of the motion library
Whether to randomly sample start times within motions
Methods
check_init
Verifies that required attributes have been initialized._seq_len or _fps have not been set.
get_seq_len
Returns the sequence length._sample_motion_start_times
Samples start times for motion clips.Tensor of motion IDs to sample from, shape [batch_size]
Duration of the sequence in seconds
- For motions with
LoopMode.WRAP: Samples uniformly from entire motion duration - For motions with
LoopMode.CLAMP: Samples uniformly ensuring enough frames remain - If
_random_start_timesis False: Returns zeros (always start from beginning)
_extract_motion_data
Extracts motion data for specified motion IDs and start times.Tensor of motion IDs, shape [batch_size]
Tensor of start times in seconds, shape [batch_size]
motion_samples: Motion data tensor of shape [batch_size, seq_len, num_dof]contacts: Contact labels of shape [batch_size, seq_len, num_rb]
- Samples frames from motion library at specified times
- Converts quaternion rotations to exponential map representation
- Converts joint rotations to DOF representation
- Concatenates root position, root rotation, and joint rotations
- Reshapes into batch format
Usage Example
Integration with Motion Generators
Motion generators like MDM useMotionSampler to load training data:
Motion Library Integration
The sampler integrates with theMotionLib class:
Motion Data Format
The extracted motion data is structured as:Motion Samples
Concatenated tensor containing:- Root position: XYZ coordinates of character root (3 values)
- Root rotation: Exponential map representation (3 values)
- Joint rotations: DOF values for all joints (num_joints × dof_per_joint)
Contacts
Binary contact labels for each rigid body:- 1.0: Body is in contact with ground
- 0.0: Body is not in contact
Loop Modes
The sampler respects motion loop modes:- WRAP: Motion repeats cyclically, can sample any start time
- CLAMP: Motion stops at end, start time limited to ensure full sequence fits
See Also
- MDM - Uses MotionSampler for training
- MotionLib - Underlying motion library
- KinCharModel - Character kinematic model