[Bf-blender-cvs] [467f65ca203] temp-gpencil-eval: Calculate Filling data when stroke is modified

Antonio Vazquez noreply at git.blender.org
Thu Jan 16 22:57:01 CET 2020


Commit: 467f65ca203484f6578e48de43ed9a4afd70b072
Author: Antonio Vazquez
Date:   Thu Jan 16 22:51:41 2020 +0100
Branches: temp-gpencil-eval
https://developer.blender.org/rB467f65ca203484f6578e48de43ed9a4afd70b072

Calculate Filling data when stroke is modified

Instead to calculate the geometry data in runtime, now this data is calculated when the stroke is created or modified and saved.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/drawgpencil.c
M	source/blender/editors/gpencil/gpencil_add_monkey.c
M	source/blender/editors/gpencil/gpencil_add_stroke.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_interpolate.c
M	source/blender/editors/gpencil/gpencil_merge.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_sculpt_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/gpencil/gpencil_uv.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index 874c4213c02..3ba0d5582d7 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -368,7 +368,6 @@ class DATA_PT_gpencil_strokes(DataButtonsPanel, Panel):
         sub.prop(gpd, "pixel_factor", text="Thickness Scale")
 
         layout.prop(gpd, "use_force_fill_recalc", text="Force Fill Update")
-        layout.prop(gpd, "use_adaptive_uv", text="Adaptive UVs")
 
 
 class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 2c49878005f..c49a3b3cb56 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -259,10 +259,8 @@ void BKE_gpencil_stroke_2d_flat_ref(const struct bGPDspoint *ref_points,
                                     float (*points2d)[2],
                                     const float scale,
                                     int *r_direction);
-void BKE_gpencil_triangulate_stroke_fill(struct bGPdata *gpd, struct bGPDstroke *gps);
-void BKE_gpencil_recalc_geometry_caches(struct Object *ob,
-                                        struct bGPDlayer *gpl,
-                                        struct bGPDstroke *gps);
+void BKE_gpencil_stroke_fill_triangulate(struct bGPDstroke *gps);
+void BKE_gpencil_stroke_geometry_update(struct bGPDstroke *gps);
 void BKE_gpencil_calc_stroke_uv(struct bGPDstroke *gps);
 
 void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
@@ -329,7 +327,6 @@ extern "C" {
 void BKE_gpencil_frame_original_pointers_update(const struct bGPDframe *gpf_orig,
                                                 const struct bGPDframe *gpf_eval);
 void BKE_gpencil_update_orig_pointers(const struct Object *ob_orig, const struct Object *ob_eval);
-void BKE_gpencil_prepare_filling_data(const struct Object *ob_orig, const struct Object *ob_eval);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 9241829075f..8b95bf6872d 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -507,15 +507,13 @@ bGPDstroke *BKE_gpencil_stroke_add(bGPDframe *gpf, int mat_idx, int totpoints, s
 
   gps->inittime = 0;
 
-  /* enable recalculation flag by default */
-  gps->flag = GP_STROKE_RECALC_GEOMETRY | GP_STROKE_3DSPACE;
+  gps->flag = GP_STROKE_3DSPACE;
 
   gps->totpoints = totpoints;
   gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
 
   /* initialize triangle memory to dummy data */
   gps->triangles = NULL;
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
   gps->tot_triangles = 0;
 
   gps->mat_nr = mat_idx;
@@ -570,12 +568,7 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src)
     gps_dst->dvert = NULL;
   }
 
-  /* Don't clear triangles, so that modifier evaluation can just use
-   * this without extra work first. Most places that need to force
-   * this data to get recalculated will destroy the data anyway though.
-   */
   gps_dst->triangles = MEM_dupallocN(gps_dst->triangles);
-  /* gps_dst->flag |= GP_STROKE_RECALC_GEOMETRY; */
 
   /* return new stroke */
   return gps_dst;
@@ -1428,8 +1421,7 @@ void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
         }
 
         /* TODO: Do we need to do this? distortion may mean we need to re-triangulate */
