[Bf-blender-cvs] [0bb31c08b59] greasepencil-object: GPencil: Sculpt brushes uses affect position flag

Antonio Vazquez noreply at git.blender.org
Thu Oct 3 16:27:52 CEST 2019


Commit: 0bb31c08b59aa88f445e68a59c77155da82dd8dd
Author: Antonio Vazquez
Date:   Thu Oct 3 16:25:38 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0bb31c08b59aa88f445e68a59c77155da82dd8dd

GPencil: Sculpt brushes uses affect position flag

This commit changes the following:

1) The affect parameters have been moved to brush. Before, this parameter was by toolsettings and this was wrong.
2) Intialize the affect postion to ON.
3) If affect position is OFF, don't apply Sculpt brush effect.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/gpencil/gpencil_brush.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index ca9c518f443..472abf7cc50 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -267,14 +267,14 @@ class GreasePencilSculptOptionsPanel:
         brush = settings.brush
 
         if tool in {'SMOOTH', 'RANDOMIZE'}:
-            layout.prop(settings, "use_edit_position", text="Affect Position")
-            layout.prop(settings, "use_edit_strength", text="Affect Strength")
-            layout.prop(settings, "use_edit_thickness", text="Affect Thickness")
+            layout.prop(brush, "use_edit_position", text="Affect Position")
+            layout.prop(brush, "use_edit_strength", text="Affect Strength")
+            layout.prop(brush, "use_edit_thickness", text="Affect Thickness")
 
             if tool == 'SMOOTH':
                 layout.prop(brush, "use_edit_pressure")
 
-            layout.prop(settings, "use_edit_uv", text="Affect UV")
+            layout.prop(brush, "use_edit_uv", text="Affect UV")
 
 
 # GP Object Tool Settings
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 4f855bd7d98..b76470e2664 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -678,6 +678,7 @@ void BKE_scene_init(Scene *sce)
                      GP_SCULPT_FLAG_ENABLE_CURSOR;
     copy_v3_v3(gp_brush->curcolor_add, curcolor_add);
     copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub);
+    gp_brush->mode_flag = GP_SCULPT_FLAGMODE_APPLY_POSITION;
 
     gp_brush = &gset->brush[GP_SCULPT_TYPE_THICKNESS];
     gp_brush->size = 25;
@@ -727,6 +728,7 @@ void BKE_scene_init(Scene *sce)
     gp_brush->flag = GP_SCULPT_FLAG_USE_FALLOFF | GP_SCULPT_FLAG_ENABLE_CURSOR;
     copy_v3_v3(gp_brush->curcolor_add, curcolor_add);
     copy_v3_v3(gp_brush->curcolor_sub, curcolor_sub);
+    gp_brush->mode_flag = GP_SCULPT_FLAGMODE_APPLY_POSITION;
   }
 
   for (int i = 0; i < ARRAY_SIZE(sce->orientation_slots); i++) {
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index a3dc177262e..af1573fa98d 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1423,9 +1423,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain)
     if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) {
       for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
         ToolSettings *ts = scene->toolsettings;
-        /* initialize use position for sculpt brushes */
-        ts->gp_sculpt.flag |= GP_SCULPT_SETT_FLAG_APPLY_POSITION;
-
         /* new strength sculpt brush */
         if (ts->gp_sculpt.brush[0].size >= 11) {
           GP_Sculpt_Settings *gset = &ts->gp_sculpt;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index c8d0ea0c01b..27b0a196c47 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3916,5 +3916,21 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
         }
       }
     }
+
+    {
+      /* Enable by default affect position for grease pencil sculpt brushes */
+      if (!DNA_struct_elem_find(fd->filesdna, "GP_Sculpt_Data", "int", "mode_flag")) {
+        for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
+          /* sculpt brushes */
+          GP_Sculpt_Settings *gset = &scene->toolsettings->gp_sculpt;
+          if (gset) {
+            for (int i = 0; i < GP_SCULPT_TYPE_MAX; i++) {
+              GP_Sculpt_Data *brush = &gset->brush[i];
+              brush->mode_flag = GP_SCULPT_FLAGMODE_APPLY_POSITION;
+            }
+          }
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index af9cadfb938..1bdab54cfa1 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -333,24 +333,18 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso,
 {
   // GP_Sculpt_Data *gp_brush = gso->brush;
   float inf = gp_brush_influence_calc(gso, radius, co);
-  /* need one flag enabled by default */
-  if ((gso->settings->flag &
-       (GP_SCULPT_SETT_FLAG_APPLY_POSITION | GP_SCULPT_SETT_FLAG_APPLY_STRENGTH |
-        GP_SCULPT_SETT_FLAG_APPLY_THICKNESS | GP_SCULPT_SETT_FLAG_APPLY_UV)) == 0) {
-    gso->settings->flag |= GP_SCULPT_SETT_FLAG_APPLY_POSITION;
-  }
 
   /* perform smoothing */
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_POSITION) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_POSITION) {
     BKE_gpencil_smooth_stroke(gps, pt_index, inf);
   }
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_STRENGTH) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_STRENGTH) {
     BKE_gpencil_smooth_stroke_strength(gps, pt_index, inf);
   }
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_THICKNESS) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_THICKNESS) {
     BKE_gpencil_smooth_stroke_thickness(gps, pt_index, inf);
   }
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_UV) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_UV) {
     BKE_gpencil_smooth_stroke_uv(gps, pt_index, inf);
   }
 
