[Bf-blender-cvs] [07c2a935cfb] temp-gpencil-eval: Tag any stroke using the material property

Antonio Vazquez noreply at git.blender.org
Thu Jan 16 22:56:53 CET 2020


Commit: 07c2a935cfb17c1d4b13d715d6ede26b632c7447
Author: Antonio Vazquez
Date:   Thu Jan 16 16:29:47 2020 +0100
Branches: temp-gpencil-eval
https://developer.blender.org/rB07c2a935cfb17c1d4b13d715d6ede26b632c7447

Tag any stroke using the material property

This is required to calculate triangulation if the material is changed from NO Fill to Fill

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

M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index eef36c3ab73..aca13d863b6 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2040,6 +2040,31 @@ void ED_gpencil_update_color_uv(Main *bmain, Material *mat)
   }
 }
 
+/* Tag any stroke using the material */
+void ED_gpencil_material_strokes_tag(Main *bmain, Material *mat)
+{
+  Material *gps_ma = NULL;
+  /* read all strokes  */
+  for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
+    if (ob->type == OB_GPENCIL) {
+      bGPdata *gpd = (bGPdata *)ob->data;
+      LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+        LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+          LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+            gps_ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1);
+            /* update */
+            if ((gps_ma) && (gps_ma == mat)) {
+              gps->tot_triangles = 0;
+              gps->flag |= GP_STROKE_RECALC_GEOMETRY;
+            }
+          }
+        }
+      }
+      DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+    }
+  }
+}
+
 static bool gpencil_check_collision(bGPDstroke *gps,
                                     bGPDstroke **gps_array,
                                     GHash *all_2d,
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index a458f1b3797..35e01df299c 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -242,10 +242,10 @@ void ED_gp_project_point_to_plane(const struct Scene *scene,
                                   const int axis,
                                   struct bGPDspoint *pt);
 void ED_gpencil_drawing_reference_get(const struct Scene *scene,
-                                 const struct Object *ob,
-                                 struct bGPDlayer *gpl,
-                                 char align_flag,
-                                 float vec[3]);
+                                      const struct Object *ob,
+                                      struct bGPDlayer *gpl,
+                                      char align_flag,
+                                      float vec[3]);
 void ED_gpencil_project_stroke_to_view(struct bContext *C,
                                        struct bGPDlayer *gpl,
                                        struct bGPDstroke *gps);
@@ -262,13 +262,15 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
 /* join objects */
 int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
 
-/* texture coordinate utilities */
+/* texture coordinate and tag utilities */
 void ED_gpencil_tpoint_to_point(struct ARegion *ar,
                                 float origin[3],
                                 const struct tGPspoint *tpt,
                                 struct bGPDspoint *pt);
 void ED_gpencil_update_color_uv(struct Main *bmain, struct Material *mat);
 
+void ED_gpencil_material_strokes_tag(struct Main *bmain, struct Material *mat);
+
 /* extend selection to stroke intersections
  * returns:
  * 0 - No hit
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index bc18af9e532..c0a004b93ce 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -112,6 +112,9 @@ static void rna_MaterialGpencil_update(Main *bmain, Scene *scene, PointerRNA *pt
 {
   Material *ma = (Material *)ptr->owner_id;
 
+  /* Tag any related stroke. */
+  ED_gpencil_material_strokes_tag(bmain, ma);
+
   rna_Material_update(bmain, scene, ptr);
   WM_main_add_notifier(NC_GPENCIL | ND_DATA, ma);
 }



More information about the Bf-blender-cvs mailing list