Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Show First 20 Lines • Show All 536 Lines • ▼ Show 20 Lines | |||||
| * (which means it may rewrite it if needed, see #BKE_pbvh_apply_vertCos(). | * (which means it may rewrite it if needed, see #BKE_pbvh_apply_vertCos(). | ||||
| */ | */ | ||||
| void BKE_pbvh_build_mesh(PBVH *bvh, | void BKE_pbvh_build_mesh(PBVH *bvh, | ||||
| const MPoly *mpoly, | const MPoly *mpoly, | ||||
| const MLoop *mloop, | const MLoop *mloop, | ||||
| MVert *verts, | MVert *verts, | ||||
| int totvert, | int totvert, | ||||
| struct CustomData *vdata, | struct CustomData *vdata, | ||||
| struct CustomData *ldata, | |||||
| const MLoopTri *looptri, | const MLoopTri *looptri, | ||||
| int looptri_num) | int looptri_num) | ||||
| { | { | ||||
| BBC *prim_bbc = NULL; | BBC *prim_bbc = NULL; | ||||
| BB cb; | BB cb; | ||||
| bvh->type = PBVH_FACES; | bvh->type = PBVH_FACES; | ||||
| bvh->mpoly = mpoly; | bvh->mpoly = mpoly; | ||||
| bvh->mloop = mloop; | bvh->mloop = mloop; | ||||
| bvh->looptri = looptri; | bvh->looptri = looptri; | ||||
| bvh->verts = verts; | bvh->verts = verts; | ||||
| bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); | bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap"); | ||||
| bvh->totvert = totvert; | bvh->totvert = totvert; | ||||
| bvh->leaf_limit = LEAF_LIMIT; | bvh->leaf_limit = LEAF_LIMIT; | ||||
| bvh->vdata = vdata; | bvh->vdata = vdata; | ||||
| bvh->ldata = ldata; | |||||
| BB_reset(&cb); | BB_reset(&cb); | ||||
| /* For each face, store the AABB and the AABB centroid */ | /* For each face, store the AABB and the AABB centroid */ | ||||
| prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc"); | prim_bbc = MEM_mallocN(sizeof(BBC) * looptri_num, "prim_bbc"); | ||||
| for (int i = 0; i < looptri_num; ++i) { | for (int i = 0; i < looptri_num; ++i) { | ||||
| const MLoopTri *lt = &looptri[i]; | const MLoopTri *lt = &looptri[i]; | ||||
| ▲ Show 20 Lines • Show All 589 Lines • ▼ Show 20 Lines | void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag) | ||||
| }; | }; | ||||
| ParallelRangeSettings settings; | ParallelRangeSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| settings.use_threading = (totnode > PBVH_THREADED_LIMIT); | settings.use_threading = (totnode > PBVH_THREADED_LIMIT); | ||||
| BLI_task_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | BLI_task_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | ||||
| } | } | ||||
| static int pbvh_get_buffers_update_flags(PBVH *bvh) | static int pbvh_get_buffers_update_flags(PBVH *bvh, bool show_vcol) | ||||
| { | { | ||||
| int update_flags = 0; | int update_flags = 0; | ||||
| update_flags |= bvh->show_mask ? GPU_PBVH_BUFFERS_SHOW_MASK : 0; | update_flags |= bvh->show_mask ? GPU_PBVH_BUFFERS_SHOW_MASK : 0; | ||||
| update_flags |= show_vcol ? GPU_PBVH_BUFFERS_SHOW_VCOL : 0; | |||||
| return update_flags; | return update_flags; | ||||
| } | } | ||||
| static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) | static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, bool show_vcol) | ||||
| { | { | ||||
| /* can't be done in parallel with OpenGL */ | /* can't be done in parallel with OpenGL */ | ||||
| for (int n = 0; n < totnode; n++) { | for (int n = 0; n < totnode; n++) { | ||||
| PBVHNode *node = nodes[n]; | PBVHNode *node = nodes[n]; | ||||
| if (node->flag & PBVH_RebuildDrawBuffers) { | if (node->flag & PBVH_RebuildDrawBuffers) { | ||||
| GPU_pbvh_buffers_free(node->draw_buffers); | GPU_pbvh_buffers_free(node->draw_buffers); | ||||
| switch (bvh->type) { | switch (bvh->type) { | ||||
| Show All 14 Lines | if (node->flag & PBVH_RebuildDrawBuffers) { | ||||
| PBVH_DYNTOPO_SMOOTH_SHADING); | PBVH_DYNTOPO_SMOOTH_SHADING); | ||||
| break; | break; | ||||
| } | } | ||||
| node->flag &= ~PBVH_RebuildDrawBuffers; | node->flag &= ~PBVH_RebuildDrawBuffers; | ||||
| } | } | ||||
| if (node->flag & PBVH_UpdateDrawBuffers) { | if (node->flag & PBVH_UpdateDrawBuffers) { | ||||
| const int update_flags = pbvh_get_buffers_update_flags(bvh); | const int update_flags = pbvh_get_buffers_update_flags(bvh, show_vcol); | ||||
| switch (bvh->type) { | switch (bvh->type) { | ||||
| case PBVH_GRIDS: | case PBVH_GRIDS: | ||||
| GPU_pbvh_grid_buffers_update(node->draw_buffers, | GPU_pbvh_grid_buffers_update(node->draw_buffers, | ||||
| bvh->grids, | bvh->grids, | ||||
| bvh->grid_flag_mats, | bvh->grid_flag_mats, | ||||
| node->prim_indices, | node->prim_indices, | ||||
| node->totprim, | node->totprim, | ||||
| &bvh->gridkey, | &bvh->gridkey, | ||||
| update_flags); | update_flags); | ||||
| break; | break; | ||||
| case PBVH_FACES: | case PBVH_FACES: | ||||
| GPU_pbvh_mesh_buffers_update(node->draw_buffers, | GPU_pbvh_mesh_buffers_update(node->draw_buffers, | ||||
| bvh->verts, | bvh->verts, | ||||
| node->vert_indices, | node->vert_indices, | ||||
| node->uniq_verts + node->face_verts, | node->uniq_verts + node->face_verts, | ||||
| CustomData_get_layer(bvh->vdata, CD_PAINT_MASK), | CustomData_get_layer(bvh->vdata, CD_PAINT_MASK), | ||||
| CustomData_get_layer(bvh->ldata, CD_MLOOPCOL), | |||||
| node->face_vert_indices, | node->face_vert_indices, | ||||
| update_flags); | update_flags); | ||||
| break; | break; | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| GPU_pbvh_bmesh_buffers_update(node->draw_buffers, | GPU_pbvh_bmesh_buffers_update(node->draw_buffers, | ||||
| bvh->bm, | bvh->bm, | ||||
| node->bm_faces, | node->bm_faces, | ||||
| node->bm_unique_verts, | node->bm_unique_verts, | ||||
| ▲ Show 20 Lines • Show All 996 Lines • ▼ Show 20 Lines | |||||
| * Version of #BKE_pbvh_draw that runs a callback. | * Version of #BKE_pbvh_draw that runs a callback. | ||||
| */ | */ | ||||
| void BKE_pbvh_draw_cb(PBVH *bvh, | void BKE_pbvh_draw_cb(PBVH *bvh, | ||||
| float (*planes)[4], | float (*planes)[4], | ||||
| float (*fnors)[3], | float (*fnors)[3], | ||||
| bool fast, | bool fast, | ||||
| bool wires, | bool wires, | ||||
| bool only_mask, | bool only_mask, | ||||
| bool show_vcol, | |||||
| void (*draw_fn)(void *user_data, GPUBatch *batch), | void (*draw_fn)(void *user_data, GPUBatch *batch), | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| struct PBVHNodeDrawCallbackData draw_data = { | struct PBVHNodeDrawCallbackData draw_data = { | ||||
| .only_mask = only_mask, | .only_mask = only_mask, | ||||
| .fast = fast, | .fast = fast, | ||||
| .wires = wires, | .wires = wires, | ||||
| .draw_fn = draw_fn, | .draw_fn = draw_fn, | ||||
| .user_data = user_data, | .user_data = user_data, | ||||
| }; | }; | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| BKE_pbvh_search_gather(bvh, | BKE_pbvh_search_gather(bvh, | ||||
| update_search_cb, | update_search_cb, | ||||
| POINTER_FROM_INT(PBVH_UpdateNormals | PBVH_UpdateDrawBuffers), | POINTER_FROM_INT(PBVH_UpdateNormals | PBVH_UpdateDrawBuffers), | ||||
| &nodes, | &nodes, | ||||
| &totnode); | &totnode); | ||||
| pbvh_update_normals(bvh, nodes, totnode, fnors); | pbvh_update_normals(bvh, nodes, totnode, fnors); | ||||
| pbvh_update_draw_buffers(bvh, nodes, totnode); | pbvh_update_draw_buffers(bvh, nodes, totnode, show_vcol); | ||||
| if (nodes) { | if (nodes) { | ||||
| MEM_freeN(nodes); | MEM_freeN(nodes); | ||||
| } | } | ||||
| if (planes) { | if (planes) { | ||||
| BKE_pbvh_search_callback( | BKE_pbvh_search_callback( | ||||
| bvh, BKE_pbvh_node_planes_contain_AABB, planes, pbvh_node_draw_cb, &draw_data); | bvh, BKE_pbvh_node_planes_contain_AABB, planes, pbvh_node_draw_cb, &draw_data); | ||||
| ▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines | |||||