Compute the translation and rotation to align the SMPL-X model output to the canonical coordinate frame. Args: joints (torch.Tensor): SMPL-X joints of shape (seq_len, joints_num, 3). Returns: delta_transl (torch.Tensor): Translation vector of shape (3,). root_q
(joints)
| 97 | return smpl_data, joints |
| 98 | |
| 99 | def get_transform_DART(joints): |
| 100 | """ |
| 101 | Compute the translation and rotation to align the SMPL-X model output to the canonical coordinate frame. |
| 102 | |
| 103 | Args: |
| 104 | joints (torch.Tensor): SMPL-X joints of shape (seq_len, joints_num, 3). |
| 105 | |
| 106 | Returns: |
| 107 | delta_transl (torch.Tensor): Translation vector of shape (3,). |
| 108 | root_quat_init (torch.Tensor): Rotation quaternion of shape (1, 4). |
| 109 | """ |
| 110 | # Indices of the relevant joints (ensure these are correct for SMPL-X) |
| 111 | pelvis_index = 0 # Pelvis (root joint) |
| 112 | r_hip, l_hip, sdr_r, sdr_l = [2, 1, 17, 16] # Right hip, Left hip, Right Shoulder, Left Shoulder |
| 113 | |
| 114 | device = joints.device |
| 115 | |
| 116 | # First frame joints positions |
| 117 | joints_0 = joints[0] # Shape: (joints_num, 3) |
| 118 | |
| 119 | # Step 1: Compute Rotation Quaternion |
| 120 | |
| 121 | # Compute x_axis (from left hip to right hip, projected onto xy-plane) |
| 122 | x_axis = (joints_0[r_hip] - joints_0[l_hip]) # Shape: (3,) |
| 123 | x_axis[2] = 0 # Project to the xy-plane (set z-component to zero) |
| 124 | x_axis = x_axis / torch.norm(x_axis) # Normalize |
| 125 | |
| 126 | # z_axis is pointing upwards (inverse gravity direction) |
| 127 | z_axis = torch.tensor([0, 0, 1], dtype=torch.float32, device=device) |
| 128 | |
| 129 | # Compute y_axis as the cross product of z_axis and x_axis |
| 130 | y_axis = torch.cross(z_axis, x_axis, dim=-1) |
| 131 | y_axis = y_axis / torch.norm(y_axis) # Normalize |
| 132 | |
| 133 | # Build rotation matrix R (from world frame to canonical frame) |
| 134 | R_inv = torch.stack([x_axis, y_axis, z_axis], dim=1).T # Shape: (3, 3) |
| 135 | |
| 136 | return R_inv |
| 137 | |
| 138 | def apply_rotation(smpl_params, R): |
| 139 | """ |
no outgoing calls
no test coverage detected