Commit: 5f49b21c5ee7ec42907f5fd1f51c839b88cda436
Author: Antonio Vazquez
Date:   Tue Apr 24 11:19:31 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5f49b21c5ee7ec42907f5fd1f51c839b88cda436

More work to prepare material conversion

Doing RNA stuff and preparing for convert Hero files

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

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

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

diff --git a/source/blender/blenkernel/intern/library_query.c 
b/source/blender/blenkernel/intern/library_query.c
index dde7a78fadc..d450e7a76aa 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -633,6 +633,10 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, 
LibraryIDLinkCallback call
                                if (material->texpaintslot != NULL) {
                                        
CALLBACK_INVOKE(material->texpaintslot->ima, IDWALK_CB_NOP);
                                }
+                               if (material->gpcolor != NULL) {
+                                       
CALLBACK_INVOKE(material->gpcolor->sima, IDWALK_CB_NOP);
+                                       CALLBACK_INVOKE(material->gpcolor->ima, 
IDWALK_CB_NOP);
+                               }
                                break;
                        }
 
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index 39ad95e9183..7b8e612b506 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -103,10 +103,30 @@ void BKE_material_free(Material *ma)
 
        MEM_SAFE_FREE(ma->texpaintslot);
 
+       MEM_SAFE_FREE(ma->gpcolor);
+
        BKE_icon_id_delete((ID *)ma);
        BKE_previewimg_free(&ma->preview);
 }
 
+static void grease_pencil_init(Material *ma)
+{
+       if ((ma) && (ma->gpcolor == NULL)) {
+               ma->gpcolor = MEM_callocN(sizeof(GpencilColorData), "Grease 
Pencil Material Settings");
+
+               GpencilColorData *gpcolor = ma->gpcolor;
+               /* set basic settings */
+               gpcolor->rgb[3] = 1.0f;
+               gpcolor->g_boxsize = 0.1f;
+               gpcolor->g_radius = 0.5f;
+               ARRAY_SET_ITEMS(gpcolor->scolor, 1.0f, 1.0f, 1.0f, 0.2f);
+               ARRAY_SET_ITEMS(gpcolor->g_scale, 1.0f, 1.0f);
+               ARRAY_SET_ITEMS(gpcolor->t_scale, 1.0f, 1.0f);
+               gpcolor->t_opacity = 1.0f;
+               gpcolor->t_pixsize = 100.0f;
+       }
+}
+
 void BKE_material_init(Material *ma)
 {
        BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ma, id));
@@ -124,6 +144,7 @@ void BKE_material_init(Material *ma)
        ma->preview = NULL;
 
        ma->alpha_threshold = 0.5f;
+
 }
 
 Material *BKE_material_add(Main *bmain, const char *name)
@@ -134,6 +155,9 @@ Material *BKE_material_add(Main *bmain, const char *name)
        
        BKE_material_init(ma);
        
+       /* grease pencil settings */
+       grease_pencil_init(ma);
+
        return ma;
 }
 
@@ -164,6 +188,10 @@ void BKE_material_copy_data(Main *bmain, Material *ma_dst, 
const Material *ma_sr
                ma_dst->texpaintslot = MEM_dupallocN(ma_src->texpaintslot);
        }
 
+       if (ma_src->gpcolor != NULL) {
+               ma_dst->gpcolor = MEM_dupallocN(ma_src->gpcolor);
+       }
+
        BLI_listbase_clear(&ma_dst->gpumaterial);
 
        /* TODO Duplicate Engine Settings and set runtime to NULL */
@@ -192,7 +220,8 @@ Material *BKE_material_localize(Material *ma)
 
        man->texpaintslot = NULL;
        man->preview = NULL;
-       
+       man->gpcolor = NULL;
+
        if (ma->nodetree)
                man->nodetree = ntreeLocalize(ma->nodetree);
        
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 6f3af94b434..0c1788e8e9b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4126,6 +4126,18 @@ static void lib_link_material(FileData *fd, Main *main)
                                ma->nodetree->id.lib = ma->id.lib;
                        }
                        
