[Bf-blender-cvs] [6bb9ec58d24] greasepencil-refactor: GPencil: Move cache recalc functions to shared module

Antonio Vazquez noreply at git.blender.org
Tue Dec 10 12:04:06 CET 2019


Commit: 6bb9ec58d24f9ef6ee3671895cb1e0dad58e19d9
Author: Antonio Vazquez
Date:   Tue Dec 10 12:03:30 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB6bb9ec58d24f9ef6ee3671895cb1e0dad58e19d9

GPencil: Move cache recalc functions to shared module

This is the first step to move the recalc of the filling to the evaluation area (like modifiers) and not in the draw manager that must only draw.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 8dc19ed32e5..83c648d6243 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -42,7 +42,7 @@ struct bGPDlayer;
 struct bGPDspoint;
 struct bGPDstroke;
 struct bGPdata;
-
+struct MaterialGPencilStyle;
 struct MDeformVert;
 
 #define GPENCIL_SIMPLIFY(scene) ((scene->r.simplify_gpencil & SIMPLIFY_GPENCIL_ENABLE))
@@ -260,6 +260,11 @@ void BKE_gpencil_stroke_2d_flat_ref(const struct bGPDspoint *ref_points,
                                     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 MaterialGPencilStyle *gp_style,
+                                        struct bGPDstroke *gps);
+void BKE_gpencil_calc_stroke_uv(struct Object *ob, struct bGPDstroke *gps);
 
 void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
 
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 1d9e0594b65..9de6f6a53fb 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2762,6 +2762,87 @@ void BKE_gpencil_triangulate_stroke_fill(bGPdata *gpd, bGPDstroke *gps)
   MEM_SAFE_FREE(uv);
 }
 
