Fix T73871: improve assignement of material to selection in multi object

editmode

This was already supported in "Select" & "Deselect" but not in "Assign".
So similar to rB6b39dc7672eb, we now check if the material corresponding
to the currently selected material slot is found in other objects
materials and assign this (instead of always assigning their 'own'
actcol).

Maniphest Tasks: T73871

Differential Revision: https://developer.blender.org/D6869
This commit is contained in:
Philipp Oeser 2020-02-17 10:29:08 +01:00
parent d95e9c7cf8
commit 282e8499b1
Notes: blender-bot 2023-02-14 00:29:15 +01:00
Referenced by issue #82049, Regression: material select button now only works for active object.
Referenced by issue #73871, Assign selection to material slot for multiple objects
1 changed files with 29 additions and 4 deletions

View File

@ -217,13 +217,38 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
View3D *v3d = CTX_wm_view3d(C);
bool changed_multi = false;
Object *obact = CTX_data_active_object(C);
const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : NULL;
uint objects_len = 0;
Object **objects = object_array_for_shading(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
if (ob->actcol <= 0) {
short mat_nr_active = -1;
if (ob->totcol == 0) {
continue;
}
if (obact && (mat_active == BKE_object_material_get(ob, obact->actcol))) {
/* Avoid searching since there may be multiple slots with the same material.
* For the active object or duplicates: match the material slot index first. */
mat_nr_active = obact->actcol - 1;
}
else {
/* Find the first matching material.
* Note: there may be multiple but that's not a common use case. */
for (short i = 0; i < ob->totcol; i++) {
const Material *mat = BKE_object_material_get(ob, i + 1);
if (mat_active == mat) {
mat_nr_active = i;
break;
}
}
if (mat_nr_active == -1) {
continue;
}
}
bool changed = false;
if (ob->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
@ -234,7 +259,7 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
changed = true;
efa->mat_nr = ob->actcol - 1;
efa->mat_nr = mat_nr_active;
}
}
}
@ -247,7 +272,7 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
for (nu = nurbs->first; nu; nu = nu->next) {
if (ED_curve_nurb_select_check(v3d, nu)) {
changed = true;
nu->mat_nr = ob->actcol - 1;
nu->mat_nr = mat_nr_active;
}
}
}
@ -259,7 +284,7 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) {
for (i = selstart; i <= selend; i++) {
changed = true;
ef->textbufinfo[i].mat_nr = ob->actcol;
ef->textbufinfo[i].mat_nr = mat_nr_active + 1;
}
}
}