Fix T38409: Snapping Bug

Issue partially caused by own errors (glicth in new BKE_boundbox_ray_hit_check() code causing segfault in volume snapping,
and we have to treat ortho and persp differently in case of face snapping, because in persp our ray_start might very well
already be *inside* the boundbox of the checked object), and partly due to the fact that ED_view3d_win_to_vector()
was returning wrong vector (negated one) for ortho views (see previous commit).
This commit is contained in:
Bastien Montagne 2014-01-30 17:11:10 +01:00
parent f54ed9f5e0
commit 0cb49286ce
Notes: blender-bot 2023-02-14 11:16:49 +01:00
Referenced by issue #38409, Snapping Bug
2 changed files with 24 additions and 12 deletions

View File

@ -3155,7 +3155,9 @@ bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], c
(!r_lambda || *r_lambda > lambda))
{
result = true;
*r_lambda = lambda;
if (r_lambda) {
*r_lambda = lambda;
}
}
}

View File

@ -1519,10 +1519,10 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
invert_m4_m4(imat, obmat);
copy_m3_m4(timat, imat);
transpose_m3(timat);
copy_v3_v3(ray_start_local, ray_start);
copy_v3_v3(ray_normal_local, ray_normal);
mul_m4_v3(imat, ray_start_local);
mul_mat3_m4_v3(imat, ray_normal_local);
@ -1536,20 +1536,30 @@ static bool snapDerivedMesh(short snap_mode, ARegion *ar, Object *ob, DerivedMes
{
BVHTreeRayHit hit;
BVHTreeFromMesh treeData;
float ray_org_local[3], local_scale;
copy_v3_v3(ray_org_local, ray_origin);
mul_m4_v3(imat, ray_org_local);
float local_scale;
/* local scale in normal direction */
local_scale = normalize_v3(ray_normal_local);
/* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far
* away ray_start values (as returned in case of ortho view3d), see T38358.
/* Only use closer ray_start in case of ortho view! In perspective one, ray_start may already
* been *inside* boundbox, leading to snap failures (see T38409).
*/
len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */
madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local,
len_v3v3(ray_start_local, ray_org_local) - len_diff);
if (!((RegionView3D *)ar->regiondata)->is_persp) {
float ray_org_local[3];
copy_v3_v3(ray_org_local, ray_origin);
mul_m4_v3(imat, ray_org_local);
/* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far
* away ray_start values (as returned in case of ortho view3d), see T38358.
*/
len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */
madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local,
len_v3v3(ray_start_local, ray_org_local) - len_diff);
}
else {
len_diff = 0.0f;
}
treeData.em_evil = em;
bvhtree_from_mesh_faces(&treeData, dm, 0.0f, 4, 6);