[Bf-blender-cvs] [966383138a4] master: Weight Paint: implement a red shade for bones with locked weights.

Alexander Gavrilov noreply at git.blender.org
Sat Jan 18 10:19:44 CET 2020


Commit: 966383138a42924b155e237a6dc32c22ace49b68
Author: Alexander Gavrilov
Date:   Tue Dec 17 16:11:31 2019 +0300
Branches: master
https://developer.blender.org/rB966383138a42924b155e237a6dc32c22ace49b68

Weight Paint: implement a red shade for bones with locked weights.

Blender supports locking vertex groups to prevent changes to the
weights. However, as mentioned in comments for D3837, it is hard
to use this because there is no interface for locking in 3D View.

This adds a red shade to bones that are associated with a locked
weight group during weight paint mode, as the first step to adding
such interface. The next step is adding a pie menu for lock/unlock.

Differential Revision: https://developer.blender.org/D6533

===================================================================

M	release/datafiles/userdef/userdef_default_theme.c
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/draw/engines/overlay/overlay_armature.c
M	source/blender/editors/include/UI_resources.h
M	source/blender/editors/interface/resources.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/makesdna/DNA_armature_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/release/datafiles/userdef/userdef_default_theme.c b/release/datafiles/userdef/userdef_default_theme.c
index 147b55f60ef..f245baa1d83 100644
--- a/release/datafiles/userdef/userdef_default_theme.c
+++ b/release/datafiles/userdef/userdef_default_theme.c
@@ -339,6 +339,7 @@ const bTheme U_theme_default = {
     .bone_solid = RGBA(0xb2b2b2ff),
     .bone_pose = RGBA(0x50c8ff50),
     .bone_pose_active = RGBA(0x8cffff50),
+    .bone_locked_weight = RGBA(0xff000080),
     .cframe = RGBA(0x60c040ff),
     .time_keyframe = RGBA(0xddd700ff),
     .time_gp_keyframe = RGBA(0xb5e61dff),
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 4f35bcc29df..ad5e7b5442c 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -997,6 +997,7 @@ class PreferenceThemeSpacePanel:
             "freestyle_face_mark",
             "split_normal",
             "bone_solid",
+            "bone_locked_weight",
             "paint_curve_pivot",
         },
         'GRAPH_EDITOR': {
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index dd3e381ef5d..4fcb10b29f3 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -27,7 +27,7 @@
  * \note Use #STRINGIFY() rather than defining with quotes.
  */
 #define BLENDER_VERSION 283
-#define BLENDER_SUBVERSION 0
+#define BLENDER_SUBVERSION 1
 /** Several breakages with 280, e.g. collections vs layers. */
 #define BLENDER_MINVERSION 280
 #define BLENDER_MINSUBVERSION 0
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6a54fc8f59e..e1424da2207 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3874,7 +3874,7 @@ static void direct_link_bones(FileData *fd, Bone *bone)
   bone->bbone_next = newdataadr(fd, bone->bbone_next);
   bone->bbone_prev = newdataadr(fd, bone->bbone_prev);
 
-  bone->flag &= ~BONE_DRAW_ACTIVE;
+  bone->flag &= ~(BONE_DRAW_ACTIVE | BONE_DRAW_LOCKED_WEIGHT);
 
   link_list(fd, &bone->childbase);
 
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index b1f70848bdc..e1ea4e3bb24 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -164,6 +164,10 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
     FROM_DEFAULT_V4_UCHAR(space_view3d.face_front);
   }
 
+  if (!USER_VERSION_ATLEAST(283, 1)) {
+    FROM_DEFAULT_V4_UCHAR(space_view3d.bone_locked_weight);
+  }
+
   /**
    * Versioning code until next subversion bump goes here.
    *
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index 0b77fcad265..416283e321b 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -35,6 +35,7 @@
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_modifier.h"
 
@@ -974,6 +975,15 @@ static bool set_pchan_color(const ArmatureDrawContext *ctx,
 /** \name Drawing Color Helpers
  * \{ */
 
