diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-02-08 18:31:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-02-08 18:34:32 +0300 |
commit | be2bd5d722bf36e076663a27537860bb1842931e (patch) | |
tree | 8f94eee3e7b5c18ada5c90eccd523a8bf0f08388 | |
parent | 92786141159430fa36e59e0229e4bbb84f2f04be (diff) |
Fix mixed weight-paint & pose mode
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 30 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_armature.c | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 13 | ||||
-rw-r--r-- | source/blender/draw/modes/pose_mode.c | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 18 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 12 |
10 files changed, 65 insertions, 44 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index f4983741071..9ed4da87395 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -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]); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 7f20c2f271b..127830c0cf7 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -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); diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index b6e4d82604c..8eb10ed5a14 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -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); diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index 5daafadada6..c14fe70e0c3 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -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; } diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 96454fd087e..45ad9853d20 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -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) diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c index 1589ff39bdf..749c3e71368 100644 --- a/source/blender/draw/modes/pose_mode.c +++ b/source/blender/draw/modes/pose_mode.c @@ -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; } } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 9f5a3c84243..3c089483054 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -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; } } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index af8a3369732..3ffbb67a492 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -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); } } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 6c80033f9df..20eb65197e5 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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) { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 9720cc1e613..d00b17d9a5e 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -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); } } } |