def execute(self, context): """ Args: context: Returns: """ selection = [] if self.modelname: log("phobos: Selecting model" + self.modelname, "INFO") roots = sUtils.getRoots() for root in roots: if nUtils.getModelName(root) == self.modelname: selection = sUtils.getChildren(root) else: log("No model name provided, deriving from selection...", "INFO") roots = set() for obj in bpy.context.selected_objects: roots.add(sUtils.getRoot(obj)) for root in list(roots): selection.extend(sUtils.getChildren(root)) sUtils.selectObjects(list(selection), True) return {'FINISHED'}
def storePose(root, posename): """Stores the current pose of all of a model's selected joints. Existing poses of the same name will be overwritten. Args: root(bpy_types.Object): root of the model the pose belongs to posename(str): name the pose will be stored under Returns: : Nothing. """ if root: filename = nUtils.getModelName(root) + '::poses' posedict = json.loads(bUtils.readTextFile(filename)) if not posedict: posedict = {posename: {'name': posename, 'joints': {}}} else: posedict[posename] = {'name': posename, 'joints': {}} links = sUtils.getChildren(root, ('link', ), True, False) sUtils.selectObjects([root] + links, clear=True, active=0) bpy.ops.object.mode_set(mode='POSE') for link in (link for link in links if 'joint/type' in link and link['joint/type'] not in ['fixed', 'floating']): link.pose.bones['Bone'].rotation_mode = 'XYZ' posedict[posename]['joints'][nUtils.getObjectName( link, 'joint')] = link.pose.bones['Bone'].rotation_euler.y bpy.ops.object.mode_set(mode='OBJECT') posedict = gUtils.roundFloatsInDict( posedict, ioUtils.getExpSettings().decimalPlaces) bUtils.updateTextFile(filename, json.dumps(posedict)) else: log("No model root provided to store the pose for", "ERROR")
def getModelListForEnumProp(self, context): """Returns list of all exportable models in the scene formatted for an EnumProperty Args: context: Returns: """ rootnames = set([nUtils.getModelName(r) for r in getExportModels()]) return sorted([(r,) * 3 for r in rootnames])
def get_robot_names(scene, context): """ Args: scene: context: Returns: """ robot_names = [(nUtils.getModelName(root),) * 3 for root in sUtils.getRootsOfSelection()] return robot_names
def get_robot_names(scene, context): """ Args: scene: context: Returns: """ robot_names = [(nUtils.getModelName(root), ) * 3 for root in sUtils.getRootsOfSelection()] return robot_names
def storePose(root, posename): """Stores the current pose of all of a model's selected joints. Existing poses of the same name will be overwritten. Args: root(bpy_types.Object): root of the model the pose belongs to posename(str): name the pose will be stored under Returns: : Nothing. """ if root: filename = nUtils.getModelName(root) + '::poses' posedict = yaml.load(bUtils.readTextFile(filename)) if not posedict: posedict = {posename: {'name': posename, 'joints': {}}} else: posedict[posename] = {'name': posename, 'joints': {}} links = sUtils.getChildren(root, ('link',), True, False) sUtils.selectObjects([root] + links, clear=True, active=0) bpy.ops.object.mode_set(mode='POSE') for link in ( link for link in links if 'joint/type' in link and link['joint/type'] not in ['fixed', 'floating'] ): link.pose.bones['Bone'].rotation_mode = 'XYZ' posedict[posename]['joints'][nUtils.getObjectName(link, 'joint')] = link.pose.bones[ 'Bone' ].rotation_euler.y bpy.ops.object.mode_set(mode='OBJECT') posedict = gUtils.roundFloatsInDict(posedict, ioUtils.getExpSettings().decimalPlaces) bUtils.updateTextFile(filename, yaml.dump(posedict, default_flow_style=False)) else: log("No model root provided to store the pose for", "ERROR")
def execute(self, context): roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [root for root in roots if nUtils.getModelName(root) == self.modelname] if len(roots) > 1: log("Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR") return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren( root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # report success to user log("Export successful.", "INFO") return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [ root for root in roots if nUtils.getModelName(root) == self.modelname ] if len(roots) > 1: log( "Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR", ) return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # TODO: Move mesh export to individual formats? This is practically SMURF # export meshes in selected formats # for meshtype in meshes.mesh_types: # mesh_path = ioUtils.getOutputMeshpath(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) # except KeyError: # log("No export function available for selected mesh function: " + meshtype, # "ERROR", "ExportModelOperator") # print(sys.exc_info()[0]) # TODO: Move texture export to individual formats? This is practically SMURF # export textures # if ioUtils.textureExportEnabled(): # texture_path = '' # for materialname in model['materials']: # mat = model['materials'][materialname] # for texturetype in ['diffuseTexture', 'normalTexture', 'displacementTexture']: # if texturetype in mat: # texpath = os.path.join(os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) # if os.path.isfile(texpath): # if texture_path == '': # texture_path = securepath(os.path.join(export_path, 'textures')) # log("Exporting textures to " + texture_path, "INFO", "ExportModelOperator") # try: # shutil.copy(texpath, os.path.join(texture_path, os.path.basename(mat[texturetype]))) # except shutil.SameFileError: # log("{} already in place".format(texturetype), "INFO", "ExportModelOperator") # report success to user log("Export successful.", "INFO", end="\n\n") return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ roots = ioUtils.getExportModels() if not roots: log("No properly defined models selected or present in scene.", 'ERROR') return {'CANCELLED'} elif not self.exportall: roots = [root for root in roots if nUtils.getModelName(root) == self.modelname] if len(roots) > 1: log( "Ambiguous model definitions: " + self.modelname + " exists " + str(len(roots)) + " times.", "ERROR", ) return {'CANCELLED'} for root in roots: # setup paths exportpath = ioUtils.getExportPath() if not securepath(exportpath): log("Could not secure path to export to.", "ERROR") continue log("Export path: " + exportpath, "DEBUG") ioUtils.exportModel(models.deriveModelDictionary(root), exportpath) # select all exported models after export is done if ioUtils.getExpSettings().selectedOnly: for root in roots: objectlist = sUtils.getChildren(root, selected_only=True, include_hidden=False) sUtils.selectObjects(objectlist, clear=False) else: bpy.ops.object.select_all(action='DESELECT') for root in roots: sUtils.selectObjects(list([root]), False) bpy.ops.phobos.select_model() # TODO: Move mesh export to individual formats? This is practically SMURF # export meshes in selected formats # for meshtype in meshes.mesh_types: # mesh_path = ioUtils.getOutputMeshpath(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) # except KeyError: # log("No export function available for selected mesh function: " + meshtype, # "ERROR", "ExportModelOperator") # print(sys.exc_info()[0]) # TODO: Move texture export to individual formats? This is practically SMURF # export textures # if ioUtils.textureExportEnabled(): # texture_path = '' # for materialname in model['materials']: # mat = model['materials'][materialname] # for texturetype in ['diffuseTexture', 'normalTexture', 'displacementTexture']: # if texturetype in mat: # texpath = os.path.join(os.path.expanduser(bpy.path.abspath('//')), mat[texturetype]) # if os.path.isfile(texpath): # if texture_path == '': # texture_path = securepath(os.path.join(export_path, 'textures')) # log("Exporting textures to " + texture_path, "INFO", "ExportModelOperator") # try: # shutil.copy(texpath, os.path.join(texture_path, os.path.basename(mat[texturetype]))) # except shutil.SameFileError: # log("{} already in place".format(texturetype), "INFO", "ExportModelOperator") # report success to user log("Export successful.", "INFO", end="\n\n") return {'FINISHED'}