Commit: 1a1152cb1ba4cc357bacd83698edd50c8350ff51
Author: Pablo Dobarro
Date:   Mon Apr 22 19:37:49 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB1a1152cb1ba4cc357bacd83698edd50c8350ff51

Brush Stroke: Use world spacing option

Quick hack to compute the stroke step using the world space location of
the brush over the mesh instead of the screen space distance, so the
user can avoid a lot of artifacts when sculpting across curved surfaces.
This would need to be implemented for texture/vertex/weight paint in the
future to keep the stroke system consistent.
It still has some problems with brushes that use original coordinates.

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

M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/editors/sculpt_paint/paint_stroke.c
M       source/blender/editors/sculpt_paint/sculpt.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 b8fe0204abd..042ee00f038 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -885,6 +885,8 @@ class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
             if brush.sculpt_capabilities.has_space_attenuation:
                 col.prop(brush, "use_space_attenuation")
 
+            col.prop(brush, "use_world_spacing")
+
             if brush.sculpt_capabilities.has_jitter:
 
                 row = col.row(align=True)
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c 
b/source/blender/editors/sculpt_paint/paint_stroke.c
index d66224034eb..e03ec6ec035 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -59,6 +59,7 @@
 #include "IMB_imbuf_types.h"
 
 #include "paint_intern.h"
+#include "sculpt_intern.h"
 
 #include <float.h>
 #include <math.h>
@@ -686,22 +687,39 @@ static int paint_space_stroke(bContext *C, wmOperator 
*op, const float final_mou
 
        float pressure, dpressure;
        float mouse[2], dmouse[2];
+       float p_final_mouse[3], p_dmouse[3], p_last_mouse_position[3];
        float length;
        float no_pressure_spacing = paint_space_stroke_spacing(scene, stroke, 
1.0f, 1.0f);
-
-       sub_v2_v2v2(dmouse, final_mouse, stroke->last_mouse_position);
-
        pressure = stroke->last_pressure;
        dpressure = final_pressure - stroke->last_pressure;
-
+       sub_v2_v2v2(dmouse, final_mouse, stroke->last_mouse_position);
        length = normalize_v2(dmouse);
 
+       if (stroke->brush->flag2 & BRUSH_WORLD_SPACING) {
+               sculpt_stroke_get_location(C, p_last_mouse_position, 
stroke->last_mouse_position);
+               bool hit = sculpt_stroke_get_location(C, p_final_mouse, 
final_mouse);
+               if (hit) {
+                       sub_v3_v3v3(p_dmouse, p_final_mouse, 
p_last_mouse_position);
+                       length = len_v3(p_dmouse);
+                       length = length * 400;
+               }
+               else {
+                       length = 0.0f;
+               }
+       }
+
        while (length > 0.0f) {
                float spacing = paint_space_stroke_spacing_variable(scene, 
stroke, pressure, dpressure, length);
 
                if (length >= spacing) {
-                       mouse[0] = stroke->last_mouse_position[0] + dmouse[0] * 
spacing;
-                       mouse[1] = stroke->last_mouse_position[1] + dmouse[1] * 
spacing;
+                       if (stroke->brush->flag2 & BRUSH_WORLD_SPACING) {
+                               mouse[0] = final_mouse[0];
+                               mouse[1] = final_mouse[1];
+                       }
+                       else {
+                               mouse[0] = stroke->last_mouse_position[0] + 
dmouse[0] * spacing;
+                               mouse[1] = stroke->last_mouse_position[1] + 
dmouse[1] * spacing;
+                       }
                        pressure = stroke->last_pressure + (spacing / length) * 
dpressure;
 
                        ups->overlap_factor = 
paint_stroke_integrate_overlap(stroke->brush, spacing / no_pressure_spacing);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index 129d191a924..14e831af0ec 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3677,6 +3677,9 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, 
PBVHNode **nodes, int t
        if (ss->cache->first_time)
                return;
 
+       if (is_zero_v3(ss->cache->grab_delta_symmetry))
+               return;
+
        mul_v3_v3v3(temp, area_no_sp, ss->cache->scale);
        mul_v3_fl(temp, displace);
        add_v3_v3(area_co, temp);
diff --git a/source/blender/makesdna/DNA_brush_types.h 
b/source/blender/makesdna/DNA_brush_types.h
index 6d8d4a2c954..5dc73989668 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -239,6 +239,7 @@ typedef struct Brush {
        int size;
        /** General purpose flag. */
        int flag;
+       int flag2;
        /** Pressure influence for mask. */
        int mask_pressure;
        /** Jitter the position of the brush. */
@@ -292,7 +293,7 @@ typedef struct Brush {
        char mask_tool;
        /** Active grease pencil tool. */
        char gpencil_tool;
-       char _pad0[2];
+       char _pad0[6];
 
        float autosmooth_factor;
 
@@ -421,6 +422,10 @@ typedef enum eBrushFlags {
        BRUSH_CURVE = (1u << 31),
 } eBrushFlags;
 
+typedef enum eBrushFlags2 {
+       BRUSH_WORLD_SPACING = (1 << 0),
+} eBrushFlags2;
+
 typedef enum {
        BRUSH_MASK_PRESSURE_RAMP = (1 << 1),
        BRUSH_MASK_PRESSURE_CUTOFF = (1 << 2),
diff --git a/source/blender/makesrna/intern/rna_brush.c 
b/source/blender/makesrna/intern/rna_brush.c
index 2cc77935897..80bff7e0e75 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1798,6 +1798,12 @@ static void rna_def_brush(BlenderRNA *brna)
                                 "When locked keep using normal of surface 
where stroke was initiated");
        RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+       prop = RNA_def_property(srna, "use_world_spacing", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag2", BRUSH_WORLD_SPACING);
+       RNA_def_property_ui_text(prop, "Use world spacing",
+                                "Compute the distance between steps in world 
space");
+       RNA_def_property_update(prop, 0, "rna_Brush_update");
+
        prop = RNA_def_property(srna, "use_pressure_strength", PROP_BOOLEAN, 
PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_ALPHA_PRESSURE);
        RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to