コード例 #1
0
def exportSubmechanisms(model, path):
    """This function exports the submechanisms contained in a robot model.

    Args:
      model(dict): The robot model to export
      path(str): The filepath to export the submechanisms data to

    Returns:

    """
    log("Phobos Submechanisms export: Creating submechanisms data at " + path,
        "INFO")
    for submechanism in model['submechanisms']:
        root = sUtils.getObjectByProperty('submechanism/name',
                                          submechanism['contextual_name'])
        linkobjs = [root] + root['submechanism/spanningtree']
        if 'submechanism/freeloader' in root:
            linkobjs += root['submechanism/freeloader']

        objects = [
            o for link in linkobjs for o in link.children
            if o.phobostype in ['visual', 'collision', 'inertial']
        ] + linkobjs
        model = deriveModelDictionary(root, root['submechanism/name'], objects)
        jointname = nUtils.getObjectName(root, 'joint')
        if jointname in model['joints']:
            del model['joints'][jointname]
            log('Removed joint which is not part of submodel: ' + jointname,
                'DEBUG')
        exportModel(model, path, ['urdf'])
コード例 #2
0
ファイル: submechanisms.py プロジェクト: Amudtogal/phobos
def exportSubmechanisms(model, path):
    """This function exports the submechanisms contained in a robot model.

    Args:
      model(dict): The robot model to export
      path(str): The filepath to export the submechanisms data to

    Returns:

    """
    log("Phobos Submechanisms export: Creating submechanisms data at " + path, "INFO")
    for submechanism in model['submechanisms']:
        root = sUtils.getObjectByProperty('submechanism/name', submechanism['contextual_name'])
        linkobjs = [root] + root['submechanism/spanningtree']
        if 'submechanism/freeloader' in root:
            linkobjs += root['submechanism/freeloader']

        objects = [
            o
            for link in linkobjs
            for o in link.children
            if o.phobostype in ['visual', 'collision', 'inertial']
        ] + linkobjs
        model = deriveModelDictionary(root, root['submechanism/name'], objects)
        jointname = nUtils.getObjectName(root, 'joint')
        if jointname in model['joints']:
            del model['joints'][jointname]
            log('Removed joint which is not part of submodel: ' + jointname, 'DEBUG')
        exportModel(model, path, ['urdf'])
コード例 #3
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'}
コード例 #4
0
def exportSubmechanisms(model, path):
    """This function exports the submechanisms contained in a robot model.

    Args:
      model(dict): The robot model to export
      path(str): The filepath to export the submechanisms data to

    Returns:

    """
    log("Phobos Submechanisms export: Creating submechanisms data at " + path,
        "INFO")
    for submechanism in model['submechanisms']:
        root = sUtils.getObjectsByProperty('submechanism/name',
                                           submechanism['contextual_name'])
        linkobjs = [
            root
        ] + root['submechanism/freeloader'] + root['submechanism/spanningtree']
        objects = [
            o for link in linkobjs for o in link.children
            if o.phobostype in ['visual', 'collision', 'inertial']
        ] + linkobjs
        model = deriveModelDictionary(root, root['submechanism/name'], objects)
        exportModel(model, path, ['urdf'])
コード例 #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'}