Bone selection: user control contrast

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.
This commit is contained in:
Jeroen Bakker 2018-06-07 09:18:57 +02:00
parent 7fb216d800
commit f447411a82
6 changed files with 47 additions and 7 deletions

@ -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()

@ -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;
}
}
}
}
}
}
}

@ -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);
}
}
}
}

@ -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;

@ -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 */

@ -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);