-        gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-        gps->tot_triangles = 0;
+        BKE_gpencil_stroke_geometry_update(gps);
       }
     }
   }
@@ -1803,8 +1795,7 @@ bool BKE_gpencil_sample_stroke(bGPDstroke *gps, const float dist, const bool sel
 
   gps->totpoints = i;
 
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-  gps->tot_triangles = 0;
+  BKE_gpencil_stroke_geometry_update(gps);
 
   return true;
 }
@@ -1965,7 +1956,7 @@ bool BKE_gpencil_split_stroke(bGPDframe *gpf,
    * Keep the end point. */
 
   BKE_gpencil_trim_stroke_points(gps, 0, old_count);
-
+  BKE_gpencil_stroke_geometry_update(gps);
   return true;
 }
 
@@ -2734,7 +2725,7 @@ static void gpencil_calc_stroke_fill_uv(const float (*points2d)[2],
 
 /* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was
  * modified) */
-void BKE_gpencil_triangulate_stroke_fill(bGPdata *gpd, bGPDstroke *gps)
+void BKE_gpencil_stroke_fill_triangulate(bGPDstroke *gps)
 {
   BLI_assert(gps->totpoints >= 3);
 
@@ -2756,20 +2747,13 @@ void BKE_gpencil_triangulate_stroke_fill(bGPdata *gpd, bGPDstroke *gps)
   float minv[2];
   float maxv[2];
   /* first needs bounding box data */
-  if (gpd->flag & GP_DATA_UV_ADAPTIVE) {
-    gpencil_calc_2d_bounding_box(points2d, gps->totpoints, minv, maxv);
-  }
-  else {
-    ARRAY_SET_ITEMS(minv, -1.0f, -1.0f);
-    ARRAY_SET_ITEMS(maxv, 1.0f, 1.0f);
-  }
+  ARRAY_SET_ITEMS(minv, -1.0f, -1.0f);
+  ARRAY_SET_ITEMS(maxv, 1.0f, 1.0f);
 
   /* calc uv data */
   gpencil_calc_stroke_fill_uv(points2d, gps, minv, maxv, uv);
 
-  /* Number of triangles */
-  gps->tot_triangles = gps->totpoints - 2;
-  /* save triangulation data in stroke cache */
+  /* Save triangulation data. */
   if (gps->tot_triangles > 0) {
     MEM_SAFE_FREE(gps->triangles);
     gps->triangles = MEM_callocN(sizeof(*gps->triangles) * gps->tot_triangles,
@@ -2793,11 +2777,6 @@ void BKE_gpencil_triangulate_stroke_fill(bGPdata *gpd, bGPDstroke *gps)
     gps->triangles = NULL;
   }
 
-  /* disable recalculation flag */
-  if (gps->flag & GP_STROKE_RECALC_GEOMETRY) {
-    gps->flag &= ~GP_STROKE_RECALC_GEOMETRY;
-  }
-
   /* clear memory */
   MEM_SAFE_FREE(tmp_triangles);
   MEM_SAFE_FREE(points2d);
@@ -2821,19 +2800,18 @@ void BKE_gpencil_calc_stroke_uv(bGPDstroke *gps)
 }
 
 /* Recalc the internal geometry caches for fill and uvs. */
-void BKE_gpencil_recalc_geometry_caches(Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
+void BKE_gpencil_stroke_geometry_update(bGPDstroke *gps)
 {
-  if (gps->flag & GP_STROKE_RECALC_GEOMETRY) {
-    if (gps->totpoints > 2) {
-      BKE_gpencil_triangulate_stroke_fill((bGPdata *)ob->data, gps);
-    }
-
-    /* calc uv data along the stroke */
-    BKE_gpencil_calc_stroke_uv(gps);
+  if (gps == NULL) {
+    return;
+  }
 
-    /* clear flag */
-    gps->flag &= ~GP_STROKE_RECALC_GEOMETRY;
+  if (gps->totpoints > 2) {
+    BKE_gpencil_stroke_fill_triangulate(gps);
   }
+
+  /* calc uv data along the stroke */
+  BKE_gpencil_calc_stroke_uv(gps);
 }
 
 float BKE_gpencil_stroke_length(const bGPDstroke *gps, bool use_3d)
@@ -2943,13 +2921,14 @@ bool BKE_gpencil_trim_stroke(bGPDstroke *gps)
       }
     }
 
-    gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-    gps->tot_triangles = 0;
     gps->totpoints = newtot;
 
     MEM_SAFE_FREE(old_points);
     MEM_SAFE_FREE(old_dvert);
   }
+
+  BKE_gpencil_stroke_geometry_update(gps);
+
   return intersect;
 }
 
