Commit: ad36cee68b5100f23285100c3aae05dbcee0043a
Author: Antonio Vazquez
Date:   Thu Apr 26 12:54:05 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBad36cee68b5100f23285100c3aae05dbcee0043a

Fix recalc of UV using materials instead of Palettes

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

M       source/blender/editors/gpencil/gpencil_paint.c
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_paint.c 
b/source/blender/editors/gpencil/gpencil_paint.c
index bb588853967..9c30489fbf3 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1147,7 +1147,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
        }
        
        /* Save material index */
-       gps->mat_nr = BKE_object_material_slot_find_index(p->ob, p->mat) - 1;
+       gps->mat_nr = BKE_object_material_slot_find_index(p->ob, p->material) - 
1;
 
        /* calculate UVs along the stroke */
        ED_gpencil_calc_stroke_uv(obact, gps);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 080a6e86584..39ddcaa95b8 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1673,36 +1673,38 @@ void ED_gpencil_calc_stroke_uv(Object *ob, bGPDstroke 
*gps)
        }
 }
 
-/* recalc uv for any stroke using the color */
-void ED_gpencil_update_color_uv(Main *bmain, Palette *palette, PaletteColor 
*palcolor)
+/* recalc uv for any stroke using the material */
+void ED_gpencil_update_color_uv(Main *bmain, Material *mat)
 {
-       
-#if 0 /* GPXX */
+       Material *gps_mat = NULL;
        /* read all strokes  */
-       for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
-               for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-                       /* only editable and visible layers are considered */
-                       if (gpencil_layer_is_editable(gpl)) {
-                               for (bGPDframe *gpf = gpl->frames.first; gpf; 
gpf = gpf->next) {
-                                       for (bGPDstroke *gps = 
gpf->strokes.first; gps; gps = gps->next) {
-                                               /* check if the color is 
editable */
-                                               if 
(ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
-                                                       continue;
-                                               }
-                                               if (gps->palette != palette) {
-                                                       continue;
-                                               }
+       for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
+               if (ob->type == OB_GPENCIL) {
+                       bGPdata *gpd = ob->data;
+                       if (gpd == NULL) {
+                               continue;
+                       }
 
-                                               /* update */
-                                               if (strcmp(palcolor->info, 
gps->colorname) == 0) {
-                                                       
ED_gpencil_calc_stroke_uv(ob, gps);
+                       for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = 
gpl->next) {
+                               /* only editable and visible layers are 
considered */
+                               if (gpencil_layer_is_editable(gpl)) {
+                                       for (bGPDframe *gpf = 
gpl->frames.first; gpf; gpf = gpf->next) {
+                                               for (bGPDstroke *gps = 
gpf->strokes.first; gps; gps = gps->next) {
+                                                       /* check if it is 
editable */
+                                                       if 
(ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
+                                                               continue;
+                                                       }
+                                                       gps_mat = 
give_current_material(ob, gps->mat_nr + 1);
+                                                       /* update */
+                                                       if ((gps_mat) && 
(gps_mat == mat)) {
+                                                               
ED_gpencil_calc_stroke_uv(ob, gps);
+                                                       }
                                                }
                                        }
                                }
                        }
                }
        }
-#endif
 }
 /* ******************************************************** */
 
diff --git a/source/blender/editors/include/ED_gpencil.h 
b/source/blender/editors/include/ED_gpencil.h
index ee6d91fa0e5..f47d61ce149 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -55,8 +55,7 @@ struct ViewLayer;
 struct View3D;
 
 struct Object;
-struct Palette;
-struct PaletteColor;
+struct Material;
 
 struct bAnimContext;
 struct KeyframeEditData;
@@ -219,6 +218,6 @@ int ED_gpencil_join_objects_exec(struct bContext *C, struct 
wmOperator *op);
 /* texture coordinate utilities */
 void ED_gpencil_tpoint_to_point(struct ARegion *ar, float origin[3], const 
struct tGPspoint *tpt, struct bGPDspoint *pt);
 void ED_gpencil_calc_stroke_uv(struct Object *ob, struct bGPDstroke *gps);
-void ED_gpencil_update_color_uv(struct Main *bmain, struct Palette *palette, 
struct PaletteColor *palcolor);
+void ED_gpencil_update_color_uv(struct Main *bmain, struct Material *mat);
 
 #endif /*  __ED_GPENCIL_H__ */
diff --git a/source/blender/makesrna/intern/rna_material.c 
b/source/blender/makesrna/intern/rna_material.c
index f445be02b34..7062403f8b4 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -86,6 +86,7 @@ const EnumPropertyItem rna_enum_ramp_blend_items[] = {
 #include "ED_node.h"
 #include "ED_image.h"
 #include "ED_screen.h"
+#include "ED_gpencil.h"
 
 static void rna_Material_update(Main *UNUSED(bmain), Scene *UNUSED(scene), 
PointerRNA *ptr)
 {
@@ -252,8 +253,8 @@ void rna_mtex_texture_slots_clear(ID *self_id, struct 
bContext *C, ReportList *r
 static void rna_gpcolordata_uv_update(Main *bmain, Scene *scene, PointerRNA 
*ptr)
 {
        /* update all uv strokes of this color */
-       GpencilColorData *gpcolor = (GpencilColorData *)ptr->data;
-       //ED_gpencil_update_color_uv(bmain, palette, gpcolor);
+       Material *ma = ptr->id.data;
+       ED_gpencil_update_color_uv(bmain, ma);
 
        rna_Material_update(bmain, scene, ptr);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to