Cleanup: rename dist -> depth
authorCampbell Barton <ideasman42@gmail.com>
Thu, 5 Oct 2017 10:06:04 +0000 (21:06 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 5 Oct 2017 10:09:12 +0000 (21:09 +1100)
Prepare to add code that stores distance to the ray, avoid confusion.

source/blender/blenkernel/BKE_pbvh.h
source/blender/blenkernel/intern/pbvh.c
source/blender/blenkernel/intern/pbvh_bmesh.c
source/blender/blenkernel/intern/pbvh_intern.h
source/blender/editors/sculpt_paint/sculpt.c

index cc84be6e2c141fef5a9e0665669ccb11eb841bbe..08959e79740ae97a805da3ec46c324276317a1eb 100644 (file)
@@ -101,12 +101,12 @@ void BKE_pbvh_raycast(
 bool BKE_pbvh_node_raycast(
         PBVH *bvh, PBVHNode *node, float (*origco)[3], bool use_origco,
         const float ray_start[3], const float ray_normal[3],
-        float *dist);
+        float *depth);
 
 bool BKE_pbvh_bmesh_node_raycast_detail(
         PBVHNode *node,
         const float ray_start[3], const float ray_normal[3],
-        float *dist, float *r_detail);
+        float *depth, float *r_detail);
 
 /* for orthographic cameras, project the far away ray segment points to the root node so
  * we can have better precision. */
index 4b154d3301c7c23a965eb3511af18d013dea6a48..bc93aa5678a80fd5a632568b5324e36068a98687 100644 (file)
@@ -1537,14 +1537,16 @@ void BKE_pbvh_raycast(
 bool ray_face_intersection_quad(
         const float ray_start[3], const float ray_normal[3],
         const float t0[3], const float t1[3], const float t2[3], const float t3[3],
-        float *dist)
+        float *depth)
 {
-       float dist_test;
+       float depth_test;
 
-       if ((isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2, &dist_test, NULL, 0.1f) && (dist_test < *dist)) ||
-           (isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t2, t3, &dist_test, NULL, 0.1f) && (dist_test < *dist)))
+       if ((isect_ray_tri_epsilon_v3(
+                ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.1f) && (depth_test < *depth)) ||
+           (isect_ray_tri_epsilon_v3(
+                ray_start, ray_normal, t0, t2, t3, &depth_test, NULL, 0.1f) && (depth_test < *depth)))
        {
-               *dist = dist_test;
+               *depth = depth_test;
                return true;
        }
        else {
@@ -1555,12 +1557,14 @@ bool ray_face_intersection_quad(
 bool ray_face_intersection_tri(
         const float ray_start[3], const float ray_normal[3],
         const float t0[3], const float t1[3], const float t2[3],
-        float *dist)
+        float *depth)
 {
-       float dist_test;
+       float depth_test;
 
-       if ((isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2, &dist_test, NULL, 0.1f) && (dist_test < *dist))) {
-               *dist = dist_test;
+       if ((isect_ray_tri_epsilon_v3(
+                ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.1f) && (depth_test < *depth)))
+       {
+               *depth = depth_test;
                return true;
        }
        else {
@@ -1572,7 +1576,7 @@ static bool pbvh_faces_node_raycast(
         PBVH *bvh, const PBVHNode *node,
         float (*origco)[3],
         const float ray_start[3], const float ray_normal[3],
-        float *dist)
+        float *depth)
 {
        const MVert *vert = bvh->verts;
        const MLoop *mloop = bvh->mloop;
@@ -1594,7 +1598,7 @@ static bool pbvh_faces_node_raycast(
                                origco[face_verts[0]],
                                origco[face_verts[1]],
                                origco[face_verts[2]],
-                               dist);
+                               depth);
                }
                else {
                        /* intersect with current coordinates */
@@ -1603,7 +1607,7 @@ static bool pbvh_faces_node_raycast(
                                vert[mloop[lt->tri[0]].v].co,
                                vert[mloop[lt->tri[1]].v].co,
                                vert[mloop[lt->tri[2]].v].co,
-                               dist);
+                               depth);
                }
        }
 
