Cleanup: Rename object materials "test" functions

"test" wasn't descriptive. Rename that part to "sync_length".
Also expose documentation from the function implementation
to describe what the functions do.

Pull Request: https://projects.blender.org/blender/blender/pulls/134058
This commit is contained in:
Hans Goudey
2025-02-04 17:46:08 +01:00
committed by Hans Goudey
parent b760c5d6ef
commit fc1fe4e78c
13 changed files with 27 additions and 25 deletions

View File

@@ -33,8 +33,12 @@ void BKE_materials_exit();
/** \name Materials
* \{ */
void BKE_object_materials_test(Main *bmain, Object *ob, ID *id);
void BKE_objects_materials_test_all(Main *bmain, ID *id);
/** Make the object's material array the same size as its data ID's material array. */
void BKE_object_materials_sync_length(Main *bmain, Object *ob, ID *id);
/** Ensure that every object using this data has a material array of the correct size. */
void BKE_objects_materials_sync_length_all(Main *bmain, ID *id);
void BKE_object_material_resize(Main *bmain, Object *ob, short totcol, bool do_id_user);
void BKE_object_material_remap(Object *ob, const unsigned int *remap);
/**

View File

@@ -808,7 +808,7 @@ static void loose_data_instantiate_obdata_process(LooseDataInstantiateContext *i
Object *ob = BKE_object_add_only_object(bmain, type, id->name + 2);
ob->data = id;
id_us_plus(id);
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
BKE_object_materials_sync_length(bmain, ob, static_cast<ID *>(ob->data));
loose_data_instantiate_object_base_instance_init(bmain,
active_collection,

View File

@@ -418,7 +418,7 @@ static void libblock_remap_data_postprocess_obdata_relink(Main *bmain, Object *o
break;
}
BKE_modifiers_test_object(ob);
BKE_object_materials_test(bmain, ob, new_id);
BKE_object_materials_sync_length(bmain, ob, new_id);
}
}

View File

@@ -605,7 +605,7 @@ void BKE_id_material_append(Main *bmain, ID *id, Material *ma)
(*matar)[(*totcol)++] = ma;
id_us_plus((ID *)ma);
BKE_objects_materials_test_all(bmain, id);
BKE_objects_materials_sync_length_all(bmain, id);
DEG_id_tag_update(id, ID_RECALC_SYNC_TO_EVAL);
DEG_relations_tag_update(bmain);
@@ -637,7 +637,7 @@ Material *BKE_id_material_pop(Main *bmain, ID *id, int index_i)
(*totcol)--;
*matar = static_cast<Material **>(MEM_reallocN(*matar, sizeof(void *) * (*totcol)));
BKE_objects_materials_test_all(bmain, id);
BKE_objects_materials_sync_length_all(bmain, id);
}
material_data_index_remove_id(id, index);
@@ -665,7 +665,7 @@ void BKE_id_material_clear(Main *bmain, ID *id)
*matar = nullptr;
}
BKE_objects_materials_test_all(bmain, id);
BKE_objects_materials_sync_length_all(bmain, id);
material_data_index_clear_id(id);
DEG_id_tag_update(id, ID_RECALC_SYNC_TO_EVAL);
@@ -977,9 +977,8 @@ void BKE_object_material_resize(Main *bmain, Object *ob, const short totcol, boo
DEG_relations_tag_update(bmain);
}
void BKE_object_materials_test(Main *bmain, Object *ob, ID *id)
void BKE_object_materials_sync_length(Main *bmain, Object *ob, ID *id)
{
/* make the ob mat-array same size as 'ob->data' mat-array */
const short *totcol;
if (id == nullptr || (totcol = BKE_id_material_len_p(id)) == nullptr) {
@@ -999,9 +998,8 @@ void BKE_object_materials_test(Main *bmain, Object *ob, ID *id)
}
}
void BKE_objects_materials_test_all(Main *bmain, ID *id)
void BKE_objects_materials_sync_length_all(Main *bmain, ID *id)
{
/* make the ob mat-array same size as 'ob->data' mat-array */
Object *ob;
const short *totcol;
@@ -1068,7 +1066,7 @@ void BKE_id_material_assign(Main *bmain, ID *id, Material *ma, short act)
id_us_plus(&ma->id);
}
BKE_objects_materials_test_all(bmain, id);
BKE_objects_materials_sync_length_all(bmain, id);
}
static void object_material_assign(
@@ -1147,7 +1145,7 @@ static void object_material_assign(
id_us_min(&mao->id);
}
ob->mat[act - 1] = ma;
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
BKE_object_materials_sync_length(bmain, ob, static_cast<ID *>(ob->data));
}
else { /* in data */
mao = (*matarar)[act - 1];
@@ -1157,7 +1155,7 @@ static void object_material_assign(
(*matarar)[act - 1] = ma;
/* Data may be used by several objects. */
if (do_test_all) {
BKE_objects_materials_test_all(bmain, static_cast<ID *>(ob->data));
BKE_objects_materials_sync_length_all(bmain, static_cast<ID *>(ob->data));
}
}
@@ -1286,7 +1284,7 @@ void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *
id_us_plus(&material_orig->id);
}
}
BKE_object_materials_test(bmain, ob_orig, data_orig);
BKE_object_materials_sync_length(bmain, ob_orig, data_orig);
}
void BKE_object_material_array_assign(

View File

@@ -1163,7 +1163,7 @@ void BKE_mesh_assign_object(Main *bmain, Object *ob, Mesh *mesh)
id_us_plus((ID *)mesh);
}
BKE_object_materials_test(bmain, ob, (ID *)mesh);
BKE_object_materials_sync_length(bmain, ob, (ID *)mesh);
BKE_modifiers_test_object(ob);
}

