From d5d3dc418912863b172ef9f79f9991bb9d46bea8 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Fri, 30 Aug 2019 14:19:07 +0200 Subject: GPencil: Use default material when slot material is empty When a material slot is empty, the default material is used. The default color used is Gray to get a good contrast in dense scenes with dark and white background. Reviewers: brecht, dfelinto, mendio, pepeland Differential Revision: https://developer.blender.org/D5625 --- source/blender/blenkernel/intern/material.c | 35 ++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'source/blender/blenkernel/intern/material.c') diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 1545ae4f48f..cc9be2c5dda 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -71,6 +71,7 @@ /* used in UI and render */ Material defmaterial; +Material defgpencil_material; static CLG_LogRef LOG = {"bke.material"}; @@ -78,6 +79,13 @@ static CLG_LogRef LOG = {"bke.material"}; void init_def_material(void) { BKE_material_init(&defmaterial); + BKE_material_gpencil_init(&defgpencil_material); +} + +/* Free the GPencil data of the deafult material, creator.c */ +void BKE_material_gpencil_default_free(void) +{ + MEM_SAFE_FREE(defgpencil_material.gp_style); } /** Free (or release) any data used by this material (does not free the material itself). */ @@ -144,6 +152,16 @@ void BKE_material_init(Material *ma) ma->blend_shadow = MA_BS_SOLID; } +void BKE_material_gpencil_init(Material *ma) +{ + BKE_material_init(ma); + + /* grease pencil settings */ + strcpy(ma->id.name, "MADefault GPencil"); + BKE_material_init_gpencil_settings(ma); + add_v3_fl(&ma->gp_style->stroke_rgba[0], 0.6f); +} + Material *BKE_material_add(Main *bmain, const char *name) { Material *ma; @@ -580,6 +598,17 @@ Material *give_current_material(Object *ob, short act) return ma_p ? *ma_p : NULL; } +Material *BKE_material_gpencil_get(Object *ob, short act) +{ + Material *ma = give_current_material(ob, act); + if (ma != NULL) { + return ma; + } + else { + return &defgpencil_material; + } +} + MaterialGPencilStyle *BKE_material_gpencil_settings_get(Object *ob, short act) { Material *ma = give_current_material(ob, act); @@ -591,7 +620,7 @@ MaterialGPencilStyle *BKE_material_gpencil_settings_get(Object *ob, short act) return ma->gp_style; } else { - return NULL; + return defgpencil_material.gp_style; } } @@ -1070,10 +1099,6 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob) } /* check indices from gpencil */ else if (ob->type == OB_GPENCIL) { - /* need one color */ - if (ob->totcol == 0) { - BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); - } BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1); } -- cgit v1.2.3