def __init__(self, motion, skeleton=feat_utils.Skeleton.PFNN): self.global_positions = motion.positions(local=False) self.joints = [joint.name for joint in motion.skel.joints] self.frame_time = 1 / motion.fps self.frame_num = 1 self.offsets = [ conversions.T2p(joint.xform_from_parent_joint) for joint in motion.skel.joints ] if skeleton == feat_utils.Skeleton.PFNN: self.joint_mapping = feat_utils.GENERIC_TO_PFNN_MAPPING else: self.joint_mapping = feat_utils.GENERIC_TO_CMU_MAPPING # humerus length self.hl = feat_utils.distance_between_points( self.transform_and_fetch_offset("lshoulder"), self.transform_and_fetch_offset("lelbow"), ) # shoulder width self.sw = feat_utils.distance_between_points( self.transform_and_fetch_offset("lshoulder"), self.transform_and_fetch_offset("rshoulder"), ) # hip width self.hw = feat_utils.distance_between_points( self.transform_and_fetch_offset("lhip"), self.transform_and_fetch_offset("rhip"), )
def _render_pose(self, pose, body_model, color): skel = pose.skel for j in skel.joints: T = pose.get_transform(j, local=False) pos = conversions.T2p(T) gl_render.render_point(pos, radius=0.03 * self.scale, color=color) if j.parent_joint is not None: # returns X that X dot vec1 = vec2 pos_parent = conversions.T2p( pose.get_transform(j.parent_joint, local=False)) p = 0.5 * (pos_parent + pos) l = np.linalg.norm(pos_parent - pos) r = 0.05 R = math.R_from_vectors(np.array([0, 0, 1]), pos_parent - pos) gl_render.render_capsule( conversions.Rp2T(R, p), l, r * self.scale, color=color, slice=8, )
def get_joint_position(j, p_root, Q_root, p_link, Q_link): if j == self._char_info.ROOT or self._joint_parent_link[ j] == self._char_info.ROOT: p, Q = p_root, Q_root else: p, Q = p_link[self._joint_parent_link[j]], Q_link[ self._joint_parent_link[j]] T_link_world = conversions.Qp2T(Q, p) T_joint_local = constants.eye_T( ) if j == self._char_info.ROOT else self._joint_xform_from_parent_link[ j] T_joint_world = np.dot(T_link_world, T_joint_local) return conversions.T2p(T_joint_world)
def keyboard_callback(self, key): motion = self.motions[self.file_idx] if key == b"s": self.cur_time = 0.0 self.time_checker.begin() elif key == b"]": next_frame = min( motion.num_frames() - 1, motion.time_to_frame(self.cur_time) + 1, ) self.cur_time = motion.frame_to_time(next_frame) elif key == b"[": prev_frame = max(0, motion.time_to_frame(self.cur_time) - 1) self.cur_time = motion.frame_to_time(prev_frame) elif key == b"+": self.play_speed = min(self.play_speed + 0.2, 5.0) elif key == b"-": self.play_speed = max(self.play_speed - 0.2, 0.2) elif key == b"r": start_time = 0.0 end_time = self.motions[0].length() fps = self.motions[0].fps save_dir = input("Enter directory to store screenshots: ") os.makedirs(save_dir, exist_ok=True) cnt_screenshot = 0 time_processed = start_time dt = 1 / fps while self.cur_time <= end_time: print( f"Recording progress: {self.cur_time:.2f}s/{end_time:.2f}s ({int(100*self.cur_time/end_time)}%) \r", end="", ) name = "screenshot_%04d" % (cnt_screenshot) p = conversions.T2p( motion.get_pose_by_time( self.cur_time).get_root_transform()) self.draw_GL() self.save_screen(dir=save_dir, name=name) self.cur_time += dt cnt_screenshot += 1 else: return False return True