Commit: 5c9312afeef9e9a1f4d6395ccb7b15f69b2446dc
Author: Antonio Vazquez
Date:   Thu Apr 26 17:42:07 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5c9312afeef9e9a1f4d6395ccb7b15f69b2446dc

Improve default Material use

If the default material has not the Grease pencil settings, add it instead to 
create a new material.

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

M       source/blender/blenkernel/BKE_material.h
M       source/blender/blenkernel/intern/gpencil.c
M       source/blender/blenkernel/intern/material.c
M       source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/blenkernel/BKE_material.h 
b/source/blender/blenkernel/BKE_material.h
index 81af482940f..7158428d647 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -60,6 +60,7 @@ struct Material *BKE_material_copy(struct Main *bmain, const 
struct Material *ma
 struct Material *BKE_material_localize(struct Material *ma);
 struct Material *give_node_material(struct Material *ma); /* returns node 
material or self */
 void BKE_material_make_local(struct Main *bmain, struct Material *ma, const 
bool lib_local);
+void BKE_material_init_gpencil_settings(struct Material *ma);
 
 /* UNUSED */
 // void automatname(struct Material *);
diff --git a/source/blender/blenkernel/intern/gpencil.c 
b/source/blender/blenkernel/intern/gpencil.c
index df83a6d108f..256428ba378 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1053,11 +1053,14 @@ Material *BKE_gpencil_color_ensure(Main *bmain, Object 
*ob)
                return NULL;
 
        mat = give_current_material(ob, ob->actcol);
-       if ((mat == NULL) || (mat->gpcolor == NULL) || (ob->totcol == 0)) {
+       if ((mat == NULL) || (mat->gpcolor == NULL)) {
                BKE_object_material_slot_add(ob);
                mat = BKE_material_add_gpencil(bmain, DATA_("Material"));
                assign_material(ob, mat, ob->totcol, BKE_MAT_ASSIGN_EXISTING);
        }
+       else if ((mat != NULL) && (mat->gpcolor == NULL)) {
+                       BKE_material_init_gpencil_settings(mat);
+       }
 
        return mat;
 }
diff --git a/source/blender/blenkernel/intern/material.c 
b/source/blender/blenkernel/intern/material.c
index c582667e8ec..a5be1f3b602 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -111,7 +111,7 @@ void BKE_material_free(Material *ma)
        BKE_previewimg_free(&ma->preview);
 }
 
-static void grease_pencil_init(Material *ma)
+void BKE_material_init_gpencil_settings(Material *ma)
 {
        if ((ma) && (ma->gpcolor == NULL)) {
                ma->gpcolor = MEM_callocN(sizeof(GpencilColorData), "Grease 
Pencil Material Settings");
@@ -167,11 +167,12 @@ Material *BKE_material_add_gpencil(Main *bmain, const 
char *name)
        ma = BKE_material_add(bmain, name);
 
        /* grease pencil settings */
-       grease_pencil_init(ma);
+       BKE_material_init_gpencil_settings(ma);
 
        return ma;
 }
 
+
 /**
  * Only copy internal data of Material ID from source to already 
allocated/initialized destination.
  * You probably nerver want to use that directly, use id_copy or 
BKE_id_copy_ex for typical needs.
diff --git a/source/blender/editors/gpencil/gpencil_utils.c 
b/source/blender/editors/gpencil/gpencil_utils.c
index 39ddcaa95b8..bf05e876f25 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1130,9 +1130,17 @@ void ED_gpencil_add_defaults(bContext *C)
        Object *ob = CTX_data_active_object(C);
        ToolSettings *ts = CTX_data_tool_settings(C);
        bGPdata *gpd = CTX_data_gpencil_data(C);
-       
+
+       /* first try to reuse default material */
+       if (ob->actcol > 0) {
+               Material *mat = give_current_material(ob, ob->actcol);
+               if ((mat) && (mat->gpcolor == NULL)) {
+                       BKE_material_init_gpencil_settings(mat);
+               }
+       }
+
        /* ensure color exist */
-       //BKE_gpencil_color_ensure(bmain, ob);
+       BKE_gpencil_color_ensure(bmain, ob);
 
        Paint *paint = BKE_brush_get_gpencil_paint(ts);
        /* if not exist, create a new one */

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

Reply via email to