diff options
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index f888cf60a24..71e3feb9ced 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -774,11 +774,12 @@ void assign_material_id(ID *id, Material *ma, short act) test_object_materials(id); } -void assign_material(Object *ob, Material *ma, short act) +void assign_material(Object *ob, Material *ma, short act, int assign_type) { Material *mao, **matar, ***matarar; char *matbits; short *totcolp; + char bit=0; if (act > MAXMAT) return; if (act < 1) act = 1; @@ -805,8 +806,29 @@ void assign_material(Object *ob, Material *ma, short act) *matarar = matar; *totcolp = act; } - + + // Determine the object/mesh linking + if (assign_type == BKE_MAT_ASSIGN_USERPREF && ob->actcol) { + /* copy from previous material */ + bit = ob->matbits[ob->actcol - 1]; + } + else { + switch(assign_type) { + case BKE_MAT_ASSIGN_OBDATA: + bit = 0; + break; + case BKE_MAT_ASSIGN_OBJECT: + bit = 1; + break; + case BKE_MAT_ASSIGN_USERPREF: + default: + bit = (U.flag & USER_MAT_ON_OB) ? 1 : 0; + break; + } + } + if (act > ob->totcol) { + /* Need more space in the material arrays */ matar = MEM_callocN(sizeof(void *) * act, "matarray2"); matbits = MEM_callocN(sizeof(char) * act, "matbits1"); if (ob->totcol) { @@ -818,17 +840,12 @@ void assign_material(Object *ob, Material *ma, short act) ob->mat = matar; ob->matbits = matbits; ob->totcol = act; - - /* copy object/mesh linking, or assign based on userpref */ - if (ob->actcol) - ob->matbits[act - 1] = ob->matbits[ob->actcol - 1]; - else - ob->matbits[act - 1] = (U.flag & USER_MAT_ON_OB) ? 1 : 0; } /* do it */ - if (ob->matbits[act - 1]) { /* in object */ + ob->matbits[act - 1] = bit; + if (bit == 1) { /* in object */ mao = ob->mat[act - 1]; if (mao) mao->id.us--; ob->mat[act - 1] = ma; @@ -854,7 +871,7 @@ void assign_matarar(struct Object *ob, struct Material ***matar, short totcol) /* now we have the right number of slots */ for (i = 0; i < totcol; i++) - assign_material(ob, (*matar)[i], i + 1); + assign_material(ob, (*matar)[i], i + 1, BKE_MAT_ASSIGN_USERPREF); if (actcol_orig > ob->totcol) actcol_orig = ob->totcol; @@ -888,7 +905,7 @@ int object_add_material_slot(Object *ob) if (ob == NULL) return FALSE; if (ob->totcol >= MAXMAT) return FALSE; - assign_material(ob, NULL, ob->totcol + 1); + assign_material(ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF); ob->actcol = ob->totcol; return TRUE; } |