[Bf-blender-cvs] [e8f6f70846e] master: PBVH: PBVH_FullyMasked and PBVH_FullyUnmasked flags
Pablo Dobarro
noreply at git.blender.org
Mon Sep 30 15:57:21 CEST 2019
Commit: e8f6f70846e57be81d5d4e28556f7a12d291f5db
Author: Pablo Dobarro
Date: Mon Sep 30 15:56:12 2019 +0200
Branches: master
https://developer.blender.org/rBe8f6f70846e57be81d5d4e28556f7a12d291f5db
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
===================================================================
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/pbvh.c
M source/blender/editors/sculpt_paint/paint_mask.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
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,
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index 7133936ff79..a93e55685d2 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -126,7 +126,7 @@ static void mask_flood_fill_task_cb(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
if (redraw) {
- BKE_pbvh_node_mark_redraw(node);
+ BKE_pbvh_node_mark_update_mask(node);
if (data->multires) {
BKE_pbvh_node_mark_normals_update(node);
}
@@ -174,6 +174,8 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
}
+ BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);
+
sculpt_undo_push_end();
if (nodes) {
@@ -283,7 +285,7 @@ static void mask_box_select_task_cb(void *__restrict userdata,
BKE_pbvh_vertex_iter_end;
if (redraw) {
- BKE_pbvh_node_mark_redraw(node);
+ BKE_pbvh_node_mark_update_mask(node);
}
}
@@ -355,6 +357,8 @@ bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *
multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
}
+ BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);
+
sculpt_undo_push_end();
ED_region_tag_redraw(ar);
@@ -542,6 +546,8 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
multires_mark_as_modified(depsgraph, ob, MULTIRES_COORDS_MODIFIED);
}
+ BKE_pbvh_update_vertex_data(pbvh, PBVH_UpdateMask);
+
sculpt_undo_push_end();
ED_region_tag_redraw(vc.ar);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 90c5c3e32f0..a871fb66686 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1857,6 +1857,12 @@ bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v)
float t[3], bb_min[3], bb_max[3];
int i;
+ if (data->ignore_fully_masked) {
+ if (BKE_pbvh_node_fully_masked_get(node)) {
+ return false;
+ }
+ }
+
if (data->original) {
BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
}
@@ -1887,6 +1893,12 @@ bool sculpt_search_circle_cb(PBVHNode *node, void *data_v)
SculptSearchCircleData *data = data_v;
float bb_min[3], bb_max[3];
+ if (data->ignore_fully_masked) {
+ if (BKE_pbvh_node_fully_masked_get(node)) {
+ return false;
+ }
+ }
+
if (data->original) {
BKE_pbvh_node_get_original_BB(node, bb_min, bb_max);
}
@@ -1920,6 +1932,27 @@ static void sculpt_clip(Sculpt *sd, SculptSession *ss, float co[3], const float
}
}
+static PBVHNode **sculpt_pbvh_gather_cursor_update(Object *ob,
+ Sculpt *sd,
+ const Brush *brush,
+ bool use_original,
+ float radius_scale,
+ int *r_totnode)
+{
+ SculptSession *ss = ob->sculpt;
+ PBVHNode **nodes = NULL;
+ SculptSearchSphereData data = {
+ .ss = ss,
+ .sd = sd,
+ .radius_squared = ss->cursor_radius,
+ .original = use_original,
+ .ignore_fully_masked = false,
+ .center = NULL,
+ };
+ BKE_pbvh_search_gather(ss->pbvh, sculpt_search_sphere_cb, &data, &nodes, r_totnode);
+ return nodes;
+}
+
static PBVHNode **sculpt_pbvh_gather_generic(Object *ob,
Sculpt *sd,
const Brush *brush,
@@ -1936,8 +1969,9 @@ static PBVHNode **sculpt_pbvh_gather_generic(Object *ob,
SculptSearchSphereData data = {
.ss = ss,
.sd = sd,
- .radius_squared = ss->cache ? SQUARE(ss->cache->radius * radius_scale) : ss->cursor_radius,
+ .radius_squared = SQUARE(ss->cache->radius * radius_scale),
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list