diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-08-31 22:33:45 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-08-31 22:46:16 +0300 |
commit | 3065dc435ca42c8f80297db97d887bdbd6f79f45 (patch) | |
tree | 6ac5495b999c09708920d3fdddd3752de90d7bde /source/blender/editors/space_view3d | |
parent | 0610c09f8c0e8188abdf377d8b6fd36be012ed0a (diff) |
Fixup for multi-objects snap functions
Sanitizing the use of TransVertStore, making sure it is always freed.
Skip meshes with no vertex selected.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_snap.c | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 484eb38297b..36fc23b35c9 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -93,32 +93,35 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); for (uint ob_index = 0; ob_index < objects_len; ob_index++) { obedit = objects[ob_index]; - if (ED_transverts_check_obedit(obedit)) { - ED_transverts_create_from_obedit(&tvs, obedit, 0); - } + BMEditMesh *em = BKE_editmesh_from_object(obedit); - if (tvs.transverts_tot == 0) { + if (em->bm->totvertsel == 0) { continue; } - copy_m3_m4(bmat, obedit->obmat); - invert_m3_m3(imat, bmat); - - 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]); - vec[0] = gridf * floorf(0.5f + vec[0] / gridf); - vec[1] = gridf * floorf(0.5f + vec[1] / gridf); - vec[2] = gridf * floorf(0.5f + vec[2] / gridf); - sub_v3_v3(vec, obedit->obmat[3]); - - mul_m3_v3(imat, vec); - copy_v3_v3(tv->loc, vec); + if (ED_transverts_check_obedit(obedit)) { + ED_transverts_create_from_obedit(&tvs, obedit, 0); } - ED_transverts_update_obedit(&tvs, obedit); + if (tvs.transverts_tot != 0) { + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); + + 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]); + vec[0] = gridf * floorf(0.5f + vec[0] / gridf); + vec[1] = gridf * floorf(0.5f + vec[1] / gridf); + vec[2] = gridf * floorf(0.5f + vec[2] / gridf); + sub_v3_v3(vec, obedit->obmat[3]); + + mul_m3_v3(imat, vec); + copy_v3_v3(tv->loc, vec); + } + ED_transverts_update_obedit(&tvs, obedit); + } ED_transverts_free(&tvs); } MEM_freeN(objects); @@ -265,39 +268,42 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); for (uint ob_index = 0; ob_index < objects_len; ob_index++) { obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + + if (em->bm->totvertsel == 0) { + continue; + } if (ED_transverts_check_obedit(obedit)) { ED_transverts_create_from_obedit(&tvs, obedit, 0); } - if (tvs.transverts_tot == 0) { - continue; - } - copy_m3_m4(bmat, obedit->obmat); - invert_m3_m3(imat, bmat); + if (tvs.transverts_tot != 0) { + copy_m3_m4(bmat, obedit->obmat); + invert_m3_m3(imat, bmat); - /* get the cursor in object space */ - sub_v3_v3v3(snap_target_local, snap_target_global, obedit->obmat[3]); - mul_m3_v3(imat, snap_target_local); + /* get the cursor in object space */ + sub_v3_v3v3(snap_target_local, snap_target_global, obedit->obmat[3]); + mul_m3_v3(imat, snap_target_local); - if (use_offset) { - float offset_local[3]; + if (use_offset) { + float offset_local[3]; - mul_v3_m3v3(offset_local, imat, offset_global); + mul_v3_m3v3(offset_local, imat, offset_global); - tv = tvs.transverts; - for (a = 0; a < tvs.transverts_tot; a++, tv++) { - add_v3_v3(tv->loc, offset_local); + tv = tvs.transverts; + for (a = 0; a < tvs.transverts_tot; a++, tv++) { + add_v3_v3(tv->loc, offset_local); + } } - } - else { - tv = tvs.transverts; - for (a = 0; a < tvs.transverts_tot; a++, tv++) { - copy_v3_v3(tv->loc, snap_target_local); + else { + tv = tvs.transverts; + for (a = 0; a < tvs.transverts_tot; a++, tv++) { + copy_v3_v3(tv->loc, snap_target_local); + } } + ED_transverts_update_obedit(&tvs, obedit); } - - ED_transverts_update_obedit(&tvs, obedit); ED_transverts_free(&tvs); } MEM_freeN(objects); @@ -615,14 +621,18 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); for (uint ob_index = 0; ob_index < objects_len; ob_index++) { obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + + if (em->bm->totvertsel == 0) { + continue; + } if (ED_transverts_check_obedit(obedit)) { ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); } global_transverts_tot += tvs.transverts_tot; - if (global_transverts_tot != 0) { - + if (tvs.transverts_tot != 0) { Object *obedit_eval = DEG_get_evaluated_object(depsgraph, obedit); copy_m3_m4(bmat, obedit_eval->obmat); |