View File

@@ -943,7 +943,7 @@ static void object_blend_read_after_liblink(BlendLibReader *reader, ID *id)
/* When the object is local and the data is library its possible
* the material list size gets out of sync. #22663. */
if (ob->data && ob->id.lib != static_cast<ID *>(ob->data)->lib) {
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
BKE_object_materials_sync_length(bmain, ob, static_cast<ID *>(ob->data));
}
/* Performs quite extensive rebuilding & validation of object-level Pose data from the Armature

View File

@@ -2510,7 +2510,7 @@ static void placeholders_ensure_valid(Main *bmain)
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
ID *obdata = static_cast<ID *>(ob->data);
if (obdata != nullptr && obdata->tag & ID_TAG_MISSING) {
BKE_object_materials_test(bmain, ob, obdata);
BKE_object_materials_sync_length(bmain, ob, obdata);
}
}
}

View File

@@ -685,7 +685,7 @@ int ED_mesh_join_objects_exec(bContext *C, wmOperator *op)
ob->totcol = mesh->totcol = totcol;
/* other mesh users */
BKE_objects_materials_test_all(bmain, (ID *)mesh);
BKE_objects_materials_sync_length_all(bmain, (ID *)mesh);
/* Free temporary copy of destination shape-keys (if applicable). */
if (nkey) {

View File

@@ -633,7 +633,7 @@ Object *add_type_with_obdata(bContext *C,
ob = BKE_object_add_for_data(bmain, scene, view_layer, type, name, obdata, true);
const short *materials_len_p = BKE_id_material_len_p(obdata);
if (materials_len_p && *materials_len_p > 0) {
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
BKE_object_materials_sync_length(bmain, ob, static_cast<ID *>(ob->data));
}
}
else {
@@ -4041,7 +4041,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
/* Ensure new object has consistent material data with its new obdata. */
if (newob) {
BKE_object_materials_test(bmain, newob, static_cast<ID *>(newob->data));
BKE_object_materials_sync_length(bmain, newob, static_cast<ID *>(newob->data));
}
/* tag obdata if it was been changed */

View File

@@ -1497,7 +1497,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
ob_dst->data = obdata_id;
/* if amount of material indices changed: */
BKE_object_materials_test(bmain, ob_dst, static_cast<ID *>(ob_dst->data));
BKE_object_materials_sync_length(bmain, ob_dst, static_cast<ID *>(ob_dst->data));
if (ob_dst->type == OB_ARMATURE) {
BKE_pose_rebuild(bmain, ob_dst, static_cast<bArmature *>(ob_dst->data), true);

View File

@@ -807,7 +807,7 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
} // loop over strips
} // loop over strokes
BKE_object_materials_test(freestyle_bmain, object_mesh, (ID *)mesh);
BKE_object_materials_sync_length(freestyle_bmain, object_mesh, (ID *)mesh);
#if 0 // XXX
BLI_assert(mesh->verts_num == vertex_index);

View File

@@ -237,7 +237,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
ob = BKE_object_add_only_object(bmain, type, safe_name);
ob->data = data;
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
BKE_object_materials_sync_length(bmain, ob, static_cast<ID *>(ob->data));
WM_main_add_notifier(NC_ID | NA_ADDED, nullptr);

View File

@@ -564,7 +564,7 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value, ReportList *r
id_us_plus(id);
ob->data = id;
BKE_object_materials_test(G_MAIN, ob, id);
BKE_object_materials_sync_length(G_MAIN, ob, id);
if (GS(id->name) == ID_CU_LEGACY) {
BKE_curve_type_test(ob);