@@ -3118,8 +3097,7 @@ void BKE_gpencil_dissolve_points(bGPDframe *gpf, bGPDstroke *gps, const short ta
     gps->totpoints = tot;
 
     /* triangles cache needs to be recalculated */
-    gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-    gps->tot_triangles = 0;
+    BKE_gpencil_stroke_geometry_update(gps);
   }
 }
 
@@ -3333,8 +3311,6 @@ static void gpencil_convert_spline(Main *bmain,
   ARRAY_SET_ITEMS(gps->caps, GP_STROKE_CAP_ROUND, GP_STROKE_CAP_ROUND);
   gps->inittime = 0.0f;
 
-  /* Enable recalculation flag by default. */
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
   gps->flag &= ~GP_STROKE_SELECT;
   gps->flag |= GP_STROKE_3DSPACE;
 
@@ -3353,10 +3329,6 @@ static void gpencil_convert_spline(Main *bmain,
   }
   totpoints = (resolu * segments) - (segments - 1);
 
-  /* Initialize triangle memory to dummy data. */
-  gps->tot_triangles = 0;
-  gps->triangles = NULL;
-
   /* Materials
    * Notice: The color of the material is the color of viewport and not the final shader color.
    */
@@ -3539,6 +3511,9 @@ static void gpencil_convert_spline(Main *bmain,
   if ((cyclic) && (!do_stroke)) {
     BKE_gpencil_close_stroke(gps);
   }
+
+  /* Recalc fill geometry. */
+  BKE_gpencil_stroke_geometry_update(gps);
 }
 
 /* Convert a curve object to grease pencil stroke.
@@ -3689,6 +3664,7 @@ bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size,
           pt->flag |= GP_SPOINT_SELECT;
         }
       }
+      BKE_gpencil_stroke_geometry_update(gps);
     }
   }
 
@@ -3827,27 +3803,6 @@ void BKE_gpencil_visible_stroke_iter(
   }
 }
 
-static void gpencil_prepare_filling(const Object *ob)
-{
-  bGPdata *gpd = (bGPdata *)ob->data;
-  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
-    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
-      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-        BKE_gpencil_recalc_geometry_caches((Object *)ob, gpl, gps);
-      }
-    }
-  }
-}
-
-void BKE_gpencil_prepare_filling_data(const struct Object *ob_orig, const struct Object *ob_eval)
-{
-  /* ToDo: Add flag to avoid this checking if nothing has changed. */
-  /* Update original data to avoid recalculation in next loops. */
-  gpencil_prepare_filling(ob_orig);
-  /* Update evaluated data. */
-  gpencil_prepare_filling(ob_eval);
-}
-
 void BKE_gpencil_frame_original_pointers_update(const struct bGPDframe *gpf_orig,
                                                 const struct bGPDframe *gpf_eval)
 {
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index f5df4fa3a3f..4cc224438f4 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -165,9 +165,6 @@ void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float epsilon)
     old_dvert = MEM_dupallocN(gps->dvert);
   }
   /* resize gps */
-  gps->flag |= GP_STROKE_RECALC_GEOMETRY;
-  gps->tot_triangles = 0;
-
   int j = 0;
   for (int i = 0; i < totpoints; i++) {
     bGPDspoint *pt_src = &old_points[i];
@@ -195,6 +192,8 @@ void BKE_gpencil_simplify_stroke(bGPDstroke *gps, float epsilon)
 
   gps->totpoints = j;
 
+  BKE_gpencil_stroke_geometry_update(gps);
+
   MEM_SAFE_FREE(old_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list