Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/bvhutils.c
| Context not available. | |||||
| if (tree) { | if (tree) { | ||||
| memset(data, 0, sizeof(*data)); | memset(data, 0, sizeof(*data)); | ||||
| data->tree = tree; | data->tree = tree; | ||||
| data->em = em; | |||||
| data->nearest_callback = NULL; | data->nearest_callback = NULL; | ||||
| data->raycast_callback = editmesh_verts_spherecast; | data->raycast_callback = editmesh_verts_spherecast; | ||||
| data->nearest_to_ray_callback = NULL; | data->nearest_to_ray_callback = NULL; | ||||
| data->em = em; | |||||
| } | } | ||||
| return tree; | return tree; | ||||
| Context not available. | |||||
| BVHTree *bvhtree_from_editmesh_looptri_ex( | BVHTree *bvhtree_from_editmesh_looptri_ex( | ||||
| BVHTreeFromEditMesh *data, BMEditMesh *em, | BVHTreeFromEditMesh *data, BMEditMesh *em, | ||||
| const BLI_bitmap *looptri_mask, int looptri_num_active, | const BLI_bitmap *looptri_mask, int looptri_num_active, | ||||
| float epsilon, int tree_type, int axis) | float epsilon, int tree_type, int axis, BVHCache **bvhCache) | ||||
| { | { | ||||
| /* BMESH specific check that we have tessfaces, | /* BMESH specific check that we have tessfaces, | ||||
| * we _could_ tessellate here but rather not - campbell | * we _could_ tessellate here but rather not - campbell */ | ||||
| * | |||||
| * this assert checks we have tessfaces, | |||||
| * if not caller should use DM_ensure_tessface() */ | |||||
| BVHTree *tree = bvhtree_from_editmesh_looptri_create_tree( | |||||
| epsilon, tree_type, axis, | |||||
| em, em->tottri, looptri_mask, looptri_num_active); | |||||
| BVHTree *tree; | |||||
| if (bvhCache) { | |||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_READ); | |||||
| tree = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_LOOPTRI); | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| if (tree == NULL) { | |||||
| BLI_rw_mutex_lock(&cache_rwlock, THREAD_LOCK_WRITE); | |||||
| tree = bvhcache_find(*bvhCache, BVHTREE_FROM_EM_LOOPTRI); | |||||
| if (tree == NULL) { | |||||
| tree = bvhtree_from_editmesh_looptri_create_tree( | |||||
| epsilon, tree_type, axis, | |||||
| em, em->tottri, looptri_mask, looptri_num_active); | |||||
| if (tree) { | |||||
| /* Save on cache for later use */ | |||||
| /* printf("BVHTree built and saved on cache\n"); */ | |||||
| bvhcache_insert(bvhCache, tree, BVHTREE_FROM_EM_LOOPTRI); | |||||
| } | |||||
| } | |||||
| BLI_rw_mutex_unlock(&cache_rwlock); | |||||
| } | |||||
| } | |||||
| else { | |||||
| tree = bvhtree_from_editmesh_looptri_create_tree( | |||||
| epsilon, tree_type, axis, | |||||
| em, em->tottri, looptri_mask, looptri_num_active); | |||||
| } | |||||
| if (tree) { | if (tree) { | ||||
| data->tree = tree; | data->tree = tree; | ||||
| data->nearest_callback = editmesh_looptri_nearest_point; | data->nearest_callback = editmesh_looptri_nearest_point; | ||||
| Context not available. | |||||
| data->nearest_to_ray_callback = NULL; | data->nearest_to_ray_callback = NULL; | ||||
| data->sphere_radius = 0.0f; | data->sphere_radius = 0.0f; | ||||
| data->em = em; | data->em = em; | ||||
| data->cached = bvhCache != NULL; | |||||
| } | } | ||||
| return tree; | return tree; | ||||
| } | } | ||||
| BVHTree *bvhtree_from_editmesh_looptri( | BVHTree *bvhtree_from_editmesh_looptri( | ||||
| 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_looptri_ex( | return bvhtree_from_editmesh_looptri_ex( | ||||
| data, em, NULL, -1, | data, em, NULL, -1, | ||||
| epsilon, tree_type, axis); | epsilon, tree_type, axis, bvhCache); | ||||
| } | } | ||||
| /** | /** | ||||
| Context not available. | |||||
| tree = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI); | tree = bvhcache_find(dm->bvhCache, BVHTREE_FROM_LOOPTRI); | ||||
| if (tree == NULL) { | if (tree == NULL) { | ||||
| int looptri_num = dm->getNumLoopTri(dm); | int looptri_num = dm->getNumLoopTri(dm); | ||||
| /* this assert checks we have tessfaces, | |||||
| * if not caller should use DM_ensure_tessface() */ | |||||
| BLI_assert(!(looptri_num == 0 && dm->getNumPolys(dm) != 0)); | BLI_assert(!(looptri_num == 0 && dm->getNumPolys(dm) != 0)); | ||||
| tree = bvhtree_from_mesh_looptri_create_tree( | tree = bvhtree_from_mesh_looptri_create_tree( | ||||
| Context not available. | |||||
| void free_bvhtree_from_editmesh(struct BVHTreeFromEditMesh *data) | void free_bvhtree_from_editmesh(struct BVHTreeFromEditMesh *data) | ||||
| { | { | ||||
| if (data->tree) { | if (data->tree) { | ||||
| BLI_bvhtree_free(data->tree); | if (!data->cached) { | ||||
| BLI_bvhtree_free(data->tree); | |||||
| } | |||||
| memset(data, 0, sizeof(*data)); | memset(data, 0, sizeof(*data)); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||