Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/bvhutils.c
| Show First 20 Lines • Show All 489 Lines • ▼ Show 20 Lines | if (tree) { | ||||
| data->raycast_callback = editmesh_verts_spherecast; | data->raycast_callback = editmesh_verts_spherecast; | ||||
| } | } | ||||
| return tree; | return tree; | ||||
| } | } | ||||
| BVHTree *bvhtree_from_editmesh_verts( | BVHTree *bvhtree_from_editmesh_verts( | ||||
| BVHTreeFromEditMesh *data, BMEditMesh *em, | BVHTreeFromEditMesh *data, BMEditMesh *em, | ||||
| float epsilon, int tree_type, int axis) | float epsilon, int tree_type, int axis, BVHCache **bvhCache) | ||||
| { | { | ||||
| return bvhtree_from_editmesh_verts_ex( | if (bvhCache) { | ||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); | |||||
| data->cached = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_VERTS, &data->tree); | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| if (data->cached == false) { | |||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); | |||||
| data->cached = bvhcache_find( | |||||
| *bvhCache, BVHTREE_FROM_EM_VERTS, &data->tree); | |||||
| if (data->cached == false) { | |||||
| data->tree = bvhtree_from_editmesh_verts_ex( | |||||
| data, em, | |||||
| NULL, -1, | |||||
| epsilon, tree_type, axis); | |||||
| /* Save on cache for later use */ | |||||
| /* printf("BVHTree built and saved on cache\n"); */ | |||||
brita_: don't forget to remove commented out code | |||||
| bvhcache_insert( | |||||
| bvhCache, data->tree, BVHTREE_FROM_EM_VERTS); | |||||
| } | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| } | |||||
| } | |||||
| else { | |||||
| data->tree = bvhtree_from_editmesh_verts_ex( | |||||
| data, em, | data, em, | ||||
| NULL, -1, | NULL, -1, | ||||
| epsilon, tree_type, axis); | epsilon, tree_type, axis); | ||||
| } | } | ||||
| return data->tree; | |||||
| } | |||||
| /** | /** | ||||
| * Builds a bvh tree where nodes are the given vertices (note: does not copy given mverts!). | * Builds a bvh tree where nodes are the given vertices (note: does not copy given mverts!). | ||||
| * \param vert_allocated if true, vert freeing will be done when freeing data. | * \param vert_allocated if true, vert freeing will be done when freeing data. | ||||
| * \param verts_mask if not null, true elements give which vert to add to BVH tree. | * \param verts_mask if not null, true elements give which vert to add to BVH tree. | ||||
| * \param verts_num_active if >= 0, number of active verts to add to BVH tree (else will be computed from mask). | * \param verts_num_active if >= 0, number of active verts to add to BVH tree (else will be computed from mask). | ||||
| */ | */ | ||||
| BVHTree *bvhtree_from_mesh_verts_ex( | BVHTree *bvhtree_from_mesh_verts_ex( | ||||
| BVHTreeFromMesh *data, const MVert *vert, const int verts_num, const bool vert_allocated, | BVHTreeFromMesh *data, const MVert *vert, const int verts_num, const bool vert_allocated, | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | if (tree) { | ||||
| data->raycast_callback = NULL; /* TODO */ | data->raycast_callback = NULL; /* TODO */ | ||||
| } | } | ||||
| return tree; | return tree; | ||||
| } | } | ||||
| BVHTree *bvhtree_from_editmesh_edges( | BVHTree *bvhtree_from_editmesh_edges( | ||||
| BVHTreeFromEditMesh *data, BMEditMesh *em, | BVHTreeFromEditMesh *data, BMEditMesh *em, | ||||
| float epsilon, int tree_type, int axis) | float epsilon, int tree_type, int axis, BVHCache **bvhCache) | ||||
| { | { | ||||
| return bvhtree_from_editmesh_edges_ex( | if (bvhCache) { | ||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); | |||||
| data->cached = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_EDGES, &data->tree); | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| if (data->cached == false) { | |||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); | |||||
| data->cached = bvhcache_find( | |||||
| *bvhCache, BVHTREE_FROM_EM_EDGES, &data->tree); | |||||
| if (data->cached == false) { | |||||
| data->tree = bvhtree_from_editmesh_edges_ex( | |||||
| data, em, | |||||
| NULL, -1, | |||||
| epsilon, tree_type, axis); | |||||
| /* Save on cache for later use */ | |||||
| /* printf("BVHTree built and saved on cache\n"); */ | |||||
Not Done Inline Actionssame here brita_: same here | |||||
| bvhcache_insert( | |||||
| bvhCache, data->tree, BVHTREE_FROM_EM_EDGES); | |||||
| } | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| } | |||||
| } | |||||
| else { | |||||
| data->tree = bvhtree_from_editmesh_edges_ex( | |||||
| data, em, | data, em, | ||||
| NULL, -1, | NULL, -1, | ||||
| epsilon, tree_type, axis); | epsilon, tree_type, axis); | ||||
| } | } | ||||
| return data->tree; | |||||
| } | |||||
| /** | /** | ||||
| * Builds a bvh tree where nodes are the given edges . | * Builds a bvh tree where nodes are the given edges . | ||||
| * \param vert/edge_allocated if true, elem freeing will be done when freeing data. | * \param vert/edge_allocated if true, elem freeing will be done when freeing data. | ||||
| * \param edges_mask if not null, true elements give which vert to add to BVH tree. | * \param edges_mask if not null, true elements give which vert to add to BVH tree. | ||||
| * \param edges_num_active if >= 0, number of active edges to add to BVH tree (else will be computed from mask). | * \param edges_num_active if >= 0, number of active edges to add to BVH tree (else will be computed from mask). | ||||
| */ | */ | ||||
| BVHTree *bvhtree_from_mesh_edges_ex( | BVHTree *bvhtree_from_mesh_edges_ex( | ||||
| BVHTreeFromMesh *data, | BVHTreeFromMesh *data, | ||||
| ▲ Show 20 Lines • Show All 734 Lines • ▼ Show 20 Lines | case BVHTREE_FROM_LOOPTRI: | ||||
| /* Save on cache for later use */ | /* Save on cache for later use */ | ||||
| /* printf("BVHTree built and saved on cache\n"); */ | /* printf("BVHTree built and saved on cache\n"); */ | ||||
| bvhcache_insert( | bvhcache_insert( | ||||
| &mesh->runtime.bvh_cache, data_cp.tree, BVHTREE_FROM_LOOPTRI); | &mesh->runtime.bvh_cache, data_cp.tree, BVHTREE_FROM_LOOPTRI); | ||||
| } | } | ||||
| BLI_rw_mutex_unlock(&cache_rwlock); | BLI_rw_mutex_unlock(&cache_rwlock); | ||||
| } | } | ||||
| break; | break; | ||||
| case BVHTREE_FROM_EM_VERTS: | |||||
| case BVHTREE_FROM_EM_EDGES: | |||||
| case BVHTREE_FROM_EM_LOOPTRI: | |||||
| BLI_assert(false); | |||||
| break; | |||||
| } | } | ||||
| if (data_cp.tree != NULL) { | if (data_cp.tree != NULL) { | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| if (BLI_bvhtree_get_tree_type(data_cp.tree) != tree_type) { | if (BLI_bvhtree_get_tree_type(data_cp.tree) != tree_type) { | ||||
| printf("tree_type %d obtained instead of %d\n", | printf("tree_type %d obtained instead of %d\n", | ||||
| BLI_bvhtree_get_tree_type(data_cp.tree), tree_type); | BLI_bvhtree_get_tree_type(data_cp.tree), tree_type); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines | |||||
don't forget to remove commented out code