From 6583fb67c6e1e5d714d723a09312e9dd25e02152 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Tue, 1 Jun 2021 15:24:29 +0200 Subject: Geometry Nodes: add empty material slot to new meshes This fixes T88455 by adding an empty material slot to newly generated meshes. This allows the object to overwrite the "default" material without any extra nodes. Technically, all polygons reference the material index 0 already, so it makes sense to add a material slot for this material index. Differential Revision: https://developer.blender.org/D11439 --- source/blender/blenkernel/intern/material.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (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 73b64e6efb3..557fe5f7e75 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -770,6 +770,7 @@ int BKE_object_material_count_eval(Object *ob) void BKE_id_material_eval_assign(ID *id, int slot, Material *material) { + BLI_assert(slot >= 1); Material ***materials_ptr = BKE_id_material_array_p(id); short *len_ptr = BKE_id_material_len_p(id); if (ELEM(NULL, materials_ptr, len_ptr)) { @@ -793,6 +794,21 @@ void BKE_id_material_eval_assign(ID *id, int slot, Material *material) (*materials_ptr)[slot_index] = material; } +/** + * Add an empty material slot if the id has no material slots. This material slot allows the + * material to be overwritten by object-linked materials. + */ +void BKE_id_material_eval_ensure_default_slot(ID *id) +{ + short *len_ptr = BKE_id_material_len_p(id); + if (len_ptr == NULL) { + return; + } + if (*len_ptr == 0) { + BKE_id_material_eval_assign(id, 1, NULL); + } +} + Material *BKE_gpencil_material(Object *ob, short act) { Material *ma = BKE_object_material_get(ob, act); -- cgit v1.2.3