Fix T53577: Rake sculpt/paint wrong on first step
authorCampbell Barton <ideasman42@gmail.com>
Mon, 18 Dec 2017 03:35:15 +0000 (14:35 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 18 Dec 2017 03:35:15 +0000 (14:35 +1100)
source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/paint.c
source/blender/editors/sculpt_paint/paint_stroke.c

index dff7f65b39a531376abc14e19659069e820a57a3..07c4598c85632028d04d8695127ef890af99c94e 100644 (file)
@@ -155,7 +155,7 @@ float paint_grid_paint_mask(const struct GridPaintMask *gpm, unsigned level,
                             unsigned x, unsigned y);
 
 /* stroke related */
-void paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, struct Brush *brush, const float mouse_pos[2]);
+bool paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, struct Brush *brush, const float mouse_pos[2]);
 void paint_update_brush_rake_rotation(struct UnifiedPaintSettings *ups, struct Brush *brush, float rotation);
 
 void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float stroke[3]);
index c1ad31a1cab7684454676abdb36c8755b6fd88d6..32813ffce25295d2f0551091dfb3d3383a4cd820 100644 (file)
@@ -638,8 +638,9 @@ void paint_update_brush_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, f
                ups->brush_rotation_sec = 0.0f;
 }
 
-void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, const float mouse_pos[2])
+bool paint_calculate_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, const float mouse_pos[2])
 {
+       bool ok = false;
        if ((brush->mtex.brush_angle_mode & MTEX_ANGLE_RAKE) || (brush->mask_mtex.brush_angle_mode & MTEX_ANGLE_RAKE)) {
                const float r = RAKE_THRESHHOLD;
                float rotation;
@@ -655,16 +656,20 @@ void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, Brush *brush, cons
                        ups->last_rake_angle = rotation;
 
                        paint_update_brush_rake_rotation(ups, brush, rotation);
+                       ok = true;
                }
                /* make sure we reset here to the last rotation to avoid accumulating
                 * values in case a random rotation is also added */
                else {
                        paint_update_brush_rake_rotation(ups, brush, ups->last_rake_angle);
+                       ok = false;
                }
        }
        else {
                ups->brush_rotation = ups->brush_rotation_sec = 0.0f;
+               ok = true;
        }
+       return ok;
 }
 
 void BKE_sculptsession_free_deformMats(SculptSession *ss)
index 2c8e88e3ccb131fff868fb1818da6e4c7338bad3..c3055144b20fd0644c5a3e697a0dbf16bb8f4e5f 100644 (file)
@@ -224,6 +224,9 @@ static bool paint_brush_update(bContext *C,
        UnifiedPaintSettings *ups = stroke->ups;
        bool location_sampled = false;
        bool location_success = false;
+       /* Use to perform all operations except applying the stroke,
+        * needed for operations that require cursor motion (rake). */
+       bool is_dry_run = false;
        bool do_random = false;
        bool do_random_mask = false;
        /* XXX: Use pressure value from first brush step for brushes which don't
@@ -362,7 +365,10 @@ static bool paint_brush_update(bContext *C,
                }
                /* curve strokes do their own rake calculation */
                else if (!(brush->flag & BRUSH_CURVE)) {
-                       paint_calculate_rake_rotation(ups, brush, mouse_init);
+                       if (!paint_calculate_rake_rotation(ups, brush, mouse_init)) {
+                               /* Not enough motion to define an angle. */
+                               is_dry_run = true;
+                       }
                }
        }
 
@@ -393,7 +399,7 @@ static bool paint_brush_update(bContext *C,
                }
        }
 
-       return location_success;
+       return location_success && (is_dry_run == false);
 }
 
 static bool paint_stroke_use_jitter(ePaintMode mode, Brush *brush, bool invert)