@@ -1614,7 +1618,7 @@ static bool pbvh_grids_node_raycast(
         PBVH *bvh, PBVHNode *node,
         float (*origco)[3],
         const float ray_start[3], const float ray_normal[3],
-        float *dist)
+        float *depth)
 {
        const int totgrid = node->totprim;
        const int gridsize = bvh->gridkey.grid_size;
@@ -1644,7 +1648,7 @@ static bool pbvh_grids_node_raycast(
                                                origco[y * gridsize + x + 1],
                                                origco[(y + 1) * gridsize + x + 1],
                                                origco[(y + 1) * gridsize + x],
-                                               dist);
+                                               depth);
                                }
                                else {
                                        hit |= ray_face_intersection_quad(
@@ -1653,7 +1657,7 @@ static bool pbvh_grids_node_raycast(
                                                CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y),
                                                CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1),
                                                CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1),
-                                               dist);
+                                               depth);
                                }
                        }
                }
@@ -1668,7 +1672,7 @@ static bool pbvh_grids_node_raycast(
 bool BKE_pbvh_node_raycast(
         PBVH *bvh, PBVHNode *node, float (*origco)[3], bool use_origco,
         const float ray_start[3], const float ray_normal[3],
-        float *dist)
+        float *depth)
 {
        bool hit = false;
 
@@ -1679,16 +1683,16 @@ bool BKE_pbvh_node_raycast(
                case PBVH_FACES:
                        hit |= pbvh_faces_node_raycast(
                                bvh, node, origco,
-                               ray_start, ray_normal, dist);
+                               ray_start, ray_normal, depth);
                        break;
                case PBVH_GRIDS:
                        hit |= pbvh_grids_node_raycast(
                                bvh, node, origco,
-                               ray_start, ray_normal, dist);
+                               ray_start, ray_normal, depth);
                        break;
                case PBVH_BMESH:
                        hit = pbvh_bmesh_node_raycast(
-                               node, ray_start, ray_normal, dist, use_origco);
+                               node, ray_start, ray_normal, depth, use_origco);
                        break;
        }
 
index c5e49883dc6a46b85a36f82eb6fa912cced8d820..529dfae05e2f0e18191720c6d1f6486c60cb9132 100644 (file)
@@ -1466,7 +1466,7 @@ static bool pbvh_bmesh_collapse_short_edges(
 
 bool pbvh_bmesh_node_raycast(
         PBVHNode *node, const float ray_start[3],
-        const float ray_normal[3], float *dist,
+        const float ray_normal[3], float *depth,
         bool use_original)
 {
        bool hit = false;
@@ -1479,7 +1479,7 @@ bool pbvh_bmesh_node_raycast(
                                node->bm_orco[t[0]],
                                node->bm_orco[t[1]],
                                node->bm_orco[t[2]],
-                               dist);
+                               depth);
                }
        }
        else {
@@ -1498,7 +1498,7 @@ bool pbvh_bmesh_node_raycast(
                                        v_tri[0]->co,
                                        v_tri[1]->co,
                                        v_tri[2]->co,
-                                       dist);
+                                       depth);
                        }
                }
        }
@@ -1509,7 +1509,7 @@ bool pbvh_bmesh_node_raycast(
 bool BKE_pbvh_bmesh_node_raycast_detail(
         PBVHNode *node,
         const float ray_start[3], const float ray_normal[3],
-        float *dist, float *r_detail)
+        float *depth, float *r_detail)
 {
        if (node->flag & PBVH_FullyHidden)
                return 0;
@@ -1531,7 +1531,7 @@ bool BKE_pbvh_bmesh_node_raycast_detail(
                                v_tri[0]->co,
                                v_tri[1]->co,
                                v_tri[2]->co,
-                               dist);
+                               depth);
 
                        if (hit_local) {
                                f_hit = f;
index 010573185683f225a0dbe40abbbf87dd142a347b..7d75930b3c60146643fbb07141415ed35953ff1b 100644 (file)
@@ -185,11 +185,11 @@ void pbvh_grow_nodes(PBVH *bvh, int totnode);
 bool ray_face_intersection_quad(
         const float ray_start[3], const float ray_normal[3],
         const float *t0, const float *t1, const float *t2, const float *t3,
-        float *r_dist);
+        float *depth);
 bool ray_face_intersection_tri(
         const float ray_start[3], const float ray_normal[3],
         const float *t0, const float *t1, const float *t2,
-        float *r_dist);
+        float *depth);
 void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
 
 /* pbvh_bmesh.c */
index 3035f4b7979af06ec4eeb88e581a0ad11f2d89cf..1bff1f460eaf9943890f2989dd98e91d09437860 100644 (file)
@@ -1538,14 +1538,14 @@ typedef struct {
        SculptSession *ss;
        const float *ray_start, *ray_normal;
        bool hit;
-       float dist;
+       float depth;
        bool original;
 } SculptRaycastData;
 
 typedef struct {
        const float *ray_start, *ray_normal;
        bool hit;
-       float dist;
+       float depth;
        float detail;
 } SculptDetailRaycastData;
 
