Beispiel #1
0
def __objects_delete__(unparented_objects):
    """Hookup function for objects delete operation

    :param unparented_objects: objects which were unparented during delete
    :type unparented_objects: list of bpy.types.Objects
    """

    # fix connections recalculations for unparented
    _connections_group_wrapper.force_recalculate(unparented_objects)
    _view3d_utils.tag_redraw_all_view3d()

    # delete unused previe models
    for obj in bpy.data.objects:
        if obj.type == 'MESH':
            if "scs_props" in obj.data and obj.data.scs_props.locator_preview_model_path != "" and not obj.parent:

                _preview_models.unlink(obj)
Beispiel #2
0
def __objects_delete__(unparented_objects):
    """Hookup function for objects delete operation

    :param unparented_objects: objects which were unparented during delete
    :type unparented_objects: list of bpy.types.Objects
    """

    # fix connections recalculations for unparented
    _connections_group_wrapper.force_recalculate(unparented_objects)
    _view3d_utils.tag_redraw_all_view3d()

    # delete unused previe models
    for obj in bpy.data.objects:
        if obj.type == 'MESH':
            if "scs_props" in obj.data and obj.data.scs_props.locator_preview_model_path != "" and not obj.parent:

                _preview_models.unlink(obj)
Beispiel #3
0
def object_data_check(scene):

    # during rendering in Blender active_object doesn't exists so ignore this case
    if not hasattr(bpy.context, "active_object"):
        return

    active_obj = bpy.context.active_object
    selected_objs = bpy.context.selected_objects

    # skip persistent check if import is in the process
    if _get_scs_globals().import_in_progress:
        return

    # CHECK FOR DATA CHANGE UPON SELECTION
    if active_obj:

        if active_obj.is_updated_data:
            _Timer.data_updated += 1

        if active_obj.is_updated:
            _Timer.updated += 1

        elif len(selected_objs) > 0:
            # search for any updated object
            for sel_obj in selected_objs[:2]:
                if sel_obj.is_updated:
                    _Timer.updated += 1
                    break
    if _Timer.updated > 0:
        _connections_group_wrapper.switch_to_update()

    # BREAK EXECUTION IF TIMER SAYS SO
    if not _Timer.can_execute():
        return

    # GET UPDATE STATES
    updated = _Timer.updated > 0
    data_updated = _Timer.data_updated > 0
    _Timer.updated = _Timer.data_updated = 0

    if not updated:
        _connections_group_wrapper.switch_to_stall()

    # NEW/COPY
    if len(scene.objects) > scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        if len(selected_objs) > 0:

            # create real selected list
            # (in case that one of selected objects is parent then children are not in this list)
            real_sel_objs = selected_objs.copy()
            for sel_obj in selected_objs:
                for child in sel_obj.children:
                    if child.select:
                        real_sel_objs.append(child)

            if real_sel_objs[0].scs_props.object_identity != "":

                old_objects = []
                for obj in real_sel_objs:
                    old_objects.append(
                        bpy.data.objects[obj.scs_props.object_identity])
                    obj.scs_props.object_identity = obj.name

                __objects_copy__(old_objects, real_sel_objs)

                lprint("D ---> COPY of the objects: %s",
                       (len(real_sel_objs), ))
                return
            else:

                for obj in real_sel_objs:
                    obj.scs_props.object_identity = obj.name

                lprint("D ---> NEW objects: %s", (len(real_sel_objs), ))
                return

    # DELETE
    if len(scene.objects) < scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        unparented_objects = []
        for obj in scene.objects:

            if obj.scs_props.parent_identity != "" and not obj.scs_props.parent_identity in bpy.data.objects:
                obj.scs_props.parent_identity = ""
                unparented_objects.append(obj)

            obj.scs_cached_num_children = len(obj.children)

        __objects_delete__(unparented_objects)

        lprint("D ---> DELETE of the objects!")
        return

    # if there is no active object then all of rest actions can not be executed at all
    if active_obj:

        # RENAME
        active_obj_identity = active_obj.scs_props.object_identity
        if active_obj.name != active_obj_identity and active_obj_identity != "":

            old_name = active_obj_identity
            new_name = active_obj.name

            active_obj.scs_props.object_identity = active_obj.name
            _fix_children(active_obj)

            __object_rename__(old_name, new_name)

            if old_name in bpy.data.objects:

                lprint("D ---> NAME SWITCHING")
                bpy.data.objects[old_name].scs_props.object_identity = old_name
                _fix_children(bpy.data.objects[old_name])

                # switching names causes invalid connections data so recalculate curves for these objects
                _connections_group_wrapper.force_recalculate(
                    [bpy.data.objects[old_name], bpy.data.objects[new_name]])

            lprint("D ---> RENAME of the active object!")
            return

        # RE/PARENT
        active_obj_children_count = len(active_obj.children)
        if active_obj_children_count > active_obj.scs_cached_num_children:

            active_obj.scs_cached_num_children = active_obj_children_count

            for obj in selected_objs:
                if obj != active_obj:

                    _fix_ex_parent(obj)
                    obj.scs_props.parent_identity = active_obj.name
                    obj.scs_cached_num_children = len(obj.children)

            __objects_reparent__(active_obj, selected_objs)

            lprint("D ---> RE/PARENT selected objects to active object %s",
                   (len(selected_objs), ))
            return

        if active_obj.parent and active_obj.parent.name != active_obj.scs_props.parent_identity:

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = active_obj.parent.name

            __objects_reparent__(active_obj.parent, [active_obj])

            lprint("D ---> RE/PARENT active object to some other parent")
            return

        # UNPARENT
        if not active_obj.select and not active_obj.parent and active_obj.scs_props.parent_identity != "":

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT active object in panel")
            return

        if ((not active_obj.parent
             and active_obj.scs_props.parent_identity != "")
                or (len(selected_objs) > 0 and not selected_objs[0].parent
                    and selected_objs[0].scs_props.parent_identity != "")):

            for obj in selected_objs:

                _fix_ex_parent(obj)
                obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT selected objects in 3D view: %s",
                   (len(selected_objs), ))
            return

        # ACTIVE SCS ROOT CHANGED
        active_scs_root = _object_utils.get_scs_root(active_obj)
        if active_scs_root and scene.scs_cached_active_scs_root != active_scs_root.name:

            __active_scs_root_change__(active_scs_root)

            scene.scs_cached_active_scs_root = active_scs_root.name
            lprint("D ---> ACTIVE SCS ROOT CHANGE: %r",
                   (active_scs_root.name, ))
            return

        # MATERIAL ASSIGNEMENT ACTION
        if data_updated or updated:

            mats_ids = {}
            new_mats = {}
            removed_mats = dict(active_obj.scs_cached_materials_ids)
            for slot in active_obj.material_slots:
                if slot.material:
                    curr_id = str(slot.material.scs_props.id)
                    mats_ids[curr_id] = 1
                    if curr_id not in active_obj.scs_cached_materials_ids:  # if not in cached -> it's newly assigned
                        new_mats[curr_id] = 1
                    elif curr_id in removed_mats:  # if in cached remove it from dictionary which stores removed materials
                        del removed_mats[curr_id]

            if len(new_mats) > 0 or len(removed_mats) > 0:
                active_obj.scs_cached_materials_ids = mats_ids

                __material_assignement__(active_obj, new_mats.keys(),
                                         removed_mats.keys())

                lprint("D ---> MATERIAL ASSIGNEMENT CHANGED")
                return
