Commit: 1746aaa86f9e4eb0ac2a272984041451f097dead
Author: Antonio Vazquez
Date:   Tue Apr 24 13:48:45 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB1746aaa86f9e4eb0ac2a272984041451f097dead

WIP:  More work converting to materials

There is a problem with the loading of converted files.

The conversion of Hero data is correct, but something is still missing.

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

M       source/blender/blenkernel/intern/library_query.c
M       source/blender/blenkernel/intern/material.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/makesdna/DNA_gpencil_types.h
M       source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/intern/library_query.c 
b/source/blender/blenkernel/intern/library_query.c
index d450e7a76aa..4a6e697a5cb 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -933,6 +933,10 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, 
LibraryIDLinkCallback call
                        case ID_GD:
                        {
                                bGPdata *gpencil = (bGPdata *) id;
+                               /* materials */
+                               for (i = 0; i < gpencil->totcol; i++) {
+                                       CALLBACK_INVOKE(gpencil->mat[i], 
IDWALK_CB_USER);
+                               }
 
                                /* relink palette for all strokes */
                                for (bGPDlayer *gp_layer = 
gpencil->layers.first; gp_layer; gp_layer = gp_layer->next) {
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 7b8e612b506..beb809ccd0a 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -43,6 +43,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_customdata_types.h"
+#include "DNA_gpencil_types.h"
 #include "DNA_ID.h"
 #include "DNA_meta_types.h"
 #include "DNA_node_types.h"
@@ -242,7 +243,8 @@ Material ***give_matarar(Object *ob)
        Mesh *me;
        Curve *cu;
        MetaBall *mb;
-       
+       bGPdata *gpd;
+
        if (ob->type == OB_MESH) {
                me = ob->data;
                return &(me->mat);
@@ -255,6 +257,10 @@ Material ***give_matarar(Object *ob)
                mb = ob->data;
                return &(mb->mat);
        }
+       else if (ob->type == OB_GPENCIL) {
+               gpd = ob->data;
+               return &(gpd->mat);
+       }
        return NULL;
 }
 
@@ -263,7 +269,8 @@ short *give_totcolp(Object *ob)
        Mesh *me;
        Curve *cu;
        MetaBall *mb;
-       
+       bGPdata *gpd;
+
        if (ob->type == OB_MESH) {
                me = ob->data;
                return &(me->totcol);
@@ -276,6 +283,10 @@ short *give_totcolp(Object *ob)
                mb = ob->data;
                return &(mb->totcol);
        }
+       else if (ob->type == OB_GPENCIL) {
+               gpd = ob->data;
+               return &(gpd->totcol);
+       }
        return NULL;
 }
 
@@ -310,6 +321,8 @@ short *give_totcolp_id(ID *id)
                        return &(((Curve *)id)->totcol);
                case ID_MB:
                        return &(((MetaBall *)id)->totcol);
+               case ID_GD:
+                       return &(((bGPdata *)id)->totcol);
                default:
                        break;
        }
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 0c1788e8e9b..d9736015f07 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4118,17 +4118,17 @@ static void lib_link_material(FileData *fd, Main *main)
                if (ma->id.tag & LIB_TAG_NEED_LINK) {
                        IDP_LibLinkProperty(ma->id.properties, fd);
                        lib_link_animdata(fd, &ma->id, ma->adt);
-                       
+
                        ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo);  // 
XXX deprecated - old animation system
-                       
+
                        if (ma->nodetree) {
                                lib_link_ntree(fd, &ma->id, ma->nodetree);
                                ma->nodetree->id.lib = ma->id.lib;
                        }
-                       
+
                        /* relink grease pencil settings */
