def execute(self, context): self.report({'INFO'}, "Training model %s..." % context.scene.speech2anim_data.training_videos_path) os.chdir( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH + '/src') reloadConfig(context) #Clean previous output #pdb.set_trace() wops.rmdir( config.TEMPDATA_OUTPUT[3:], wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH)) wops.mkdir( config.TEMPDATA_OUTPUT[3:], wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH)) d = context.scene.speech2anim_data DataManager.Train(d.training_videos_path, d.training_model_path) paths = DataManager.getTrainingVideoPaths(d.training_videos_path) #TODO: refactor #for every video in the training folder for path in paths: #get the name name = path.split('/')[-1:][0].split('.')[0] exists = False #if we don't have it in the list, add it for p in d.training_videos_list: if p.name == name: exists = True if not exists: item = d.training_videos_list.add() item.path = path item.name = name for i, p in enumerate(d.training_videos_list): exists = False for path in paths: name = path.split('/')[-1:][0].split('.')[0] if p.name == name: exists = True if not exists: d.training_videos_list.remove(i) return {'FINISHED'}
def execute(self, context): #TODO: use constants context.scene.sequence_editor_clear() #remove linked files for i, item in enumerate( context.scene.speech2anim_data.training_videos_list): BlenderManager.remove_link(bpy.data.sounds, item.name + '.wav') BlenderManager.remove_link(bpy.data.movieclips, item.name + '.avi') addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) #wops.rmdir('tempAudioFiles', addon_path) context.scene.speech2anim_data.initialized = False context.scene.speech2anim_data.training_videos_path = "" context.scene.speech2anim_data.training_model_path = "" context.scene.speech2anim_data.animate_model_path = "" context.scene.speech2anim_data.input_file = "" context.scene.speech2anim_data.config_type = 'DEFAULT' context.scene.speech2anim_data.animation_config_type = 'DEFAULT' context.scene.speech2anim_data.external_config_path = "" context.scene.speech2anim_data.external_animation_config_path = "" context.scene.speech2anim_data.selected_training_video_index = 0 context.scene.speech2anim_data.training_videos_list.clear() wops.rmdir('output', addon_path) wops.mkdir('output', addon_path) wops.rmdir('lib/openpose/TrainingVideos', addon_path) wops.rmdir('src/models', addon_path) wops.delete(addon_path + '/src/training.log') return {'FINISHED'}
def execute(self, context): config_name = context.scene.speech2anim_data.external_animation_config_path addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) wops.copy(addon_path + '/src/default_animation_config.py', config_name) bpy.ops.s2a.open_file(path=config_name) return {'FINISHED'}
def execute(self, context): #TODO: use constants addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) wops.rmdir('lib/openpose/TrainingVideos', addon_path) wops.rmdir('src/models', addon_path) #wops.rmdir('tempAudioFiles', addon_path) return {'FINISHED'}
def execute(self, context): os.chdir( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH + '/src') wops.rmdir( config.DATA_OUTPUT[3:], wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH)) wops.mkdir( config.DATA_OUTPUT[3:], wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH)) d = context.scene.speech2anim_data DataManager.GenerateFinalTrainingFile(d.training_model_path) DataManager.DoTrain() return {'FINISHED'}
def execute(self, context): if not context.object.tempUserData: self.report({'ERROR'}, "There's no loaded data") return {'CANCELLED'} scn = context.scene idx = scn.speech2anim_data.selected_training_video_index addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) try: item = scn.speech2anim_data.training_videos_list[idx] except IndexError: return {'CANCELLED'} training_file = CSVFile() training_file.from_file(addon_path + '/output/tempdata/' + item.name + '/training_data.csv') training_file = training_file.to_dict() training_info = CSVFile() training_info.from_file(addon_path + '/output/tempdata/' + item.name + '/training_info.csv') training_info_dict = training_info.to_dict() for label_group in config.LABEL_GROUPS: group_name = label_group['group_name'] #print(group_name) new_group_labels = [0] * len(training_file[group_name]) for i, label_name in enumerate(label_group['label_names']): #print(label_name, i) for j, frame in enumerate( training_info_dict[config.FRAME_INDEX_COLNAME]): context.scene.frame_set(int(frame)) value = int(context.object.tempUserData[label_name]) #print(frame, value, j) training_info_dict[label_name][j] = value if value: #print("add to training","row:", j,"label:", i) new_group_labels[j] = i + 1 training_file[group_name] = new_group_labels training_info.from_dict(training_info_dict) training_info.saveAs(addon_path + '/output/tempdata/' + item.name + '/training_info') new_training_file = CSVFile() new_training_file.from_dict(training_file) new_training_file.saveAs(addon_path + '/output/tempdata/' + item.name + '/training_data') return {'FINISHED'}
def invoke(self, context, event): scn = context.scene idx = scn.speech2anim_data.selected_training_video_index addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) try: item = scn.speech2anim_data.training_videos_list[idx] except IndexError: pass else: if self.action == 'CLEAR_POSE': filename = item.name + '.avi' BlenderManager.erase_sequence(filename) wops.delete(addon_path + '/output/openpose/renders/' + filename) wops.rmdir('output/openpose/' + item.name, addon_path) self.report({'INFO'}, 'Pose cleared for video {}'.format(item.name)) elif self.action == 'CLEAR_AUDIO': filename = item.name + '.wav' #BlenderManager.erase_sequence(filename) #wops.delete(addon_path+'/tempAudioFiles/'+filename) wops.rmdir('output/opensmile/' + item.name, addon_path) self.report({'INFO'}, 'Audio cleared for video {}'.format(item.name)) elif self.action == 'SEE_INFO': if not context.object.type == 'ARMATURE': self.report({'ERROR'}, 'Please, select an armature') return {"CANCELLED"} data = CSVFile() data.from_file(addon_path + '/output/tempdata/' + item.name + '/training_info.csv') data = data.to_dict() data_funcs = CSVFile() data_funcs.from_file(addon_path + '/output/tempdata/' + item.name + '/training_info_funcs.csv') data_funcs = data_funcs.to_dict() all_data = {**data_funcs, **data} BlenderManager.plotData(context.object, all_data) #load video and audio context.scene.sequence_editor_clear() space_data = None #TODO:refactor, promote to function for area in bpy.context.screen.areas: if area.type == 'SEQUENCE_EDITOR': space_data = area.spaces.active override = { 'area': area, 'screen': context.screen, 'region': context.region, 'window': context.window, 'scene': context.scene, 'blend_data': context.blend_data } if os.path.isfile(addon_path + '/output/openpose/renders/' + item.name + '.avi'): bpy.ops.sequencer.movie_strip_add( override, filepath=addon_path + '/output/openpose/renders/' + item.name + '.avi', frame_start=0) else: print( "Can't find pose video:", addon_path + '/output/openpose/renders/' + item.name + '.avi') if os.path.isfile(addon_path + '/tempAudioFiles/' + item.name + '.wav'): bpy.ops.sequencer.sound_strip_add( override, filepath=addon_path + '/tempAudioFiles/' + item.name + '.wav', frame_start=0) else: print( "Can't find audio file:", addon_path + '/tempAudioFiles/' + item.name + '.wav') self.report({'INFO'}, 'Seeing info for video {}'.format(item.name)) return {"FINISHED"}
def execute(self, context): addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) bpy.ops.s2a.open_file(path=addon_path + '/src/training.log') return {'FINISHED'}
def poll(cls, context): addon_path = wops.clear( bpy.utils.user_resource("SCRIPTS", "addons") + config.ADDON_PATH) return os.path.isfile(addon_path + '/src/training.log')