diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_pbvh.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_subdiv_ccg.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 33 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_intern.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subdiv_ccg.c | 11 |
7 files changed, 69 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 881f3356a86..8c925ee2ae1 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -296,6 +296,7 @@ typedef struct SculptSession { int *pmap_mem; /* Mesh Face Sets */ + int totfaces; int *face_sets; /* BMesh for dynamic topology sculpting */ diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 16a7e4d38d0..b4f16bfd899 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -219,6 +219,8 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden, int totgrid, int gridsize); +void BKE_pbvh_sync_face_sets_to_grids(PBVH *bvh); + /* multires level, only valid for type == PBVH_GRIDS */ const struct CCGKey *BKE_pbvh_get_grid_key(const PBVH *pbvh); @@ -298,6 +300,8 @@ void BKE_pbvh_grids_update(PBVH *bvh, void **gridfaces, struct DMFlagMat *flagmats, unsigned int **grid_hidden); +void BKE_pbvh_subdiv_cgg_set(PBVH *bvh, struct SubdivCCG *subdiv_ccg); +void BKE_pbvh_face_sets_set(PBVH *bvh, int *face_sets); void BKE_pbvh_face_sets_color_set(PBVH *bvh, int seed, int color_default); diff --git a/source/blender/blenkernel/BKE_subdiv_ccg.h b/source/blender/blenkernel/BKE_subdiv_ccg.h index f8534371b17..99b134dab3e 100644 --- a/source/blender/blenkernel/BKE_subdiv_ccg.h +++ b/source/blender/blenkernel/BKE_subdiv_ccg.h @@ -305,6 +305,8 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, const bool include_duplicates, SubdivCCGNeighbors *r_neighbors); +int BKE_subdiv_cgg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 719336f7351..f52ec5f568f 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -1525,6 +1525,7 @@ static void sculpt_update_object( ss->multires = mmd; ss->totvert = me_eval->totvert; ss->totpoly = me_eval->totpoly; + ss->totfaces = me->totpoly; ss->mvert = NULL; ss->mpoly = NULL; ss->mloop = NULL; @@ -1532,25 +1533,26 @@ static void sculpt_update_object( else { ss->totvert = me->totvert; ss->totpoly = me->totpoly; + ss->totfaces = me->totpoly; ss->mvert = me->mvert; ss->mpoly = me->mpoly; ss->mloop = me->mloop; ss->multires = NULL; ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); + } - /* Sculpt Face Sets. */ - if (!CustomData_has_layer(&me->pdata, CD_SCULPT_FACE_SETS)) { - ss->face_sets = CustomData_add_layer( - &me->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, me->totpoly); - for (int i = 0; i < me->totpoly; i++) { - ss->face_sets[i] = 1; - } - - /* Set the default face set color if the datalayer did not exist. */ - me->face_sets_color_default = 1; + /* Sculpt Face Sets. */ + if (!CustomData_has_layer(&me->pdata, CD_SCULPT_FACE_SETS)) { + ss->face_sets = CustomData_add_layer( + &me->pdata, CD_SCULPT_FACE_SETS, CD_CALLOC, NULL, me->totpoly); + for (int i = 0; i < me->totpoly; i++) { + ss->face_sets[i] = 1; } - ss->face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS); + + /* Set the default face set color if the datalayer did not exist. */ + me->face_sets_color_default = 1; } + ss->face_sets = CustomData_get_layer(&me->pdata, CD_SCULPT_FACE_SETS); ss->subdiv_ccg = me_eval->runtime.subdiv_ccg; @@ -1558,6 +1560,9 @@ static void sculpt_update_object( BLI_assert(pbvh == ss->pbvh); UNUSED_VARS_NDEBUG(pbvh); + BKE_pbvh_subdiv_cgg_set(ss->pbvh, ss->subdiv_ccg); + BKE_pbvh_face_sets_set(ss->pbvh, ss->face_sets); + BKE_pbvh_face_sets_color_set(ss->pbvh, me->face_sets_color_seed, me->face_sets_color_default); if (need_pmap && ob->type == OB_MESH && !ss->pmap) { diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 9a4ce8acb11..ac0c9d030cf 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -383,6 +383,25 @@ int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden, return totquad; } +void BKE_pbvh_sync_face_sets_to_grids(PBVH *bvh) +{ + const int gridsize = bvh->gridkey.grid_size; + for (int i = 0; i < bvh->totgrid; i++) { + BLI_bitmap *gh = bvh->grid_hidden[i]; + const int face_index = BKE_subdiv_cgg_grid_to_face_index(bvh->subdiv_ccg, i); + if (!gh && bvh->face_sets[face_index] < 0) { + gh = bvh->grid_hidden[i] = BLI_BITMAP_NEW(bvh->gridkey.grid_area, "partialvis_update_grids"); + } + if (gh) { + for (int y = 0; y < gridsize; y++) { + for (int x = 0; x < gridsize; x++) { + BLI_BITMAP_SET(gh, y * gridsize + x, bvh->face_sets[face_index] < 0); + } + } + } + } +} + static void build_grid_leaf_node(PBVH *bvh, PBVHNode *node) { int totquads = BKE_pbvh_count_grid_quads( @@ -1289,10 +1308,14 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata, switch (bvh->type) { case PBVH_GRIDS: GPU_pbvh_grid_buffers_update(node->draw_buffers, + bvh->subdiv_ccg, bvh->grids, bvh->grid_flag_mats, node->prim_indices, node->totprim, + bvh->face_sets, + bvh->face_sets_color_seed, + bvh->face_sets_color_default, &bvh->gridkey, update_flags); break; @@ -2974,3 +2997,13 @@ MVert *BKE_pbvh_get_verts(const PBVH *bvh) BLI_assert(bvh->type == PBVH_FACES); return bvh->verts; } + +void BKE_pbvh_subdiv_cgg_set(PBVH *bvh, SubdivCCG *subdiv_ccg) +{ + bvh->subdiv_ccg = subdiv_ccg; +} + +void BKE_pbvh_face_sets_set(PBVH *bvh, int *face_sets) +{ + bvh->face_sets = face_sets; +} diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h index af92f11e219..21cb5649330 100644 --- a/source/blender/blenkernel/intern/pbvh_intern.h +++ b/source/blender/blenkernel/intern/pbvh_intern.h @@ -138,6 +138,7 @@ struct PBVH { int face_sets_color_seed; int face_sets_color_default; + int *face_sets; /* Grid Data */ CCGKey gridkey; @@ -168,6 +169,7 @@ struct PBVH { int cd_face_node_offset; struct BMLog *bm_log; + struct SubdivCCG *subdiv_ccg; }; /* pbvh.c */ diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index 3c1a9c4d3d6..dff7170e517 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -1780,3 +1780,14 @@ void BKE_subdiv_ccg_neighbor_coords_get(const SubdivCCG *subdiv_ccg, } #endif } + +int BKE_subdiv_cgg_grid_to_face_index(const SubdivCCG *subdiv_ccg, const int grid_index) +{ + Subdiv *subdiv = subdiv_ccg->subdiv; + OpenSubdiv_TopologyRefiner *topology_refiner = subdiv->topology_refiner; + SubdivCCGFace *face = subdiv_ccg->grid_faces[grid_index]; + + const int face_grid_index = grid_index - face->start_grid_index; + const int face_index = face - subdiv_ccg->faces; + return face_index; +} |