Fix mixed weight-paint & pose mode
authorCampbell Barton <ideasman42@gmail.com>
Thu, 8 Feb 2018 15:31:09 +0000 (02:31 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 8 Feb 2018 15:34:32 +0000 (02:34 +1100)
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_armature.c
source/blender/draw/intern/draw_manager.c
source/blender/draw/modes/pose_mode.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/transform/transform_conversions.c

index f49837410716cfa3b96541f942993aa17bd12326..9ed4da873957b3e0aca1091ae746abc0d7f4a931 100644 (file)
@@ -141,8 +141,10 @@ void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
 void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
 void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
 
+bool BKE_object_pose_context_check_ex(struct Object *ob, bool selected);
 bool BKE_object_pose_context_check(struct Object *ob);
 struct Object *BKE_object_pose_armature_get(struct Object *ob);
+struct Object *BKE_object_pose_armature_get_visible(struct Object *ob, struct ViewLayer *view_layer);
 
 void BKE_object_get_parent_matrix(struct Scene *scene, struct Object *ob,
                                   struct Object *par, float parentmat[4][4]);
index 7f20c2f271b786aaeaacc32fe99dcb0a1c4c8c08..127830c0cf79f9dbf53aecfaa13384efdf78a620 100644 (file)
@@ -1153,14 +1153,13 @@ static void copy_object_lod(Object *obn, const Object *ob, const int UNUSED(flag
        obn->currentlod = (LodLevel *)obn->lodlevels.first;
 }
 
-bool BKE_object_pose_context_check(Object *ob)
+bool BKE_object_pose_context_check_ex(Object *ob, bool selected)
 {
        if ((ob) &&
            (ob->type == OB_ARMATURE) &&
            (ob->pose) &&
-           // (ob->mode & OB_MODE_POSE)
-           (((bArmature *)ob->data)->flag & ARM_POSEMODE)
-           )
+           /* Currently using selection when the object isn't active. */
+           ((selected == false) || (ob->flag & SELECT)))
        {
                return true;
        }
@@ -1169,22 +1168,41 @@ bool BKE_object_pose_context_check(Object *ob)
        }
 }
 
+bool BKE_object_pose_context_check(Object *ob)
+{
+       return BKE_object_pose_context_check_ex(ob, false);
+}
+
 Object *BKE_object_pose_armature_get(Object *ob)
 {
        if (ob == NULL)
                return NULL;
 
-       if (BKE_object_pose_context_check(ob))
+       if (BKE_object_pose_context_check_ex(ob, false))
                return ob;
 
        ob = modifiers_isDeformedByArmature(ob);
 
-       if (BKE_object_pose_context_check(ob))
+       /* Only use selected check when non-active. */
+       if (BKE_object_pose_context_check_ex(ob, true))
                return ob;
 
        return NULL;
 }
 