+/* texture coordinate utilities */
+void BKE_gpencil_calc_stroke_uv(Object *ob, bGPDstroke *gps)
+{
+  if (gps == NULL) {
+    return;
+  }
+  MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
+  float pixsize;
+  if (gp_style) {
+    pixsize = gp_style->texture_pixsize / 1000000.0f;
+  }
+  else {
+    /* use this value by default */
+    pixsize = 0.0001f;
+  }
+  pixsize = MAX2(pixsize, 0.0000001f);
+
+  bGPDspoint *pt = NULL;
+  bGPDspoint *ptb = NULL;
+  int i;
+  float totlen = 0.0f;
+
+  /* first read all points and calc distance */
+  for (i = 0; i < gps->totpoints; i++) {
+    pt = &gps->points[i];
+    /* first point */
+    if (i == 0) {
+      pt->uv_fac = 0.0f;
+      continue;
+    }
+
+    ptb = &gps->points[i - 1];
+    totlen += len_v3v3(&pt->x, &ptb->x) / pixsize;
+    pt->uv_fac = totlen;
+  }
+
+  /* normalize the distance using a factor */
+  float factor;
+
+  /* if image, use texture width */
+  if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) &&
+      (gp_style->sima)) {
+    factor = gp_style->sima->gen_x;
+  }
+  else if (totlen == 0) {
+    return;
+  }
+  else {
+    factor = totlen;
+  }
+
+  for (i = 0; i < gps->totpoints; i++) {
+    pt = &gps->points[i];
+    pt->uv_fac /= factor;
+  }
+}
+
+/* Recalc the internal geometry caches for fill and uvs. */
+void BKE_gpencil_recalc_geometry_caches(Object *ob,
+                                        bGPDlayer *gpl,
+                                        MaterialGPencilStyle *gp_style,
+                                        bGPDstroke *gps)
+{
+  if (gps->flag & GP_STROKE_RECALC_GEOMETRY) {
+    /* Calculate triangles cache for filling area (must be done only after changes) */
+    if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
+      if ((gps->totpoints > 2) && (gp_style->flag & GP_STYLE_FILL_SHOW) &&
+          ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0) ||
+           (gpl->blend_mode != eGplBlendMode_Regular))) {
+        BKE_gpencil_triangulate_stroke_fill((bGPdata *)ob->data, gps);
+      }
+    }
+
+    /* calc uv data along the stroke */
+    BKE_gpencil_calc_stroke_uv(ob, gps);
+
+    /* clear flag */
+    gps->flag &= ~GP_STROKE_RECALC_GEOMETRY;
+  }
+}
+
 float BKE_gpencil_stroke_length(const bGPDstroke *gps, bool use_3d)
 {
   if (!gps->points || gps->totpoints < 2) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 7c98035bbc0..ed2f962ab05 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -407,30 +407,6 @@ static bool gpencil_can_draw_stroke(struct MaterialGPencilStyle *gp_style,
   return true;
 }
 
-/* recalc the internal geometry caches for fill and uvs */
-static void gpencil_recalc_geometry_caches(Object *ob,
-                                           bGPDlayer *gpl,
-                                           MaterialGPencilStyle *gp_style,
-                                           bGPDstroke *gps)
-{
-  if (gps->flag & GP_STROKE_RECALC_GEOMETRY) {
-    /* Calculate triangles cache for filling area (must be done only after changes) */
-    if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
-      if ((gps->totpoints > 2) && (gp_style->flag & GP_STYLE_FILL_SHOW) &&
-          ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0) ||
-           (gpl->blend_mode != eGplBlendMode_Regular))) {
-        BKE_gpencil_triangulate_stroke_fill((bGPdata *)ob->data, gps);
-      }
-    }
-
-    /* calc uv data along the stroke */
-    ED_gpencil_calc_stroke_uv(ob, gps);
-
-    /* clear flag */
-    gps->flag &= ~GP_STROKE_RECALC_GEOMETRY;
-  }
-}
-
 static void set_wireframe_color(Object *ob,
                                 bGPDlayer *gpl,
                                 View3D *v3d,
@@ -1360,7 +1336,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache,
 
     /* be sure recalc all cache in source stroke to avoid recalculation when frame change
      * and improve fps */
-    gpencil_recalc_geometry_caches(
+    BKE_gpencil_recalc_geometry_caches(
         ob, gpl, gp_style, (gps->runtime.gps_orig) ? gps->runtime.gps_orig : gps);
 
     /* if the fill has any value, it's considered a fill and is not drawn if simplify fill is
@@ -1394,7 +1370,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache,
              (gpl->blend_mode == eGplBlendMode_Regular))) {
           /* recalc strokes uv (geometry can be changed by modifiers) */
           if (gps->flag & GP_STROKE_RECALC_GEOMETRY) {
-            ED_gpencil_calc_stroke_uv(ob, gps);
+            BKE_gpencil_calc_stroke_uv(ob, gps);
           }
 
           gpencil_add_stroke_vertexdata(
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 023cc32227d..e91e3e704c4 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1241,7 +1241,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
   }
 
   /* calculate UVs along the stroke */
-  ED_gpencil_calc_stroke_uv(obact, gps);
+  BKE_gpencil_calc_stroke_uv(obact, gps);
 
   /* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke
    * is added on listbase head because the drawing order is inverse and the head stroke is the
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 97623c3c092..66ac9ecccb3 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -1347,7 +1347,7 @@ static void gpencil_primitive_interaction_end(bContext *C,
     gps->tot_triangles = 0;
 
     /* calculate UVs along the stroke */
-    ED_gpencil_calc_stroke_uv(tgpi->ob, gps);
+    BKE_gpencil_calc_stroke_uv(tgpi->ob, gps);
   }
 
   /* transfer stroke from temporary buffer to the actual frame */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index a35f1b6196c..d72a0da3ac0 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1961,63 +1961,6 @@ void ED_gpencil_tpoint_to_point(ARegion *ar, float origin[3], const tGPspoint *t
   pt->uv_rot = tpt->uv_rot;
 }
 
-/* texture coordinate utilities */
-void ED_gpencil_calc_stroke_uv(Object *ob, bGPDstroke *gps)
-{
-  if (gps == NULL) {
-    return;
-  }
-  MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
-  float pixsize;
-  if (gp_style) {
-    pixsize = gp_style->texture_pixsize / 1000000.0f;
-  }
-  else {
-    /* use this value by default */
-    pixsize = 0.0001f;
-  }
-  pixsize = MAX2(pixsize, 0.0000001f);
-
-  bGPDspoint *pt = NULL;
-  bGPDspoint *ptb = NULL;
-  int i;
-  float totlen = 0.0f;
-
-  /* first read all points and calc distance */
-  for (i = 0; i < gps->totpoints; i++) {
-    pt = &gps->points[i];
-    /* first point */
-    if (i == 0) {
-      pt->uv_fac = 0.0f;
-      continue;
-    }
-
-    ptb = &gps->points[i - 1];
-    totlen += len_v3v3(&pt->x, &ptb->x) / pixsize;
-    pt->uv_fac = totlen;
-  }
-
-  /* normalize the distance using a factor */
-  float factor;
-
-  /* if image, use texture width */
-  if ((gp_style) && (gp_style->stroke_style == GP_STYLE_STROKE_STYLE_TEXTURE) &&
-      (gp_style->sima)) {
-    factor = gp_style->sima->gen_x;
-  }
-  else if (totlen == 0) {
-    return;
-  }
-  else {
-    factor = totlen;
-  }
-
-  for (i = 0; i < gps->totpoints; i++) {
-    pt = &gps->points[i];
-    pt->uv_fac /= factor;
-  }
-}
-
 /* recalc uv for any stroke using the material */
 void ED_gpencil_update_color_uv(Main *bmain, Material *mat)
 {
@@ -2042,7 +1985,7 @@ void ED_gpencil_update_color_uv(Main *bmain, Material *mat)
               gps_ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1);
               /* update */
               if ((gps_ma) && (gps_ma == mat)) {
-                ED_gpencil_calc_stroke_uv(ob, gps);
+                BKE_gpencil_calc_stroke_uv(ob, gps);
               }
             }
           }
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 3dd8b734d89..1a74531d119 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -261,7 +261,6 @@ void ED_gpencil_tpoint_to_point(struct ARegion *ar,
                                 float origin[3],
                                 con

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list