Beispiel #4
0
def object_data_check(scene):

    # during rendering in Blender active_object doesn't exists so ignore this case
    if not hasattr(bpy.context, "active_object"):
        return

    active_obj = bpy.context.active_object
    selected_objs = bpy.context.selected_objects

    # skip persistent check if import is in the process
    if _get_scs_globals().import_in_progress:
        return

    # CHECK FOR DATA CHANGE UPON SELECTION
    if active_obj:

        if active_obj.is_updated_data:
            _Timer.data_updated += 1

        if active_obj.is_updated:
            _Timer.updated += 1

        elif len(selected_objs) > 0:
            # search for any updated object
            for sel_obj in selected_objs[:2]:
                if sel_obj.is_updated:
                    _Timer.updated += 1
                    break
    if _Timer.updated > 0:
        _connections_group_wrapper.switch_to_update()

    # BREAK EXECUTION IF TIMER SAYS SO
    if not _Timer.can_execute():
        return

    # GET UPDATE STATES
    updated = _Timer.updated > 0
    data_updated = _Timer.data_updated > 0
    _Timer.updated = _Timer.data_updated = 0

    if not updated:
        _connections_group_wrapper.switch_to_stall()

    # NEW/COPY
    if len(scene.objects) > scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        if len(selected_objs) > 0:

            # create real selected list
            # (in case that one of selected objects is parent then children are not in this list)
            real_sel_objs = selected_objs.copy()
            for sel_obj in selected_objs:
                for child in sel_obj.children:
                    if child.select:
                        real_sel_objs.append(child)

            if real_sel_objs[0].scs_props.object_identity != "":

                old_objects = []
                for obj in real_sel_objs:
                    old_objects.append(bpy.data.objects[obj.scs_props.object_identity])
                    obj.scs_props.object_identity = obj.name

                __objects_copy__(old_objects, real_sel_objs)

                lprint("D ---> COPY of the objects: %s", (len(real_sel_objs),))
                return
            else:

                for obj in real_sel_objs:
                    obj.scs_props.object_identity = obj.name

                lprint("D ---> NEW objects: %s", (len(real_sel_objs),))
                return

    # DELETE
    if len(scene.objects) < scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        unparented_objects = []
        for obj in scene.objects:

            if obj.scs_props.parent_identity != "" and not obj.scs_props.parent_identity in bpy.data.objects:
                obj.scs_props.parent_identity = ""
                unparented_objects.append(obj)

            obj.scs_cached_num_children = len(obj.children)

        __objects_delete__(unparented_objects)

        lprint("D ---> DELETE of the objects!")
        return

    # if there is no active object then all of rest actions can not be executed at all
    if active_obj:

        # RENAME
        active_obj_identity = active_obj.scs_props.object_identity
        if active_obj.name != active_obj_identity and active_obj_identity != "":

            old_name = active_obj_identity
            new_name = active_obj.name

            active_obj.scs_props.object_identity = active_obj.name
            _fix_children(active_obj)

            __object_rename__(old_name, new_name)

            if old_name in bpy.data.objects:

                lprint("D ---> NAME SWITCHING")
                bpy.data.objects[old_name].scs_props.object_identity = old_name
                _fix_children(bpy.data.objects[old_name])

                # switching names causes invalid connections data so recalculate curves for these objects
                _connections_group_wrapper.force_recalculate([bpy.data.objects[old_name], bpy.data.objects[new_name]])

            lprint("D ---> RENAME of the active object!")
            return

        # RE/PARENT
        active_obj_children_count = len(active_obj.children)
        if active_obj_children_count > active_obj.scs_cached_num_children:

            active_obj.scs_cached_num_children = active_obj_children_count

            for obj in selected_objs:
                if obj != active_obj:

                    _fix_ex_parent(obj)
                    obj.scs_props.parent_identity = active_obj.name
                    obj.scs_cached_num_children = len(obj.children)

            __objects_reparent__(active_obj, selected_objs)

            lprint("D ---> RE/PARENT selected objects to active object %s", (len(selected_objs),))
            return

        if active_obj.parent and active_obj.parent.name != active_obj.scs_props.parent_identity:

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = active_obj.parent.name

            __objects_reparent__(active_obj.parent, [active_obj])

            lprint("D ---> RE/PARENT active object to some other parent")
            return

        # UNPARENT
        if not active_obj.select and not active_obj.parent and active_obj.scs_props.parent_identity != "":

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT active object in panel")
            return

        if ((not active_obj.parent and active_obj.scs_props.parent_identity != "") or
                (len(selected_objs) > 0 and not selected_objs[0].parent and selected_objs[0].scs_props.parent_identity != "")):

            for obj in selected_objs:

                _fix_ex_parent(obj)
                obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT selected objects in 3D view: %s", (len(selected_objs),))
            return

        # ACTIVE SCS ROOT CHANGED
        active_scs_root = _object_utils.get_scs_root(active_obj)
        if active_scs_root and scene.scs_cached_active_scs_root != active_scs_root.name:

            __active_scs_root_change__(active_scs_root)

            scene.scs_cached_active_scs_root = active_scs_root.name
            lprint("D ---> ACTIVE SCS ROOT CHANGE: %r", (active_scs_root.name,))
            return

        # MATERIAL ASSIGNEMENT ACTION
        if data_updated or updated:

            mats_ids = {}
            new_mats = {}
            removed_mats = dict(active_obj.scs_cached_materials_ids)
            for slot in active_obj.material_slots:
                if slot.material:
                    curr_id = str(slot.material.scs_props.id)
                    mats_ids[curr_id] = 1
                    if curr_id not in active_obj.scs_cached_materials_ids:  # if not in cached -> it's newly assigned
                        new_mats[curr_id] = 1
                    elif curr_id in removed_mats:  # if in cached remove it from dictionary which stores removed materials
                        del removed_mats[curr_id]

            if len(new_mats) > 0 or len(removed_mats) > 0:
                active_obj.scs_cached_materials_ids = mats_ids

                __material_assignement__(active_obj, new_mats.keys(), removed_mats.keys())

                lprint("D ---> MATERIAL ASSIGNEMENT CHANGED")
                return
