Fix T60014: material link pref ignored

The PreferencesEdit.material_link only worked for adding slots,
adding an initial new material didn't respect the preference.
This commit is contained in:
Campbell Barton 2019-01-03 12:15:03 +11:00
parent f7e9642da9
commit 847b21ee08
Notes: blender-bot 2023-02-14 11:28:43 +01:00
Referenced by issue #60014, PreferencesEdit.material_link not respected
3 changed files with 27 additions and 8 deletions

View File

@ -78,7 +78,8 @@ enum {
BKE_MAT_ASSIGN_OBJECT
};
struct Material *give_current_material(struct Object *ob, short act);
struct Material **give_current_material_p(struct Object *ob, short act);
struct Material *give_current_material(struct Object *ob, short act);
void assign_material_id(struct Main *bmain, struct ID *id, struct Material *ma, short act);
void assign_material(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type);
void assign_matarar(struct Main *bmain, struct Object *ob, struct Material ***matar, short totcol);

View File

@ -543,9 +543,9 @@ void BKE_material_clear_id(Main *bmain, ID *id, bool update_data)
}
}
Material *give_current_material(Object *ob, short act)
Material **give_current_material_p(Object *ob, short act)
{
Material ***matarar, *ma;
Material ***matarar, **ma_p;
const short *totcolp;
if (ob == NULL) return NULL;
@ -565,7 +565,7 @@ Material *give_current_material(Object *ob, short act)
}
if (ob->matbits && ob->matbits[act - 1]) { /* in object */
ma = ob->mat[act - 1];
ma_p = &ob->mat[act - 1];
}
else { /* in data */
@ -576,12 +576,21 @@ Material *give_current_material(Object *ob, short act)
matarar = give_matarar(ob);
if (matarar && *matarar) ma = (*matarar)[act - 1];
else ma = NULL;
if (matarar && *matarar) {
ma_p = &(*matarar)[act - 1];
}
else {
ma_p = NULL;
}
}
return ma;
return ma_p;
}
Material *give_current_material(Object *ob, short act)
{
Material **ma_p = give_current_material_p(ob, act);
return ma_p ? *ma_p : NULL;
}
Material *give_node_material(Material *ma)

View File

@ -483,6 +483,15 @@ static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
if (prop) {
if (RNA_struct_is_a(ptr.type, &RNA_Object)) {
/* Add slot follows user-preferences for creating new slots,
* RNA pointer assignment doesn't, see: T60014. */
Object *ob = ptr.data;
if (give_current_material_p(ob, ob->actcol) == NULL) {
BKE_object_material_slot_add(bmain, ob);
}
}
/* when creating new ID blocks, use is already 1, but RNA
* pointer use also increases user, so this compensates it */
id_us_min(&ma->id);