def _do_execute(self, context, root): logger = logging.getLogger() logger.setLevel(self.log_level) if self.save_log: handler = log_handler(self.log_level, filepath=self.filepath + '.mmd_tools.export.log') logger.addHandler(handler) rig = mmd_model.Model(root) arm = rig.armature() if arm is None: self.report({ 'ERROR' }, '[Skipped] The armature object of MMD model "%s" can\'t be found' % root.name) return {'CANCELLED'} orig_pose_position = None if not root.mmd_root.is_built: # use 'REST' pose when the model is not built orig_pose_position = arm.data.pose_position arm.data.pose_position = 'REST' arm.update_tag() context.scene.frame_set(context.scene.frame_current) try: meshes = rig.meshes() if self.visible_meshes_only: meshes = (x for x in meshes if x in context.visible_objects) pmx_exporter.export( filepath=self.filepath, scale=self.scale, root=rig.rootObject(), armature=rig.armature(), meshes=meshes, rigid_bodies=rig.rigidBodies(), joints=rig.joints(), copy_textures=self.copy_textures, sort_materials=self.sort_materials, sort_vertices=self.sort_vertices, disable_specular=self.disable_specular, ) self.report({'INFO'}, 'Exported MMD model "%s" to "%s"' % (root.name, self.filepath)) except Exception as e: err_msg = traceback.format_exc() logging.error(err_msg) raise finally: if orig_pose_position: arm.data.pose_position = orig_pose_position if self.save_log: logger.removeHandler(handler) return {'FINISHED'}
def _do_execute(self, context, root): logger = logging.getLogger() logger.setLevel(self.log_level) if self.save_log: handler = log_handler(self.log_level, filepath=self.filepath + '.mmd_tools.export.log') logger.addHandler(handler) if root: bpy.ops.mmd_tools.clear_temp_materials() bpy.ops.mmd_tools.clear_uv_morph_view() rig = mmd_model.Model(root) arm = rig.armature() orig_pose_position = None if not root.mmd_root.is_built: # use 'REST' pose when the model is not built orig_pose_position = arm.data.pose_position arm.data.pose_position = 'REST' arm.update_tag() context.scene.frame_set(context.scene.frame_current) try: pmx_exporter.export( filepath=self.filepath, scale=self.scale, root=rig.rootObject(), armature=rig.armature(), meshes=rig.meshes(), rigid_bodies=rig.rigidBodies(), joints=rig.joints(), copy_textures=self.copy_textures, sort_materials=self.sort_materials, sort_vertices=self.sort_vertices, disable_specular=self.disable_specular, ) self.report({'INFO'}, 'Exported MMD model "%s" to "%s"' % (root.name, self.filepath)) except Exception as e: err_msg = traceback.format_exc() logging.error(err_msg) raise finally: if orig_pose_position: arm.data.pose_position = orig_pose_position if self.save_log: logger.removeHandler(handler) return {'FINISHED'}