From 8c6a1d8f954e91bb676d97c8f0f7f162b41db4c3 Mon Sep 17 00:00:00 2001 From: Germano Date: Fri, 4 May 2018 08:29:00 -0300 Subject: Mesh Remap: Face Data: Do not use large epsilon values to create bvhtree. If you need the approximation, use raycast radius. --- source/blender/blenkernel/intern/mesh_remap.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index 84994e80784..8e93be14f6b 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -2013,13 +2013,7 @@ void BKE_mesh_remap_calc_polys_from_dm( BVHTreeRayHit rayhit = {0}; float hit_dist; - if (mode & MREMAP_USE_NORPROJ) { - bvhtree_from_mesh_looptri( - &treedata, dm_src, MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius), 2, 6); - } - else { - bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2); - } + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2); if (mode == MREMAP_MODE_POLY_NEAREST) { nearest.index = -1; @@ -2062,6 +2056,7 @@ void BKE_mesh_remap_calc_polys_from_dm( BLI_space_transform_apply_normal(space_transform, tmp_no); } + treedata.sphere_radius = ray_radius; if (mesh_remap_bvhtree_query_raycast( &treedata, &rayhit, tmp_co, tmp_no, ray_radius, max_dist, &hit_dist)) { @@ -2211,8 +2206,9 @@ void BKE_mesh_remap_calc_polys_from_dm( /* At this point, tmp_co is a point on our poly surface, in mesh_src space! */ while (n--) { + treedata.sphere_radius = ray_radius / w; if (mesh_remap_bvhtree_query_raycast( - &treedata, &rayhit, tmp_co, tmp_no, ray_radius / w, max_dist, &hit_dist)) + &treedata, &rayhit, tmp_co, tmp_no, treedata.sphere_radius, max_dist, &hit_dist)) { const MLoopTri *lt = &treedata.looptri[rayhit.index]; -- cgit v1.2.3 From 3dd6912fce9285c52cdff26739068703ca378a86 Mon Sep 17 00:00:00 2001 From: Germano Date: Fri, 4 May 2018 09:01:56 -0300 Subject: Mesh Remap: Face Corner Data: Do not use large epsilon values to create bvhtrees. Use ray radius instead. --- source/blender/blenkernel/intern/mesh_remap.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index 8e93be14f6b..cf4c70c4aaa 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -422,9 +422,6 @@ typedef struct IslandResult { #define MREMAP_RAYCAST_APPROXIMATE_NR 3 /* Each approximated raycasts will have n times bigger radius than previous one. */ #define MREMAP_RAYCAST_APPROXIMATE_FAC 5.0f -/* BVH epsilon value we have to give to bvh 'constructor' when doing approximated raycasting. */ -#define MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(_ray_radius) \ - ((float)MREMAP_RAYCAST_APPROXIMATE_NR * MREMAP_RAYCAST_APPROXIMATE_FAC * (_ray_radius)) /* min 16 rays/face, max 400. */ #define MREMAP_RAYCAST_TRI_SAMPLES_MIN 4 @@ -547,9 +544,7 @@ void BKE_mesh_remap_calc_verts_from_dm( bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI, 2); if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) { - if (mode & MREMAP_USE_NORPROJ) { - treedata.sphere_radius = ray_radius; - } + treedata.sphere_radius = ray_radius; for (i = 0; i < numverts_dst; i++) { copy_v3_v3(tmp_co, verts_dst[i].co); normal_short_to_float_v3(tmp_no, verts_dst[i].no); @@ -1205,8 +1200,6 @@ void BKE_mesh_remap_calc_loops_from_dm( IslandResult **islands_res; size_t islands_res_buff_size = MREMAP_DEFAULT_BUFSIZE; - const float bvh_epsilon = (mode & MREMAP_USE_NORPROJ) ? MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius) : 0.0f; - if (!use_from_vert) { vcos_src = MEM_mallocN(sizeof(*vcos_src) * (size_t)num_verts_src, __func__); dm_src->getVertCos(dm_src, vcos_src); @@ -1356,7 +1349,7 @@ void BKE_mesh_remap_calc_loops_from_dm( } /* verts 'ownership' is transfered to treedata here, which will handle its freeing. */ bvhtree_from_mesh_verts_ex(&treedata[tindex], verts_src, num_verts_src, verts_allocated_src, - verts_active, num_verts_active, bvh_epsilon, 2, 6); + verts_active, num_verts_active, 0.0, 2, 6); if (verts_allocated_src) { verts_allocated_src = false; /* Only 'give' our verts once, to first tree! */ } @@ -1403,7 +1396,7 @@ void BKE_mesh_remap_calc_loops_from_dm( verts_src, verts_allocated_src, loops_src, loops_allocated_src, looptri_src, num_looptri_src, false, - looptri_active, num_looptri_active, bvh_epsilon, 2, 6); + looptri_active, num_looptri_active, 0.0, 2, 6); if (verts_allocated_src) { verts_allocated_src = false; /* Only 'give' our verts once, to first tree! */ } @@ -1416,7 +1409,7 @@ void BKE_mesh_remap_calc_loops_from_dm( } else { BLI_assert(num_trees == 1); - bvhtree_from_mesh_looptri(&treedata[0], dm_src, bvh_epsilon, 2, 6); + bvhtree_from_mesh_looptri(&treedata[0], dm_src, 0.0, 2, 6); } } @@ -1572,8 +1565,10 @@ void BKE_mesh_remap_calc_loops_from_dm( } while (n--) { + float radius = ray_radius / w; + tdata->sphere_radius = radius; if (mesh_remap_bvhtree_query_raycast( - tdata, &rayhit, tmp_co, tmp_no, ray_radius / w, max_dist, &hit_dist)) + tdata, &rayhit, tmp_co, tmp_no, radius, max_dist, &hit_dist)) { islands_res[tindex][plidx_dst].factor = (hit_dist ? (1.0f / hit_dist) : 1e18f) * w; islands_res[tindex][plidx_dst].hit_dist = hit_dist; @@ -2258,7 +2253,6 @@ void BKE_mesh_remap_calc_polys_from_dm( #undef MREMAP_RAYCAST_APPROXIMATE_NR #undef MREMAP_RAYCAST_APPROXIMATE_FAC -#undef MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON #undef MREMAP_RAYCAST_TRI_SAMPLES_MIN #undef MREMAP_RAYCAST_TRI_SAMPLES_MAX #undef MREMAP_DEFAULT_BUFSIZE -- cgit v1.2.3 From aea637456e7db640f9a1a83416769245a9b18a7d Mon Sep 17 00:00:00 2001 From: Germano Date: Fri, 4 May 2018 09:21:42 -0300 Subject: BKE: BVHtree: Replace all external references of `bvhtree_from_mesh_looptri` with `bvhtree_from_mesh_get`. --- source/blender/blenkernel/BKE_bvhutils.h | 2 -- source/blender/blenkernel/intern/bvhutils.c | 2 +- source/blender/blenkernel/intern/mesh_remap.c | 2 +- source/blender/makesrna/intern/rna_object_api.c | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index b9f07e07f12..57a6c413ce0 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -148,8 +148,6 @@ BVHTree *bvhtree_from_editmesh_looptri_ex( const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis, BVHCache **bvhCache); -BVHTree *bvhtree_from_mesh_looptri( - struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis); BVHTree *bvhtree_from_mesh_looptri_ex( struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 416ac3cbaa0..440db911298 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -1127,7 +1127,7 @@ BVHTree *bvhtree_from_editmesh_looptri( * * \note for editmesh this is currently a duplicate of bvhtree_from_mesh_faces */ -BVHTree *bvhtree_from_mesh_looptri( +static BVHTree *bvhtree_from_mesh_looptri( BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index cf4c70c4aaa..1b05745550d 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -1409,7 +1409,7 @@ void BKE_mesh_remap_calc_loops_from_dm( } else { BLI_assert(num_trees == 1); - bvhtree_from_mesh_looptri(&treedata[0], dm_src, 0.0, 2, 6); + bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_LOOPTRI, 2); } } diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index be63fc4abc8..9b8a98a8831 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -336,7 +336,7 @@ static void rna_Object_ray_cast( BVHTreeFromMesh treeData = {NULL}; /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */ - bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6); + bvhtree_from_mesh_get(&treeData, ob->derivedFinal, BVHTREE_FROM_LOOPTRI, 4); /* may fail if the mesh has no faces, in that case the ray-cast misses */ if (treeData.tree != NULL) { @@ -385,7 +385,7 @@ static void rna_Object_closest_point_on_mesh( } /* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */ - bvhtree_from_mesh_looptri(&treeData, ob->derivedFinal, 0.0f, 4, 6); + bvhtree_from_mesh_get(&treeData, ob->derivedFinal, BVHTREE_FROM_LOOPTRI, 4); if (treeData.tree == NULL) { BKE_reportf(reports, RPT_ERROR, "Object '%s' could not create internal data for finding nearest point", -- cgit v1.2.3