[Bf-blender-cvs] [edbebeb44f9] greasepencil-refactor: Move filling data and orig pointers evaluation to Depsgraph

Antonio Vazquez noreply at git.blender.org
Sat Jan 18 11:54:30 CET 2020


Commit: edbebeb44f9595ef0334d8fb0fd61e5fd4cf4c67
Author: Antonio Vazquez
Date:   Tue Jan 14 13:30:41 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBedbebeb44f9595ef0334d8fb0fd61e5fd4cf4c67

Move filling data and orig pointers evaluation to Depsgraph

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/BKE_gpencil_modifier.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 7e9e01cc297..ef46087e332 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -322,4 +322,15 @@ void BKE_gpencil_visible_stroke_iter(struct Object *ob,
 extern void (*BKE_gpencil_batch_cache_dirty_tag_cb)(struct bGPdata *gpd);
 extern void (*BKE_gpencil_batch_cache_free_cb)(struct bGPdata *gpd);
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /*  __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h
index 949fce74cd0..0d352a6b316 100644
--- a/source/blender/blenkernel/BKE_gpencil_modifier.h
+++ b/source/blender/blenkernel/BKE_gpencil_modifier.h
@@ -321,10 +321,4 @@ void BKE_gpencil_modifiers_calc(struct Depsgraph *depsgraph,
 void BKE_gpencil_prepare_eval_data(struct Depsgraph *depsgraph,
                                    struct Scene *scene,
                                    struct Object *ob);
-void BKE_gpencil_update_refences(struct Depsgraph *depsgraph,
-                                 struct Scene *scene,
-                                 struct Object *ob);
-void BKE_gpencil_prepare_filling_data(struct Depsgraph *depsgraph,
-                                      struct Scene *scene,
-                                      struct Object *ob);
 #endif /* __BKE_GPENCIL_MODIFIER_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 0d3f98c7b55..1e88fec50da 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -3839,4 +3839,79 @@ void BKE_gpencil_visible_stroke_iter(
   }
 }
 
+void BKE_gpencil_prepare_filling_data(const Object *ob)
+{
+  bGPdata *gpd = (bGPdata *)ob->data;
+
+  /* Loop original strokes and generate triangulation for filling.
+   * The first time this is slow, but in next loops, the strokes has all data calculated and
+   * doesn't need calc again except if some modifier update the stroke geometry. */
+  for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+    for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+      for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+        MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get((Object *)ob,
+                                                                           gps->mat_nr + 1);
+        if (gp_style) {
+          BKE_gpencil_recalc_geometry_caches((Object *)ob, gpl, gp_style, gps);
+        }
+      }
+    }
+  }
+}
+
+static void gpencil_update_frame_reference_pointers(const struct bGPDframe *gpf_orig,
+                                                    const struct bGPDframe *gpf_eval)
+{
+  int stroke_idx = -1;
+  for (bGPDstroke *gps_orig = gpf_orig->strokes.first; gps_orig; gps_orig = gps_orig->next) {
+    stroke_idx++;
+
+    /* Assign original stroke pointer. */
+    if (gpf_eval != NULL) {
+      bGPDstroke *gps_eval = BLI_findlink(&gpf_eval->strokes, stroke_idx);
+      if (gps_eval != NULL) {
+        gps_eval->runtime.gps_orig = gps_orig;
+
+        /* Assign original point pointer. */
+        for (int i = 0; i < gps_orig->totpoints; i++) {
+          bGPDspoint *pt_eval = &gps_eval->points[i];
+          pt_eval->runtime.pt_orig = &gps_orig->points[i];
+          pt_eval->runtime.idx_orig = i;
+        }
+      }
+    }
+  }
+}
+
+void BKE_gpencil_update_orig_pointers(const Object *ob_orig, const Object *ob_eval)
+{
+  bGPdata *gpd_eval = (bGPdata *)ob_eval->data;
+  bGPdata *gpd_orig = (bGPdata *)ob_orig->data;
+
+  /* Assign pointers to the original stroke and points to the evaluated data. This must
+   * be done before apply any modifier because at this moment the structure is equals,
+   * so we can assume the layer index is the same in both datablocks.
+   * This data will be used by operators. */
+
+  int layer_idx = -1;
+  for (bGPDlayer *gpl = gpd_orig->layers.first; gpl; gpl = gpl->next) {
+    layer_idx++;
+    /* Retry evaluated layer. */
+    bGPDlayer *gpl_eval = BLI_findlink(&gpd_eval->layers, layer_idx);
+    if (gpl_eval == NULL) {
+      continue;
+    }
+    int frame_idx = -1;
+    for (bGPDframe *gpf_orig = gpl->frames.first; gpf_orig; gpf_orig = gpf_orig->next) {
+      frame_idx++;
+      /* Retry evaluated frame. */
+      bGPDframe *gpf_eval = BLI_findlink(&gpl_eval->frames, frame_idx);
+      if (gpf_eval == NULL) {
+        continue;
+      }
+      /* Update frame reference pointers. */
+      gpencil_update_frame_reference_pointers(gpf_orig, gpf_eval);
+    }
+  }
+}
 /** \} */
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index ab6f19e788d..27eafec7ec1 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -860,29 +860,6 @@ static void gpencil_assign_object_eval(Object *object)
   }
 }
 
