diff options
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh.c')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 5e07437d426..95d8e37d1c7 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -232,16 +232,11 @@ static int partition_indices_material(PBVH *bvh, int lo, int hi) void pbvh_grow_nodes(PBVH *bvh, int totnode) { - if (totnode > bvh->node_mem_count) { - PBVHNode *prev = bvh->nodes; - bvh->node_mem_count *= 1.33; + if (UNLIKELY(totnode > bvh->node_mem_count)) { + bvh->node_mem_count = bvh->node_mem_count + (bvh->node_mem_count / 3); if (bvh->node_mem_count < totnode) bvh->node_mem_count = totnode; - bvh->nodes = MEM_mallocN(sizeof(PBVHNode) * bvh->node_mem_count, - "bvh nodes"); - memcpy(bvh->nodes, prev, bvh->totnode * sizeof(PBVHNode)); - memset(bvh->nodes + bvh->totnode, 0, (bvh->node_mem_count - bvh->totnode) * sizeof(PBVHNode)); - MEM_freeN(prev); + bvh->nodes = MEM_recallocN(bvh->nodes, sizeof(PBVHNode) * bvh->node_mem_count); } bvh->totnode = totnode; @@ -575,7 +570,7 @@ void BKE_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int } /* Do a full rebuild with on Grids data structure */ -void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, +void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap **grid_hidden) { BBC *prim_bbc = NULL; @@ -585,7 +580,6 @@ void BKE_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, bvh->type = PBVH_GRIDS; bvh->grids = grids; - bvh->gridadj = gridadj; bvh->gridfaces = gridfaces; bvh->grid_flag_mats = flagmats; bvh->totgrid = totgrid; @@ -699,16 +693,16 @@ static void pbvh_iter_end(PBVHIter *iter) static void pbvh_stack_push(PBVHIter *iter, PBVHNode *node, int revisiting) { - if (iter->stacksize == iter->stackspace) { - PBVHStack *newstack; - + if (UNLIKELY(iter->stacksize == iter->stackspace)) { iter->stackspace *= 2; - newstack = MEM_callocN(sizeof(PBVHStack) * iter->stackspace, "PBVHStack"); - memcpy(newstack, iter->stack, sizeof(PBVHStack) * iter->stacksize); - if (iter->stackspace > STACK_FIXED_DEPTH) - MEM_freeN(iter->stack); - iter->stack = newstack; + if (iter->stackspace != STACK_FIXED_DEPTH) { + iter->stack = MEM_reallocN(iter->stack, sizeof(PBVHStack) * iter->stackspace); + } + else { + iter->stack = MEM_mallocN(sizeof(PBVHStack) * iter->stackspace, "PBVHStack"); + memcpy(iter->stack, iter->stackfixed, sizeof(PBVHStack) * iter->stacksize); + } } iter->stack[iter->stacksize].node = node; @@ -800,7 +794,7 @@ void BKE_pbvh_search_gather(PBVH *bvh, while ((node = pbvh_iter_next(&iter))) { if (node->flag & PBVH_Leaf) { - if (tot == space) { + if (UNLIKELY(tot == space)) { /* resize array if needed */ space = (tot == 0) ? 32 : space * 2; array = MEM_recallocN_id(array, sizeof(PBVHNode *) * space, __func__); @@ -948,6 +942,7 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes, int n; if (bvh->type == PBVH_BMESH) { + BLI_assert(face_nors == NULL); pbvh_bmesh_normals_update(nodes, totnode); return; } @@ -1285,6 +1280,16 @@ PBVHType BKE_pbvh_type(const PBVH *bvh) return bvh->type; } +bool BKE_pbvh_has_faces(const PBVH *bvh) +{ + if (bvh->type == PBVH_BMESH) { + return (bvh->bm->totface != 0); + } + else { + return (bvh->totprim != 0); + } +} + void BKE_pbvh_bounding_box(const PBVH *bvh, float min[3], float max[3]) { if (bvh->totnode) { @@ -1377,7 +1382,7 @@ void BKE_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *to } } -void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, CCGElem ***griddata, DMGridAdjacency **gridadj) +void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, CCGElem ***griddata) { switch (bvh->type) { case PBVH_GRIDS: @@ -1386,7 +1391,6 @@ void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int if (maxgrid) *maxgrid = bvh->totgrid; if (gridsize) *gridsize = bvh->gridkey.grid_size; if (griddata) *griddata = bvh->grids; - if (gridadj) *gridadj = bvh->gridadj; break; case PBVH_FACES: case PBVH_BMESH: @@ -1395,7 +1399,6 @@ void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int if (maxgrid) *maxgrid = 0; if (gridsize) *gridsize = 0; if (griddata) *griddata = NULL; - if (gridadj) *gridadj = NULL; break; } } @@ -1424,6 +1427,15 @@ void BKE_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *pro } } +void BKE_pbvh_node_get_bm_orco_data( + PBVHNode *node, + int (**r_orco_tris)[3], int *r_orco_tris_num, float (**r_orco_coords)[3]) +{ + *r_orco_tris = node->bm_ortri; + *r_orco_tris_num = node->bm_tot_ortri; + *r_orco_coords = node->bm_orco; +} + /********************************* Raycast ***********************************/ typedef struct { @@ -1597,7 +1609,9 @@ bool BKE_pbvh_node_raycast( return hit; } -void BKE_pbvh_raycast_project_ray_root (PBVH *bvh, bool original, float ray_start[3], float ray_end[3], float ray_normal[3]) +void BKE_pbvh_raycast_project_ray_root( + PBVH *bvh, bool original, + float ray_start[3], float ray_end[3], float ray_normal[3]) { if (bvh->nodes) { float rootmin_start, rootmin_end; @@ -1770,13 +1784,12 @@ void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], pbvh_draw_BB(bvh); } -void BKE_pbvh_grids_update(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, void **gridfaces, +void BKE_pbvh_grids_update(PBVH *bvh, CCGElem **grids, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap **grid_hidden) { int a; bvh->grids = grids; - bvh->gridadj = gridadj; bvh->gridfaces = gridfaces; if (flagmats != bvh->grid_flag_mats || bvh->grid_hidden != grid_hidden) { @@ -1955,7 +1968,7 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node, vi->fno = NULL; vi->mvert = NULL; - BKE_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL); + BKE_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids); BKE_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert); BKE_pbvh_node_get_verts(bvh, node, &vert_indices, &verts); vi->key = &bvh->gridkey; |