def get_bvh_string(skeleton, frames): print("generate bvh string", len(skeleton.animated_joints)) frames = np.array(frames) frames = skeleton.add_fixed_joint_parameters_to_motion(frames) frame_time = skeleton.frame_time bvh_writer = BVHWriter(None, skeleton, frames, frame_time, True) return bvh_writer.generate_bvh_string()
def export_frames_to_bvh_file(output_dir, skeleton, frames, prefix="", time_stamp=True, is_quaternion=True): """ Exports a list of frames to a bvh file Parameters --------- * output_dir : string directory without trailing os.sep * skeleton : Skeleton contains joint hiearchy information * frames : np.ndarray Represents the motion """ if len(frames) > 0 and len(frames[0]) < skeleton.reference_frame_length: frames = skeleton.add_fixed_joint_parameters_to_motion(frames) bvh_writer = BVHWriter(None, skeleton, frames, skeleton.frame_time, is_quaternion) if time_stamp: filepath = output_dir + os.sep + prefix + "_" + \ str(datetime.now().strftime("%d%m%y_%H%M%S")) + ".bvh" elif prefix != "": filepath = output_dir + os.sep + prefix + ".bvh" else: filepath = output_dir + os.sep + "output" + ".bvh" bvh_writer.write(filepath)
def export_to_file(self, filename): if self._motion is not None: frame_time = self.frameTime skeleton = self._graph.skeleton frames = skeleton.add_fixed_joint_parameters_to_motion( self._motion.mv.frames) bvh_writer = BVHWriter(None, skeleton, frames, frame_time, True) bvh_writer.write(filename)
def get_bvh_string(self): skeleton = self._visualization.skeleton print("generate bvh string", len(skeleton.animated_joints)) frames = self._motion.get_frames() frames = skeleton.add_fixed_joint_parameters_to_motion(frames) frame_time = self._motion.get_frame_time() bvh_writer = BVHWriter(None, skeleton, frames, frame_time, True) return bvh_writer.generate_bvh_string()
def generate_bvh_string(self): quat_frames = np.array(self.frames) if len(quat_frames) > 0 and len( quat_frames[0]) < self.skeleton.reference_frame_length: quat_frames = self.skeleton.add_fixed_joint_parameters_to_motion( quat_frames) bvh_writer = BVHWriter(None, self.skeleton, quat_frames, self.skeleton.frame_time, True) return bvh_writer.generate_bvh_string()
def save_motion(self, save_path): if not save_path.endswith(os.sep): save_path += os.sep for filename, frames in self.aligned_motions.items(): BVHWriter(save_path + filename, self.skeleton, frames, frame_time=self.ref_bvhreader.frame_time, is_quaternion=False)
def get_bvh_writer(skeleton, quat_frames, is_quaternion=True): """ Returns ------- * bvh_writer: BVHWriter An instance of the BVHWriter class filled with Euler frames. """ if len(quat_frames) > 0 and len( quat_frames[0]) < skeleton.reference_frame_length: quat_frames = skeleton.add_fixed_joint_parameters_to_motion( quat_frames) bvh_writer = BVHWriter(None, skeleton, quat_frames, skeleton.frame_time, is_quaternion) return bvh_writer
def save_warped_motion(self, save_path): if not save_path.endswith(os.sep): save_path += os.sep skeleton = Skeleton(self.ref_bvhreader) warping_index_dic = {} for filename, motion_data in self.warped_motions.items(): BVHWriter(save_path + filename, skeleton, motion_data['frames'], frame_time=self.ref_bvhreader.frame_time, is_quaternion=False) warping_index_dic[filename] = np.array( motion_data['warping_index']).tolist() with open(save_path + 'timewarping.json', 'wb') as outfile: json.dump(warping_index_dic, outfile)
def export_to_file(self, filename, export_format="bvh", frame_range=None): if self._motion is not None: frame_time = self._motion.get_frame_time() if export_format == "bvh": skeleton = self._visualization.skeleton frames = self._motion.get_frames() frames = np.array(frames) if frames is not None: print("frames shape", frames.shape) else: print("frames is none") print("ref framee length", skeleton.reference_frame_length) joint_count = 0 for joint_name in skeleton.nodes.keys(): if len(skeleton.nodes[joint_name].children ) > 0 and "EndSite" not in joint_name: joint_count += 1 skeleton.reference_frame_length = joint_count * 4 + 3 frames = skeleton.add_fixed_joint_parameters_to_motion(frames) if frame_range is not None: bvh_writer = BVHWriter( None, skeleton, frames[frame_range[0]:frame_range[1], :], frame_time, True) else: bvh_writer = BVHWriter(None, skeleton, frames, frame_time, True) bvh_writer.write(filename) elif export_format == "fbx": export_motion_vector_to_fbx_file(self._visualization.skeleton, self._motion, filename) elif export_format == "json": self._visualization.skeleton.save_to_json(filename) else: print("unsupported format", export_format)
def export_to_file(self, filename, sample_idx=0): if sample_idx < len(self.samples): frame_time = self.frameTime frames = self.skeleton.add_fixed_joint_parameters_to_motion(self.samples[0].frames) bvh_writer = BVHWriter(None, self.skeleton, frames, frame_time, True) bvh_writer.write(filename)
def splitt_motion(frames, keyframes, mname, skeleton_file='skeleton.bvh', outputpath=''): """ Splitt a Motion by the given Keyframes Parameters ---------- frames : numpy.ndarray The frames of the walking motion keyframes : dict of list of int A dictionary containing a list for each feature. Each list contains all Keyframes for this feature. mname: string Subfix of the splitted motions (i.e. the original name of the motion) skeleton_file: string (optional) The path to the skeleton file. Default is the 'skeleton.bvh' in the current folder outputpath: string (optional) The path where to save the motions. Default is the current folder Returns ------- None """ # Calc number of steps for status update n = 0.0 counter = 0.0 for feature in keyframes: n += len(keyframes[feature]) tmpmins = [] tmpmax = [] for feature in keyframes: tmpmins.append(min(keyframes[feature])[0]) tmpmax.append(max(keyframes[feature])[1]) firstframe = min(tmpmins) lastframe = max(tmpmax) reader = BVHReader(skeleton_file) skel = SkeletonBuilder().load_from_bvh(reader) for feature in keyframes: # save first step: if firstframe in keyframes[feature][0]: keyframe = keyframes[feature][0] subframes = frames[keyframe[0]:keyframe[1]] name = 'begin_' + str(keyframe[0]) + '_' + str(keyframe[1]) \ + '_' + feature + '_' + mname BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889) keyframes[feature] = keyframes[feature][1:] # last step: if lastframe in keyframes[feature][-1]: keyframe = keyframes[feature][-1] subframes = frames[keyframe[0]:keyframe[1]] name = 'end_' + str(keyframe[0]) + '_' + str(keyframe[1]) \ + '_' + feature + '_' + mname BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889) keyframes[feature] = keyframes[feature][:-1] for keyframe in keyframes[feature]: subframes = frames[keyframe[0]:keyframe[1]] name = str(keyframe[0]) + '_' + str(keyframe[1]) \ + '_' + feature + '_' + mname BVHWriter(outputpath + os.sep + name, skel, subframes, 0.013889) counter += 1.0