def execute(self, context): # identify all entities' roots in the scene rootobjects = ioUtils.getEntityRoots() if not rootobjects: log("There are no entities to export!", "WARNING") # derive entities and export if necessary modellist = [] for root in rootobjects: log("Adding entity '" + str(root["entity/name"]) + "' to scene.", "INFO") if root["entity/type"] in entity_types: # TODO delete me? # try: if (self.exportModels and 'export' in entity_types[root['entity/type']] and root['modelname'] not in models): modelpath = os.path.join(ioUtils.getExportPath(), self.sceneName, root['modelname']) exportModel(models.deriveModelDictionary(root), modelpath) models.add(root['modelname']) # known entity export entity = entity_types[root["entity/type"]]['derive']( root, os.path.join(ioUtils.getExportPath(), self.sceneName)) # TODO delete me? # except KeyError: # log("Required method ""deriveEntity"" not implemented for type " + entity["entity/type"], "ERROR") # continue # generic entity export else: entity = deriveGenericEntity(root) exportlist.append(entity) return {'FINISHED'}
def execute(self, context): exportlist = [] # TODO variable not used exportsettings = ioUtils.getExpSettings() # identify all entities' roots in the scene entities = ioUtils.getExportEntities() if not entities: log("There are no entities to export!", "WARNING") return {'CANCELLED'} # derive entities and export if necessary models = set() for root in entities: log("Adding entity '" + str(root["entity/name"]) + "' to scene.", "INFO") if root["entity/type"] in entity_types: # TODO delete me? # try: if (self.exportModels and 'export' in entity_types[root['entity/type']] and root['modelname'] not in models): modelpath = os.path.join(ioUtils.getExportPath(), self.sceneName, root['modelname']) # FIXME: the following is a hack, the problem is that # robots are always smurf entities if root['entity/type'] == 'smurf': formatlist = ['smurf', 'urdf'] else: formatlist = [root['entity/type']] exportModel(root, modelpath, formatlist) models.add(root['modelname']) # known entity export entity = entity_types[root["entity/type"]]['derive']( root, os.path.join(ioUtils.getExportPath(), self.sceneName)) # TODO delete me? # except KeyError: # log("Required method ""deriveEntity"" not implemented for type " + entity["entity/type"], "ERROR") # continue # generic entity export else: entity = deriveGenericEntity(root) exportlist.append(entity) for scenetype in scene_types: typename = "export_scene_" + scenetype # check if format exists and should be exported if getattr(bpy.data.worlds[0], typename): scene_types[scenetype]['export'](exportlist, os.path.join( ioUtils.getExportPath(), self.sceneName)) return {'FINISHED'}
def execute(self, context): """ Args: context: Returns: """ # identify all entities' roots in the scene rootobjects = ioUtils.getEntityRoots() if not rootobjects: log("There are no entities to export!", "WARNING") # derive entities and export if necessary models = set() for root in entities: log("Adding entity '" + str(root["entity/name"]) + "' to scene.", "INFO") if root["entity/type"] in entity_types: # TODO delete me? # try: if ( self.exportModels and 'export' in entity_types[root['entity/type']] and root['model/name'] not in models ): modelpath = os.path.join( ioUtils.getExportPath(), self.sceneName, root['model/name'] ) exportModel(models.deriveModelDictionary(root), modelpath) models.add(root['model/name']) # known entity export entity = entity_types[root["entity/type"]]['derive']( root, os.path.join(ioUtils.getExportPath(), self.sceneName) ) # TODO delete me? # except KeyError: # log("Required method ""deriveEntity"" not implemented for type " + entity["entity/type"], "ERROR") # continue # generic entity export else: entity = deriveGenericEntity(root) exportlist.append(entity) for scenetype in scene_types: typename = "export_scene_" + scenetype # check if format exists and should be exported if getattr(bpy.context.scene, typename): scene_types[scenetype]['export']( exportlist, os.path.join(ioUtils.getExportPath(), self.sceneName) ) return {'FINISHED'}
def exportSMURFsScene(entities, path, selected_only=True, subfolder=True): """Exports an arranged scene into SMURFS. It will export only entities with a valid entity/name, and entity/type property. :param selected_only: If True only selected entities get exported. :type selected_only: bool :param subfolder: If True the models are exported into separate subfolders :type subfolder: bool """ outputlist = [] # identify all entities in the scene entities = [ e for e in [obj for obj in bpy.context.scene.objects if isEntity(obj)] if ((selected_only and e.select) or not selected_only) ] if len(entities) == 0: log("There are no entities to export!", "WARNING", __name__ + ".exportSMURFsScene") return log("Exporting scene to " + path, "INFO", "exportSMURFsScene") for entity in entities: log("Exporting " + str(entity["entity/name"]) + " to SMURFS", "INFO") if entity["entity/type"] in entity_types: if hasattr(entity_types[entity["entity/type"]], 'deriveEntity'): entry = entity_types[entity["entity/type"]].deriveEntity( entity, path, subfolder) # known entity export else: log("Required method " "deriveEntity" " not implemented", "ERROR") else: # generic entity export entry = deriveGenericEntity(entity) outputlist.append(entry) with open( os.path.join(path, bpy.data.worlds['World'].sceneName + '.smurfs'), 'w') as outputfile: sceneinfo = "# SMURF scene " + bpy.data.worlds[ 'World'].sceneName + "; created " + datetime.now().strftime( "%Y%m%d_%H:%M") + "\n" sceneinfo += "# created with Phobos " + version + " - https://github.com/rock-simulation/phobos\n\n" outputfile.write(sceneinfo) epsilon = 10**(-bpy.data.worlds[0].phobosexportsettings.decimalPlaces ) # TODO: implement this separately entitiesdict = epsilonToZero( {'entities': outputlist}, epsilon, bpy.data.worlds[0].phobosexportsettings.decimalPlaces) outputfile.write(yaml.dump(entitiesdict))