[Bf-blender-cvs] [109fc7682b7] soc-2017-sculpting_improvements: Initial commit on: Adaptive spacing (based on diff by LetterRip see:T50939). First prototype to calculate spacing distance by measuring distance drawn on surface rather than drawn on screen. The code is just a prototype, it needs a clean up and further testing.

witt noreply at git.blender.org
Tue May 30 16:44:11 CEST 2017


Commit: 109fc7682b7f2e6cb9a1f56bfbcab96fefdb4c46
Author: witt
Date:   Tue May 30 16:16:12 2017 +0200
Branches: soc-2017-sculpting_improvements
https://developer.blender.org/rB109fc7682b7f2e6cb9a1f56bfbcab96fefdb4c46

Initial commit on: Adaptive spacing (based on diff by LetterRip see:T50939).
First prototype to calculate spacing distance by measuring distance drawn on surface rather than drawn on screen.
The code is just a prototype, it needs a clean up and further testing.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_brush.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_view3d/view3d_draw.c
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 d58453deaef..7701ea712cb 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1032,7 +1032,7 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
                 row = col.row(align=True)
                 row.prop(brush, "rake_factor", slider=True)
 
-            # use_original_normal and sculpt_plane
+            # use_original_normal and sculpt_plane and sculpt_plane_range
             if capabilities.has_sculpt_plane:
                 col.separator()
                 row = col.row(align=True)
@@ -1041,6 +1041,9 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
 
                 row.prop(brush, "sculpt_plane", text="")
 
+                row = col.row()
+                row.prop(brush, "sculpt_plane_range")
+
             if brush.sculpt_tool == 'MASK':
                 col.prop(brush, "mask_tool", text="")
 
@@ -1437,11 +1440,13 @@ class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
             col.separator()
             col.prop(brush, "rate", text="Rate", slider=True)
 
-        if brush.use_space:
+        if brush.use_space or brush.use_line or brush.use_curve:
             col.separator()
             row = col.row(align=True)
             row.prop(brush, "spacing", text="Spacing")
             row.prop(brush, "use_pressure_spacing", toggle=True, text="")
