Esempio n. 1
0
def exportPreview(model, path, mesh_format=''):
    """This function exports a given robot model to a specified filepath as YAML.

    :param model: The robot model to export
    :type model: dict -- the generated robot model dictionary
    :param path:  The filepath to export the robot to. *WITH filename!*
    :type path: str

    """
    log("Phobos Thumbnail export: Creating thumbnail in " + path, "INFO")
    visuals = []
    for linkname in model['links']:
        for visualname in model['links'][linkname]['visual']:
            visuals.append(bpy.data.objects[visualname])
    createPreview(visuals, path, model['name'])
Esempio n. 2
0
def exportPreview(model, path):
    """This function exports a given robot model to a specified filepath as YAML.

    Args:
      model(dict -- the generated robot model dictionary): The robot model to export
      path(str): The filepath to export the robot to. *WITH filename!*

    Returns:

    """
    log("Phobos Thumbnail export: Creating thumbnail in " + path, "INFO")
    visuals = []
    for linkname in model['links']:
        for visualname in model['links'][linkname]['visual']:
            visuals.append(bpy.data.objects[visualname])
    createPreview(visuals, path, model['name'])
Esempio n. 3
0
def exportPreview(model, path):
    """This function exports a given robot model to a specified filepath as YAML.

    Args:
      model(dict -- the generated robot model dictionary): The robot model to export
      path(str): The filepath to export the robot to. *WITH filename!*

    Returns:

    """
    log("Phobos Thumbnail export: Creating thumbnail in " + path, "INFO")
    visuals = []
    for linkname in model['links']:
        for visualname in model['links'][linkname]['visual']:
            visuals.append(bpy.data.objects[visualname])
    createPreview(visuals, path, model['name'])
Esempio n. 4
0
def bakeModel(objlist,
              modelname,
              posename="",
              decimate_type='COLLAPSE',
              decimate_parameter=0.1):
    """This function gets a list of objects and creates a single, simplified mesh from it and exports it to .stl.

    Args:
      objlist(list: list): The list of blender objects to join and export as simplified stl file.
      modelname(str): The new models name and filename.
      posename: (Default value = "")
      decimate_type: (Default value = 'COLLAPSE')
      decimate_parameter: (Default value = 0.1)
      objlist: 

    Returns:

    """
    if bpy.context.scene.phobosexportsettings.relativePath:
        # CHECK careful with path consistency (Windows)
        outpath = securepath(
            os.path.expanduser(
                os.path.join(bpy.path.abspath("//"),
                             bpy.context.scene.phobosexportsettings.path)))
    else:
        # CHECK careful with path consistency (Windows)
        outpath = securepath(
            os.path.expanduser(bpy.context.scene.phobosexportsettings.path))

    # TODO delete me?
    # bake_outpath = securepath(os.path.join(outpath, modelname) if savetosubfolder else outpath)
    bake_outpath = outpath

    if bpy.context.scene.phobosexportsettings.structureExport:
        securepath(os.path.join(bake_outpath, 'bakes'))
        bake_outpath = os.path.join(bake_outpath, 'bakes/')

    export_name = modelname + '_' + posename

    visuals = [
        o for o in objlist if ("phobostype" in o and o.phobostype == "visual")
    ]
    if len(visuals) > 0:

        log("Baking model to " + bake_outpath, "INFO")
        sUtils.selectObjects(visuals, active=0)
        log("Copying objects for joining...", "INFO")
        bpy.ops.object.duplicate(linked=False, mode='TRANSLATION')
        log("Joining...", "INFO")
        bpy.ops.object.join()
        obj = bpy.context.active_object
        log("Deleting vertices...", "INFO")
        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.remove_doubles()
        bpy.ops.object.editmode_toggle()
        log("Adding modifier...", "INFO")

        bpy.ops.object.modifier_add(type='DECIMATE')
        bpy.context.object.modifiers["Decimate"].decimate_type = decimate_type
        if decimate_type == 'COLLAPSE':
            bpy.context.object.modifiers["Decimate"].ratio = decimate_parameter
        elif decimate_type == 'UNSUBDIV':
            bpy.context.object.modifiers[
                "Decimate"].iterations = decimate_parameter
        elif decimate_type == 'DISSOLVE':
            bpy.context.object.modifiers[
                "Decimate"].angle_limit = decimate_parameter

        log("Applying modifier...", "INFO")
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Decimate")
        obj.name = export_name + ".obj"

        # TODO use_selection might cause bugs, depending on Blender version
        bpy.ops.export_scene.obj(filepath=os.path.join(bake_outpath, obj.name),
                                 use_selection=True)

        obj.hide_render = True
        previewfile = export_name
        bUtils.createPreview(visuals,
                             export_path=bake_outpath,
                             modelname=modelname,
                             previewfile=previewfile)

        obj.select = True

        bpy.ops.object.delete()
        log("Done baking...", "INFO")

    else:
        log("No visuals to bake!", "WARNING")
