From 881334c499c839679b4b40e0ce1ca6bda3c03a39 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 15 Oct 2018 13:38:10 +1100 Subject: [PATCH] Cleanup: remove DerivedMesh bvhtree_from_mesh_get --- source/blender/blenkernel/BKE_bvhutils.h | 4 - source/blender/blenkernel/BKE_mesh.h | 7 - source/blender/blenkernel/intern/bvhutils.c | 222 +------------------- 3 files changed, 1 insertion(+), 232 deletions(-) diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 35112c5a0ac..018f535a4cb 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -151,10 +151,6 @@ 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, - const int type, const int tree_type); - BVHTree *BKE_bvhtree_from_mesh_get( struct BVHTreeFromMesh *data, struct Mesh *mesh, const int type, const int tree_type); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 89bde516264..bb4b06c1df1 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -245,13 +245,6 @@ void BKE_mesh_calc_normals_looptri( const struct MLoop *mloop, const struct MLoopTri *looptri, int looptri_num, float (*r_tri_nors)[3]); -void BKE_mesh_loop_tangents_ex( - const struct MVert *mverts, const int numVerts, const struct MLoop *mloops, - float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv, - const int numLoops, const struct MPoly *mpolys, const int numPolys, - struct ReportList *reports); -void BKE_mesh_loop_tangents( - struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports); void BKE_mesh_loop_manifold_fan_around_vert_next( const struct MLoop *mloops, const struct MPoly *mpolys, const int *loop_to_poly, const int *e2lfan_curr, const uint mv_pivot_index, diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index bb3d468fd7b..15c7ba54732 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -42,7 +42,7 @@ #include "BLI_math.h" #include "BLI_threads.h" -#include "BKE_DerivedMesh.h" +#include "BKE_bvhutils.h" #include "BKE_editmesh.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" @@ -1086,226 +1086,6 @@ static BLI_bitmap *loose_edges_map_get( return loose_edges_mask; } -/** - * Builds or queries a bvhcache for the cache bvhtree of the request type. - */ -BVHTree *bvhtree_from_mesh_get( - struct BVHTreeFromMesh *data, struct DerivedMesh *dm, - const int type, const int tree_type) -{ - BVHTree *tree = NULL; - - BVHTree_NearestPointCallback nearest_callback = NULL; - BVHTree_RayCastCallback raycast_callback = NULL; - - MVert *mvert = NULL; - MEdge *medge = NULL; - MFace *mface = NULL; - MLoop *mloop = NULL; - const MLoopTri *looptri = NULL; - bool vert_allocated = false; - bool edge_allocated = false; - bool face_allocated = false; - bool loop_allocated = false; - bool looptri_allocated = false; - - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); - bool in_cache = bvhcache_find(dm->bvhCache, type, &tree); - BLI_rw_mutex_unlock(&cache_rwlock); - - if (in_cache && tree == NULL) { - memset(data, 0, sizeof(*data)); - return tree; - } - - switch (type) { - case BVHTREE_FROM_VERTS: - case BVHTREE_FROM_LOOSEVERTS: - raycast_callback = mesh_verts_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, type, &tree); - if (in_cache == false) { - BLI_bitmap *loose_verts_mask = NULL; - int loose_vert_num = -1; - int verts_num = dm->getNumVerts(dm); - - if (type == BVHTREE_FROM_LOOSEVERTS) { - medge = DM_get_edge_array(dm, &edge_allocated); - - loose_verts_mask = loose_verts_map_get( - medge, dm->getNumEdges(dm), mvert, - verts_num, &loose_vert_num); - - if (edge_allocated) { - MEM_freeN(medge); - edge_allocated = false; - } - medge = NULL; - } - - tree = bvhtree_from_mesh_verts_create_tree( - 0.0, tree_type, 6, mvert, verts_num, - loose_verts_mask, loose_vert_num); - - if (loose_verts_mask != NULL) { - MEM_freeN(loose_verts_mask); - } - - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, type); - - } - - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_EDGES: - case BVHTREE_FROM_LOOSEEDGES: - nearest_callback = mesh_edges_nearest_point; - raycast_callback = mesh_edges_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - medge = DM_get_edge_array(dm, &edge_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, type, &tree); - if (in_cache == false) { - BLI_bitmap *loose_edges_mask = NULL; - int loose_edges_num = -1; - int edges_num = dm->getNumEdges(dm); - - if (type == BVHTREE_FROM_LOOSEEDGES) { - loose_edges_mask = loose_edges_map_get( - medge, edges_num, &loose_edges_num); - } - - tree = bvhtree_from_mesh_edges_create_tree( - mvert, medge, edges_num, - loose_edges_mask, loose_edges_num, 0.0, tree_type, 6); - - if (loose_edges_mask != NULL) { - MEM_freeN(loose_edges_mask); - } - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, type); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_FACES: - nearest_callback = mesh_faces_nearest_point; - raycast_callback = mesh_faces_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - mface = DM_get_tessface_array(dm, &face_allocated); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, BVHTREE_FROM_FACES, &tree); - if (in_cache == false) { - int numFaces = dm->getNumTessFaces(dm); - BLI_assert(!(numFaces == 0 && dm->getNumPolys(dm) != 0)); - - tree = bvhtree_from_mesh_faces_create_tree( - 0.0, tree_type, 6, mvert, mface, numFaces, NULL, -1); - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_FACES); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - - case BVHTREE_FROM_LOOPTRI: - nearest_callback = mesh_looptri_nearest_point; - raycast_callback = mesh_looptri_spherecast; - - mvert = DM_get_vert_array(dm, &vert_allocated); - mloop = DM_get_loop_array(dm, &loop_allocated); - looptri = dm->getLoopTriArray(dm); - - if (in_cache == false) { - BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); - in_cache = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI, &tree); - if (in_cache == false) { - int looptri_num = dm->getNumLoopTri(dm); - - /* this assert checks we have looptris, - * if not caller should use DM_ensure_looptri() */ - BLI_assert(!(looptri_num == 0 && dm->getNumPolys(dm) != 0)); - - tree = bvhtree_from_mesh_looptri_create_tree( - 0.0, tree_type, 6, - mvert, mloop, looptri, looptri_num, NULL, -1); - - /* Save on cache for later use */ - /* printf("BVHTree built and saved on cache\n"); */ - bvhcache_insert(&dm->bvhCache, tree, BVHTREE_FROM_LOOPTRI); - } - BLI_rw_mutex_unlock(&cache_rwlock); - } - break; - } - - if (tree != NULL) { -#ifdef DEBUG - if (BLI_bvhtree_get_tree_type(tree) != tree_type) { - printf("tree_type %d obtained instead of %d\n", BLI_bvhtree_get_tree_type(tree), tree_type); - } -#endif - data->tree = tree; - - data->nearest_callback = nearest_callback; - data->raycast_callback = raycast_callback; - - data->vert = mvert; - data->edge = medge; - data->face = mface; - data->loop = mloop; - data->looptri = looptri; - data->vert_allocated = vert_allocated; - data->edge_allocated = edge_allocated; - data->face_allocated = face_allocated; - data->loop_allocated = loop_allocated; - data->looptri_allocated = looptri_allocated; - - data->cached = true; - } - else { - if (vert_allocated) { - MEM_freeN(mvert); - } - if (edge_allocated) { - MEM_freeN(medge); - } - if (face_allocated) { - MEM_freeN(mface); - } - if (loop_allocated) { - MEM_freeN(mloop); - } - if (looptri_allocated) { - MEM_freeN((void *)looptri); - } - - memset(data, 0, sizeof(*data)); - } - - return tree; -} - /** * Builds or queries a bvhcache for the cache bvhtree of the request type. */