@@ -4322,10 +4322,10 @@ static void sculpt_raycast_cb(PBVHNode *node, void *data_v, float *tmin)
                }
 
                if (BKE_pbvh_node_raycast(srd->ss->pbvh, node, origco, use_origco,
-                                         srd->ray_start, srd->ray_normal, &srd->dist))
+                                         srd->ray_start, srd->ray_normal, &srd->depth))
                {
                        srd->hit = 1;
-                       *tmin = srd->dist;
+                       *tmin = srd->depth;
                }
        }
 }
@@ -4335,10 +4335,10 @@ static void sculpt_raycast_detail_cb(PBVHNode *node, void *data_v, float *tmin)
        if (BKE_pbvh_node_get_tmin(node) < *tmin) {
                SculptDetailRaycastData *srd = data_v;
                if (BKE_pbvh_bmesh_node_raycast_detail(node, srd->ray_start, srd->ray_normal,
-                                                      &srd->dist, &srd->detail))
+                                                      &srd->depth, &srd->detail))
                {
                        srd->hit = 1;
-                       *tmin = srd->dist;
+                       *tmin = srd->depth;
                }
        }
 }
@@ -4385,8 +4385,7 @@ bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
        Object *ob;
        SculptSession *ss;
        StrokeCache *cache;
-       float ray_start[3], ray_end[3], ray_normal[3], dist;
-       SculptRaycastData srd;
+       float ray_start[3], ray_end[3], ray_normal[3], depth;
        bool original;
        ViewContext vc;
 
@@ -4400,28 +4399,35 @@ bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
 
        sculpt_stroke_modifiers_check(C, ob);
 
-       dist = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, original);
-
-       srd.original = original;
-       srd.ss = ob->sculpt;
-       srd.hit = 0;
-       srd.ray_start = ray_start;
-       srd.ray_normal = ray_normal;
-       srd.dist = dist;
+       depth = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, original);
 
-       BKE_pbvh_raycast(ss->pbvh, sculpt_raycast_cb, &srd,
-                        ray_start, ray_normal, srd.original);
-
-       copy_v3_v3(out, ray_normal);
-       mul_v3_fl(out, srd.dist);
-       add_v3_v3(out, ray_start);
+       bool hit = false;
+       {
+               SculptRaycastData srd = {
+                       .original = original,
+                       .ss = ob->sculpt,
+                       .hit = 0,
+                       .ray_start = ray_start,
+                       .ray_normal = ray_normal,
+                       .depth = depth,
+               };
+               BKE_pbvh_raycast(
+                       ss->pbvh, sculpt_raycast_cb, &srd,
+                       ray_start, ray_normal, srd.original);
+               if (srd.hit) {
+                       hit = true;
+                       copy_v3_v3(out, ray_normal);
+                       mul_v3_fl(out, srd.depth);
+                       add_v3_v3(out, ray_start);
+               }
+       }
 
        //used in vwpaint
-       if (cache && srd.hit){
+       if (cache && hit){
                copy_v3_v3(cache->true_location, out);
        }
 
-       return srd.hit;
+       return hit;
 }
 
 static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession *ss)
@@ -5487,7 +5493,7 @@ static void sample_detail(bContext *C, int ss_co[2])
        ViewContext vc;
        Object *ob;
        Sculpt *sd;
-       float ray_start[3], ray_end[3], ray_normal[3], dist;
+       float ray_start[3], ray_end[3], ray_normal[3], depth;
        SculptDetailRaycastData srd;
        float mouse[2] = {ss_co[0], ss_co[1]};
        view3d_set_viewcontext(C, &vc);
@@ -5497,12 +5503,12 @@ static void sample_detail(bContext *C, int ss_co[2])
 
        sculpt_stroke_modifiers_check(C, ob);
 
-       dist = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, false);
+       depth = sculpt_raycast_init(&vc, mouse, ray_start, ray_end, ray_normal, false);
 
        srd.hit = 0;
        srd.ray_start = ray_start;
        srd.ray_normal = ray_normal;
-       srd.dist = dist;
+       srd.depth = depth;
        srd.detail = sd->constant_detail;
 
        BKE_pbvh_raycast(ob->sculpt->pbvh, sculpt_raycast_detail_cb, &srd,