[Bf-blender-cvs] [d55ea7bf811] sculpt-mode-features: New sculpt brush cursor with normal radius

Pablo Dobarro noreply at git.blender.org
Wed Mar 13 16:37:34 CET 2019


Commit: d55ea7bf8115f7b14a384d69729a6cade94174e4
Author: Pablo Dobarro
Date:   Wed Mar 13 16:18:30 2019 +0100
Branches: sculpt-mode-features
https://developer.blender.org/rBd55ea7bf8115f7b14a384d69729a6cade94174e4

New sculpt brush cursor with normal radius

>From D3594

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

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/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
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 22571080628..8ae36617c03 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -270,6 +270,11 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
             if not self.is_popover:
                 brush_basic_sculpt_settings(col, context, brush)
 
+            # normal_radius_factor
+            col.separator()
+            row = col.row()
+            row.prop(brush, "normal_radius_factor", slider=True)
+
             # 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 cc445413f61..e297240157b 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -61,6 +61,7 @@ struct SubdivCCG;
 enum eOverlayFlags;
 
 #include "DNA_object_enums.h"
+#include "DNA_view3d_types.h"
 
 extern const char PAINT_CURSOR_SCULPT[3];
 extern const char PAINT_CURSOR_VERTEX_PAINT[3];
@@ -246,6 +247,13 @@ typedef struct SculptSession {
 
 	struct StrokeCache *cache;
 
+	float cursor_radius;
+	float cursor_location[3];
+	float cursor_view_normal[3];
+	float cursor_normal[3];
+
+	RegionView3D *rv3d;
+
 	union {
 		struct {
 			struct SculptVertexPaintGeomMap gmap;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 87d1a6c6915..73803df30ef 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -99,7 +99,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 *depth, float* normal, float *nearest_vertex_co);
 
 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 7dc772576c5..a8ce32d6d77 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1544,9 +1544,9 @@ bool ray_face_intersection_quad(
 	float depth_test;
 
 	if ((isect_ray_tri_epsilon_v3(
-	         ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.1f) && (depth_test < *depth)) ||
+	         ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.0f) && (depth_test < *depth)) ||
 	    (isect_ray_tri_epsilon_v3(
-	         ray_start, ray_normal, t0, t2, t3, &depth_test, NULL, 0.1f) && (depth_test < *depth)))
+	         ray_start, ray_normal, t0, t2, t3, &depth_test, NULL, 0.0f) && (depth_test < *depth)))
 	{
 		*depth = depth_test;
 		return true;
@@ -1564,7 +1564,7 @@ bool ray_face_intersection_tri(
 	float depth_test;
 
 	if ((isect_ray_tri_epsilon_v3(
-	         ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.1f) && (depth_test < *depth)))
+	         ray_start, ray_normal, t0, t1, t2, &depth_test, NULL, 0.0f) && (depth_test < *depth)))
 	{
 		*depth = depth_test;
 		return true;
@@ -1646,14 +1646,16 @@ 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 *depth, float *normal, float *nearest_vertex_co)
 {
 	const MVert *vert = bvh->verts;
 	const MLoop *mloop = bvh->mloop;
 	const int *faces = node->prim_indices;
 	int i, totface = node->totprim;
 	bool hit = false;
-
+	float min_depth = FLT_MAX;
+	float location[3] = {0.0f};
+	copy_v3_fl(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];
@@ -1678,6 +1680,17 @@ static bool pbvh_faces_node_raycast(
 			        vert[mloop[lt->tri[1]].v].co,
 			        vert[mloop[lt->tri[2]].v].co,
 			        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);
+				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);
+					}
+				}
+			}
+
 		}
 	}
 
@@ -1688,12 +1701,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 *depth, float *normal, float *nearest_vertex_co)
 {
 	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);
 	for (int i = 0; i < totgrid; ++i) {
 		CCGElem *grid = bvh->grids[node->prim_indices[i]];
 		BLI_bitmap *gh;
@@ -1728,6 +1743,21 @@ static bool pbvh_grids_node_raycast(
 					        CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1),
 					        CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1),
 					        depth);
+
+					if (hit && *depth < min_depth) {
+						min_depth = *depth;
+						madd_v3_v3v3fl(location, ray_start, ray_normal, *depth);
+						normal_tri_v3(
+						            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)));
+							}
+						}
+					}
 				}
 			}
 		}
@@ -1742,7 +1772,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 *depth, float *normal, float *nearest_vertex_co)
 {
 	bool hit = false;
 
@@ -1753,16 +1783,16 @@ bool BKE_pbvh_node_raycast(
 		case PBVH_FACES:
 			hit |= pbvh_faces_node_raycast(
 			        bvh, node, origco,
-			        ray_start, ray_normal, depth);
+			        ray_start, ray_normal, depth, normal, nearest_vertex_co);
 			break;
 		case PBVH_GRIDS:
 			hit |= pbvh_grids_node_raycast(
 			        bvh, node, origco,
-			        ray_start, ray_normal, depth);
+			        ray_start, ray_normal, depth, normal, nearest_vertex_co);
 			break;
 		case PBVH_BMESH:
 			hit = pbvh_bmesh_node_raycast(
-			        node, ray_start, ray_normal, depth, use_origco);
+			        node, ray_start, ray_normal, depth, use_origco, normal, nearest_vertex_co);
 			break;
 	}
 
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index cd97fcf432e..8ae0e6cb78c 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1503,10 +1503,12 @@ 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)
+        bool use_original, float *normal, float *nearest_vertex_co)
 {
 	bool hit = false;
 
+	float min_depth = FLT_MAX;
+	float location[3] = {0.0f};
 	if (use_original && node->bm_tot_ortri) {
 		for (int i = 0; i < node->bm_tot_ortri; i++) {
 			const int *t = node->bm_ortri[i];
@@ -1535,6 +1537,16 @@ bool pbvh_bmesh_node_raycast(
 				        v_tri[1]->co,
 				        v_tri[2]->co,
 				        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);
+					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);
+						}
+					}
+				}
 			}
 		}
 	}
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index b9610179630..6959aee4f3e 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -196,7 +196,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);
+        bool use_original, float *normal, float *nearest_vertex_co);
 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/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index 863afcf70aa..b39cac8ff05 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -47,11 +47,14 @@
 #include "BKE_colortools.h"
 
 #include "WM_api.h"
+#include "wm_cursors.h"
 
 #include "IMB_imbuf_types.h"
 
 #include "ED_view3d.h"
 
+#include "DEG_depsgraph.h"
+
 #include "GPU_draw.h"
 #include "GPU_immediate.h"
 #include "GPU_immediate_util.h"
@@ -585,7 +588,7 @@ static bool sculpt_get_brush_geometry(
 
 /* Draw an overlay that shows what effect the brush's texture will
  * have on brush strength */
-static void paint_draw_tex_overlay(
+static bool paint_draw_tex_overlay(
         UnifiedPaintSettings *ups, Brush *brush,
         ViewContext *vc, int x, int y, float zoom, bool col, bool primary)
 {
@@ -603,7 +606,7 @@ static void paint_draw_tex_overlay(
 	    (valid &&
 	    ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_VIEW, MT

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list