[Bf-blender-cvs] [7c194b367e3] sculpt-mode-features: Automasking System: Topology automasking initial implementation

Pablo Dobarro noreply at git.blender.org
Fri Mar 22 16:17:23 CET 2019


Commit: 7c194b367e353d36e1e0daec0542d712669b7698
Author: Pablo Dobarro
Date:   Fri Mar 22 16:16:51 2019 +0100
Branches: sculpt-mode-features
https://developer.blender.org/rB7c194b367e353d36e1e0daec0542d712669b7698

Automasking System: Topology automasking initial implementation

This commit adds a general automasking system and the topology
automasking option (not topology falloff, that can be added later). It
should be faster and with fewer memory errors that the last version I
made. It is designed to work with every brush and every stroke mode, but
for now, I only added support for draw and grab to avoid changing every
brush until the system is more polished.

The main purpose of adding this in such an early stage of development is
to check if the cursor is working correctly. The purpose of the vertex
preview in the cursor was to show the active vertex for automasking, so
now I can test if the whole system is behaving as it should.

Limitations:
- Only meshes for now (no dyntopo or multires). I still need to think
about what to do with dyntopo. I don't know if brushes that generate new
topology are going to work with this.
- It only stores a binary mask (a vertex can be active or not). This
could be changed if the future to support topological falloff or other
more complex types of automasking.
- As it is now, brushes that use stroke space update the active vertex
dynamically, setting it to the closest vertex to the brush location each
sample. This often causes masking errors with small brushes. I'm
considering changing it to always check topology using the initial
active vertex, but it is going to be much slower.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 7e3855bbb44..f6825668b0d 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -279,6 +279,10 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
             row = col.row()
             row.prop(brush, "curve_preset")
 
