[Bf-blender-cvs] [a67f218b541] master: GPencil: Use evaluated data for Sculpt Brushes

Antonio Vazquez noreply at git.blender.org
Sun Aug 25 16:05:16 CEST 2019


Commit: a67f218b541791a2e4468813794f5bcff1e08a88
Author: Antonio Vazquez
Date:   Sun Aug 25 16:04:23 2019 +0200
Branches: master
https://developer.blender.org/rBa67f218b541791a2e4468813794f5bcff1e08a88

GPencil: Use evaluated data for Sculpt Brushes

As part of T66294 is needed to use the evaluated data for Sculpt brushes to make possible to Sculpt a transformed stroke.

Without this commit, it was impossible sculpt the stroke if the modifier moves away the stroke point from original position. Also, some calculation is done in order to determine the rotation to transform the brush effect too.

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

M	source/blender/editors/gpencil/gpencil_brush.c

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

diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 4312bed657e..7b8cfc58a5f 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -134,6 +134,9 @@ typedef struct tGP_BrushEditData {
   /* - effect vector (e.g. 2D/3D translation for grab brush) */
   float dvec[3];
 
+  /* rotation for evaluated data */
+  float rot_eval;
+
   /* - multiframe falloff factor */
   float mf_falloff;
 
@@ -157,8 +160,12 @@ typedef struct tGP_BrushEditData {
 } tGP_BrushEditData;
 
 /* Callback for performing some brush operation on a single point */
-typedef bool (*GP_BrushApplyCb)(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2]);
+typedef bool (*GP_BrushApplyCb)(tGP_BrushEditData *gso,
+                                bGPDstroke *gps,
+                                float rotation,
+                                int pt_index,
+                                const int radius,
+                                const int co[2]);
 
 /* ************************************************ */
 /* Utility Functions */
@@ -294,6 +301,20 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c
   return influence;
 }
 
+/* Force recal filling data */
+static void gp_recalc_geometry(bGPDstroke *gps)
+{
+  bGPDstroke *gps_orig = gps->runtime.gps_orig;
+  if (gps_orig) {
+    gps_orig->flag |= GP_STROKE_RECALC_GEOMETRY;
+    gps_orig->tot_triangles = 0;
+  }
+  else {
+    gps->flag |= GP_STROKE_RECALC_GEOMETRY;
+    gps->tot_triangles = 0;
+  }
+}
+
 /* ************************************************ */
 /* Brush Callbacks */
 /* This section defines the callbacks used by each brush to perform their magic.
@@ -305,8 +326,12 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c
 
 /* A simple (but slower + inaccurate)
  * smooth-brush implementation to test the algorithm for stroke smoothing. */