+            col.separator()
+            col.prop(brush, "use_adaptive_space", text="Adaptive Spacing")
 
         if brush.use_line or brush.use_curve:
             col.separator()
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 8bd4bdf89e1..afc172ebd75 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -105,6 +105,7 @@ void BKE_brush_weight_set(const struct Scene *scene, struct Brush *brush, float
 int  BKE_brush_use_locked_size(const struct Scene *scene, const struct Brush *brush);
 int  BKE_brush_use_alpha_pressure(const struct Scene *scene, const struct Brush *brush);
 int  BKE_brush_use_size_pressure(const struct Scene *scene, const struct Brush *brush);
+int  BKE_brush_use_adaptive_spacing(const struct Brush *brush);
 
 /* scale unprojected radius to reflect a change in the brush's 2D size */
 void BKE_brush_scale_unprojected_radius(
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 57b707a31d3..80aa8efa0a9 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -78,7 +78,8 @@ static void brush_defaults(Brush *brush)
 	brush->alpha = 0.5f; /* brush strength/intensity probably variable should be renamed? */
 	brush->autosmooth_factor = 0.0f;
 	brush->crease_pinch_factor = 0.5f;
-	brush->sculpt_plane = SCULPT_DISP_DIR_AREA;
+	brush->sculpt_plane = SCULPT_DISP_DIR_AREA; /* default to the area normal as the sculpt plane displacement direction */
+	brush->sculpt_plane_range= 1; /* how large an area to determine the normal of the plane in brush radiuses */
 	brush->plane_offset = 0.0f; /* how far above or below the plane that is found by averaging the faces */
 	brush->plane_trim = 0.5f;
 	brush->clone.alpha = 0.5f;
@@ -94,7 +95,7 @@ static void brush_defaults(Brush *brush)
 	zero_v3(brush->secondary_rgb);
 
 	/* BRUSH STROKE SETTINGS */
-	brush->flag |= (BRUSH_SPACE | BRUSH_SPACE_ATTEN);
+	brush->flag |= (BRUSH_SPACE | BRUSH_SPACE_ATTEN | BRUSH_ADAPTIVE_SPACE);
 	brush->spacing = 10; /* how far each brush dot should be spaced as a percentage of brush diameter */
 
 	brush->smooth_stroke_radius = 75;
@@ -104,6 +105,8 @@ static void brush_defaults(Brush *brush)
 
 	brush->jitter = 0.0f;
 
+	brush->adaptive_space_factor = 1;
+
 	/* BRUSH TEXTURE SETTINGS */
 	BKE_texture_mtex_default(&brush->mtex);
 	BKE_texture_mtex_default(&brush->mask_mtex);
@@ -844,6 +847,12 @@ int BKE_brush_use_alpha_pressure(const Scene *scene, const Brush *brush)
 	       (brush->flag & BRUSH_ALPHA_PRESSURE);
 }
 
+
+int BKE_brush_use_adaptive_spacing(const Brush *brush)
+{
+	return (brush->flag & BRUSH_ADAPTIVE_SPACE); //FIXME make sure we are in view3D
+}
+
 void BKE_brush_unprojected_radius_set(Scene *scene, Brush *brush, float unprojected_radius)
 {
 	UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index d3260db1477..09ba7f23809 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1575,6 +1575,16 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 
+		Brush *br;
+		for (br = main->brush.first; br; br = br->id.next) {
+			br->flag |= BRUSH_SPACE_ATTEN; // enable adaptive attenuation
+			//TODO currently too slow to be enabled on by default
+			//br->flag |= BRUSH_ADAPTIVE_SPACE;
+			if (br->ob_mode & OB_MODE_SCULPT)
+				br->sculpt_plane_range = 1.0;				
+		}
+
+
 		/* Fix for T50736, Glare comp node using same var for two different things. */
 		if (!DNA_struct_elem_find(fd->filesdna, "NodeGlare", "char", "star_45")) {
 			FOREACH_NODETREE(main, ntree, id) {
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 7e05ab929ae..57cf54837de 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -32,6 +32,7 @@
 #ifndef __PAINT_INTERN_H__
 #define __PAINT_INTERN_H__
 
+
 struct ARegion;
 struct bContext;
 struct Brush;
@@ -76,6 +77,7 @@ bool paint_supports_smooth_stroke(struct Brush *br, enum PaintMode mode);
 bool paint_supports_texture(enum PaintMode mode);
 bool paint_supports_jitter(enum PaintMode mode);
 
+
 struct wmKeyMap *paint_stroke_modal_keymap(struct wmKeyConfig *keyconf);
 int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
 int paint_stroke_exec(struct bContext *C, struct wmOperator *op);
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 05270dbfa09..d6dd6be0d75 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -66,16 +66,40 @@
 #include "IMB_imbuf_types.h"
 
 #include "paint_intern.h"
+#include "sculpt_intern.h"
 
 #include <float.h>
 #include <math.h>
 
+#include <stdio.h>
+
 //#define DEBUG_TIME
 
 #ifdef DEBUG_TIME
 #  include "PIL_time_utildefines.h"
 #endif
 
+/*Debug spacing calc define DEBUG_DRAW to get info about sampling etc.*/
+/*#define DEBUG_DRAW*/
+
+#ifdef DEBUG_DRAW
+static void bl_debug_draw(void);
+/* add these locally when using these functions for testing */
+extern void bl_debug_draw_quad_clear(void);
+extern void bl_debug_draw_quad_add(const float v0[3], const float v1[3], const float v2[3], const float v3[3]);
+extern void bl_debug_draw_edge_add(const float v0[3], const float v1[3]);
+extern void bl_debug_color_set(const unsigned int col);
+
+void bl_debug_draw_point(const float pos[3],const float thickness){
+	float h = thickness*0.5;
+	float v1[] = {pos[0]-h,pos[1]-h,pos[2]};
+	float v2[] = {pos[0]-h,pos[1]+h,pos[2]};
+	float v3[] = {pos[0]+h,pos[1]-h,pos[2]};
+	float v4[] = {pos[0]+h,pos[1]+h,pos[2]};
+	bl_debug_draw_quad_add(v1,v2,v3,v4);
+}
+#endif
+
 typedef struct PaintSample {
 	float mouse[2];
 	float pressure;
@@ -101,8 +125,10 @@ typedef struct PaintStroke {
 	int cur_sample;
 
 	float last_mouse_position[2];
+	float last_v3_mouse_position[3];
 	/* space distance covered so far */
 	float stroke_distance;
+	float distance_since_last_dab;
 
 	/* Set whether any stroke step has yet occurred
 	 * e.g. in sculpt mode, stroke doesn't start until cursor
@@ -444,6 +470,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float
 	 * will create too many dabs */
 	copy_v2_v2(stroke->last_mouse_position, mouse_in);
 	stroke->last_pressure = pressure;
+	stroke->distance_since_last_dab = 0.0f;
 
 	if (paint_stroke_use_jitter(mode, brush, stroke->stroke_mode == BRUSH_STROKE_INVERT)) {
 		float delta[2];
@@ -474,6 +501,14 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, const float
 		return;
 	}
 
+#ifdef DEBUG_DRAW
+	bl_debug_color_set(0x0000FF);
+	bl_debug_draw_point(ups->last_location,0.05f);
+	bl_debug_color_set(0x000000);
+#endif
+
+	copy_v3_v3(stroke->last_v3_mouse_position, location);
+
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
 	RNA_float_set(&itemptr, "size", ups->pixel_radius);
@@ -516,36 +551,56 @@ static bool paint_smooth_stroke(
 	return true;
 }
 
-static float paint_space_stroke_spacing(const Scene *scene, PaintStroke *stroke, float size_pressure, float spacing_pressure)
+static const float MIN_BRUSH_SIZE_PIXELS = 1.0f;
+static const float MAGIC_50 = 50.0f;
+static const float MAGIC_1_5 = 1.5f;
+
+/* Brush spacing ignoring both pressure and brush angle to the geometry */
+static float paint_space_unadjusted_stroke_spacing(const Scene *scene, PaintStroke *stroke) {
+
+	const float size_clamp = max_ff(MIN_BRUSH_SIZE_PIXELS, BKE_brush_size_get(scene, stroke->brush));
+
+	return max_ff(MIN_BRUSH_SIZE_PIXELS, size_clamp * stroke->brush->spacing / MAGIC_50);
+}
+
+static float paint_space_stroke_adaptive_spacing(const Scene *scene, PaintStroke *stroke, float spacing)
+{
+	spacing = spacing * stroke->brush->adaptive_space_factor;
+
+	return spacing;
+}
+
+static float paint_space_stroke_pressure_spacing(const Scene *scene, PaintStroke *stroke, float size_pressure, float spacing_pressure, float spacing)
 {
 	/* brushes can have a minimum size of 1.0 but with pressure it can be smaller then a pixel
 	 * causing very high step sizes, hanging blender [#32381] */
-	const float size_clamp = max_ff(1.0f, BKE_brush_size_get(scene, stroke->brush) * size_pressure);
-	float spacing = stroke->brush->spacing;
+	//TODO size_clamp should probably be calculated at the start and used throughout
+	const float size_clamp = max

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list