Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
def __material_assignement__(obj, new_mat_ids, removed_mat_ids):
    """Hookup function for material reassignement on object.

    :param obj: object on which material assignement happend
    :type obj: bpy.types.Object
    :param new_mat_ids: ID of newly added materials
    :type new_mat_ids: iter
    :param removed_mat_ids: ID of removed materials
    :type removed_mat_ids: iter
    """

    # create actual new materials list
    new_mats = []
    for mat in bpy.data.materials:
        curr_mat_id = str(mat.scs_props.id)
        if curr_mat_id in new_mat_ids:
            new_mats.append(mat)

    scs_root = _object_utils.get_scs_root(obj)
    if scs_root:
        _looks.add_materials(scs_root, new_mats)
        if len(removed_mat_ids) > 0:
            _looks.clean_unused(scs_root)
Esempio n. 6
0
def __material_assignement__(obj, new_mat_ids, removed_mat_ids):
    """Hookup function for material reassignement on object.

    :param obj: object on which material assignement happend
    :type obj: bpy.types.Object
    :param new_mat_ids: ID of newly added materials
    :type new_mat_ids: iter
    :param removed_mat_ids: ID of removed materials
    :type removed_mat_ids: iter
    """

    # create actual new materials list
    new_mats = []
    for mat in bpy.data.materials:
        curr_mat_id = str(mat.scs_props.id)
        if curr_mat_id in new_mat_ids:
            new_mats.append(mat)

    scs_root = _object_utils.get_scs_root(obj)
    if scs_root:
        _looks.add_materials(scs_root, new_mats)
        if len(removed_mat_ids) > 0:
            _looks.clean_unused(scs_root)
Esempio n. 7
0
def make_scs_root_object(context, dialog=False):
    # FAIRLY SMART SELECTION OF SCS GAME OBJECT CONTENT
    scs_game_object_content = []
    for obj in context.selected_objects:
        if not obj.parent:
            scs_game_object_content.append(obj)
        else:
            if not obj.parent.select:
                scs_game_object_content.append(obj)

    # ADD SCS ROOT OBJECT (EMPTY OBJECT)
    bpy.ops.object.empty_add(
        view_align=False,
        location=context.scene.cursor_location,
    )

    # SET PROPERTIES

    name = _name.get_unique("game_object", bpy.data.objects)
    bpy.context.active_object.name = name
    new_scs_root = bpy.data.objects.get(name)
    new_scs_root.scs_props.scs_root_object_export_enabled = True
    new_scs_root.scs_props.empty_object_type = 'SCS_Root'

    # SET A NEW NAME DIALOG
    if dialog:
        bpy.ops.object.add_scs_root_object_dialog_operator('INVOKE_DEFAULT')

    # PARENT OBJECTS TO SCS ROOT OBJECT
    part_inventory = new_scs_root.scs_object_part_inventory
    if len(scs_game_object_content) > 0:

        bpy.ops.object.select_all(action='DESELECT')

        new_scs_root_mats = []
        # select content object for parenting later
        for obj in scs_game_object_content:
            obj.select = True

            # fix old parent with new children number and cleaned looks
            if obj.parent:
                ex_parent_obj = obj.parent
                obj.parent = None

                ex_parent_obj.scs_cached_num_children = len(
                    ex_parent_obj.children)

                ex_parent_scs_root = get_scs_root(ex_parent_obj)
                if ex_parent_scs_root:
                    _looks.clean_unused(ex_parent_scs_root)

            obj.scs_props.parent_identity = new_scs_root.name
            obj.scs_cached_num_children = len(obj.children)

            for slot in obj.material_slots:
                if slot.material and slot.material not in new_scs_root_mats:
                    new_scs_root_mats.append(slot.material)

        _looks.add_materials(new_scs_root, new_scs_root_mats)

        bpy.ops.object.parent_set(type='OBJECT', keep_transform=False)
        bpy.ops.object.select_all(action='DESELECT')
        new_scs_root.select = True

        # fix children count to prevent persistent to hook up
        new_scs_root.scs_cached_num_children = len(new_scs_root.children)

        for part_name in collect_parts_on_root(new_scs_root):
            _inventory.add_item(part_inventory, part_name)

    # MAKE DEFAULT PART IF THERE IS NO PARTS
    if len(part_inventory) == 0:
        _inventory.add_item(part_inventory, _PART_consts.default_name)

    return new_scs_root
Esempio n. 8
0
def make_scs_root_object(context, dialog=False):
    # FAIRLY SMART SELECTION OF SCS GAME OBJECT CONTENT
    scs_game_object_content = []
    for obj in context.selected_objects:
        if not obj.parent:
            scs_game_object_content.append(obj)
        else:
            if not obj.parent.select:
                scs_game_object_content.append(obj)

    # ADD SCS ROOT OBJECT (EMPTY OBJECT)
    bpy.ops.object.empty_add(view_align=False, location=context.scene.cursor_location)

    # SET PROPERTIES

    name = _name.get_unique("game_object", bpy.data.objects)
    bpy.context.active_object.name = name
    new_scs_root = bpy.data.objects.get(name)
    new_scs_root.scs_props.scs_root_object_export_enabled = True
    new_scs_root.scs_props.empty_object_type = "SCS_Root"

    # SET A NEW NAME DIALOG
    if dialog:
        bpy.ops.object.add_scs_root_object_dialog_operator("INVOKE_DEFAULT")

    # PARENT OBJECTS TO SCS ROOT OBJECT
    part_inventory = new_scs_root.scs_object_part_inventory
    if len(scs_game_object_content) > 0:

        bpy.ops.object.select_all(action="DESELECT")

        new_scs_root_mats = []
        # select content object for parenting later
        for obj in scs_game_object_content:
            obj.select = True

            # fix old parent with new children number and cleaned looks
            if obj.parent:
                ex_parent_obj = obj.parent
                obj.parent = None

                ex_parent_obj.scs_cached_num_children = len(ex_parent_obj.children)

                ex_parent_scs_root = get_scs_root(ex_parent_obj)
                if ex_parent_scs_root:
                    _looks.clean_unused(ex_parent_scs_root)

            obj.scs_props.parent_identity = new_scs_root.name
            obj.scs_cached_num_children = len(obj.children)

            for slot in obj.material_slots:
                if slot.material and slot.material not in new_scs_root_mats:
                    new_scs_root_mats.append(slot.material)

        _looks.add_materials(new_scs_root, new_scs_root_mats)

        bpy.ops.object.parent_set(type="OBJECT", keep_transform=False)
        bpy.ops.object.select_all(action="DESELECT")
        new_scs_root.select = True

        # fix children count to prevent persistent to hook up
        new_scs_root.scs_cached_num_children = len(new_scs_root.children)

        for part_name in collect_parts_on_root(new_scs_root):
            _inventory.add_item(part_inventory, part_name)

    # MAKE DEFAULT PART IF THERE IS NO PARTS
    if len(part_inventory) == 0:
        _inventory.add_item(part_inventory, _PART_consts.default_name)

    return new_scs_root