diff options
author | Ines Almeida <britalmeida@gmail.com> | 2018-05-20 10:33:31 +0300 |
---|---|---|
committer | Ines Almeida <britalmeida@gmail.com> | 2018-05-22 13:20:59 +0300 |
commit | e12df10120a0761031df6e33c0a6c212efd6a761 (patch) | |
tree | 795bdc08a275efce73c216dee57fe3fc47e3bdf5 /source/blender/editors/space_view3d/view3d_snap.c | |
parent | 7f714fdbb2643ce9886d27a4493e9c7c5235c30e (diff) |
COW Operators: Fix VIEW3D_OT_snap_cursor_to _active _selected _center and _grid
Reviewers: sergey, aligorith
Differential Revision: https://developer.blender.org/D3414
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_snap.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_snap.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index c5dd5d9ed24..c2a696dcdc4 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -51,6 +51,7 @@ #include "BKE_tracking.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "WM_api.h" #include "WM_types.h" @@ -498,6 +499,7 @@ static int snap_curs_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) curs[2] = gridf * floorf(0.5f + curs[2] / gridf); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); /* hrm */ + DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); return OPERATOR_FINISHED; } @@ -573,6 +575,8 @@ static void bundle_midpoint(Scene *scene, Object *ob, float vec[3]) static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) { + const Depsgraph *depsgraph = CTX_data_depsgraph(C); + ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); Object *obedit = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); @@ -586,7 +590,6 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) zero_v3(centroid); if (obedit) { - if (ED_transverts_check_obedit(obedit)) ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); @@ -594,13 +597,14 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) return false; } - copy_m3_m4(bmat, obedit->obmat); + Object *obedit_eval = DEG_get_evaluated_object(depsgraph, obedit); + copy_m3_m4(bmat, obedit_eval->obmat); tv = tvs.transverts; for (a = 0; a < tvs.transverts_tot; a++, tv++) { copy_v3_v3(vec, tv->loc); mul_m3_v3(bmat, vec); - add_v3_v3(vec, obedit->obmat[3]); + add_v3_v3(vec, obedit_eval->obmat[3]); add_v3_v3(centroid, vec); minmax_v3v3_v3(min, max, vec); } @@ -617,15 +621,16 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) } else { Object *obact = CTX_data_active_object(C); - + if (obact && (obact->mode & OB_MODE_POSE)) { - bArmature *arm = obact->data; + Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); + bArmature *arm = obact_eval->data; bPoseChannel *pchan; - for (pchan = obact->pose->chanbase.first; pchan; pchan = pchan->next) { + for (pchan = obact_eval->pose->chanbase.first; pchan; pchan = pchan->next) { if (arm->layer & pchan->bone->layer) { if (pchan->bone->flag & BONE_SELECTED) { copy_v3_v3(vec, pchan->pose_head); - mul_m4_v3(obact->obmat, vec); + mul_m4_v3(obact_eval->obmat, vec); add_v3_v3(centroid, vec); minmax_v3v3_v3(min, max, vec); count++; @@ -634,15 +639,15 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) } } else { - CTX_DATA_BEGIN (C, Object *, ob, selected_objects) + FOREACH_SELECTED_OBJECT_BEGIN(view_layer_eval, ob_eval) { - copy_v3_v3(vec, ob->obmat[3]); + copy_v3_v3(vec, ob_eval->obmat[3]); /* special case for camera -- snap to bundles */ - if (ob->type == OB_CAMERA) { + if (ob_eval->type == OB_CAMERA) { /* snap to bundles should happen only when bundles are visible */ if (v3d->flag2 & V3D_SHOW_RECONSTRUCTION) { - bundle_midpoint(scene, ob, vec); + bundle_midpoint(scene, DEG_get_original_object(ob_eval), vec); } } @@ -650,7 +655,7 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) minmax_v3v3_v3(min, max, vec); count++; } - CTX_DATA_END; + FOREACH_SELECTED_OBJECT_END; } if (count == 0) { @@ -678,6 +683,7 @@ static int snap_curs_to_sel_exec(bContext *C, wmOperator *UNUSED(op)) if (snap_curs_to_sel_ex(C, curs)) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); + DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); return OPERATOR_FINISHED; } @@ -708,31 +714,36 @@ void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot) static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]) { + const Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *obedit = CTX_data_edit_object(C); if (obedit) { - if (ED_object_editmode_calc_active_center(obedit, select_only, r_center)) { - mul_m4_v3(obedit->obmat, r_center); + Object *ob_edit_eval = DEG_get_evaluated_object(depsgraph, obedit); + + if (ED_object_editmode_calc_active_center(ob_edit_eval, select_only, r_center)) { + mul_m4_v3(ob_edit_eval->obmat, r_center); return true; } } else { Object *ob = CTX_data_active_object(C); - if (ob) { + Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); + if (ob->mode & OB_MODE_POSE) { - bPoseChannel *pchan = BKE_pose_channel_active(ob); + bPoseChannel *pchan = BKE_pose_channel_active(ob_eval); if (pchan) { if (!select_only || (pchan->bone->flag & BONE_SELECTED)) { copy_v3_v3(r_center, pchan->pose_head); - mul_m4_v3(ob->obmat, r_center); + mul_m4_v3(ob_eval->obmat, r_center); return true; } } } else { - if (!select_only || (ob->flag & SELECT)) { - copy_v3_v3(r_center, ob->obmat[3]); + + if (!select_only || (ob_eval->flag & SELECT)) { + copy_v3_v3(r_center, ob_eval->obmat[3]); return true; } } @@ -752,6 +763,8 @@ static int snap_curs_to_active_exec(bContext *C, wmOperator *UNUSED(op)) if (snap_calc_active_center(C, false, curs)) { WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); + DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); + return OPERATOR_FINISHED; } else { @@ -786,7 +799,8 @@ static int snap_curs_to_center_exec(bContext *C, wmOperator *UNUSED(op)) zero_v3(curs); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); - + DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); + return OPERATOR_FINISHED; } |