Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_shading.c
| Show First 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | void OBJECT_OT_material_slot_remove(wmOperatorType *ot) | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | ||||
| } | } | ||||
| static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op)) | static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| bool changed_multi = false; | 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; | uint objects_len = 0; | ||||
| Object **objects = object_array_for_shading(C, &objects_len); | Object **objects = object_array_for_shading(C, &objects_len); | ||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *ob = objects[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; | continue; | ||||
| } | } | ||||
| } | |||||
| bool changed = false; | bool changed = false; | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| BMEditMesh *em = BKE_editmesh_from_object(ob); | BMEditMesh *em = BKE_editmesh_from_object(ob); | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMIter iter; | BMIter iter; | ||||
| if (em) { | if (em) { | ||||
| BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | ||||
| if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | ||||
| changed = true; | changed = true; | ||||
| efa->mat_nr = ob->actcol - 1; | efa->mat_nr = mat_nr_active; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | ||||
| Nurb *nu; | Nurb *nu; | ||||
| ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data); | ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data); | ||||
| if (nurbs) { | if (nurbs) { | ||||
| for (nu = nurbs->first; nu; nu = nu->next) { | for (nu = nurbs->first; nu; nu = nu->next) { | ||||
| if (ED_curve_nurb_select_check(v3d, nu)) { | if (ED_curve_nurb_select_check(v3d, nu)) { | ||||
| changed = true; | changed = true; | ||||
| nu->mat_nr = ob->actcol - 1; | nu->mat_nr = mat_nr_active; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (ob->type == OB_FONT) { | else if (ob->type == OB_FONT) { | ||||
| EditFont *ef = ((Curve *)ob->data)->editfont; | EditFont *ef = ((Curve *)ob->data)->editfont; | ||||
| int i, selstart, selend; | int i, selstart, selend; | ||||
| if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) { | if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) { | ||||
| for (i = selstart; i <= selend; i++) { | for (i = selstart; i <= selend; i++) { | ||||
| changed = true; | changed = true; | ||||
| ef->textbufinfo[i].mat_nr = ob->actcol; | ef->textbufinfo[i].mat_nr = mat_nr_active + 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (changed) { | if (changed) { | ||||
| changed_multi = true; | changed_multi = true; | ||||
| DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); | ||||
| WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); | ||||
| ▲ Show 20 Lines • Show All 1,855 Lines • Show Last 20 Lines | |||||