diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_bvhutils.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/bvhutils.c | 23 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_remap.c | 33 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/shrinkwrap.c | 4 | ||||
-rw-r--r-- | source/blender/editors/physics/particle_object.c | 4 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 4 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_surface.c | 4 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_surfacedeform.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_weightvgproximity.c | 6 | ||||
-rw-r--r-- | source/blender/render/intern/source/bake_api.c | 2 |
11 files changed, 59 insertions, 34 deletions
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index b3122f8adb9..33e88a6b8f8 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -113,8 +113,6 @@ BVHTree *bvhtree_from_editmesh_verts_ex( const BLI_bitmap *mask, int verts_num_active, float epsilon, int tree_type, int axis); -BVHTree *bvhtree_from_mesh_verts( - struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, int tree_type, int axis); BVHTree *bvhtree_from_mesh_verts_ex( struct BVHTreeFromMesh *data, const struct MVert *vert, const int numVerts, const bool vert_allocated, const BLI_bitmap *mask, int verts_num_active, @@ -138,9 +136,6 @@ BVHTree *bvhtree_from_mesh_edges_ex( const BLI_bitmap *edges_mask, int edges_num_active, float epsilon, int tree_type, int axis); -BVHTree *bvhtree_from_mesh_faces( - struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, float epsilon, - int tree_type, int axis); BVHTree *bvhtree_from_mesh_faces_ex( struct BVHTreeFromMesh *data, const struct MVert *vert, const bool vert_allocated, @@ -166,6 +161,8 @@ BVHTree *bvhtree_from_mesh_looptri_ex( const BLI_bitmap *mask, int looptri_num_active, float epsilon, int tree_type, int axis); +BVHTree *bvhtree_from_mesh_get(struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type); + /** * Frees data allocated by a call to bvhtree_from_mesh_*. */ diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index cd2c7194237..90a75b8d3cc 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -501,7 +501,7 @@ BVHTree *bvhtree_from_editmesh_verts( /* Builds a bvh tree where nodes are the vertices of the given dm * and stores the BVHTree in dm->bvhCache */ -BVHTree *bvhtree_from_mesh_verts( +static BVHTree *bvhtree_from_mesh_verts( BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { @@ -859,7 +859,7 @@ static void bvhtree_from_mesh_faces_setup_data( } /* Builds a bvh tree where nodes are the tesselated faces of the given dm */ -BVHTree *bvhtree_from_mesh_faces( +static BVHTree *bvhtree_from_mesh_faces( BVHTreeFromMesh *data, DerivedMesh *dm, float epsilon, int tree_type, int axis) { @@ -1225,6 +1225,25 @@ BVHTree *bvhtree_from_mesh_looptri_ex( return tree; } +/** + * Builds or queries a bvhcache for the cache bvhtree of the request type. + */ +BVHTree *bvhtree_from_mesh_get( + struct BVHTreeFromMesh *data, struct DerivedMesh *mesh, int type) +{ + switch (type) { + case BVHTREE_FROM_VERTS: + return bvhtree_from_mesh_verts(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_EDGES: + return bvhtree_from_mesh_edges(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_FACES: + return bvhtree_from_mesh_faces(data, mesh, 0.0f, 2, 6); + case BVHTREE_FROM_LOOPTRI: + return bvhtree_from_mesh_looptri(data, mesh, 0.0f, 2, 6); + } + return NULL; +} + /** \} */ diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 28e4af32a71..934cfbe9374 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3508,9 +3508,9 @@ static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra nearest.dist_sq = FLT_MAX; if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) - bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_VERTS); else - bvhtree_from_mesh_looptri(&treeData, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, target, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { fail = true; diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index 0af4dae4506..f99dd5574b2 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -131,7 +131,7 @@ float BKE_mesh_remap_calc_difference_from_dm( float result = 0.0f; int i; - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -460,7 +460,7 @@ void BKE_mesh_remap_calc_verts_from_dm( float tmp_co[3], tmp_no[3]; if (mode == MREMAP_MODE_VERT_NEAREST) { - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -485,7 +485,7 @@ void BKE_mesh_remap_calc_verts_from_dm( float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES); nearest.index = -1; for (i = 0; i < numverts_dst; i++) { @@ -543,7 +543,13 @@ void BKE_mesh_remap_calc_verts_from_dm( float *weights = MEM_mallocN(sizeof(*weights) * tmp_buff_size, __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_looptri(&treedata, dm_src, (mode & MREMAP_USE_NORPROJ) ? ray_radius : 0.0f, 2, 6); + if (mode & MREMAP_USE_NORPROJ) { + bvhtree_from_mesh_looptri( + &treedata, dm_src, ray_radius, 2, 6); + } + else { + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI); + } if (mode == MREMAP_MODE_VERT_POLYINTERP_VNORPROJ) { for (i = 0; i < numverts_dst; i++) { @@ -676,7 +682,7 @@ void BKE_mesh_remap_calc_edges_from_dm( dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_verts(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_VERTS); nearest.index = -1; for (i = 0; i < numedges_dst; i++) { @@ -776,7 +782,7 @@ void BKE_mesh_remap_calc_edges_from_dm( MEM_freeN(vert_to_edge_src_map_mem); } else if (mode == MREMAP_MODE_EDGE_NEAREST) { - bvhtree_from_mesh_edges(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_EDGES); nearest.index = -1; for (i = 0; i < numedges_dst; i++) { @@ -803,7 +809,7 @@ void BKE_mesh_remap_calc_edges_from_dm( float (*vcos_src)[3] = MEM_mallocN(sizeof(*vcos_src) * (size_t)dm_src->getNumVerts(dm_src), __func__); dm_src->getVertCos(dm_src, vcos_src); - bvhtree_from_mesh_looptri(&treedata, dm_src, 0.0f, 2, 6); + bvhtree_from_mesh_get(&treedata, dm_src, BVHTREE_FROM_LOOPTRI); for (i = 0; i < numedges_dst; i++) { interp_v3_v3v3(tmp_co, verts_dst[edges_dst[i].v1].co, verts_dst[edges_dst[i].v2].co, 0.5f); @@ -1360,7 +1366,7 @@ void BKE_mesh_remap_calc_loops_from_dm( } else { BLI_assert(num_trees == 1); - bvhtree_from_mesh_verts(&treedata[0], dm_src, bvh_epsilon, 2, 6); + bvhtree_from_mesh_get(&treedata[0], dm_src, BVHTREE_FROM_VERTS); } } else { /* We use polygons. */ @@ -2007,10 +2013,13 @@ void BKE_mesh_remap_calc_polys_from_dm( BVHTreeRayHit rayhit = {0}; float hit_dist; - bvhtree_from_mesh_looptri( - &treedata, dm_src, - (mode & MREMAP_USE_NORPROJ) ? MREMAP_RAYCAST_APPROXIMATE_BVHEPSILON(ray_radius) : 0.0f, - 2, 6); + 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); + } if (mode == MREMAP_MODE_POLY_NEAREST) { nearest.index = -1; diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 618f495dbf1..0d381248ef2 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -158,7 +158,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) return; } - TIMEIT_BENCH(bvhtree_from_mesh_verts(&treeData, calc->target, 0.0, 2, 6), bvhtree_verts); + TIMEIT_BENCH(bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_VERTS), bvhtree_verts); if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; @@ -588,7 +588,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) } /* Create a bvh-tree of the given target */ - bvhtree_from_mesh_looptri(&treeData, calc->target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, calc->target, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { OUT_OF_MEMORY(); return; diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 546fac6b7a3..f4334a2e872 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -692,11 +692,11 @@ static bool remap_hair_emitter(Scene *scene, Object *ob, ParticleSystem *psys, if (dm->getNumTessFaces(dm) != 0) { mface = dm->getTessFaceArray(dm); - bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6); + bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_FACES); } else if (dm->getNumEdges(dm) != 0) { medge = dm->getEdgeArray(dm); - bvhtree_from_mesh_edges(&bvhtree, dm, 0.0, 2, 6); + bvhtree_from_mesh_get(&bvhtree, dm, BVHTREE_FROM_EDGES); } else { dm->release(dm); diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index d248d0df4e3..569c662d31c 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -1687,10 +1687,10 @@ static bool snapDerivedMesh( if (treedata->tree == NULL) { switch (snapdata->snap_to) { case SCE_SNAP_MODE_EDGE: - bvhtree_from_mesh_edges(treedata, dm, 0.0f, 2, 6); + bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_EDGES); break; case SCE_SNAP_MODE_VERTEX: - bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6); + bvhtree_from_mesh_get(treedata, dm, BVHTREE_FROM_VERTS); break; } } diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index 7bb4c0b2fd1..389cffe85e7 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -159,9 +159,9 @@ static void deformVerts(ModifierData *md, Object *ob, surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh"); if (surmd->dm->getNumPolys(surmd->dm)) - bvhtree_from_mesh_looptri(surmd->bvhtree, surmd->dm, 0.0, 2, 6); + bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_LOOPTRI); else - bvhtree_from_mesh_edges(surmd->bvhtree, surmd->dm, 0.0, 2, 6); + bvhtree_from_mesh_get(surmd->bvhtree, surmd->dm, BVHTREE_FROM_EDGES); } } diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index fc605dd48e1..5006fe4a6e0 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -960,7 +960,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos) return false; } - bvhtree_from_mesh_looptri(&treeData, tdm, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData, tdm, BVHTREE_FROM_LOOPTRI); if (treeData.tree == NULL) { modifier_setError((ModifierData *)smd, "Out of memory"); freeAdjacencyMap(vert_edges, adj_array, edge_polys); diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 09991887f69..c60c9690ac3 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -149,7 +149,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], if (dist_v) { /* Create a bvh-tree of the given target's verts. */ - bvhtree_from_mesh_verts(&treeData_v, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_v, target, BVHTREE_FROM_VERTS); if (treeData_v.tree == NULL) { OUT_OF_MEMORY(); return; @@ -157,7 +157,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], } if (dist_e) { /* Create a bvh-tree of the given target's edges. */ - bvhtree_from_mesh_edges(&treeData_e, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_e, target, BVHTREE_FROM_EDGES); if (treeData_e.tree == NULL) { OUT_OF_MEMORY(); return; @@ -165,7 +165,7 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], } if (dist_f) { /* Create a bvh-tree of the given target's faces. */ - bvhtree_from_mesh_looptri(&treeData_f, target, 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData_f, target, BVHTREE_FROM_LOOPTRI); if (treeData_f.tree == NULL) { OUT_OF_MEMORY(); return; diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c index 505af3c2fa8..7f7acceb5dd 100644 --- a/source/blender/render/intern/source/bake_api.c +++ b/source/blender/render/intern/source/bake_api.c @@ -526,7 +526,7 @@ bool RE_bake_pixels_populate_from_objects( if (dm_highpoly[i]->getNumTessFaces(dm_highpoly[i]) != 0) { /* Create a bvh-tree for each highpoly object */ - bvhtree_from_mesh_faces(&treeData[i], dm_highpoly[i], 0.0, 2, 6); + bvhtree_from_mesh_get(&treeData[i], dm_highpoly[i], BVHTREE_FROM_FACES); if (treeData[i].tree == NULL) { printf("Baking: out of memory while creating BHVTree for object \"%s\"\n", highpoly[i].ob->id.name + 2); |