+static void bone_locked_color_shade(float color[4])
+{
+  float locked_color[4];
+
+  UI_GetThemeColor4fv(TH_BONE_LOCKED_WEIGHT, locked_color);
+
+  interp_v3_v3v3(color, color, locked_color, locked_color[3]);
+}
+
 static const float *get_bone_solid_color(const ArmatureDrawContext *ctx,
                                          const EditBone *UNUSED(eBone),
                                          const bPoseChannel *pchan,
@@ -989,6 +999,11 @@ static const float *get_bone_solid_color(const ArmatureDrawContext *ctx,
     static float disp_color[4];
     copy_v4_v4(disp_color, pchan->draw_data->solid_color);
     set_pchan_color(ctx, PCHAN_COLOR_SOLID, boneflag, constflag, disp_color);
+
+    if (boneflag & BONE_DRAW_LOCKED_WEIGHT) {
+      bone_locked_color_shade(disp_color);
+    }
+
     return disp_color;
   }
 
@@ -1009,7 +1024,7 @@ static const float *get_bone_solid_with_consts_color(const ArmatureDrawContext *
   const float *col = get_bone_solid_color(ctx, eBone, pchan, arm, boneflag, constflag);
 
   static float consts_color[4];
-  if ((arm->flag & ARM_POSEMODE) &&
+  if ((arm->flag & ARM_POSEMODE) && !(boneflag & BONE_DRAW_LOCKED_WEIGHT) &&
       set_pchan_color(ctx, PCHAN_COLOR_CONSTS, boneflag, constflag, consts_color)) {
     interp_v3_v3v3(consts_color, col, consts_color, 0.5f);
   }
@@ -1065,6 +1080,10 @@ static const float *get_bone_wire_color(const ArmatureDrawContext *ctx,
   else if (arm->flag & ARM_POSEMODE) {
     copy_v4_v4(disp_color, pchan->draw_data->wire_color);
     set_pchan_color(ctx, PCHAN_COLOR_NORMAL, boneflag, constflag, disp_color);
+
+    if (boneflag & BONE_DRAW_LOCKED_WEIGHT) {
+      bone_locked_color_shade(disp_color);
+    }
   }
   else {
     copy_v3_v3(disp_color, ctx->color.vertex);
@@ -1518,7 +1537,7 @@ static void draw_bone_custom_shape(ArmatureDrawContext *ctx,
       drw_shgroup_bone_custom_empty(ctx, disp_mat, col_wire, pchan->custom);
     }
   }
-  if ((boneflag & BONE_DRAWWIRE) == 0) {
+  if ((boneflag & BONE_DRAWWIRE) == 0 && (boneflag & BONE_DRAW_LOCKED_WEIGHT) == 0) {
     drw_shgroup_bone_custom_solid(ctx, disp_mat, col_solid, col_hint, col_wire, pchan->custom);
   }
   else {
@@ -2010,6 +2029,8 @@ static void draw_armature_edit(ArmatureDrawContext *ctx)
           boneflag |= BONE_DRAW_ACTIVE;
         }
 
+        boneflag &= ~BONE_DRAW_LOCKED_WEIGHT;
+
         draw_bone_relations(ctx, eBone, NULL, arm, boneflag, constflag);
 
         if (arm->drawtype == ARM_ENVELOPE) {
@@ -2054,6 +2075,7 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
   bPoseChannel *pchan;
   int index = -1;
   const bool show_text = DRW_state_show_text();
+  bool draw_locked_weights = false;
 
   /* We can't safely draw non-updated pose, might contain NULL bone pointers... */
   if (ob->pose->flag & POSE_RECALC) {
@@ -2089,6 +2111,28 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
     }
   }
 
+  /* In weight paint mode retrieve the vertex group lock status. */
+  if ((draw_ctx->object_mode == OB_MODE_WEIGHT_PAINT) && (draw_ctx->object_pose == ob) &&
+      (draw_ctx->obact != NULL)) {
+    draw_locked_weights = true;
+
+    for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+      pchan->bone->flag &= ~BONE_DRAW_LOCKED_WEIGHT;
+    }
+
+    const Object *obact_orig = DEG_get_original_object(draw_ctx->obact);
+
+    LISTBASE_FOREACH (bDeformGroup *, dg, &obact_orig->defbase) {
+      if (dg->flag & DG_LOCK_WEIGHT) {
+        pchan = BKE_pose_channel_find_name(ob->pose, dg->name);
+
+        if (pchan) {
+          pchan->bone->flag |= BONE_DRAW_LOCKED_WEIGHT;
+        }
+      }
+    }
+  }
+
   for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next, index += 0x10000) {
     Bone *bone = pchan->bone;
     const bool bone_visible = (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0;
@@ -2120,6 +2164,10 @@ static void draw_armature_pose(ArmatureDrawContext *ctx)
           boneflag |= BONE_DRAW_ACTIVE;
         }
 
+        if (!draw_locked_weights) {
+          boneflag &= ~BONE_DRAW_LOCKED_WEIGHT;
+        }
+
         draw_bone_relations(ctx, NULL, pchan, arm, boneflag, constflag);
 
         if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index bd8eed4e4aa..66662c8c27d 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -143,6 +143,7 @@ typedef enum ThemeColorID {
   TH_BONE_SOLID,
   TH_BONE_POSE,
   TH_BONE_POSE_ACTIVE,
+  TH_BONE_LOCKED_WEIGHT,
 
   TH_STRIP,
   TH_STRIP_SELECT,
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index f8b4d85a212..37921b48401 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -443,6 +443,9 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
         case TH_BONE_POSE_ACTIVE:
           cp = ts->bone_pose_active;
           break;
+        case TH_BONE_LOCKED_WEIGHT:
+          cp = ts->bone_locked_weight;
+          break;
         case TH_STRIP:
           cp = ts->strip;
           break;
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index e8e0569f15e..05fa78aab1c 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -3179,6 +3179,8 @@ static int vertex_group_lock_exec(bContext *C, wmOperator *op)
 
   vgroup_lock_all(ob, action);
 
+  WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+
   return OPERATOR_FINISHED;
 }
 
diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h
index 354344328d3..7192b1295aa 100644
--- a/source/blender/makesdna/DNA_armature_types.h
+++ b/source/blender/makesdna/DNA_armature_types.h
@@ -252,7 +252,8 @@ typedef enum eBone_Flag {
   BONE_ADD_PARENT_END_ROLL = (1 << 24),
   /** this bone was transformed by the mirror function */
   BONE_TRANSFORM_MIRROR = (1 << 25),
-
+  /** this bone is associated with a locked vertex group, ONLY USE FOR DRAWING */
+  BONE_DRAW_LOCKED_WEIGHT = (1 << 26),
 } eBone_Flag;
 
 /* bone->inherit_scale_mode */
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index f0a852a7a1a..d81d8db3bd3 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -283,13 +283,12 @@ typedef struct ThemeSpace {
   unsigned char normal[4];
   unsigned char vertex_normal[4];
   unsigned char loop_normal[4];
-  unsigned char bone_solid[4], bone_pose[4], bone_pose_active[4];
+  unsigned char bone_solid[4], bone_pose[4], bone_pose_active[4], bone_locked

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list