Commit: 0cb49286ce45f1b2ce16db0e174170ef2a671dba
Author: Bastien Montagne
Date:   Thu Jan 30 17:11:10 2014 +0100
https://developer.blender.org/rB0cb49286ce45f1b2ce16db0e174170ef2a671dba

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).

===================================================================

M       source/blender/blenkernel/intern/object.c
M       source/blender/editors/transform/transform_snap.c

===================================================================

diff --git a/source/blender/blenkernel/intern/object.c 
b/source/blender/blenkernel/intern/object.c
index 019885d..d8170af 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -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;
+                       }
                }
        }
        
diff --git a/source/blender/editors/transform/transform_snap.c 
b/source/blender/editors/transform/transform_snap.c
index 91f8da1..a51ed85 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -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);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to