Esempio n. 1
0
def getExportEntities():
    # DOCU add some docstring
    if getExpSettings().selectedOnly:
        roots = [obj for obj in sUtils.getSelectedObjects() if sUtils.isEntity(obj)]
    else:
        roots = [obj for obj in bpy.context.scene.objects if sUtils.isEntity(obj)]
    return roots
Esempio n. 2
0
def getEntityRoots():
    """Returns all objects for which entity properties are specified.

    This list typically consits

    Returns:

    """
    if getExpSettings().selectedOnly:
        roots = [
            obj for obj in sUtils.getSelectedObjects() if sUtils.isEntity(obj)
        ]
    else:
        roots = [
            obj for obj in bpy.context.scene.objects if sUtils.isEntity(obj)
        ]
    return roots
Esempio n. 3
0
File: io.py Progetto: snrkiwi/phobos
def getEntityRoots():
    """Returns all objects for which entity properties are specified.

    Returns:
        list: roots of well-defined entities in the scene

    """
    roots = [obj for obj in bpy.context.scene.objects if sUtils.isEntity(obj)
             and (not getExpSettings().selectedOnly or obj.select)]
    return roots
Esempio n. 4
0
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))
Esempio n. 5
0
def getEntityRoots():
    """Returns all objects for which entity properties are specified.

    Args:

    Returns:
      list: roots of well-defined entities in the scene

    """
    roots = [
        obj
        for obj in bpy.context.scene.objects
        if sUtils.isEntity(obj) and (not getExpSettings().selectedOnly or obj.select)
    ]
    return roots