def execute(self, context): root = sUtils.getRoot(context.selected_objects[0]) objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist) poses = models.getPoses(root['modelname']) i = 1 for pose in poses: sUtils.selectObjects([root] + objectlist, clear=True, active=0) models.loadPose(root['modelname'], pose) parameter = self.decimate_ratio if self.decimate_type == 'UNSUBDIV': parameter = self.decimate_iteration elif self.decimate_type == 'DISSOLVE': parameter = self.decimate_angle_limit exporter.bakeModel(objectlist, root['modelname'], pose, decimate_type=self.decimate_type, decimate_parameter=parameter) display.setProgress(i / len(poses)) i += 1 sUtils.selectObjects([root] + objectlist, clear=True, active=0) bpy.ops.scene.reload_models_and_poses_operator() return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ root = sUtils.getRoot(context.selected_objects[0]) objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist) poses = models.getPoses(root['model/name']) i = 1 for pose in poses: sUtils.selectObjects([root] + objectlist, clear=True, active=0) models.loadPose(root['model/name'], pose) parameter = self.decimate_ratio if self.decimate_type == 'UNSUBDIV': parameter = self.decimate_iteration elif self.decimate_type == 'DISSOLVE': parameter = self.decimate_angle_limit exporter.bakeModel( objectlist, root['model/name'], pose, decimate_type=self.decimate_type, decimate_parameter=parameter, ) display.setProgress(i / len(poses)) i += 1 sUtils.selectObjects([root] + objectlist, clear=True, active=0) bpy.ops.scene.reload_models_and_poses_operator() return {'FINISHED'}
def exportModel(root, export_path, entitytypes=None, model=None): # derive model model = models.buildModelDictionary(root) if not model: model = models.buildModelDictionary(root) # export model in selected formats if entitytypes is None: entitytypes = entities.entity_types for entitytype in entitytypes: typename = "export_entity_" + entitytype # check if format exists and should be exported if not getattr(bpy.data.worlds[0], typename, False): continue # format exists and is exported: if ioUtils.getExpSettings().structureExport: model_path = os.path.join(export_path, entitytype) else: model_path = export_path securepath(model_path) try: entities.entity_types[entitytype]['export'](model, model_path) log( "Export model: " + model['name'] + ' as ' + entitytype + " to " + model_path, "DEBUG") except KeyError: log( "No export function available for selected model type: " + entitytype, "ERROR") continue # TODO: Move mesh export to individual formats? This is practically SMURF # export meshes in selected formats i = 1 mt = len([ m for m in meshes.mesh_types if getattr(bpy.data.worlds[0], "export_mesh_" + m) ]) mc = len(model['meshes']) n = mt * mc for meshtype in meshes.mesh_types: mesh_path = ioUtils.getOutputMeshpath(export_path, meshtype) try: typename = "export_mesh_" + meshtype if getattr(bpy.data.worlds[0], typename): securepath(mesh_path) for meshname in model['meshes']: meshes.mesh_types[meshtype]['export']( model['meshes'][meshname], mesh_path) display.setProgress( i / n, 'Exporting ' + meshname + '.' + meshtype + '...') i += 1 except KeyError: log( "No export function available for selected mesh function: " + meshtype, "ERROR") print(sys.exc_info()[0]) display.setProgress(0) # TODO: Move texture export to individual formats? This is practically SMURF # TODO: Also, this does not properly take care of textures embedded in a .blend file # export textures if ioUtils.getExpSettings().exportTextures: for materialname in model['materials']: mat = model['materials'][materialname] for texturetype in [ 'diffuseTexture', 'normalTexture', 'displacementTexture' ]: if texturetype in mat: sourcepath = os.path.join( os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) if os.path.isfile(sourcepath): texture_path = securepath( os.path.join(export_path, 'textures')) log("Exporting textures to " + texture_path, "INFO") try: shutil.copy( sourcepath, os.path.join( texture_path, os.path.basename(mat[texturetype]))) except shutil.SameFileError: log("{} already in place".format(texturetype), "INFO")
def exportModel(model, exportpath='.', entitytypes=None): """Exports model to a given path in the provided formats. Args: model(dict): dictionary of model to export exportpath(str, optional): path to export root (Default value = '.') entitytypes(list of str, optional): export types - model will be exported to all (Default value = None) Returns: """ if not exportpath: exportpath = getExportPath() if not entitytypes: entitytypes = getEntityTypesForExport() # TODO: Move texture export to individual formats? This is practically SMURF # TODO: Also, this does not properly take care of textures embedded in a .blend file # export textures if getExpSettings().exportTextures: path = os.path for materialname in model['materials']: mat = model['materials'][materialname] for texturetype in ['diffuseTexture', 'normalTexture', 'displacementTexture']: # skip materials without texture if texturetype not in mat: continue sourcepath = path.join(path.expanduser(bpy.path.abspath('//')), mat[texturetype]) if path.isfile(sourcepath): texture_path = securepath(path.join(exportpath, 'textures')) log( "Exporting texture {} of material {} to {}.".format( texturetype, mat[texturetype], texture_path ), 'INFO', ) try: shutil.copy( sourcepath, path.join(texture_path, path.basename(mat[texturetype])) ) except shutil.SameFileError: log( "{} of material {} already in place.".format(texturetype, materialname), 'WARNING', ) # update the texture path in the model mat[texturetype] = 'textures/' + path.basename(mat[texturetype]) # export model in selected formats for entitytype in entitytypes: typename = "export_entity_" + entitytype # check if format exists and should be exported if not getattr(bpy.context.scene, typename, False): continue # format exists and is exported: model_path = os.path.join(exportpath, entitytype) securepath(model_path) # export model using entity export function log("Export model '" + model['name'] + "' as " + entitytype + " to " + model_path, "DEBUG") # pass a model copy to the entity export, as these might alter the dictionary newmodel = copy_model(model) entity_types[entitytype]['export'](newmodel, model_path) # export meshes in selected formats i = 1 mt = len([m for m in mesh_types if getattr(bpy.context.scene, "export_mesh_" + m, False)]) mc = len(model['meshes']) n = mt * mc for meshtype in mesh_types: mesh_path = getOutputMeshpath(exportpath, meshtype) try: if getattr(bpy.context.scene, "export_mesh_" + meshtype, False): securepath(mesh_path) for meshname in model['meshes']: mesh_types[meshtype]['export'](model['meshes'][meshname], mesh_path) display.setProgress(i / n, 'Exporting ' + meshname + '.' + meshtype + '...') i += 1 except KeyError as e: log("Error exporting mesh {0} as {1}: {2}".format(meshname, meshtype, str(e)), "ERROR") display.setProgress(0)
def exportModel(model, exportpath='.', entitytypes=None): """Exports model to a given path in the provided formats. Args: model(dict): dictionary of model to export exportpath(str): path to export root entitytypes(list of str): export types - model will be exported to all Returns: """ if not exportpath: exportpath = getExportPath() if not entitytypes: entitytypes = getEntityTypesForExport() # export model in selected formats for entitytype in entitytypes: typename = "export_entity_" + entitytype # check if format exists and should be exported if not getattr(bpy.data.window_managers[0], typename, False): continue # format exists and is exported: model_path = os.path.join(exportpath, entitytype) securepath(model_path) # the following is not surrounded by try..catch as that may mask exceptions occurring # inside the export function; also, only existing functionars register to display anyway entity_types[entitytype]['export'](model, model_path) log( "Export model: " + model['name'] + ' as ' + entitytype + " to " + model_path, "DEBUG") # export meshes in selected formats i = 1 mt = len([ m for m in mesh_types if getattr(bpy.data.window_managers[0], "export_mesh_" + m) ]) mc = len(model['meshes']) n = mt * mc for meshtype in mesh_types: mesh_path = getOutputMeshpath(exportpath, meshtype) try: typename = "export_mesh_" + meshtype if getattr(bpy.data.window_managers[0], typename): securepath(mesh_path) for meshname in model['meshes']: mesh_types[meshtype]['export'](model['meshes'][meshname], mesh_path) display.setProgress( i / n, 'Exporting ' + meshname + '.' + meshtype + '...') i += 1 except KeyError: log( "No export function available for selected mesh function: " + meshtype, "ERROR") print(sys.exc_info()[0]) display.setProgress(0) # TODO: Move texture export to individual formats? This is practically SMURF # TODO: Also, this does not properly take care of textures embedded in a .blend file # export textures if getExpSettings().exportTextures: for materialname in model['materials']: mat = model['materials'][materialname] for texturetype in [ 'diffuseTexture', 'normalTexture', 'displacementTexture' ]: if texturetype in mat: sourcepath = os.path.join( os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) if os.path.isfile(sourcepath): texture_path = securepath( os.path.join(exportpath, 'textures')) log("Exporting textures to " + texture_path, "INFO") try: shutil.copy( sourcepath, os.path.join( texture_path, os.path.basename(mat[texturetype]))) except shutil.SameFileError: log("{} already in place".format(texturetype), "INFO")