[Bf-blender-cvs] [448669a630d] master: Fix T72092: Clay Strips Brush stroke crash with Brush Detail Size

Pablo Dobarro noreply at git.blender.org
Mon Dec 9 16:54:01 CET 2019


Commit: 448669a630d318a5cd090af3083c985740a68e8e
Author: Pablo Dobarro
Date:   Sun Dec 1 20:29:11 2019 +0100
Branches: master
https://developer.blender.org/rB448669a630d318a5cd090af3083c985740a68e8e

Fix T72092: Clay Strips Brush stroke crash with Brush Detail Size

Some other areas in the brush code outside sculpt mode assume that
pressure is multiplied directly on top of the initial size. This patch
calculates the pixel radius correctly using the brush size from sculpt
mode to get the dyntopo detail size.
When the new brush input system is in place, all these values will come
directly from the brush input code with all the custom curves applied
per brush, so all paint modes will have a correct brush behavior and all
this sculpt mode specific code won't be necessary.

Reviewed By: jbakker

Maniphest Tasks: T72092

Differential Revision: https://developer.blender.org/D6339

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

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/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index fc0c6d748cb..372ea954630 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -335,6 +335,7 @@ static bool paint_brush_update(bContext *C,
   ups->size_pressure_value = stroke->cached_size_pressure;
 
   ups->pixel_radius = BKE_brush_size_get(scene, brush);
+  ups->initial_pixel_radius = BKE_brush_size_get(scene, brush);
 
   if (BKE_brush_use_size_pressure(brush) && paint_supports_dynamic_size(brush, mode)) {
     ups->pixel_radius *= stroke->cached_size_pressure;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 8be44066741..b35fc11aedc 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -6730,11 +6730,12 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, Po
   if (BKE_brush_use_size_pressure(brush) &&
       paint_supports_dynamic_size(brush, PAINT_MODE_SCULPT)) {
     cache->radius = sculpt_brush_dynamic_size_get(brush, cache, cache->initial_radius);
-    cache->dyntopo_radius = cache->initial_radius * cache->pressure;
+    cache->dyntopo_pixel_radius = sculpt_brush_dynamic_size_get(
+        brush, cache, ups->initial_pixel_radius);
   }
   else {
     cache->radius = cache->initial_radius;
-    cache->dyntopo_radius = cache->initial_radius;
+    cache->dyntopo_pixel_radius = ups->initial_pixel_radius;
   }
 
   cache->radius_squared = cache->radius * cache->radius;
@@ -7345,12 +7346,11 @@ static void sculpt_stroke_update_step(bContext *C,
     BKE_pbvh_bmesh_detail_size_set(ss->pbvh, object_space_constant_detail);
   }
   else if (sd->flags & SCULPT_DYNTOPO_DETAIL_BRUSH) {
-    BKE_pbvh_bmesh_detail_size_set(ss->pbvh,
-                                   ss->cache->dyntopo_radius * sd->detail_percent / 100.0f);
+    BKE_pbvh_bmesh_detail_size_set(ss->pbvh, ss->cache->radius * sd->detail_percent / 100.0f);
   }
   else {
     BKE_pbvh_bmesh_detail_size_set(ss->pbvh,
-                                   (ss->cache->dyntopo_radius / (float)ups->pixel_radius) *
+                                   (ss->cache->radius / ss->cache->dyntopo_pixel_radius) *
                                        (float)(sd->detail_size * U.pixelsize) / 0.4f);
   }
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 324ca250c86..e9ad31d6f25 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -319,8 +319,8 @@ typedef struct StrokeCache {
   float location[3];
   float last_location[3];
 
-  /* This radius variable is not affected by pressure curves */
-  float dyntopo_radius;
+  /* Original pixel radius with the pressure curve applied for dyntopo detail size */
+  float dyntopo_pixel_radius;
 
   bool is_last_valid;
 
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 5336ea381c3..980fbfa72e0 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1277,6 +1277,9 @@ typedef struct UnifiedPaintSettings {
   /* radius of brush, premultiplied with pressure.
    * In case of anchored brushes contains the anchored radius */
   float pixel_radius;
+  float initial_pixel_radius;
+
+  char _pad[4];
 
   /* drawing pressure */
   float size_pressure_value;



More information about the Bf-blender-cvs mailing list