+                       ma->gpcolor = newdataadr(fd, ma->gpcolor);
                        if (ma->gpcolor != NULL) {
-                               ma->gpcolor = newlibadr(fd, ma->id.lib, 
ma->gpcolor);
                                GpencilColorData *gpcolor = ma->gpcolor;
                                if (gpcolor->sima != NULL) {
                                        gpcolor->sima = newlibadr(fd, 
ma->id.lib, gpcolor->sima);
@@ -6396,6 +6396,10 @@ static void direct_link_gpencil(FileData *fd, bGPdata 
*gpd)
        /* clear drawing cache */
        gpd->batch_cache_data = NULL;
 
+       /* materials */
+       gpd->mat = newdataadr(fd, gpd->mat);
+       test_pointer_array(fd, (void **)&gpd->mat);
+
        /* relink palettes */
        link_list(fd, &gpd->palettes);
        for (palette = gpd->palettes.first; palette; palette = palette->next) {
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index f7f1b0f951f..a466e6e8380 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -65,6 +65,7 @@
 #include "BKE_idprop.h"
 #include "BKE_layer.h"
 #include "BKE_main.h"
+#include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_node.h"
 #include "BKE_report.h"
@@ -744,6 +745,64 @@ void do_versions_after_linking_280(Main *main)
                }
        }
 
+       /* Special Hero files conversion PaletteColors to Materials */
+       for (Object *ob = main->object.first; ob; ob = ob->id.next) {
+               if ((ob->type == OB_GPENCIL) && (ob->data)) {
+                       bGPdata *gpd = ob->data;
+                       /* do not convert already converted files */
+                       if (gpd->totcol > 0) {
+                               continue;
+                       }
+                       for (const bGPDpaletteref *palslot = 
gpd->palette_slots.first; palslot; palslot = palslot->next) {
+                               Palette *palette = palslot->palette;
+                               for (PaletteColor *palcolor = 
palette->colors.first; palcolor; palcolor = palcolor->next) {
+                                       
+                                       /* create material slot */
+                                       BKE_object_material_slot_add(ob);
+                                       Material *ma = BKE_material_add(main, 
palcolor->info);
+                                       assign_material(ob, ma, ob->totcol, 
BKE_MAT_ASSIGN_EXISTING);
+
+                                       /* copy color settings */
+                                       GpencilColorData *gpcolor = ma->gpcolor;
+                                       copy_v4_v4(gpcolor->rgb, palcolor->rgb);
+                                       copy_v4_v4(gpcolor->fill, 
palcolor->fill);
+                                       copy_v4_v4(gpcolor->scolor, 
palcolor->scolor);
+                                       gpcolor->flag = palcolor->flag;
+                                       gpcolor->stroke_style = 
palcolor->stroke_style;
+                                       gpcolor->fill_style = 
palcolor->fill_style;
+                                       gpcolor->index = palcolor->index;
+                                       gpcolor->mix_factor = 
palcolor->mix_factor;
+                                       gpcolor->g_angle = palcolor->g_angle;
+                                       gpcolor->g_radius = palcolor->g_radius;
+                                       gpcolor->g_boxsize = 
palcolor->g_boxsize;
+                                       copy_v2_v2(gpcolor->g_scale, 
palcolor->g_scale);
+                                       copy_v2_v2(gpcolor->g_shift, 
palcolor->g_shift);
+                                       gpcolor->t_angle = palcolor->t_angle;
+                                       copy_v2_v2(gpcolor->t_scale, 
palcolor->t_scale);
+                                       copy_v2_v2(gpcolor->t_offset, 
palcolor->t_offset);
+                                       gpcolor->t_opacity = 
palcolor->t_opacity;
+                                       gpcolor->t_pixsize = 
palcolor->t_pixsize;
+                                       gpcolor->sima = palcolor->sima;
+                                       gpcolor->ima = palcolor->ima;
+                                       gpcolor->mode = palcolor->mode;
+
+                                       /* fix strokes */
+                                       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) {
+                                                               if ((palette == 
gps->palette) && (STREQ(gps->colorname, palcolor->info))) {
+                                                                       
gps->matindex = ob->totcol;
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                       }
+               }
+       }
+
+
 }
 
 static void do_version_layer_collections_idproperties(ListBase *lb)
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index 9706039a7e8..838829f5209 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2670,6 +2670,8 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd)
                        write_animdata(wd, gpd->adt);
                }
 
+               writedata(wd, DATA, sizeof(void *) * gpd->totcol, gpd->mat);
+
                /* write grease-pencil layers to file */
                writelist(wd, DATA, bGPDlayer, &gpd->layers);
                for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
diff --git a/source/blender/makesdna/DNA_gpencil_types.h 
b/source/blender/makesdna/DNA_gpencil_types.h
index c57ae2ec7e7..ecc1791e3b5 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -389,6 +389,10 @@ typedef struct bGPdata {
        int active_palette_slot;    /* index of active palette slot */
 
        ListBase palette_slots;     /* list of bGPDpaletteref's - (2.8+) */
+
+       struct Material **mat;      /* materials array */
+       short totcol;               /* total materials */
+       char pad[6];
 } bGPdata;
 
 
diff --git a/source/blender/makesrna/intern/rna_gpencil.c 
b/source/blender/makesrna/intern/rna_gpencil.c
index 4d3ac516e37..f50786fa996 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1430,7 +1430,14 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
        /* Animation Data */
        rna_def_animdata_common(srna);
        
-       
+       /* materials */
+       prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
+       RNA_def_property_struct_type(prop, "Material");
+       RNA_def_property_ui_text(prop, "Materials", "");
+       RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
+       RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, 
NULL, NULL, "rna_IDMaterials_assign_int");
+
        /* Palette Slots */
        prop = RNA_def_property(srna, "palette_slots", PROP_COLLECTION, 
PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "palette_slots", NULL);

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

Reply via email to