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).
This commit is contained in:
Bastien Montagne 2014-07-28 15:15:18 +02:00
parent 1a9252d97e
commit c4b47b89f7
Notes: blender-bot 2023-02-14 10:17:46 +01:00
Referenced by issue #41191, Face snapping doesn't work properly
1 changed files with 21 additions and 1 deletions

View File

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