+            col.separator()
+            row = col.row()
+            row.prop(brush, "automasking_mode")
+
             # topology_rake_factor
             if (capabilities.has_topology_rake and
                 context.sculpt_object.use_dynamic_topology_sculpting
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index e297240157b..0ef03b1bea6 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -62,6 +62,7 @@ enum eOverlayFlags;
 
 #include "DNA_object_enums.h"
 #include "DNA_view3d_types.h"
+#include "DNA_meshdata_types.h"
 
 extern const char PAINT_CURSOR_SCULPT[3];
 extern const char PAINT_CURSOR_VERTEX_PAINT[3];
@@ -252,6 +253,10 @@ typedef struct SculptSession {
 	float cursor_view_normal[3];
 	float cursor_normal[3];
 
+	/* Automasking active vertex */
+	MVert *active_vertex_mesh;
+	int active_vertex_mesh_index;
+
 	RegionView3D *rv3d;
 
 	union {
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 73803df30ef..f71e0af178c 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -21,6 +21,7 @@
  * \ingroup bke
  * \brief A BVH for high poly meshes.
  */
+#include "DNA_meshdata_types.h"
 
 #include "BLI_bitmap.h"
 #include "BLI_ghash.h"
@@ -48,6 +49,13 @@ typedef struct {
 	float (*co)[3];
 } PBVHProxyNode;
 
+typedef struct {
+	float normal[3];
+	float nearest_vertex_co[3];
+	MVert *active_vertex_mesh;
+	int active_vertex_mesh_index;
+} RaycastOutputData;
+
 /* Callbacks */
 
 /* returns 1 if the search should continue from this node, 0 otherwise */
@@ -99,7 +107,7 @@ void BKE_pbvh_raycast(
 bool BKE_pbvh_node_raycast(
         PBVH *bvh, PBVHNode *node, float (*origco)[3], bool use_origco,
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float* normal, float *nearest_vertex_co);
+        float *depth, RaycastOutputData *output_data);
 
 bool BKE_pbvh_bmesh_node_raycast_detail(
         PBVHNode *node,
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index a8ce32d6d77..17443c9ebdc 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1646,7 +1646,7 @@ static bool pbvh_faces_node_raycast(
         PBVH *bvh, const PBVHNode *node,
         float (*origco)[3],
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float *normal, float *nearest_vertex_co)
+        float *depth, RaycastOutputData* output_data)
 {
 	const MVert *vert = bvh->verts;
 	const MLoop *mloop = bvh->mloop;
@@ -1655,7 +1655,7 @@ static bool pbvh_faces_node_raycast(
 	bool hit = false;
 	float min_depth = FLT_MAX;
 	float location[3] = {0.0f};
-	copy_v3_fl(nearest_vertex_co, 0.0f);
+	copy_v3_fl(output_data->nearest_vertex_co, 0.0f);
 	for (i = 0; i < totface; ++i) {
 		const MLoopTri *lt = &bvh->looptri[faces[i]];
 		const int *face_verts = node->face_vert_indices[i];
@@ -1682,11 +1682,13 @@ static bool pbvh_faces_node_raycast(
 			        depth);
 			if (hit && *depth < min_depth) {
 				min_depth = *depth;
-				normal_tri_v3(normal, vert[mloop[lt->tri[0]].v].co, vert[mloop[lt->tri[1]].v].co, vert[mloop[lt->tri[2]].v].co);
+				normal_tri_v3(output_data->normal, vert[mloop[lt->tri[0]].v].co, vert[mloop[lt->tri[1]].v].co, vert[mloop[lt->tri[2]].v].co);
 				madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
 				for (int j = 0; j < 3; j++) {
-					if (len_squared_v3v3(location, vert[mloop[lt->tri[j]].v].co) < len_squared_v3v3(location, nearest_vertex_co)) {
-						copy_v3_v3(nearest_vertex_co, vert[mloop[lt->tri[j]].v].co);
+					if (len_squared_v3v3(location, vert[mloop[lt->tri[j]].v].co) < len_squared_v3v3(location, output_data->nearest_vertex_co)) {
+						copy_v3_v3(output_data->nearest_vertex_co, vert[mloop[lt->tri[j]].v].co);
+						output_data->active_vertex_mesh = &bvh->verts[mloop[lt->tri[j]].v];
+						output_data->active_vertex_mesh_index = mloop[lt->tri[j]].v;
 					}
 				}
 			}
@@ -1701,14 +1703,14 @@ static bool pbvh_grids_node_raycast(
         PBVH *bvh, PBVHNode *node,
         float (*origco)[3],
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float *normal, float *nearest_vertex_co)
+        float *depth, RaycastOutputData *output_data)
 {
 	const int totgrid = node->totprim;
 	const int gridsize = bvh->gridkey.grid_size;
 	bool hit = false;
 	float min_depth = FLT_MAX;
 	float location[3] = {0.0f};
-	copy_v3_fl(nearest_vertex_co, 0.0f);
+	copy_v3_fl(output_data->nearest_vertex_co, 0.0f);
 	for (int i = 0; i < totgrid; ++i) {
 		CCGElem *grid = bvh->grids[node->prim_indices[i]];
 		BLI_bitmap *gh;
@@ -1748,13 +1750,13 @@ static bool pbvh_grids_node_raycast(
 						min_depth = *depth;
 						madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
 						normal_tri_v3(
-						            normal,
+						            output_data->normal,
 						            CCG_grid_elem_co(&bvh->gridkey, grid, x, y),
 						            CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y),
 						            CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1));
 						for (int j = 0; j < 4; j++) {
-							if (len_squared_v3v3(location, CCG_grid_elem_co(&bvh->gridkey, grid, x + (j & 1), y + ((j & 2) >> 1))) < len_squared_v3v3(location, nearest_vertex_co)) {
-								copy_v3_v3(nearest_vertex_co, CCG_grid_elem_co(&bvh->gridkey, grid, x + (j & 1), y + ((j & 2) >> 1)));
+							if (len_squared_v3v3(location, CCG_grid_elem_co(&bvh->gridkey, grid, x + (j & 1), y + ((j & 2) >> 1))) < len_squared_v3v3(location, output_data->nearest_vertex_co)) {
+								copy_v3_v3(output_data->nearest_vertex_co, CCG_grid_elem_co(&bvh->gridkey, grid, x + (j & 1), y + ((j & 2) >> 1)));
 							}
 						}
 					}
@@ -1772,7 +1774,7 @@ static bool pbvh_grids_node_raycast(
 bool BKE_pbvh_node_raycast(
         PBVH *bvh, PBVHNode *node, float (*origco)[3], bool use_origco,
         const float ray_start[3], const float ray_normal[3],
-        float *depth, float *normal, float *nearest_vertex_co)
+        float *depth, RaycastOutputData *output_data)
 {
 	bool hit = false;
 
@@ -1783,16 +1785,16 @@ bool BKE_pbvh_node_raycast(
 		case PBVH_FACES:
 			hit |= pbvh_faces_node_raycast(
 			        bvh, node, origco,
-			        ray_start, ray_normal, depth, normal, nearest_vertex_co);
+			        ray_start, ray_normal, depth, output_data);
 			break;
 		case PBVH_GRIDS:
 			hit |= pbvh_grids_node_raycast(
 			        bvh, node, origco,
-			        ray_start, ray_normal, depth, normal, nearest_vertex_co);
+			        ray_start, ray_normal, depth, output_data);
 			break;
 		case PBVH_BMESH:
 			hit = pbvh_bmesh_node_raycast(
-			        node, ray_start, ray_normal, depth, use_origco, normal, nearest_vertex_co);
+			        node, ray_start, ray_normal, depth, use_origco, output_data);
 			break;
 	}
 
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 8ae0e6cb78c..3c150a125c6 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1503,7 +1503,7 @@ static bool pbvh_bmesh_collapse_short_edges(
 bool pbvh_bmesh_node_raycast(
         PBVHNode *node, const float ray_start[3],
         const float ray_normal[3], float *depth,
-        bool use_original, float *normal, float *nearest_vertex_co)
+        bool use_original, RaycastOutputData *output_data)
 {
 	bool hit = false;
 
@@ -1539,11 +1539,11 @@ bool pbvh_bmesh_node_raycast(
 				        depth);
 				if (hit && *depth < min_depth) {
 					min_depth = *depth;
-					normal_tri_v3(normal, v_tri[0]->co, v_tri[1]->co, v_tri[2]->co);
+					normal_tri_v3(output_data->normal, v_tri[0]->co, v_tri[1]->co, v_tri[2]->co);
 					madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
 					for (int j = 0; j < 3; j++) {
-						if (len_squared_v3v3(location, v_tri[j]->co) < len_squared_v3v3(location, nearest_vertex_co)) {
-							copy_v3_v3(nearest_vertex_co, v_tri[j]->co);
+						if (len_squared_v3v3(location, v_tri[j]->co) < len_squared_v3v3(location, output_data->nearest_vertex_co)) {
+							copy_v3_v3(output_data->nearest_vertex_co, v_tri[j]->co);
 						}
 					}
 				}
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 6959aee4f3e..1c0fda19ed3 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -21,6 +21,8 @@
  * \ingroup bli
  */
 
+#include "BKE_pbvh.h"
+
 /* Axis-aligned bounding box */
 typedef struct {
 	float bmin[3], bmax[3];
@@ -196,7 +198,7 @@ void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag);
 bool pbvh_bmesh_node_raycast(
         PBVHNode *node, const float ray_start[3],
         const float ray_normal[3], float *dist,
-        bool use_original, float *normal, float *nearest_vertex_co);
+        bool use_original, RaycastOutputData *output_data);
 bool pbvh_bmesh_node_nearest_to_ray(
         PBVHNode *node, const float ray_start[3],
         const float ray_normal[3], float *depth, float *dist_sq,
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index bb1ec336979..d47a01e9a9b 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -31,6 +31,7 @@
 #include "BLI_task.h"
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
+#include "BLI_stack.h"
 
 #include "BLT_translation.h"
 
@@ -1554,6 +1555,26 @@ static void calc_brush_local_mat(const Brush *brush, Object *ob,
 	invert_m4_m4(local_mat, tmat);
 }
 
+static bool sculpt_automasking_compatible(SculptSession *ss){
+	if (BKE_pbvh_ty

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list