+Object *BKE_object_pose_armature_get_visible(Object *ob, ViewLayer *view_layer)
+{
+       Object *ob_armature = BKE_object_pose_armature_get(ob);
+       if (ob_armature) {
+               Base *base = BKE_view_layer_base_find(view_layer, ob_armature);
+               if (base) {
+                       if (BASE_VISIBLE(base)) {
+                               return ob_armature;
+                       }
+               }
+       }
+       return NULL;
+}
 void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
 {
        copy_v3_v3(ob_tar->loc, ob_src->loc);
index b6e4d82604c6c92b54eb2e7f2d03ae309fa99106..8eb10ed5a1471fc479a4bb91cae215fcc4bc7c28 100644 (file)
@@ -476,6 +476,8 @@ typedef struct DRWContextState {
         * May be NULL when used for selection or depth buffer. */
        const struct bContext *evil_C;
 
+       struct Object *object_pose;
+
 } DRWContextState;
 
 const DRWContextState *DRW_context_state_get(void);
index 5daafadada61299a5b464a659efc8d3dd0bf419a..c14fe70e0c35233a23c3f8afd9c94a81915cb518 100644 (file)
@@ -1310,7 +1310,7 @@ static void draw_armature_pose(Object *ob, const float const_color[4])
        {
                const DRWContextState *draw_ctx = DRW_context_state_get();
 
-               if (draw_ctx->object_mode & OB_MODE_POSE) {
+               if ((draw_ctx->object_mode & OB_MODE_POSE) || (ob == draw_ctx->object_pose)) {
                        arm->flag |= ARM_POSEMODE;
                }
 
index 96454fd087e053b2e3e0424c7f1440446cd3da90..45ad9853d20838fb7314e0be1b4c0a43a263e3ce 100644 (file)
@@ -2678,6 +2678,19 @@ static void drw_viewport_var_init(void)
 
        memset(viewport_matrix_override.override, 0x0, sizeof(viewport_matrix_override.override));
        memset(DST.common_instance_data, 0x0, sizeof(DST.common_instance_data));
+
+       /* Not a viewport variable, we could split this out. */
+       {
+               if (DST.draw_ctx.object_mode & OB_MODE_POSE) {
+                       DST.draw_ctx.object_pose = DST.draw_ctx.obact;
+               }
+               else if (DST.draw_ctx.object_mode & OB_MODE_WEIGHT_PAINT) {
+                       DST.draw_ctx.object_pose = BKE_object_pose_armature_get(DST.draw_ctx.obact);
+               }
+               else {
+                       DST.draw_ctx.object_pose = NULL;
+               }
+       }
 }
 
 void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type)
index 1589ff39bdfcc54c40b1b63911ebcace2598f723..749c3e71368bbf2f0bf74b87cb74bf4f865b5849 100644 (file)
@@ -145,7 +145,7 @@ bool DRW_pose_mode_armature(Object *ob, Object *active_ob)
 
        /* Armature parent is also handled by pose mode engine. */
        if ((active_ob != NULL) && ((draw_ctx->object_mode & OB_MODE_WEIGHT_PAINT) != 0)) {
-               if (active_ob->parent == ob) {
+               if (ob == draw_ctx->object_pose) {
                        return true;
                }
        }
index 9f5a3c842432eed0920509ad299cec1e447164a3..3c08948305423e15aab3714d59409b3923aa1437 100644 (file)
@@ -408,14 +408,15 @@ int ED_operator_posemode_context(bContext *C)
 {
        Object *obpose = ED_pose_object_from_context(C);
 
-
        if (obpose) {
-               EvaluationContext eval_ctx;
-               CTX_data_eval_ctx(C, &eval_ctx);
-               if ((eval_ctx.object_mode & OB_MODE_EDIT) == 0) {
+               const WorkSpace *workspace = CTX_wm_workspace(C);
+               /* TODO, should we allow this out of pose mode? */
+               if (workspace->object_mode & OB_MODE_POSE) {
+                       // if ((workspace->object_mode & OB_MODE_EDIT) == 0) {
                        if (BKE_object_pose_context_check(obpose)) {
                                return 1;
                        }
+                       // }
                }
        }
 
@@ -428,12 +429,13 @@ int ED_operator_posemode(bContext *C)
 
 
        if (obact) {
-               EvaluationContext eval_ctx;
-               CTX_data_eval_ctx(C, &eval_ctx);
-               if ((eval_ctx.object_mode & OB_MODE_EDIT) == 0) {
+               const WorkSpace *workspace = CTX_wm_workspace(C);
+               if ((workspace->object_mode & OB_MODE_EDIT) == 0) {
                        Object *obpose;
                        if ((obpose = BKE_object_pose_armature_get(obact))) {
-                               if ((obact == obpose) || (eval_ctx.object_mode & OB_MODE_WEIGHT_PAINT)) {
+                               if (((workspace->object_mode & OB_MODE_POSE) && (obact == obpose)) ||
+                                   (workspace->object_mode & OB_MODE_WEIGHT_PAINT))
+                               {
                                        return 1;
                                }
                        }
index af8a33697321dae68295e3f353bc034f37f11bdc..3ffbb67a49232e74605d971d4add8c358782fad4 100644 (file)
@@ -1778,12 +1778,10 @@ static void draw_selected_name(
                                Object *armobj = BKE_object_pose_armature_get(ob);
                                if (armobj) {
                                        bArmature *arm = armobj->data;
-                                       if (arm->flag & ARM_POSEMODE) {
-                                               if (arm->act_bone) {
-                                                       if (arm->act_bone->layer & arm->layer) {
-                                                               s += BLI_strcpy_rlen(s, msg_sep);
-                                                               s += BLI_strcpy_rlen(s, arm->act_bone->name);
-                                                       }
+                                       if (arm->act_bone) {
+                                               if (arm->act_bone->layer & arm->layer) {
+                                                       s += BLI_strcpy_rlen(s, msg_sep);
+                                                       s += BLI_strcpy_rlen(s, arm->act_bone->name);
                                                }
                                        }
                                }
index 6c80033f9dff7063c7a232eb300e80fcfce32d18..20eb65197e502988bfe714a81515c74c22727c92 100644 (file)
@@ -2821,24 +2821,12 @@ static int viewselected_exec(bContext *C, wmOperator *op)
        }
 
        if (ob && (eval_ctx.object_mode & OB_MODE_WEIGHT_PAINT)) {
-               /* hard-coded exception, we look for the one selected armature */
-               /* this is weak code this way, we should make a generic active/selection callback interface once... */
-               Base *base;
-               for (base = view_layer->object_bases.first; base; base = base->next) {
-                       if (TESTBASELIB(base)) {
-                               if (base->object->type == OB_ARMATURE) {
-                                       const bArmature *arm = base->object->data;
-                                       if (arm->flag & ARM_POSEMODE) {
-                                               break;
-                                       }
-                               }
-                       }
+               Object *ob_armature = BKE_object_pose_armature_get_visible(ob, view_layer);
+               if (ob_armature) {
+                       ob = ob_armature;
                }
-               if (base)
-                       ob = base->object;
        }
 
-
        if (is_gp_edit) {
                CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
                {
index 9720cc1e6132f479e1be6ad0a755fe0581044906..d00b17d9a5e534301266284611cd2c94d9e3a606 100644 (file)
@@ -8231,13 +8231,11 @@ void createTransData(bContext *C, TransInfo *t)
                 * lines below just check is also visible */
                Object *ob_armature = modifiers_isDeformedByArmature(ob);
                if (ob_armature) {
-                       const bArmature *arm = ob_armature->data;
-                       if (arm->flag & ARM_POSEMODE) {
-                               Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature);
-                               if (base_arm) {
-                                       if (BASE_VISIBLE(base_arm)) {
-                                               createTransPose(t, ob_armature);
-                                       }
+//                     const bArmature *arm = ob_armature->data;
+                       Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature);
+                       if (base_arm) {
+                               if (BASE_VISIBLE(base_arm)) {
+                                       createTransPose(t, ob_armature);
                                }
                        }
                }