Fix mixed weight-paint & pose mode

This commit is contained in:
Campbell Barton
2018-02-09 02:31:09 +11:00
parent 9278614115
commit be2bd5d722
10 changed files with 65 additions and 44 deletions

View 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]);

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

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

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

View 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)

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

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

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

View 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)
{

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