diff options
author | Howard Trickey <howard.trickey@gmail.com> | 2013-01-04 19:06:34 +0400 |
---|---|---|
committer | Howard Trickey <howard.trickey@gmail.com> | 2013-01-04 19:06:34 +0400 |
commit | 0f565149864ac34d54c5a0e517a8db88cf67a6d6 (patch) | |
tree | bf419fa0c2e54fdf92fa9a4b8025e8e0f5393b0a | |
parent | 4fa340c71691c68148ca72379f21f000f0f35664 (diff) |
Fix knife cut bug #33625, failure to cut in otho mode sometimes.
Problem was that the code to limit the front and back planes
for better precision assumed line would have center near origin.
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index c8a1264fd10..542d568f7b8 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -1315,7 +1315,7 @@ static void knife_bgl_get_mats(KnifeTool_OpData *UNUSED(kcd), bglMats *mats) //copy_m4_m4(mats->projection, kcd->vc.rv3d->winmat); } -/* Calculate maximum excursion (doubled) from (0,0,0) of mesh */ +/* Calculate maximum excursion from (0,0,0) of mesh */ static void calc_ortho_extent(KnifeTool_OpData *kcd) { BMIter iter; @@ -1328,7 +1328,18 @@ static void calc_ortho_extent(KnifeTool_OpData *kcd) for (i = 0; i < 3; i++) max_xyz = max_ff(max_xyz, fabs(v->co[i])); } - kcd->ortho_extent = 2 * max_xyz; + kcd->ortho_extent = max_xyz; +} + +/* Clip the line (v1, v2) to planes perpendicular to it and distances d from + * the closest point on the line to the origin */ +static void clip_to_ortho_planes(float v1[3], float v2[3], float d) { + float closest[3]; + const float origin[3] = {0.0f, 0.0f, 0.0f}; + + closest_to_line_v3(closest, origin, v1, v2); + dist_ensure_v3_v3fl(v1, closest, d); + dist_ensure_v3_v3fl(v2, closest, d); } /* Finds visible (or all, if cutting through) edges that intersects the current screen drag line */ @@ -1375,8 +1386,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd) if (kcd->is_ortho) { if (kcd->ortho_extent == 0.0f) calc_ortho_extent(kcd); - limit_dist_v3(v1, v3, kcd->ortho_extent + 10.0f); - limit_dist_v3(v2, v4, kcd->ortho_extent + 10.0f); + clip_to_ortho_planes(v1, v3, kcd->ortho_extent + 10.0f); + clip_to_ortho_planes(v2, v4, kcd->ortho_extent + 10.0f); } BLI_smallhash_init(ehash); |