MCPcopy Index your code
hub / github.com/MotrixLab/MotionDiffuse / forward_kinematics

Method forward_kinematics

text2motion/utils/skeleton.py:104–123  ·  view source on GitHub ↗
(self, quat_params, root_pos, skel_joints=None, do_root_R=True)

Source from the content-addressed store, hash-verified

102
103 # Be sure root joint is at the beginning of kinematic chains
104 def forward_kinematics(self, quat_params, root_pos, skel_joints=None, do_root_R=True):
105 # quat_params (batch_size, joints_num, 4)
106 # joints (batch_size, joints_num, 3)
107 # root_pos (batch_size, 3)
108 if skel_joints is not None:
109 offsets = self.get_offsets_joints_batch(skel_joints)
110 if len(self._offset.shape) == 2:
111 offsets = self._offset.expand(quat_params.shape[0], -1, -1)
112 joints = torch.zeros(quat_params.shape[:-1] + (3,)).to(self.device)
113 joints[:, 0] = root_pos
114 for chain in self._kinematic_tree:
115 if do_root_R:
116 R = quat_params[:, 0]
117 else:
118 R = torch.tensor([[1.0, 0.0, 0.0, 0.0]]).expand(len(quat_params), -1).detach().to(self.device)
119 for i in range(1, len(chain)):
120 R = qmul(R, quat_params[:, chain[i]])
121 offset_vec = offsets[:, chain[i]]
122 joints[:, chain[i]] = qrot(R, offset_vec) + joints[:, chain[i-1]]
123 return joints
124
125 # Be sure root joint is at the beginning of kinematic chains
126 def forward_kinematics_np(self, quat_params, root_pos, skel_joints=None, do_root_R=True):

Callers

nothing calls this directly

Calls 4

qmulFunction · 0.85
qrotFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected