예제 #1
0
def _get_objects_by_type(blender_objects, parts):
    """Gets lists for different types of objects used by SCS.
    It actually returns: mesh objects, locators (prefab, model, collision) and armature object.

    :param blender_objects: list of the objects that should be sorted by type
    :type blender_objects: list of bpy.types.Object
    :param parts: transitional parts class instance for adding users (parts without users won't be exported)
    :type parts: io_scs_tools.exp.transition_structs.parts.PartsTrans
    :return: more lists of objects in order: meshes, prefab_locators, model_locators, collision_locators and armutare object as last
    :rtype: list of [list]
    """

    prefab_locator_list = []
    model_locator_list = []
    collision_locator_list = []
    mesh_object_list = []
    armature_object = None

    for obj in blender_objects:

        # LOCATORS
        if obj.type == 'EMPTY':
            if obj.scs_props.locator_type == 'Prefab':
                prefab_locator_list.append(obj)

                if _object_utils.has_part_property(obj):
                    parts.add_user(obj)

            elif obj.scs_props.locator_type == 'Model':
                model_locator_list.append(obj)

                parts.add_user(obj)

            elif obj.scs_props.locator_type == 'Collision':
                collision_locator_list.append(obj)

                parts.add_user(obj)

        # ARMATURES
        elif obj.type == 'ARMATURE':
            if not armature_object:
                armature_object = obj
            else:
                lprint(
                    "W More armatures detected on SCS Root object, only first one will be used!"
                )

        # MESHES
        elif obj.type == 'MESH':

            # MESH OBJECTS
            if obj.data.scs_props.locator_preview_model_path == "":  # Export object only if it's not a Preview Model...
                mesh_object_list.append(obj)

                parts.add_user(obj)

        else:
            print('!!! - Unhandled object type: %r' % str(obj.type))

    return mesh_object_list, prefab_locator_list, model_locator_list, collision_locator_list, armature_object
예제 #2
0
def __objects_reparent__(parent, new_objs):
    """Hookup function for objects reparent operation.

    :param parent: parent object where all of the objects were parented
    :type parent: bpy.types.Object
    :param new_objs: list of object which were parented to object
    :type new_objs: list of bpy.types.Object
    """

    # fixing parts on newly parented object
    scs_root_object = _object_utils.get_scs_root(parent)
    if scs_root_object:

        part_inventory = scs_root_object.scs_object_part_inventory
        assign_part_index = scs_root_object.scs_props.active_scs_part

        # if active is out of range assign first one
        if assign_part_index >= len(part_inventory) or assign_part_index < 0:
            assign_part_index = 0

        new_mats = []
        for new_obj in new_objs:
            if _object_utils.has_part_property(new_obj):
                new_obj.scs_props.scs_part = part_inventory[
                    assign_part_index].name

            for slot in new_obj.material_slots:
                if slot.material and slot.material not in new_mats:
                    new_mats.append(slot.material)

        _looks.add_materials(scs_root_object, new_mats)
예제 #3
0
    def locator_type_update(self, context):

        obj = context.object

        # PREVIEW MODELS LOADING
        if obj.scs_props.locator_type in ("Collision", "None"):
            _preview_models.unload(obj)
        elif not obj.scs_props.locator_preview_model_present:
            _preview_models.load(obj)

        # SCS_PART RESET
        if not _object_utils.has_part_property(obj):
            obj.scs_props.scs_part = ""
        else:

            scs_root_object = _object_utils.get_scs_root(obj)

            if scs_root_object:

                part_inventory = scs_root_object.scs_object_part_inventory

                # set part index to active or first
                # NOTE: direct access needed otherwise get function sets invalid index because
                # active object has still old part value
                part_index = scs_root_object.scs_props.active_scs_part_get_direct()
                if part_index >= len(part_inventory) or part_index < 0:
                    part_index = 0

                obj.scs_props.scs_part = part_inventory[part_index].name

            else:  # if no root assign default

                obj.scs_props.scs_part = _PART_consts.default_name
예제 #4
0
    def locator_type_update(self, context):

        obj = context.object

        # PREVIEW MODELS LOADING
        if obj.scs_props.locator_type in ("Collision", "None"):
            _preview_models.unload(obj)
        elif not obj.scs_props.locator_preview_model_present:
            _preview_models.load(obj)

        # SCS_PART RESET
        if not _object_utils.has_part_property(obj):
            obj.scs_props.scs_part = ""
        else:

            scs_root_object = _object_utils.get_scs_root(obj)

            if scs_root_object:

                part_inventory = scs_root_object.scs_object_part_inventory

                # set part index to active or first
                # NOTE: direct access needed otherwise get function sets invalid index because
                # active object has still old part value
                part_index = scs_root_object.scs_props.active_scs_part_get_direct(
                )
                if part_index >= len(part_inventory) or part_index < 0:
                    part_index = 0

                obj.scs_props.scs_part = part_inventory[part_index].name

            else:  # if no root assign default

                obj.scs_props.scs_part = _PART_consts.default_name
예제 #5
0
def __objects_reparent__(parent, new_objs):
    """Hookup function for objects reparent operation.

    :param parent: parent object where all of the objects were parented
    :type parent: bpy.types.Object
    :param new_objs: list of object which were parented to object
    :type new_objs: list of bpy.types.Object
    """

    # fixing parts on newly parented object
    scs_root_object = _object_utils.get_scs_root(parent)
    if scs_root_object:

        part_inventory = scs_root_object.scs_object_part_inventory
        assign_part_index = scs_root_object.scs_props.active_scs_part

        # if active is out of range assign first one
        if assign_part_index >= len(part_inventory) or assign_part_index < 0:
            assign_part_index = 0

        new_mats = []
        for new_obj in new_objs:
            if _object_utils.has_part_property(new_obj):
                new_obj.scs_props.scs_part = part_inventory[assign_part_index].name

            for slot in new_obj.material_slots:
                if slot.material and slot.material not in new_mats:
                    new_mats.append(slot.material)

        _looks.add_materials(scs_root_object, new_mats)
예제 #6
0
def __objects_reparent__(parent, new_objs):
    """Hookup function for objects reparent operation.

    :param parent: parent object where all of the objects were parented
    :type parent: bpy.types.Object
    :param new_objs: list of object which were parented to object
    :type new_objs: list of bpy.types.Object
    """

    # fixing parts on newly parented object
    scs_root_object = _object_utils.get_scs_root(parent)
    if scs_root_object:

        part_inventory = scs_root_object.scs_object_part_inventory
        assign_part_index = scs_root_object.scs_props.active_scs_part

        # if active is out of range assign first one
        if assign_part_index >= len(part_inventory) or assign_part_index < 0:
            assign_part_index = 0

        new_mats = []
        for new_obj in new_objs:
            # NOTE: second condition prevents overwriting part on object which already have
            # valid part from before (This might happen when re-parenting from one SCS Root to another)
            if _object_utils.has_part_property(
                    new_obj
            ) and new_obj.scs_props.scs_part not in part_inventory:
                new_obj.scs_props.scs_part = part_inventory[
                    assign_part_index].name

            for slot in new_obj.material_slots:
                if slot.material and slot.material not in new_mats:
                    new_mats.append(slot.material)

        _looks.add_materials(scs_root_object, new_mats)