+                       /* relink grease pencil settings */
+                       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);
+                               }
+                               if (gpcolor->ima != NULL) {
+                                       gpcolor->ima = newlibadr(fd, 
ma->id.lib, gpcolor->ima);
+                               }
+                       }
+
                        ma->id.tag &= ~LIB_TAG_NEED_LINK;
                }
        }
@@ -4146,6 +4158,8 @@ static void direct_link_material(FileData *fd, Material 
*ma)
        
        ma->preview = direct_link_preview_image(fd, ma->preview);
        BLI_listbase_clear(&ma->gpumaterial);
+
+       ma->gpcolor = newdataadr(fd, ma->gpcolor);
 }
 
 /* ************ READ PARTICLE SETTINGS ***************** */
@@ -9428,6 +9442,10 @@ static void expand_material(FileData *fd, Main *mainvar, 
Material *ma)
        
        if (ma->nodetree)
                expand_nodetree(fd, mainvar, ma->nodetree);
+
+       if (ma->gpcolor)
+               expand_doit(fd, mainvar, ma->gpcolor);
+
 }
 
 static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la)
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index ccc028914b9..9706039a7e8 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2321,6 +2321,11 @@ static void write_material(WriteData *wd, Material *ma)
                }
 
                write_previews(wd, ma->preview);
+
+               /* grease pencil settings */
+               if (ma->gpcolor) {
+                       writestruct(wd, DATA, GpencilColorData, 1, ma->gpcolor);
+               }
        }
 }
 
diff --git a/source/blender/makesdna/DNA_gpencil_types.h 
b/source/blender/makesdna/DNA_gpencil_types.h
index d71d20c09d2..c57ae2ec7e7 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -201,7 +201,7 @@ typedef struct bGPDstroke {
        char tmp_layerinfo[128];
 
        float falloff;          /* runtime falloff factor (only for transform) 
*/
-       char pad1[4];
+       int matindex;           /* index of the current used material */
 } bGPDstroke;
 
 /* bGPDstroke->flag */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c 
b/source/blender/makesrna/intern/rna_gpencil.c
index 1705d4705bb..4d3ac516e37 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -957,6 +957,12 @@ static void rna_def_gpencil_stroke(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Palette", "Palette that stroke's color 
comes from");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+       /* Material Index */
+       prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "matindex");
+       RNA_def_property_ui_text(prop, "Material Index", "Number of material 
used in this stroke");
+       RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, 
"rna_GPencil_update");
+
        /* Settings */
        prop = RNA_def_property(srna, "draw_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
diff --git a/source/blender/makesrna/intern/rna_material.c 
b/source/blender/makesrna/intern/rna_material.c
index ed88fe0e619..3c5b63db228 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -421,7 +421,7 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
        RNA_def_property_range(prop, 0.0, 1.0);
        RNA_def_property_float_sdna(prop, NULL, "rgb");
        RNA_def_property_array(prop, 4);
-       RNA_def_property_ui_text(prop, "Color", "");
+       RNA_def_property_ui_text(prop, "Color Rgba", "");
        RNA_def_property_update(prop, NC_SCREEN | NC_SCENE | ND_TOOLSETTINGS | 
ND_DATA | NC_GPENCIL, "rna_Material_update");
 
        prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
@@ -442,7 +442,7 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
        RNA_def_property_float_sdna(prop, NULL, "fill");
        RNA_def_property_array(prop, 4);
        RNA_def_property_range(prop, 0.0f, 1.0f);
-       RNA_def_property_ui_text(prop, "Fill Color", "Color for filling region 
bounded by each stroke");
+       RNA_def_property_ui_text(prop, "Fill Color Rgba", "Color for filling 
region bounded by each stroke");
        RNA_def_property_update(prop, NC_SCREEN | NC_SCENE | ND_TOOLSETTINGS | 
ND_DATA | NC_GPENCIL, "rna_Material_update");
 
        /* Fill alpha */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to