diff options
author | Pablo Dobarro <pablodp606@gmail.com> | 2019-09-30 16:56:12 +0300 |
---|---|---|
committer | Pablo Dobarro <pablodp606@gmail.com> | 2019-09-30 16:58:03 +0300 |
commit | e8f6f70846e57be81d5d4e28556f7a12d291f5db (patch) | |
tree | d86a3780a58439f185e580b16372faa5a3b427c4 /source/blender/blenkernel | |
parent | 3dc027add3976557e120a1afdb58e80628ae32b0 (diff) |
PBVH: PBVH_FullyMasked and PBVH_FullyUnmasked flags
This commit introduces flags to tag the PBVH nodes as fully masked or unmasked. This is used in do_brush_actions to filter fully masked nodes during a stroke. Other tools can also be updated to use this flags.
Sculpt updates now require a flag to update the mask or the vertex coordinates.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D5935
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_pbvh.h | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 109 |
2 files changed, 127 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 426f81d889a..0d3b00cf927 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -50,18 +50,21 @@ typedef struct { } PBVHProxyNode; typedef enum { - PBVH_Leaf = 1, + PBVH_Leaf = 1 << 0, - PBVH_UpdateNormals = 2, - PBVH_UpdateBB = 4, - PBVH_UpdateOriginalBB = 8, - PBVH_UpdateDrawBuffers = 16, - PBVH_UpdateRedraw = 32, + PBVH_UpdateNormals = 1 << 1, + PBVH_UpdateBB = 1 << 2, + PBVH_UpdateOriginalBB = 1 << 3, + PBVH_UpdateDrawBuffers = 1 << 4, + PBVH_UpdateRedraw = 1 << 5, + PBVH_UpdateMask = 1 << 6, - PBVH_RebuildDrawBuffers = 64, - PBVH_FullyHidden = 128, + PBVH_RebuildDrawBuffers = 1 << 7, + PBVH_FullyHidden = 1 << 8, + PBVH_FullyMasked = 1 << 9, + PBVH_FullyUnmasked = 1 << 10, - PBVH_UpdateTopology = 256, + PBVH_UpdateTopology = 1 << 11, } PBVHNodeFlags; typedef struct PBVHFrustumPlanes { @@ -229,11 +232,16 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, /* Node Access */ void BKE_pbvh_node_mark_update(PBVHNode *node); +void BKE_pbvh_node_mark_update_mask(PBVHNode *node); void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node); void BKE_pbvh_node_mark_redraw(PBVHNode *node); void BKE_pbvh_node_mark_normals_update(PBVHNode *node); void BKE_pbvh_node_mark_topology_update(PBVHNode *node); void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden); +void BKE_pbvh_node_fully_masked_set(PBVHNode *node, int fully_masked); +bool BKE_pbvh_node_fully_masked_get(PBVHNode *node); +void BKE_pbvh_node_fully_unmasked_set(PBVHNode *node, int fully_masked); +bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node); void BKE_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, @@ -267,6 +275,7 @@ void BKE_pbvh_bmesh_after_stroke(PBVH *bvh); /* Update Bounding Box/Redraw and clear flags */ void BKE_pbvh_update_bounds(PBVH *bvh, int flags); +void BKE_pbvh_update_vertex_data(PBVH *bvh, int flags); void BKE_pbvh_update_normals(PBVH *bvh, struct SubdivCCG *subdiv_ccg); void BKE_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]); void BKE_pbvh_get_grid_updates(PBVH *bvh, bool clear, void ***r_gridfaces, int *r_totface); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 7bbf1068aa7..b3e511aad8e 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -1103,6 +1103,56 @@ static void pbvh_faces_update_normals(PBVH *bvh, PBVHNode **nodes, int totnode) MEM_freeN(vnors); } +static void pbvh_update_mask_redraw_task_cb(void *__restrict userdata, + const int n, + const TaskParallelTLS *__restrict UNUSED(tls)) +{ + + PBVHUpdateData *data = userdata; + PBVH *bvh = data->bvh; + PBVHNode *node = data->nodes[n]; + if (node->flag & PBVH_UpdateMask) { + + bool has_unmasked = false; + bool has_masked = true; + if (node->flag & PBVH_Leaf) { + PBVHVertexIter vd; + + BKE_pbvh_vertex_iter_begin(bvh, node, vd, PBVH_ITER_UNIQUE) + { + if (vd.mask && *vd.mask < 1.0f) { + has_unmasked = true; + } + if (vd.mask && *vd.mask > 0.0f) { + has_masked = false; + } + } + BKE_pbvh_vertex_iter_end; + } + else { + has_unmasked = true; + has_masked = true; + } + BKE_pbvh_node_fully_masked_set(node, !has_unmasked); + BKE_pbvh_node_fully_unmasked_set(node, has_masked); + + node->flag &= ~PBVH_UpdateMask; + } +} + +static void pbvh_update_mask_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag) +{ + PBVHUpdateData data = { + .bvh = bvh, + .nodes = nodes, + .flag = flag, + }; + + TaskParallelSettings settings; + BKE_pbvh_parallel_range_settings(&settings, true, totnode); + BLI_task_parallel_range(0, totnode, &data, pbvh_update_mask_redraw_task_cb, &settings); +} + static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) @@ -1305,6 +1355,26 @@ void BKE_pbvh_update_bounds(PBVH *bvh, int flag) MEM_SAFE_FREE(nodes); } +void BKE_pbvh_update_vertex_data(PBVH *bvh, int flag) +{ + if (!bvh->nodes) { + return; + } + + PBVHNode **nodes; + int totnode; + + BKE_pbvh_search_gather(bvh, update_search_cb, POINTER_FROM_INT(flag), &nodes, &totnode); + + if (flag & (PBVH_UpdateMask)) { + pbvh_update_mask_redraw(bvh, nodes, totnode, flag); + } + + if (nodes) { + MEM_freeN(nodes); + } +} + void BKE_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]) { PBVHIter iter; @@ -1435,6 +1505,11 @@ void BKE_pbvh_node_mark_update(PBVHNode *node) PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; } +void BKE_pbvh_node_mark_update_mask(PBVHNode *node) +{ + node->flag |= PBVH_UpdateMask | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; +} + void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node) { node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; @@ -1462,6 +1537,40 @@ void BKE_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden) } } +void BKE_pbvh_node_fully_masked_set(PBVHNode *node, int fully_masked) +{ + BLI_assert(node->flag & PBVH_Leaf); + + if (fully_masked) { + node->flag |= PBVH_FullyMasked; + } + else { + node->flag &= ~PBVH_FullyMasked; + } +} + +bool BKE_pbvh_node_fully_masked_get(PBVHNode *node) +{ + return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyMasked); +} + +void BKE_pbvh_node_fully_unmasked_set(PBVHNode *node, int fully_masked) +{ + BLI_assert(node->flag & PBVH_Leaf); + + if (fully_masked) { + node->flag |= PBVH_FullyUnmasked; + } + else { + node->flag &= ~PBVH_FullyUnmasked; + } +} + +bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node) +{ + return (node->flag & PBVH_Leaf) && (node->flag & PBVH_FullyUnmasked); +} + void BKE_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, const int **r_vert_indices, |