예제 #7
0
def __objects_reparent__(parent, new_objs):
    """Hookup function for objects reparent operation.

    :param parent: parent object where all of the objects were parented
    :type parent: bpy.types.Object
    :param new_objs: list of object which were parented to object
    :type new_objs: list of bpy.types.Object
    """

    # fixing parts on newly parented object
    scs_root_object = _object_utils.get_scs_root(parent)
    if scs_root_object:

        part_inventory = scs_root_object.scs_object_part_inventory
        assign_part_index = scs_root_object.scs_props.active_scs_part

        # if active is out of range assign first one
        if assign_part_index >= len(part_inventory) or assign_part_index < 0:
            assign_part_index = 0

        new_mats = []
        for new_obj in new_objs:
            # NOTE: second condition prevents overwriting part on object which already have
            # valid part from before (This might happen when re-parenting from one SCS Root to another)
            if _object_utils.has_part_property(new_obj) and new_obj.scs_props.scs_part not in part_inventory:
                new_obj.scs_props.scs_part = part_inventory[assign_part_index].name

            for slot in new_obj.material_slots:
                if slot.material and slot.material not in new_mats:
                    new_mats.append(slot.material)

        _looks.add_materials(scs_root_object, new_mats)
예제 #8
0
파일: pix.py 프로젝트: rridhan/BlenderTools
def _get_objects_by_type(blender_objects, parts):
    """Gets lists for different types of objects used by SCS.
    It actually returns: mesh objects, locators (prefab, model, collision) and armature object.

    :param blender_objects: list of the objects that should be sorted by type
    :type blender_objects: list of bpy.types.Object
    :param parts: transitional parts class instance to collect parts to
    :type parts: io_scs_tools.exp.transition_structs.parts.PartsTrans
    :return: more lists of objects in order: meshes, prefab_locators, model_locators, collision_locators and armutare object as last
    :rtype: list of [list]
    """

    prefab_locator_list = []
    model_locator_list = []
    collision_locator_list = []
    mesh_object_list = []
    armature_object = None

    for obj in blender_objects:

        # LOCATORS
        if obj.type == "EMPTY":
            if obj.scs_props.locator_type == "Prefab":
                prefab_locator_list.append(obj)

                if _object_utils.has_part_property(obj):
                    parts.add(obj.scs_props.scs_part)

            elif obj.scs_props.locator_type == "Model":
                model_locator_list.append(obj)

                parts.add(obj.scs_props.scs_part)

            elif obj.scs_props.locator_type == "Collision":
                collision_locator_list.append(obj)

                parts.add(obj.scs_props.scs_part)

        # ARMATURES
        elif obj.type == "ARMATURE":
            if not armature_object:
                armature_object = obj
            else:
                lprint("W More armatures detected on SCS Root object, only first one will be used!")

        # MESHES
        elif obj.type == "MESH":

            # MESH OBJECTS
            if obj.data.scs_props.locator_preview_model_path == "":  # Export object only if it's not a Preview Model...
                mesh_object_list.append(obj)

                parts.add(obj.scs_props.scs_part)

        else:
            print("!!! - Unhandled object type: %r" % str(obj.type))

    return mesh_object_list, prefab_locator_list, model_locator_list, collision_locator_list, armature_object
예제 #9
0
    def locator_type_update(self, context):

        obj = context.object

        # safety check to ensure we are dealing with proper object
        # NOTE: if this gets triggered during import, it's very likely that another object
        # was already set as active. In that case error might occur while accessing scs properties.
        if not hasattr(obj, "scs_props"):
            return

        # PREVIEW MODELS LOADING
        if obj.scs_props.locator_type in ("Collision", "None"):
            _preview_models.unload(obj)
        elif not obj.scs_props.locator_preview_model_present:
            _preview_models.load(obj)

        # SCS_PART RESET
        if not _object_utils.has_part_property(obj):
            obj.scs_props.scs_part = ""
        else:

            scs_root_object = _object_utils.get_scs_root(obj)

            if scs_root_object:

                part_inventory = scs_root_object.scs_object_part_inventory

                # set part index to active or first
                # NOTE: direct access needed otherwise get function sets invalid index because
                # active object has still old part value
                part_index = scs_root_object.scs_props.active_scs_part_get_direct(
                )
                if part_index >= len(part_inventory) or part_index < 0:
                    part_index = 0

                obj.scs_props.scs_part = part_inventory[part_index].name

            else:  # if no root assign default

                obj.scs_props.scs_part = _PART_consts.default_name