-static bool gp_brush_smooth_apply(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_smooth_apply(tGP_BrushEditData *gso,
+                                  bGPDstroke *gps,
+                                  float UNUSED(rot_eval),
+                                  int pt_index,
+                                  const int radius,
+                                  const int co[2])
 {
   // GP_Sculpt_Data *gp_brush = gso->brush;
   float inf = gp_brush_influence_calc(gso, radius, co);
@@ -331,7 +356,7 @@ static bool gp_brush_smooth_apply(
     BKE_gpencil_smooth_stroke_uv(gps, pt_index, inf);
   }
 
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
+  gp_recalc_geometry(gps);
 
   return true;
 }
@@ -340,8 +365,12 @@ static bool gp_brush_smooth_apply(
 /* Line Thickness Brush */
 
 /* Make lines thicker or thinner by the specified amounts */
-static bool gp_brush_thickness_apply(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_thickness_apply(tGP_BrushEditData *gso,
+                                     bGPDstroke *gps,
+                                     float UNUSED(rot_eval),
+                                     int pt_index,
+                                     const int radius,
+                                     const int co[2])
 {
   bGPDspoint *pt = gps->points + pt_index;
   float inf;
@@ -380,8 +409,12 @@ static bool gp_brush_thickness_apply(
 /* Color Strength Brush */
 
 /* Make color more or less transparent by the specified amounts */
-static bool gp_brush_strength_apply(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_strength_apply(tGP_BrushEditData *gso,
+                                    bGPDstroke *gps,
+                                    float UNUSED(rot_eval),
+                                    int pt_index,
+                                    const int radius,
+                                    const int co[2])
 {
   bGPDspoint *pt = gps->points + pt_index;
   float inf;
@@ -424,6 +457,8 @@ typedef struct tGPSB_Grab_StrokeData {
   int *points;
   /* array of influence weights for each of the included points */
   float *weights;
+  /* angles to calc transformation */
+  float *rot_eval;
 
   /* capacity of the arrays */
   int capacity;
@@ -451,6 +486,7 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
 
     memset(data->points, 0, sizeof(int) * data->capacity);
     memset(data->weights, 0, sizeof(float) * data->capacity);
+    memset(data->rot_eval, 0, sizeof(float) * data->capacity);
   }
   else {
     /* Create new instance */
@@ -461,6 +497,7 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
 
     data->points = MEM_callocN(sizeof(int) * data->capacity, "GP Stroke Grab Indices");
     data->weights = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab Weights");
+    data->rot_eval = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab X");
 
     /* hook up to the cache */
     BLI_ghash_insert(gso->stroke_customdata, gps, data);
@@ -468,8 +505,12 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
 }
 
 /* store references to stroke points in the initial stage */
-static bool gp_brush_grab_store_points(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_grab_store_points(tGP_BrushEditData *gso,
+                                       bGPDstroke *gps,
+                                       float rot_eval,
+                                       int pt_index,
+                                       const int radius,
+                                       const int co[2])
 {
   tGPSB_Grab_StrokeData *data = BLI_ghash_lookup(gso->stroke_customdata, gps);
   float inf = gp_brush_influence_calc(gso, radius, co);
@@ -480,6 +521,7 @@ static bool gp_brush_grab_store_points(
   /* insert this point into the set of affected points */
   data->points[data->size] = pt_index;
   data->weights[data->size] = inf;
+  data->rot_eval[data->size] = rot_eval;
   data->size++;
 
   /* done */
@@ -503,6 +545,16 @@ static void gp_brush_grab_calc_dvec(tGP_BrushEditData *gso)
     mval_f[0] = (float)(gso->mval[0] - gso->mval_prev[0]);
     mval_f[1] = (float)(gso->mval[1] - gso->mval_prev[1]);
 
+    /* apply evaluated data transformation */
+    if (gso->rot_eval != 0.0f) {
+      const float cval = cos(gso->rot_eval);
+      const float sval = sin(gso->rot_eval);
+      float r[2];
+      r[0] = (mval_f[0] * cval) - (mval_f[1] * sval);
+      r[1] = (mval_f[0] * sval) + (mval_f[1] * cval);
+      copy_v2_v2(mval_f, r);
+    }
+
     ED_view3d_win_to_delta(gso->ar, mval_f, gso->dvec, zfac);
   }
   else {
@@ -527,6 +579,10 @@ static void gp_brush_grab_apply_cached(tGP_BrushEditData *gso,
     bGPDspoint *pt = &gps->points[data->points[i]];
     float delta[3] = {0.0f};
 
+    /* get evaluated transformation */
+    gso->rot_eval = data->rot_eval[i];
+    gp_brush_grab_calc_dvec(gso);
+
     /* adjust the amount of displacement to apply */
     mul_v3_v3fl(delta, gso->dvec, data->weights[i]);
 
@@ -545,7 +601,7 @@ static void gp_brush_grab_apply_cached(tGP_BrushEditData *gso,
     /* compute lock axis */
     gpsculpt_compute_lock_axis(gso, pt, save_pt);
   }
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
+  gp_recalc_geometry(gps);
 }
 
 /* free customdata used for handling this stroke */
@@ -554,8 +610,9 @@ static void gp_brush_grab_stroke_free(void *ptr)
   tGPSB_Grab_StrokeData *data = (tGPSB_Grab_StrokeData *)ptr;
 
   /* free arrays */
-  MEM_freeN(data->points);
-  MEM_freeN(data->weights);
+  MEM_SAFE_FREE(data->points);
+  MEM_SAFE_FREE(data->weights);
+  MEM_SAFE_FREE(data->rot_eval);
 
   /* ... and this item itself, since it was also allocated */
   MEM_freeN(data);
@@ -564,9 +621,12 @@ static void gp_brush_grab_stroke_free(void *ptr)
 /* ----------------------------------------------- */
 /* Push Brush */
 /* NOTE: Depends on gp_brush_grab_calc_dvec() */
-
-static bool gp_brush_push_apply(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_push_apply(tGP_BrushEditData *gso,
+                                bGPDstroke *gps,
+                                float rot_eval,
+                                int pt_index,
+                                const int radius,
+                                const int co[2])
 {
   bGPDspoint *pt = gps->points + pt_index;
   float save_pt[3];
@@ -593,7 +653,6 @@ static bool gp_brush_push_apply(
 
 /* ----------------------------------------------- */
 /* Pinch Brush */
-
 /* Compute reference midpoint for the brush - this is what we'll be moving towards */
 static void gp_brush_calc_midpoint(tGP_BrushEditData *gso)
 {
@@ -630,8 +689,12 @@ static void gp_brush_calc_midpoint(tGP_BrushEditData *gso)
 }
 
 /* Shrink distance between midpoint and this point... */
-static bool gp_brush_pinch_apply(
-    tGP_BrushEditData *gso, bGPDstroke *gps, int pt_index, const int radius, const int co[2])
+static bool gp_brush_pinch_apply(tGP_BrushEditData *gso,
+                                 bGPDstroke *gps,
+                                 float UNUSED(rot_eval),
+                                 int pt_index,
+                                 const int radius,
+                                 const int co[2])
 {
   bGPDspoint *pt = gps->points + pt_index;
   float fac, inf;
@@ -673,7 +736,7 @@ static bool gp_brush_pinch_apply(
   /* compute lock axis */
   gpsculpt_compute_lock_axis(gso, pt, save_pt);
 
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
+  gp_recalc_geometry(gps);
 
   /* done */
   return true;
@@ -681,13 +744,16 @@ static bool gp_brush_pinch_apply(
 
 /* ----------------------------------------------- */
 /* Twist Brush - Rotate Around midpoint */
-
 /* Take the screenspace coordinates of the point, rotate this around the brush midpoint,
  * convert the rotated point and convert it into "data" space
  */
 
-static bool gp_brush_twist_apply(
-    tGP_Brush

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list