From 86f8470a5da2efbd8d521df2759b3a0d06160667 Mon Sep 17 00:00:00 2001 From: Howard Trickey Date: Fri, 30 Aug 2013 16:34:44 +0000 Subject: Some knife fixes. Avoids duplicating verts; better handling of cut-through ortho. Now cut lines detect vertices that they pass (almost) exactly over and snap to them, to avoid making verts vert close to other ones. Added radius arg to BKE_bmbvh_ray_cast so that can detect an obscuring face when the ray might otherwise go exactly between two triangles. Needed an isect_line_tri_epsilon function for similar reason. Fixes last part of bug #35002. Other knife bugs still present but getting this commit in now before continuing bug fixing. --- source/blender/blenkernel/intern/editmesh_bvh.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source/blender/blenkernel/intern/editmesh_bvh.c') diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index fced3472566..ab8d223dd71 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -193,11 +193,14 @@ static void bmbvh_ray_cast_cb(void *userdata, int index, const BVHTreeRay *ray, const BMLoop **ltri = bmcb_data->looptris[index]; float dist, uv[2]; const float *tri_cos[3]; + bool isect; bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage); - if (isect_ray_tri_v3(ray->origin, ray->direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv) && - (dist < hit->dist)) + isect = ray->radius > 0.0f ? + isect_ray_tri_epsilon_v3(ray->origin, ray->direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv, ray->radius) : + isect_ray_tri_v3(ray->origin, ray->direction, tri_cos[0], tri_cos[1], tri_cos[2], &dist, uv); + if (isect && dist < hit->dist) { hit->dist = dist; hit->index = index; @@ -213,7 +216,7 @@ static void bmbvh_ray_cast_cb(void *userdata, int index, const BVHTreeRay *ray, } } -BMFace *BKE_bmbvh_ray_cast(BMBVHTree *bmtree, const float co[3], const float dir[3], +BMFace *BKE_bmbvh_ray_cast(BMBVHTree *bmtree, const float co[3], const float dir[3], const float radius, float *r_dist, float r_hitout[3], float r_cagehit[3]) { BVHTreeRayHit hit; @@ -229,7 +232,7 @@ BMFace *BKE_bmbvh_ray_cast(BMBVHTree *bmtree, const float co[3], const float dir bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->em->looptris; bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage; - BLI_bvhtree_ray_cast(bmtree->tree, co, dir, 0.0f, &hit, bmbvh_ray_cast_cb, &bmcb_data); + BLI_bvhtree_ray_cast(bmtree->tree, co, dir, radius, &hit, bmbvh_ray_cast_cb, &bmcb_data); if (hit.index != -1 && hit.dist != dist) { if (r_hitout) { if (bmtree->flag & BMBVH_RETURN_ORIG) { -- cgit v1.2.3