Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def __objects_copy__(old_objects, new_objects):
    """Hookup function for objects copy operation.

    :param old_objects: old objects from which new ones were created
    :type old_objects: list of bpy.types.Object
    :param new_objects: copies of old objects
    :type new_objects: list of bpy.types.Object
    """

    # try to copy connections for new objects
    _connections_group_wrapper.copy_check(old_objects, new_objects)
    _view3d_utils.tag_redraw_all_view3d()

    # also check for any preview models which should be also copied to new ones
    for i, old_obj in enumerate(old_objects):

        if old_obj.scs_props.locator_preview_model_present:
            _preview_models.load(new_objects[i])
Exemplo n.º 4
0
def __objects_copy__(old_objects, new_objects):
    """Hookup function for objects copy operation.

    :param old_objects: old objects from which new ones were created
    :type old_objects: list of bpy.types.Object
    :param new_objects: copies of old objects
    :type new_objects: list of bpy.types.Object
    """

    # try to copy connections for new objects
    _connections_group_wrapper.copy_check(old_objects, new_objects)
    _view3d_utils.tag_redraw_all_view3d()

    # also check for any preview models which should be also copied to new ones
    for i, old_obj in enumerate(old_objects):

        if old_obj.scs_props.locator_preview_model_present:
            _preview_models.load(new_objects[i])
Exemplo n.º 5
0
    def locator_show_preview_model_update(self, context):
        """Update function for Locator Show Preview Model record on Objects.

        :param context: Blender Context
        :type context: bpy.types.Context
        :return: None
        """
        obj = context.object

        if not _preview_models.load(obj):
            _preview_models.unload(obj)
        return None
Exemplo n.º 6
0
    def locator_show_preview_model_update(self, context):
        """Update function for Locator Show Preview Model record on Objects.

        :param context: Blender Context
        :type context: bpy.types.Context
        :return: None
        """
        obj = context.object

        if not _preview_models.load(obj):
            _preview_models.unload(obj)
        return None
Exemplo n.º 7
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
Exemplo n.º 8
0
    def show_preview_models_update(self, context):
        """
        :param context:
        :return:
        """
        scene = context.scene

        for obj in bpy.data.objects:
            if obj.type == 'EMPTY':
                if scene.scs_props.show_preview_models:
                    if not _preview_models.load(obj):
                        _preview_models.unload(obj)
                else:
                    _preview_models.unload(obj)
        return None
Exemplo n.º 9
0
    def show_preview_models_update(self, context):
        """
        :param context:
        :return:
        """
        scene = context.scene

        for obj in bpy.data.objects:
            if obj.type == 'EMPTY':
                if scene.scs_props.show_preview_models:
                    if not _preview_models.load(obj):
                        _preview_models.unload(obj)
                else:
                    _preview_models.unload(obj)
        return None
Exemplo n.º 10
0
    def locator_preview_model_path_update(self, context):
        """Update function for Locator Preview Model record on Objects.

        :param context: Blender Context
        :type context: bpy.types.Context
        :return: None
        """
        obj = context.object

        if _preview_models.load(obj):

            # fix selection because in case of actual loading model from file selection will be messed up
            obj.select = True
            bpy.context.scene.objects.active = obj

        else:

            _preview_models.unload(obj)

        return None
Exemplo n.º 11
0
    def locator_preview_model_path_update(self, context):
        """Update function for Locator Preview Model record on Objects.

        :param context: Blender Context
        :type context: bpy.types.Context
        :return: None
        """
        obj = context.object

        if _preview_models.load(obj):

            # fix selection because in case of actual loading model from file selection will be messed up
            obj.select = True
            bpy.context.scene.objects.active = obj

        else:

            _preview_models.unload(obj)

        return None