Esempio n. 5
0
def bakeModel(objlist, modelname, posename="", decimate_type='COLLAPSE', decimate_parameter=0.1):
    """This function gets a list of objects and creates a single, simplified mesh from it and exports it to .stl.

    Args:
      objlist(list: list): The list of blender objects to join and export as simplified stl file.
      modelname(str): The new models name and filename.
      posename: (Default value = "")
      decimate_type: (Default value = 'COLLAPSE')
      decimate_parameter: (Default value = 0.1)
      objlist: 

    Returns:

    """
    if bpy.context.scene.phobosexportsettings.relativePath:
        # CHECK careful with path consistency (Windows)
        outpath = securepath(
            os.path.expanduser(
                os.path.join(bpy.path.abspath("//"), bpy.context.scene.phobosexportsettings.path)
            )
        )
    else:
        # CHECK careful with path consistency (Windows)
        outpath = securepath(os.path.expanduser(bpy.context.scene.phobosexportsettings.path))

    # TODO delete me?
    # bake_outpath = securepath(os.path.join(outpath, modelname) if savetosubfolder else outpath)
    bake_outpath = outpath

    if bpy.context.scene.phobosexportsettings.structureExport:
        securepath(os.path.join(bake_outpath, 'bakes'))
        bake_outpath = os.path.join(bake_outpath, 'bakes/')

    export_name = modelname + '_' + posename

    visuals = [o for o in objlist if ("phobostype" in o and o.phobostype == "visual")]
    if len(visuals) > 0:

        log("Baking model to " + bake_outpath, "INFO")
        sUtils.selectObjects(visuals, active=0)
        log("Copying objects for joining...", "INFO")
        bpy.ops.object.duplicate(linked=False, mode='TRANSLATION')
        log("Joining...", "INFO")
        bpy.ops.object.join()
        obj = bpy.context.active_object
        log("Deleting vertices...", "INFO")
        bpy.ops.object.editmode_toggle()
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.select_all(action='TOGGLE')
        bpy.ops.mesh.remove_doubles()
        bpy.ops.object.editmode_toggle()
        log("Adding modifier...", "INFO")

        bpy.ops.object.modifier_add(type='DECIMATE')
        bpy.context.object.modifiers["Decimate"].decimate_type = decimate_type
        if decimate_type == 'COLLAPSE':
            bpy.context.object.modifiers["Decimate"].ratio = decimate_parameter
        elif decimate_type == 'UNSUBDIV':
            bpy.context.object.modifiers["Decimate"].iterations = decimate_parameter
        elif decimate_type == 'DISSOLVE':
            bpy.context.object.modifiers["Decimate"].angle_limit = decimate_parameter

        log("Applying modifier...", "INFO")
        bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Decimate")
        obj.name = export_name + ".obj"

        # TODO use_selection might cause bugs, depending on Blender version
        bpy.ops.export_scene.obj(filepath=os.path.join(bake_outpath, obj.name), use_selection=True)

        obj.hide_render = True
        previewfile = export_name
        bUtils.createPreview(
            visuals, export_path=bake_outpath, modelname=modelname, previewfile=previewfile
        )

        obj.select = True

        bpy.ops.object.delete()
        log("Done baking...", "INFO")

    else:
        log("No visuals to bake!", "WARNING")