-void BKE_gpencil_prepare_filling_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
-{
-  Object *ob_orig = (Object *)DEG_get_original_id(&ob->id);
-  bGPdata *gpd_orig = (bGPdata *)ob_orig->data;
-
-  /* Loop original strokes and generate triangulation for filling.
-   * The first time this is slow, but in next loops, the strokes has all data calculated and
-   * doesn't need calc again except if some modifier update the stroke geometry. */
-  for (bGPDlayer *gpl = gpd_orig->layers.first; gpl; gpl = gpl->next) {
-    int remap_cfra = gpencil_remap_time_get(depsgraph, scene, ob, gpl);
-    bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, remap_cfra, GP_GETFRAME_USE_PREV);
-    if (gpf == NULL) {
-      continue;
-    }
-    for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-      MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
-      if (gp_style) {
-        BKE_gpencil_recalc_geometry_caches(ob, gpl, gp_style, gps);
-      }
-    }
-  }
-}
-
 void BKE_gpencil_prepare_eval_data(Depsgraph *depsgraph, Scene *scene, Object *ob)
 {
   Object *ob_orig = (Object *)DEG_get_original_id(&ob->id);
@@ -996,73 +973,3 @@ void BKE_gpencil_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
     BKE_gpencil_lattice_clear(ob);
   }
 }
-
-static void gpencil_update_frame_reference_pointers(bGPDframe *gpf_orig, bGPDframe *gpf_eval)
-{
-  int stroke_idx = -1;
-  for (bGPDstroke *gps_orig = gpf_orig->strokes.first; gps_orig; gps_orig = gps_orig->next) {
-    stroke_idx++;
-
-    /* Assign original stroke pointer. */
-    if (gpf_eval != NULL) {
-      bGPDstroke *gps_eval = BLI_findlink(&gpf_eval->strokes, stroke_idx);
-      if (gps_eval != NULL) {
-        gps_eval->runtime.gps_orig = gps_orig;
-
-        /* Assign original point pointer. */
-        for (int i = 0; i < gps_orig->totpoints; i++) {
-          bGPDspoint *pt_eval = &gps_eval->points[i];
-          pt_eval->runtime.pt_orig = &gps_orig->points[i];
-          pt_eval->runtime.idx_orig = i;
-        }
-      }
-    }
-  }
-}
-
-void BKE_gpencil_update_refences(Depsgraph *depsgraph, Scene *scene, Object *ob)
-{
-  bGPdata *gpd_eval = (bGPdata *)ob->data;
-
-  /* use original data to get reference pointers to original data */
-  Object *ob_orig = DEG_get_original_object(ob);
-  bGPdata *gpd_orig = (bGPdata *)ob_orig->data;
-
-  const bool is_render = (bool)(DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
-  const bool time_remap = BKE_gpencil_has_time_modifiers(ob);
-  int cfra_eval = (int)DEG_get_ctime(depsgraph);
-
-  /* Assign pointers to the original stroke and points to the evaluated data. This must
-   * be done before apply any modifier because at this moment the structure is equals,
-   * so we can assume the layer index is the same in both datablocks.
-   * This data will be used by operators. */
-
-  int layer_idx = -1;
-  for (bGPDlayer *gpl = gpd_orig->layers.first; gpl; gpl = gpl->next) {
-    layer_idx++;
-
-    /* Remap frame (Time modifier) */
-    int remap_cfra = cfra_eval;
-    if (time_remap) {
-      remap_cfra = BKE_gpencil_time_modifier(depsgraph, scene, ob, gpl, cfra_eval, is_render);
-    }
-    bGPDframe *gpf_orig = BKE_gpencil_layer_frame_get(gpl, remap_cfra, GP_GETFRAME_USE_PREV);
-    if (gpf_orig == NULL) {
-      continue;
-    }
-
-    /* Retry evaluated layer. */
-    bGPDlayer *gpl_eval = BLI_findlink(&gpd_eval->layers, layer_idx);
-    if (gpl_eval == NULL) {
-      continue;
-    }
-
-    /* Retry evaluated frame. */
-    bGPDframe *gpf_eval = BKE_gpencil_layer_frame_get(gpl_eval, remap_cfra, GP_GETFRAME_USE_PREV);
-    if (gpf_eval == NULL) {
-      continue;
-    }
-    /* Update frame reference pointers. */
-    gpencil_update_frame_reference_pointers(gpf_orig, gpf_eval);
-  }
-}
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 0b3957f8428..65a095febda 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -215,9 +215,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
       BKE_lattice_modifiers_calc(depsgraph, scene, ob);
       break;
     case OB_GPENCIL: {
-      BKE_gpencil_prepare_filling_data(depsgraph, scene, ob);
       BKE_gpencil_prepare_eval_data(depsgraph, scene, ob);
-      BKE_gpencil_update_refences(depsgraph, scene, ob);
       BKE_gpencil_modifiers_calc(depsgraph, scene, ob);
       break;
     }
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
index 996d807480d..19956865520 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -43,6 +43,7 @@
 #include "BKE_curve.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
+#include "BKE_gpencil.h"
 #include "BKE_layer.h"
 #include "BKE_library.h

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list