Bone selection: user control contrast
authorJeroen Bakker <j.bakker@atmind.nl>
Thu, 7 Jun 2018 07:18:57 +0000 (09:18 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Thu, 7 Jun 2018 07:26:06 +0000 (09:26 +0200)
Experiment: let the user be in control of the alpha channel as some rigs
are hard too see during bone selection. Especially rigs that were
designed for 2.79 wireframe mode.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/modes/pose_mode.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index c1793d95245df6b5c98339ca4ac16b69bf496d2d..c17b089e04c2194a6f937a3fbd4a84c5e8d5366c 100644 (file)
@@ -3724,7 +3724,11 @@ class VIEW3D_PT_overlay(Panel):
             col = layout.column()
             col.active = display_all
             col.prop(overlay, "show_transparent_bones")
-            col.prop(overlay, "show_bone_selection")
+            row = col.split(0.65)
+            row.prop(overlay, "show_bone_selection")
+            sub = row.column()
+            sub.active = display_all and overlay.show_bone_selection
+            sub.prop(overlay, "bone_selection_alpha", text="")
 
         elif context.mode == 'EDIT_ARMATURE':
             col.separator()
index 83a0f21002a788883a0940075c4b53fcbe64e5e6..eb165efb4f9f8ca6a79626af5ebe75e5d691af04 100644 (file)
@@ -1581,5 +1581,17 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                                }
                        }
                }
+               if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", "bone_selection_alpha")) {
+                       for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+                               for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+                                       for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+                                               if (sl->spacetype == SPACE_VIEW3D) {
+                                                       View3D *v3d = (View3D *)sl;
+                                                       v3d->overlay.bone_selection_alpha = 0.5f;
+                                               }
+                                       }
+                               }
+                       }
+               }
        }
 }
index 586fb590ebf4c9bb9f7443c8db0d9e745086ada6..ad9567cd9c0e6a60380d7abce1304bd8a6b4848f 100644 (file)
@@ -72,13 +72,15 @@ typedef struct POSE_Data {
 
 typedef struct POSE_PrivateData {
        DRWShadingGroup *bone_selection_shgrp;
+       DRWShadingGroup *bone_selection_invert_shgrp;
+       float blend_color[4];
+       float blend_color_invert[4];
 } POSE_PrivateData; /* Transient data */
 
 static struct {
        struct GPUShader *bone_selection_sh;
 } e_data = {NULL};
 
-static float blend_color[4] = {0.0, 0.0, 0.0, 0.5};
 
 /* *********** FUNCTIONS *********** */
 static bool POSE_is_bone_selection_overlay_active(void)
@@ -105,11 +107,14 @@ static void POSE_cache_init(void *vedata)
 {
        POSE_PassList *psl = ((POSE_Data *)vedata)->psl;
        POSE_StorageList *stl = ((POSE_Data *)vedata)->stl;
+       const DRWContextState *draw_ctx = DRW_context_state_get();
+       View3D *v3d = draw_ctx->v3d;
 
        if (!stl->g_data) {
                /* Alloc transient pointers */
                stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
        }
+       POSE_PrivateData *ppd = stl->g_data;
 
        {
                /* Solid bones */
@@ -150,13 +155,18 @@ static void POSE_cache_init(void *vedata)
 
        {
                if (POSE_is_bone_selection_overlay_active()) {
+                       copy_v4_fl4(ppd->blend_color, 0.0f, 0.0f, 0.0f, v3d->overlay.bone_selection_alpha);
+                       copy_v4_fl4(ppd->blend_color_invert, 0.0f, 0.0f, 0.0f, pow(v3d->overlay.bone_selection_alpha, 4));
                        DRWShadingGroup *grp;
                        psl->bone_selection = DRW_pass_create(
                                "Bone Selection",
                                DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND);
                        grp = DRW_shgroup_create(e_data.bone_selection_sh, psl->bone_selection);
-                       DRW_shgroup_uniform_vec4(grp, "color", blend_color, 1);
+                       DRW_shgroup_uniform_vec4(grp, "color", ppd->blend_color, 1);
                        stl->g_data->bone_selection_shgrp = grp;
+                       grp = DRW_shgroup_create(e_data.bone_selection_sh, psl->bone_selection);
+                       DRW_shgroup_uniform_vec4(grp, "color", ppd->blend_color_invert, 1);
+                       stl->g_data->bone_selection_invert_shgrp = grp;
                }
        }
 }
@@ -206,12 +216,16 @@ static void POSE_cache_populate(void *vedata, Object *ob)
        }
        else if (ob->type == OB_MESH &&
                 !DRW_state_is_select() &&
-                POSE_is_bone_selection_overlay_active() &&
-                POSE_is_driven_by_active_armature(ob))
+                POSE_is_bone_selection_overlay_active())
        {
                struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
                if (geom) {
-                       DRW_shgroup_call_object_add(stl->g_data->bone_selection_shgrp, geom, ob);
+                       if (POSE_is_driven_by_active_armature(ob)) {
+                               DRW_shgroup_call_object_add(stl->g_data->bone_selection_shgrp, geom, ob);
+                       }
+                       else {
+                               DRW_shgroup_call_object_add(stl->g_data->bone_selection_invert_shgrp, geom, ob);
+                       }
                }
        }
 }
index 3bd416d7251707cb4e084992c626d06ed33bad39..7b395153417cf32e3d80dcb1f0ffa9289148f177 100644 (file)
@@ -332,6 +332,7 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
 
        v3d->overlay.flag = V3D_OVERLAY_LOOK_DEV;
        v3d->overlay.wireframe_threshold = 0.5f;
+       v3d->overlay.bone_selection_alpha = 0.5f;
 
        v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR;
 
index ea90ac261dacab3609bf0c2a42c4d81af974f7b1..b1bf7c3692c7898d0c42f7f1fa2cc33bc7a6ffaa 100644 (file)
@@ -169,9 +169,10 @@ typedef struct View3DOverlay {
 
        /* Armature edit/pose mode settings */
        int arm_flag;
+       float bone_selection_alpha;
 
        /* Other settings */
-       float wireframe_threshold, pad;
+       float wireframe_threshold;
 } View3DOverlay;
 
 /* 3D ViewPort Struct */
index 185c9a38098d1d421c2e28b86bc3c0afcdffe29e..1db826bdb4372217c1d4ae5302725c89698d4b01 100644 (file)
@@ -2571,6 +2571,14 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Bone Selection", "Show the Bone Selection Overlay");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+       prop = RNA_def_property(srna, "bone_selection_alpha", PROP_FLOAT, PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "overlay.bone_selection_alpha");
+       RNA_def_property_float_default(prop, 0.5f);
+       RNA_def_property_ui_text(prop, "Opacity", "Opacity to use for bone selection");
+       RNA_def_property_range(prop, 0.0f, 1.0f);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
        prop = RNA_def_property(srna, "show_motion_paths", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_HIDE_MOTION_PATHS);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);