Exemplo n.º 12
0
def _get_custom_visual_elements():
    """Returns dictionaries of elements, that require custom OpenGL drawing in 3D viewports."""
    prefab_locators = {}
    collision_locators = {}
    model_locators = {}

    scs_globals = _get_scs_globals()

    # print(' time: %s' % str(time()))

    def set_locators_original_draw_size(obj):
        """Set original drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        # _object.set_attr_if_different(obj, "empty_draw_size", obj.scs_props.locators_orig_draw_size)
        if obj.empty_draw_size != obj.scs_props.locators_orig_draw_size:
            obj.empty_draw_size = obj.scs_props.locators_orig_draw_size
            obj.scs_props.locators_orig_draw_size = 0.0
        if obj.empty_draw_type != obj.scs_props.locators_orig_draw_type:
            obj.empty_draw_type = obj.scs_props.locators_orig_draw_type
            obj.scs_props.locators_orig_draw_type = ''

    def store_locators_original_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        if obj.scs_props.locators_orig_draw_size == 0.0:
            _object_utils.set_attr_if_different(obj.scs_props,
                                                "locators_orig_draw_size",
                                                obj.empty_draw_size)
            _object_utils.set_attr_if_different(obj.scs_props,
                                                "locators_orig_draw_type",
                                                obj.empty_draw_type)

    def set_locators_prefab_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = scs_globals.locator_empty_size * scs_globals.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size",
                                            new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type",
                                            'PLAIN_AXES')

    def set_locators_model_draw_size(obj):
        """Set Model Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = scs_globals.locator_empty_size * scs_globals.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size",
                                            new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type",
                                            'PLAIN_AXES')

    def set_locators_coll_draw_size(obj):
        """Set Collision Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = 0.5
        if obj.scs_props.locator_collider_type == 'Box':
            bigest_value = max(obj.scs_props.locator_collider_box_x,
                               obj.scs_props.locator_collider_box_y,
                               obj.scs_props.locator_collider_box_z)
            new_draw_size = (0.1 * bigest_value) * 12
        elif obj.scs_props.locator_collider_type in ('Sphere', 'Capsule',
                                                     'Cylinder'):
            new_draw_size = (0.1 * obj.scs_props.locator_collider_dia) * 12
        elif obj.scs_props.locator_collider_type == 'Convex':
            bbox = obj.scs_props.get("coll_convex_bbox", None)
            bbcenter = obj.scs_props.get("coll_convex_bbcenter", None)
            if bbox and bbcenter:
                scaling = _math_utils.scaling_width_margin(
                    bbox, obj.scs_props.locator_collider_margin)
                val = []
                for axis in range(3):
                    val.append(
                        (bbox[axis] + abs(bbcenter[axis])) * scaling[axis])
                bigest_value = max(val)
                new_draw_size = (0.1 * bigest_value) * 12
        _object_utils.set_attr_if_different(obj, "empty_draw_size",
                                            new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type",
                                            'PLAIN_AXES')

    for visib_obj in bpy.context.visible_objects:
        # print('object: "%s"' % obj.name)
        if visib_obj.type == 'EMPTY' and visib_obj.scs_props.empty_object_type == 'Locator':

            if visib_obj.scs_props.locator_type == 'Prefab':
                prefab_locators[visib_obj.name] = visib_obj
                if visib_obj.scs_props.locators_orig_draw_size == 0.0:
                    store_locators_original_draw_size(visib_obj)
                set_locators_prefab_draw_size(visib_obj)
            elif visib_obj.scs_props.locator_type == 'Model':
                model_locators[visib_obj.name] = visib_obj
                store_locators_original_draw_size(visib_obj)
                set_locators_model_draw_size(visib_obj)
            elif visib_obj.scs_props.locator_type == 'Collision':
                collision_locators[visib_obj.name] = visib_obj
                store_locators_original_draw_size(visib_obj)
                set_locators_coll_draw_size(visib_obj)
            else:
                if visib_obj.scs_props.locators_orig_draw_size != 0.0:
                    set_locators_original_draw_size(visib_obj)

            # load any lost preview models or switch their layers if needed
            if scs_globals.show_preview_models:
                if visib_obj.scs_props.locator_preview_model_path != "":
                    if visib_obj.scs_props.locator_preview_model_present is False:
                        _preview_models.load(visib_obj)
                    else:
                        # identify preview model and alter it's layers array to object layers array
                        _preview_models.fix_visibility(visib_obj)

        else:

            # fix all preview models which parents are not visible anymore
            is_scs_mesh = visib_obj.type == "MESH" and visib_obj.data and "scs_props" in visib_obj.data
            if is_scs_mesh and visib_obj.data.scs_props.locator_preview_model_path != "":

                if visib_obj.parent and visib_obj.parent not in bpy.context.visible_objects:
                    _preview_models.fix_visibility(visib_obj.parent)

    return prefab_locators, collision_locators, model_locators
Exemplo n.º 13
0
def _get_custom_visual_elements():
    """Returns dictionaries of elements, that require custom OpenGL drawing in 3D viewports."""
    prefab_locators = {}
    collision_locators = {}
    model_locators = {}

    scene = bpy.context.scene

    # print(' time: %s' % str(time()))

    def set_locators_original_draw_size(obj):
        """Set original drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        # _object.set_attr_if_different(obj, "empty_draw_size", obj.scs_props.locators_orig_draw_size)
        if obj.empty_draw_size != obj.scs_props.locators_orig_draw_size:
            obj.empty_draw_size = obj.scs_props.locators_orig_draw_size
            obj.scs_props.locators_orig_draw_size = 0.0
        if obj.empty_draw_type != obj.scs_props.locators_orig_draw_type:
            obj.empty_draw_type = obj.scs_props.locators_orig_draw_type
            obj.scs_props.locators_orig_draw_type = ''

    def store_locators_original_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        if obj.scs_props.locators_orig_draw_size == 0.0:
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_size", obj.empty_draw_size)
            _object_utils.set_attr_if_different(obj.scs_props, "locators_orig_draw_type", obj.empty_draw_type)

    def set_locators_prefab_draw_size(obj):
        """Set Prefab Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = scene.scs_props.locator_empty_size * scene.scs_props.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')

    def set_locators_model_draw_size(obj):
        """Set Model Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        # new_draw_size = (scene.scs_props.locator_empty_size * (scene.scs_props.locator_size * 10)) / 6
        new_draw_size = scene.scs_props.locator_empty_size * scene.scs_props.locator_size
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')

    def set_locators_coll_draw_size(obj):
        """Set Collision Locator drawing style for Empty object.

        :param obj: Blender Object
        :type obj: bpy.types.Object
        """
        new_draw_size = 0.5
        if obj.scs_props.locator_collider_type == 'Box':
            bigest_value = max(obj.scs_props.locator_collider_box_x, obj.scs_props.locator_collider_box_y, obj.scs_props.locator_collider_box_z)
            new_draw_size = (0.1 * bigest_value) * 12
        elif obj.scs_props.locator_collider_type in ('Sphere', 'Capsule', 'Cylinder'):
            new_draw_size = (0.1 * obj.scs_props.locator_collider_dia) * 12
        elif obj.scs_props.locator_collider_type == 'Convex':
            bbox = obj.scs_props.get("coll_convex_bbox", None)
            bbcenter = obj.scs_props.get("coll_convex_bbcenter", None)
            if bbox and bbcenter:
                scaling = _math_utils.scaling_width_margin(bbox, obj.scs_props.locator_collider_margin)
                val = []
                for axis in range(3):
                    val.append((bbox[axis] + abs(bbcenter[axis])) * scaling[axis])
                bigest_value = max(val)
                new_draw_size = (0.1 * bigest_value) * 12
        _object_utils.set_attr_if_different(obj, "empty_draw_size", new_draw_size)
        _object_utils.set_attr_if_different(obj, "empty_draw_type", 'PLAIN_AXES')

    for visib_obj in bpy.context.visible_objects:
        # print('object: "%s"' % obj.name)
        if visib_obj.type == 'EMPTY' and visib_obj.scs_props.empty_object_type == 'Locator':

            if visib_obj.scs_props.locator_type == 'Prefab':
                prefab_locators[visib_obj.name] = visib_obj
                if visib_obj.scs_props.locators_orig_draw_size == 0.0:
                    store_locators_original_draw_size(visib_obj)
                set_locators_prefab_draw_size(visib_obj)
            elif visib_obj.scs_props.locator_type == 'Model':
                model_locators[visib_obj.name] = visib_obj
                store_locators_original_draw_size(visib_obj)
                set_locators_model_draw_size(visib_obj)
            elif visib_obj.scs_props.locator_type == 'Collision':
                collision_locators[visib_obj.name] = visib_obj
                store_locators_original_draw_size(visib_obj)
                set_locators_coll_draw_size(visib_obj)
            else:
                if visib_obj.scs_props.locators_orig_draw_size != 0.0:
                    set_locators_original_draw_size(visib_obj)

            # load any lost preview models or switch their layers if needed
            if bpy.context.scene.scs_props.show_preview_models:
                if visib_obj.scs_props.locator_preview_model_path != "":
                    if visib_obj.scs_props.locator_preview_model_present is False:
                        _preview_models.load(visib_obj)
                    else:
                        # identify preview model and alter it's layers array to object layers array
                        _preview_models.fix_visibility(visib_obj)

        else:

            # fix all preview models which parents are not visible anymore
            is_scs_mesh = visib_obj.type == "MESH" and visib_obj.data and "scs_props" in visib_obj.data
            if is_scs_mesh and visib_obj.data.scs_props.locator_preview_model_path != "":

                if visib_obj.parent and not visib_obj.parent in bpy.context.visible_objects:
                    _preview_models.fix_visibility(visib_obj.parent)

    return prefab_locators, collision_locators, model_locators