@@ -847,15 +841,9 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
    */
   const float inf = gp_brush_influence_calc(gso, radius, co) / 2.0f;
   const float fac = BLI_rng_get_float(gso->rng) * inf;
-  /* need one flag enabled by default */
-  if ((gso->settings->flag &
-       (GP_SCULPT_SETT_FLAG_APPLY_POSITION | GP_SCULPT_SETT_FLAG_APPLY_STRENGTH |
-        GP_SCULPT_SETT_FLAG_APPLY_THICKNESS | GP_SCULPT_SETT_FLAG_APPLY_UV)) == 0) {
-    gso->settings->flag |= GP_SCULPT_SETT_FLAG_APPLY_POSITION;
-  }
 
   /* apply random to position */
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_POSITION) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_POSITION) {
     /* Jitter is applied perpendicular to the mouse movement vector
      * - We compute all effects in screenspace (since it's easier)
      *   and then project these to get the points/distances in
@@ -910,7 +898,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
     }
   }
   /* apply random to strength */
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_STRENGTH) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_STRENGTH) {
     if (BLI_rng_get_float(gso->rng) > 0.5f) {
       pt->strength += fac;
     }
@@ -921,7 +909,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
     CLAMP_MAX(pt->strength, 1.0f);
   }
   /* apply random to thickness (use pressure) */
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_THICKNESS) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_THICKNESS) {
     if (BLI_rng_get_float(gso->rng) > 0.5f) {
       pt->pressure += fac;
     }
@@ -932,7 +920,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
     CLAMP_MIN(pt->pressure, 0.0f);
   }
   /* apply random to UV (use pressure) */
-  if (gso->settings->flag & GP_SCULPT_SETT_FLAG_APPLY_UV) {
+  if (gso->gp_brush->mode_flag & GP_SCULPT_FLAGMODE_APPLY_UV) {
     if (BLI_rng_get_float(gso->rng) > 0.5f) {
       pt->uv_rot += fac;
     }
@@ -1282,10 +1270,6 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op)
 
   const bool is_weight_mode = ob->mode == OB_MODE_WEIGHT_GPENCIL;
   /* set the brush using the tool */
-#if 0
-  GP_Sculpt_Settings *gset = &ts->gp_sculpt;
-  eGP_Sculpt_Types mode = is_weight_mode ? gset->weighttype : gset->brushtype;
-#endif
   tGP_BrushEditData *gso;
 
   /* setup operator data */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index ca572f1ddf1..82f4b9db6b5 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1042,7 +1042,7 @@ typedef enum eGP_Lockaxis_Types {
 typedef struct GP_Sculpt_Data {
   /** Radius of brush. */
   short size;
-  /** EGP_Sculpt_Flag. */
+  /** eGP_Sculpt_Flag. */
   short flag;
   /** Strength of effect. */
   float strength;
@@ -1052,7 +1052,8 @@ typedef struct GP_Sculpt_Data {
   float curcolor_sub[3];
   /** Target weight. */
   float weight;
-  char _pad[4];
+  /** eGP_Sculpt_Mode_Flag. */
+  int mode_flag;
 } GP_Sculpt_Data;
 
 /* Settings for a GPencil Speed Guide */
@@ -1089,6 +1090,18 @@ typedef enum eGP_Sculpt_Flag {
   GP_SCULPT_FLAG_PRESSURE_RADIUS = (1 << 6),
 } eGP_Sculpt_Flag;
 
+/* GP_Sculpt_Data.mode_flag */
+typedef enum eGP_Sculpt_Mode_Flag {
+  /* apply brush to position */
+  GP_SCULPT_FLAGMODE_APPLY_POSITION = (1 << 0),
+  /* apply brush to strength */
+  GP_SCULPT_FLAGMODE_APPLY_STRENGTH = (1 << 1),
+  /* apply brush to thickness */
+  GP_SCULPT_FLAGMODE_APPLY_THICKNESS = (1 << 2),
+  /* apply brush to uv data */
+  GP_SCULPT_FLAGMODE_APPLY_UV = (1 << 3),
+} eGP_Sculpt_Mode_Flag;
+
 /* GPencil Stroke Sculpting Settings */
 typedef struct GP_Sculpt_Settings {
   /** GP_SCULPT_TYPE_MAX. */
@@ -1123,18 +1136,10 @@ typedef struct GP_Sculpt_Settings {
 typedef enum eGP_Sculpt_SettingsFlag {
   /* only affect selected points */
   GP_SCULPT_SETT_FLAG_DEPRECATED = (1 << 0),
-  /* apply brush to position */
-  GP_SCULPT_SETT_FLAG_APPLY_POSITION = (1 << 1),
-  /* apply brush to strength */
-  GP_SCULPT_SETT_FLAG_APPLY_STRENGTH = (1 << 2),
-  /* apply brush to thickness */
-  GP_SCULPT_SETT_FLAG_APPLY_THICKNESS = (1 << 3),
   /* apply brush to thickness */
   GP_SCULPT_SETT_FLAG_WEIGHT_MODE = (1 << 4),
   /* enable falloff for multiframe editing */
   GP_SCULPT_SETT_FLAG_FRAME_FALLOFF = (1 << 5),
-  /* apply brush to uv data */
-  GP_SCULPT_SETT_FLAG_APPLY_UV = (1 << 6),
   /* apply primitive curve */
   GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE = (1 << 7),
 } eGP_Sculpt_SettingsFlag;
diff --git a/source/blender/makesrna/inte

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list