From c4b47b89f76d259792b3a8f0f9b6718668996000 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 28 Jul 2014 15:15:18 +0200 Subject: Fix T41191: Face snapping doesn't work properly. Issue was caused by rB47ec0394ca3d, which disabled BBox check in editmode - but bbox check was also setting `len_diff`, which is mandatory when doing ray_start_local correction for ortho view... Now, in this case, we do a quick rough compute of len_diff from vertices coordinates (accuracy is not needed here, we just have to be sure corrected `ray_start_local` remains 'before' (outside) of the geometry). --- source/blender/editors/transform/transform_snap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 2aba8b792d2..26eb836bdc9 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -1493,6 +1493,8 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes const float mval[2], float r_loc[3], float r_no[3], float *r_dist_px, float *r_depth, bool do_bb) { bool retval = false; + const bool do_ray_start_correction = (snap_mode == SCE_SNAP_MODE_FACE && ar && + !((RegionView3D *)ar->regiondata)->is_persp); int totvert = dm->getNumVerts(dm); if (totvert > 0) { @@ -1519,6 +1521,24 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes return retval; } } + else if (do_ray_start_correction) { + /* We *need* a reasonably valid len_diff in this case. + * Default to distance from object's center (i.e. point (0,0,0) since we are in local space) + * minus farthest vertex from this center. + */ + int i = totvert; + MVert *mv = dm->getVertArray(dm); + float max_dist_squared = 0.0f; + + for (; i; i--, mv++) { + const float d = len_squared_v3(mv->co); + if (d > max_dist_squared) { + max_dist_squared = d; + } + } + + len_diff = len_v3(ray_start_local) - sqrtf(max_dist_squared); + } switch (snap_mode) { case SCE_SNAP_MODE_FACE: @@ -1530,7 +1550,7 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes * been *inside* boundbox, leading to snap failures (see T38409). * Note also ar might be null (see T38435), in this case we assume ray_start is ok! */ - if (ar && !((RegionView3D *)ar->regiondata)->is_persp) { + if (do_ray_start_correction) { float ray_org_local[3]; copy_v3_v3(ray_org_local, ray_origin); -- cgit v1.2.3