MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / apply_rotation

Function apply_rotation

motion_rep/retarget_motion.py:138–166  ·  view source on GitHub ↗

Update SMPL parameters based on the rotation matrix R. Args: smpl_params (dict): Dictionary containing SMPL parameters ('global_orient', 'transl', etc.). R (torch.Tensor): Rotation matrix of shape (3, 3). Returns: smpl_params (dict): Updated SMPL parameters.

(smpl_params, R)

Source from the content-addressed store, hash-verified

136 return R_inv
137
138def apply_rotation(smpl_params, R):
139 """
140 Update SMPL parameters based on the rotation matrix R.
141
142 Args:
143 smpl_params (dict): Dictionary containing SMPL parameters ('global_orient', 'transl', etc.).
144 R (torch.Tensor): Rotation matrix of shape (3, 3).
145
146 Returns:
147 smpl_params (dict): Updated SMPL parameters.
148 """
149 N = smpl_params['global_orient'].shape[0] # Number of frames
150 device = smpl_params['global_orient'].device
151
152 # Convert global_orient from axis-angle to 3x3 matrix
153 global_orient_mat = axis_angle_to_mat3x3(smpl_params['global_orient'].view(-1, 3)) # Shape: (N, 3, 3)
154
155 # Adjust the global orientation by the computed rotation
156 adjusted_global_orient_mat = torch.matmul(R[None,], global_orient_mat) # Shape: (N, 3, 3)
157
158 # Convert adjusted global_orient back to axis-angle
159 smpl_params['global_orient'] = mat3x3_to_axis_angle(adjusted_global_orient_mat) # Shape: (N, 3)
160
161 # Adjust the translation by rotating
162 smpl_params['transl'] += smplx_root.to(device)
163 smpl_params['transl'] = torch.matmul(R[None,], smpl_params['transl'][..., None]).squeeze(-1)
164 smpl_params['transl'] -= smplx_root.to(device)
165
166 return smpl_params
167
168def canonicalize_motion(smpl_params, joints, set_floor=False):
169 # Get transformation and update smpl_params

Callers 2

canonicalize_motionFunction · 0.85
process_hmr_motionFunction · 0.85

Calls 2

axis_angle_to_mat3x3Function · 0.85
mat3x3_to_axis_angleFunction · 0.85

Tested by

no test coverage detected