From 9c1da81a4c173437c1e556afde7b32eef4b0a47d Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 28 Jul 2020 18:26:56 +0200 Subject: Fix T54544: "Copy Materials to Selected" only works when materials are defined on the mesh. Build a temp matarray storing materials from obdata and source object (depending on slots 'allocation' of source object), and assign those to targets. Also remove limitation of 'using same obdata is forbidden', just never edit obdata materials in that case... Certainly not perfect, but already much better than existing code. --- source/blender/blenkernel/intern/material.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 0e2d8fcf4c7..34835fd1e35 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -955,7 +955,8 @@ void BKE_object_material_remap_calc(Object *ob_dst, Object *ob_src, short *remap void BKE_object_material_array_assign(Main *bmain, struct Object *ob, struct Material ***matar, - short totcol) + int totcol, + const bool to_object_only) { int actcol_orig = ob->actcol; short i; @@ -966,7 +967,15 @@ void BKE_object_material_array_assign(Main *bmain, /* now we have the right number of slots */ for (i = 0; i < totcol; i++) { - BKE_object_material_assign(bmain, ob, (*matar)[i], i + 1, BKE_MAT_ASSIGN_USERPREF); + if (to_object_only && ob->matbits[i] == 0) { + /* If we only assign to object, and that slot uses obdata material, do nothing. */ + continue; + } + BKE_object_material_assign(bmain, + ob, + (*matar)[i], + i + 1, + to_object_only ? BKE_MAT_ASSIGN_OBJECT : BKE_MAT_ASSIGN_USERPREF); } if (actcol_orig > ob->totcol) { -- cgit v1.2.3