Beispiel #5
0
def object_data_check(scene):
    active_obj = bpy.context.active_object
    selected_objs = bpy.context.selected_objects

    # skip persistent check if import is in the process
    if _get_scs_globals().import_in_progress:
        return

    # CHECK FOR DATA CHANGE UPON SELECTION
    updating = False
    if active_obj:
        if active_obj.is_updated:
            updating = True
            lprint("D ---> DATA UPDATE ON ACTIVE: %r", (time(),))

        elif len(selected_objs) > 0:
            # search for any updated object
            for sel_obj in selected_objs[:2]:
                if sel_obj.is_updated:
                    updating = True
                    lprint("D ---> DATA UPDATE ON SELECTED: %r", (time(),))
                    break
    if updating:
        _connections_group_wrapper.switch_to_update()

    if _Timer.can_execute():
        if not updating:
            _connections_group_wrapper.switch_to_stall()
    else:
        return

    # NEW/COPY
    if len(scene.objects) > scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        if len(selected_objs) > 0:

            # create real selected list
            # (in case that one of selected objects is parent then children are not in this list)
            real_sel_objs = selected_objs.copy()
            for sel_obj in selected_objs:
                for child in sel_obj.children:
                    if child.select:
                        real_sel_objs.append(child)

            if real_sel_objs[0].scs_props.object_identity != "":

                old_objects = []
                for obj in real_sel_objs:
                    old_objects.append(bpy.data.objects[obj.scs_props.object_identity])
                    obj.scs_props.object_identity = obj.name

                __objects_copy__(old_objects, real_sel_objs)

                lprint("D ---> COPY of the objects: %s", (len(real_sel_objs),))
                return
            else:

                for obj in real_sel_objs:
                    obj.scs_props.object_identity = obj.name

                lprint("D ---> NEW objects: %s", (len(real_sel_objs),))
                return

    # DELETE
    if len(scene.objects) < scene.scs_cached_num_objects:

        scene.scs_cached_num_objects = len(scene.objects)

        unparented_objects = []
        for obj in scene.objects:

            if obj.scs_props.parent_identity != "" and not obj.scs_props.parent_identity in bpy.data.objects:
                obj.scs_props.parent_identity = ""
                unparented_objects.append(obj)

            obj.scs_cached_num_children = len(obj.children)

        __objects_delete__(unparented_objects)

        lprint("D ---> DELETE of the objects!")
        return

    # if there is no active object then all of rest actions can not be executed at all
    if active_obj:

        # RENAME
        active_obj_identity = active_obj.scs_props.object_identity
        if active_obj.name != active_obj_identity and active_obj_identity != "":

            old_name = active_obj_identity
            new_name = active_obj.name

            active_obj.scs_props.object_identity = active_obj.name

            __object_rename__(old_name, new_name)

            if old_name in bpy.data.objects:

                lprint("D ---> NAME SWITCHING")
                bpy.data.objects[old_name].scs_props.object_identity = old_name
                # switching names causes invalid connections data so recalculate curves for these objects
                _connections_group_wrapper.force_recalculate([bpy.data.objects[old_name], bpy.data.objects[new_name]])

            lprint("D ---> RENAME of the active object!")
            return

        # RE/PARENT
        active_obj_children_count = len(active_obj.children)
        if active_obj_children_count > active_obj.scs_cached_num_children:

            active_obj.scs_cached_num_children = active_obj_children_count

            for obj in selected_objs:
                if obj != active_obj:

                    _fix_ex_parent(obj)
                    obj.scs_props.parent_identity = active_obj.name
                    obj.scs_cached_num_children = len(obj.children)

            __objects_reparent__(active_obj, selected_objs)

            lprint("D ---> RE/PARENT selected objects to active object %s", (len(selected_objs),))
            return

        if active_obj.parent and active_obj.parent.name != active_obj.scs_props.parent_identity:

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = active_obj.parent.name

            __objects_reparent__(active_obj.parent, [active_obj])

            lprint("D ---> RE/PARENT active object to some other parent")
            return

        # UNPARENT
        if not active_obj.select and not active_obj.parent and active_obj.scs_props.parent_identity != "":

            _fix_ex_parent(active_obj)
            active_obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT active object in panel")
            return

        if ((not active_obj.parent and active_obj.scs_props.parent_identity != "") or
                (len(selected_objs) > 0 and not selected_objs[0].parent and selected_objs[0].scs_props.parent_identity != "")):

            for obj in selected_objs:

                _fix_ex_parent(obj)
                obj.scs_props.parent_identity = ""

            lprint("D ---> UNPARENT selected objects in 3D view: %s", (len(selected_objs),))
            return