diff options
-rw-r--r-- | source/blender/blenkernel/BKE_editmesh_bvh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editmesh_bvh.c | 15 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_utils.c | 2 |
4 files changed, 14 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_editmesh_bvh.h b/source/blender/blenkernel/BKE_editmesh_bvh.h index cdab48f239c..b0761f216d2 100644 --- a/source/blender/blenkernel/BKE_editmesh_bvh.h +++ b/source/blender/blenkernel/BKE_editmesh_bvh.h @@ -45,7 +45,7 @@ BMBVHTree *BKE_bmbvh_new(struct BMEditMesh *em, int flag, struct Scene *sce void BKE_bmbvh_free(BMBVHTree *tree); struct BVHTree *BKE_bmbvh_tree_get(BMBVHTree *tree); struct BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], - float r_hitout[3], float r_cagehit[3]); + float *r_dist, float r_hitout[3], float r_cagehit[3]); /* find a vert closest to co in a sphere of radius maxdist */ struct BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *tree, const float co[3], const float maxdist); diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index a94d1d1e5aa..7921468fdc6 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -237,17 +237,18 @@ static void raycallback(void *userdata, int index, const BVHTreeRay *ray, BVHTre } BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3], - float r_hitout[3], float r_cagehit[3]) + float *r_dist, float r_hitout[3], float r_cagehit[3]) { BVHTreeRayHit hit; + const float dist = r_dist ? *r_dist : FLT_MAX; - hit.dist = FLT_MAX; + hit.dist = dist; hit.index = -1; - - tree->uv[0] = tree->uv[1] = 0.0f; + + zero_v2(tree->uv); BLI_bvhtree_ray_cast(tree->tree, co, dir, 0.0f, &hit, raycallback, tree); - if (hit.dist != FLT_MAX && hit.index != -1) { + if (hit.index != -1 && hit.dist != dist) { if (r_hitout) { if (tree->flag & BMBVH_RETURN_ORIG) { const float *co1, *co2, *co3; @@ -271,6 +272,10 @@ BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const float dir[3 } } + if (r_dist) { + *r_dist = hit.dist; + } + return tree->em->looptris[hit.index][0]->f; } diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 27a0d11314c..022e753dd40 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -1268,7 +1268,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, add_v3_v3(p1, no); /* ray cast */ - f_hit = BKE_bmbvh_ray_cast(bmtree, p1, no, NULL, NULL); + f_hit = BKE_bmbvh_ray_cast(bmtree, p1, no, NULL, NULL, NULL); } /* ok, if visible add the new point */ @@ -1502,7 +1502,7 @@ static BMFace *knife_find_closest_face(KnifeTool_OpData *kcd, float co[3], float knife_input_ray_segment(kcd, kcd->curr.mval, 1.0f, origin, origin_ofs); sub_v3_v3v3(ray, origin_ofs, origin); - f = BKE_bmbvh_ray_cast(kcd->bmbvh, origin, ray, co, cageco); + f = BKE_bmbvh_ray_cast(kcd->bmbvh, origin, ray, NULL, co, cageco); if (is_space) *is_space = !f; diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index eb32aee8d43..01e3ed4f4cb 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -1391,7 +1391,7 @@ int BMBVH_VertVisible(BMBVHTree *tree, BMEdge *e, RegionView3D *r3d) static BMFace *edge_ray_cast(struct BMBVHTree *tree, const float co[3], const float dir[3], float *r_hitout, BMEdge *e) { - BMFace *f = BKE_bmbvh_ray_cast(tree, co, dir, r_hitout, NULL); + BMFace *f = BKE_bmbvh_ray_cast(tree, co, dir, NULL, r_hitout, NULL); if (f && BM_edge_in_face(f, e)) return NULL; |