예제 #1
0
    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'}
예제 #2
0
    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'}
예제 #3
0
파일: io.py 프로젝트: Amudtogal/phobos
    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'}
예제 #4
0
    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 root['modelname'] == 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'}
예제 #5
0
파일: io.py 프로젝트: hwiedDFKI/phobos
    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'}
예제 #6
0
파일: io.py 프로젝트: Amudtogal/phobos
    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'}