def _update_global_ts(self): for i in range(len(self._updated)): if self._updated[i] is False: parent = self._skeleton.get_parent_node_at(i) global_t = mm.vec3_to_se3(self._root_position) if parent is None \ else self._global_ts[self._skeleton.get_parent_index_at(i)] local_p = mm.vec3_to_se3( self._skeleton.get_node_at(i).get_translation()) self._global_ts[i] = np.dot(np.dot(global_t, local_p), self._local_rs[i]) self._updated[i] = True
def _rec_make_skeleton_joint(skeleton_: motion.Skeleton, htr_joint: Htr.Joint, parent=None): skeleton_joint = motion.JointNode(htr_joint.name) # (base_translation) (base_rotation) (local_translation) = (transformation) # translation is translation part of (transformation) if parent is None: # root node skeleton_joint.set_translation(mm.o_vec3()) skeleton_.set_root(skeleton_joint) else: if self.property_dict["EulerRotationOrder"] != "XYZ": raise ValueError("undefined euler rotation order") # XYZ order # base_local_r : se3 = (base_rotation) base_local_r = mm.so3_to_se3( np.dot( np.dot( mm.rot_x(self.root.base_euler_rotation[0] * mm.RAD), mm.rot_y(self.root.base_euler_rotation[1] * mm.RAD)), mm.rot_z(self.root.base_euler_rotation[2] * mm.RAD))) base_local_p = htr_joint.base_translation # choose average of local_translation as fixed local translation of skeleton local_p = np.average(htr_joint.translations, 0) fixed_translation = base_local_p + mm.se3_to_vec3( np.dot(base_local_r, mm.vec3_to_se3(local_p))) skeleton_joint.set_translation(fixed_translation * scale) skeleton_.add_node(skeleton_joint, parent) for child in self.find_children(htr_joint): _rec_make_skeleton_joint(skeleton_, child, skeleton_joint)
def _make_base_transformations(self, skeleton: motion.Skeleton): # base_transformations are used for calculating local_rs from htr # base_transformations are same order as motion.Skeleton.get_nodes() base_ts = list() for node in skeleton.get_nodes(): htr_joint = self.joint_dict[node.label] if self.property_dict["EulerRotationOrder"] != "XYZ": raise ValueError("undefined euler rotation order") # XYZ order # base_local_r : se3 = (base_rotation) base_local_r = mm.so3_to_se3( np.dot( np.dot(mm.rot_x(self.root.base_euler_rotation[0] * mm.RAD), mm.rot_y(self.root.base_euler_rotation[1] * mm.RAD)), mm.rot_z(self.root.base_euler_rotation[2] * mm.RAD))) base_local_p = htr_joint.base_translation base_ts.append(np.dot(mm.vec3_to_se3(base_local_p), base_local_r)) return base_ts
def _set_local_rs_from_htr(self, frame: int, joint_posture: motion.JointPosture, base_ts: list): skeleton = joint_posture.get_skeleton() for i in range(len(skeleton.get_nodes())): skeleton_joint = skeleton.get_node_at(i) htr_joint = self.joint_dict[skeleton_joint.label] if htr_joint is self.root: print("root!!!") root_position = mm.se3_to_vec3( np.dot(base_ts[i], mm.vec3_to_se3(htr_joint.translations[frame]))) joint_posture.set_root_position(root_position) # (base_transformation) (local_transformation) = (transformation) # XYZ order local_r_so3 = np.dot( np.dot(mm.rot_x(htr_joint.euler_rotations[frame][0] * mm.RAD), mm.rot_y(htr_joint.euler_rotations[frame][1] * mm.RAD)), mm.rot_z(htr_joint.euler_rotations[frame][2] * mm.RAD)) base_local_r_so3 = mm.se3_to_so3(base_ts[i]) r_so3 = np.dot(base_local_r_so3, local_r_so3) joint_posture.set_local_r_without_update( i, mm.so3_to_se3(r_so3, mm.o_vec3()))
def set_root_position(self, root_position): self._root_position = root_position for index in range(len(self._global_ts)): self._global_ts[index] = np.dot( mm.vec3_to_se3(self._root_position), self._global_ts[index])