Fix #112372: Object materials ignored without geometry material slots #112408

Open
Iliya Katushenock wants to merge 1 commits from mod_moder/blender:tmp_fix_object_mat_count into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 11 additions and 6 deletions

View File

@ -39,6 +39,7 @@
#include "BLI_array_utils.h"
#include "BLI_listbase.h"
#include "BLI_math_base.hh"
#include "BLI_math_color.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
@ -735,13 +736,15 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
ID *data = get_evaluated_object_data_with_materials(ob);
const short *tot_slots_data_ptr = BKE_id_material_len_p(data);
const int tot_slots_data = tot_slots_data_ptr ? *tot_slots_data_ptr : 0;
const int tot_slot_object = ob->totcol;
const int tot_slot = blender::math::max<int>(tot_slots_data, tot_slot_object);
if (tot_slots_data == 0) {
if (tot_slot == 0) {
return nullptr;
}
/* Clamp to number of slots if index is out of range, same convention as used for rendering. */
const int slot_index = clamp_i(act - 1, 0, tot_slots_data - 1);
const int slot_index = clamp_i(act - 1, 0, tot_slot - 1);
const int tot_slots_object = ob->totcol;
Material ***materials_data_ptr = BKE_id_material_array_p(data);
@ -760,7 +763,7 @@ Material *BKE_object_material_get_eval(Object *ob, short act)
}
}
/* Otherwise use data from object-data. */
if (slot_index < tot_slots_data) {
if (slot_index < tot_slot) {
Material *material = materials_data[slot_index];
return material;
}
@ -776,7 +779,8 @@ int BKE_object_material_count_eval(const Object *ob)
BLI_assert(ob->data != nullptr);
const ID *id = get_evaluated_object_data_with_materials(const_cast<Object *>(ob));
const short *len_p = BKE_id_material_len_p(const_cast<ID *>(id));
return len_p ? *len_p : 0;
const int tot_slot_object = ob->totcol;
return blender::math::max<int>(len_p ? *len_p : 0, tot_slot_object);
}
void BKE_id_material_eval_assign(ID *id, int slot, Material *material)

View File

@ -75,13 +75,14 @@ ENUM_OPERATORS(eMRDataType, MR_DATA_POLYS_SORTED)
BLI_INLINE int mesh_render_mat_len_get(const Object *object, const Mesh *me)
{
const int tot_slot_object = std::max<int>(1, object->totcol);
if (me->edit_mesh != NULL) {
const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
if (editmesh_eval_final != NULL) {
return std::max<int>(1, editmesh_eval_final->totcol);
return std::max<int>(tot_slot_object, editmesh_eval_final->totcol);
}
}
return std::max<int>(1, me->totcol);
return std::max<int>(tot_slot_object, me->totcol);
}
struct MeshBufferList {