diff --git a/source/blender/blenkernel/BKE_deform.hh b/source/blender/blenkernel/BKE_deform.hh index 1f6e8ffe8fa..ef34228169f 100644 --- a/source/blender/blenkernel/BKE_deform.hh +++ b/source/blender/blenkernel/BKE_deform.hh @@ -44,6 +44,7 @@ void BKE_object_defgroup_active_index_set(Object *ob, int new_index); */ const ListBase *BKE_id_defgroup_list_get(const ID *id); ListBase *BKE_id_defgroup_list_get_mutable(ID *id); +int BKE_defgroup_name_index(const ListBase *defbase, const char *name); int BKE_id_defgroup_name_index(const ID *id, const char *name); bool BKE_defgroup_listbase_name_find(const ListBase *defbase, const char *name, diff --git a/source/blender/blenkernel/intern/armature_deform.cc b/source/blender/blenkernel/intern/armature_deform.cc index dab72be491f..d30c7705c6a 100644 --- a/source/blender/blenkernel/intern/armature_deform.cc +++ b/source/blender/blenkernel/intern/armature_deform.cc @@ -516,7 +516,7 @@ static void armature_deform_coords_impl(const Object *ob_arm, if (BKE_object_supports_vertex_groups(ob_target)) { /* Collect the vertex group names from the evaluated data. */ - armature_def_nr = BLI_findstringindex(defbase, defgrp_name, offsetof(bDeformGroup, name)); + armature_def_nr = BKE_defgroup_name_index(defbase, defgrp_name); defbase_len = BLI_listbase_count(defbase); /* get a vertex-deform-index to posechannel array */ diff --git a/source/blender/blenkernel/intern/deform.cc b/source/blender/blenkernel/intern/deform.cc index 5009844375a..edd5686176b 100644 --- a/source/blender/blenkernel/intern/deform.cc +++ b/source/blender/blenkernel/intern/deform.cc @@ -523,15 +523,20 @@ bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name) return static_cast(BLI_findstring(defbase, name, offsetof(bDeformGroup, name))); } -int BKE_id_defgroup_name_index(const ID *id, const char *name) +int BKE_defgroup_name_index(const ListBase *defbase, const char *name) { int index; - if (!BKE_id_defgroup_name_find(id, name, &index, nullptr)) { + if (!BKE_defgroup_listbase_name_find(defbase, name, &index, nullptr)) { return -1; } return index; } +int BKE_id_defgroup_name_index(const ID *id, const char *name) +{ + return BKE_defgroup_name_index(BKE_id_defgroup_list_get(id), name); +} + bool BKE_defgroup_listbase_name_find(const ListBase *defbase, const char *name, int *r_index, diff --git a/source/blender/blenkernel/intern/geometry_component_curves.cc b/source/blender/blenkernel/intern/geometry_component_curves.cc index 01d846fcf69..b17abb9231c 100644 --- a/source/blender/blenkernel/intern/geometry_component_curves.cc +++ b/source/blender/blenkernel/intern/geometry_component_curves.cc @@ -366,8 +366,8 @@ class CurvesVertexGroupsAttributeProvider final : public DynamicAttributesProvid return {}; } const std::string name = attribute_id; - const int vertex_group_index = BLI_findstringindex( - &curves->vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int vertex_group_index = BKE_defgroup_name_index(&curves->vertex_group_names, + name.c_str()); if (vertex_group_index < 0) { return {}; } @@ -396,8 +396,8 @@ class CurvesVertexGroupsAttributeProvider final : public DynamicAttributesProvid return {}; } const std::string name = attribute_id; - const int vertex_group_index = BLI_findstringindex( - &curves->vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int vertex_group_index = BKE_defgroup_name_index(&curves->vertex_group_names, + name.c_str()); if (vertex_group_index < 0) { return {}; } diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc index 82f4f2ec237..2c633e35c1a 100644 --- a/source/blender/blenkernel/intern/geometry_component_mesh.cc +++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc @@ -893,8 +893,8 @@ class MeshVertexGroupsAttributeProvider final : public DynamicAttributesProvider return {}; } const std::string name = attribute_id; - const int vertex_group_index = BLI_findstringindex( - &mesh->vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int vertex_group_index = BKE_defgroup_name_index(&mesh->vertex_group_names, + name.c_str()); if (vertex_group_index < 0) { return {}; } @@ -924,8 +924,8 @@ class MeshVertexGroupsAttributeProvider final : public DynamicAttributesProvider } const std::string name = attribute_id; - const int vertex_group_index = BLI_findstringindex( - &mesh->vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int vertex_group_index = BKE_defgroup_name_index(&mesh->vertex_group_names, + name.c_str()); if (vertex_group_index < 0) { return {}; } diff --git a/source/blender/blenkernel/intern/grease_pencil_vertex_groups.cc b/source/blender/blenkernel/intern/grease_pencil_vertex_groups.cc index 58f681ca4d8..7f7cbfa7dc8 100644 --- a/source/blender/blenkernel/intern/grease_pencil_vertex_groups.cc +++ b/source/blender/blenkernel/intern/grease_pencil_vertex_groups.cc @@ -54,7 +54,7 @@ void validate_drawing_vertex_groups(GreasePencil &grease_pencil) int ensure_vertex_group(const StringRef name, ListBase &vertex_group_names) { - int def_nr = BLI_findstringindex(&vertex_group_names, name.data(), offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.data()); if (def_nr < 0) { bDeformGroup *defgroup = MEM_cnew(__func__); STRNCPY(defgroup->name, name.data()); @@ -76,7 +76,7 @@ void assign_to_vertex_group_from_mask(bke::CurvesGeometry &curves, ListBase &vertex_group_names = curves.vertex_group_names; /* Look for existing group, otherwise lazy-initialize if any vertex is selected. */ - int def_nr = BLI_findstringindex(&vertex_group_names, name.data(), offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.data()); /* Lazily add the vertex group if any vertex is selected. */ if (def_nr < 0) { @@ -110,8 +110,7 @@ void assign_to_vertex_group(GreasePencil &grease_pencil, const StringRef name, c ".selection", bke::AttrDomain::Point, true); /* Look for existing group, otherwise lazy-initialize if any vertex is selected. */ - int def_nr = BLI_findstringindex( - &vertex_group_names, name.data(), offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.data()); const MutableSpan dverts = curves.deform_verts_for_write(); for (const int i : dverts.index_range()) { @@ -149,8 +148,7 @@ bool remove_from_vertex_group(GreasePencil &grease_pencil, bke::CurvesGeometry &curves = drawing.strokes_for_write(); ListBase &vertex_group_names = curves.vertex_group_names; - const int def_nr = BLI_findstringindex( - &vertex_group_names, name.data(), offsetof(bDeformGroup, name)); + const int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.data()); if (def_nr < 0) { /* No vertices assigned to the group in this drawing. */ continue; @@ -208,8 +206,7 @@ void select_from_group(GreasePencil &grease_pencil, bke::CurvesGeometry &curves = drawing.strokes_for_write(); ListBase &vertex_group_names = curves.vertex_group_names; - const int def_nr = BLI_findstringindex( - &vertex_group_names, name.data(), offsetof(bDeformGroup, name)); + const int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.data()); if (def_nr < 0) { /* No vertices assigned to the group in this drawing. */ continue; diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_weight_paint.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_weight_paint.cc index 623eb5b1213..311d652817a 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_weight_paint.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_weight_paint.cc @@ -295,8 +295,7 @@ static void get_root_and_tips_of_bones(Span bones, static int lookup_or_add_deform_group_index(CurvesGeometry &curves, const char *deform_group_name) { - int def_nr = BLI_findstringindex( - &curves.vertex_group_names, deform_group_name, offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&curves.vertex_group_names, deform_group_name); /* Lazily add the vertex group. */ if (def_nr == -1) { @@ -482,10 +481,8 @@ static int weight_sample_invoke(bContext *C, wmOperator * /*op*/, const wmEvent const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index); /* Skip drawing when it doesn't use the active vertex group. */ - const int drawing_defgroup_nr = BLI_findstringindex( - &info.drawing.strokes().vertex_group_names, - object_defgroup->name, - offsetof(bDeformGroup, name)); + const int drawing_defgroup_nr = BKE_defgroup_name_index( + &info.drawing.strokes().vertex_group_names, object_defgroup->name); if (drawing_defgroup_nr == -1) { continue; } @@ -633,8 +630,8 @@ static int grease_pencil_weight_invert_exec(bContext *C, wmOperator *op) threading::parallel_for_each(drawings, [&](MutableDrawingInfo info) { bke::CurvesGeometry &curves = info.drawing.strokes_for_write(); /* Active vgroup index of drawing. */ - const int drawing_vgroup_index = BLI_findstringindex( - &curves.vertex_group_names, active_defgroup->name, offsetof(bDeformGroup, name)); + const int drawing_vgroup_index = BKE_defgroup_name_index(&curves.vertex_group_names, + active_defgroup->name); if (drawing_vgroup_index == -1) { return; } @@ -904,8 +901,8 @@ static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op) /* Get the active vertex group in the drawing when it needs to be locked. */ int active_vertex_group = -1; if (object_defgroup && lock_active_group) { - active_vertex_group = BLI_findstringindex( - &curves.vertex_group_names, object_defgroup->name, offsetof(bDeformGroup, name)); + active_vertex_group = BKE_defgroup_name_index(&curves.vertex_group_names, + object_defgroup->name); } /* Put the lock state of every vertex group in a boolean array. */ diff --git a/source/blender/editors/mesh/editmesh_select_similar.cc b/source/blender/editors/mesh/editmesh_select_similar.cc index ab7b64a2755..ef4d42a83cc 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.cc +++ b/source/blender/editors/mesh/editmesh_select_similar.cc @@ -1130,7 +1130,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) GSetIterator gs_iter; GSET_ITER (gs_iter, gset) { const char *name = static_cast(BLI_gsetIterator_getKey(&gs_iter)); - int vgroup_id = BLI_findstringindex(defbase, name, offsetof(bDeformGroup, name)); + int vgroup_id = BKE_defgroup_name_index(defbase, name); if (vgroup_id != -1) { BLI_BITMAP_ENABLE(defbase_selected, vgroup_id); found_any = true; diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 7fb894d7a4a..e14ce85c20c 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -3607,7 +3607,7 @@ static int vgroup_do_remap(Object *ob, const char *name_array, wmOperator *op) name = name_array; for (def = static_cast(defbase->first), i = 0; def; def = def->next, i++) { - sort_map[i] = BLI_findstringindex(defbase, name, offsetof(bDeformGroup, name)); + sort_map[i] = BKE_defgroup_name_index(defbase, name); name += MAX_VGROUP_NAME; BLI_assert(sort_map[i] != -1); diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_weight_angle.cc b/source/blender/modifiers/intern/MOD_grease_pencil_weight_angle.cc index fc111083c55..618f6ba1c7f 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_weight_angle.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_weight_angle.cc @@ -21,6 +21,7 @@ #include "RNA_access.hh" #include "BKE_curves.hh" +#include "BKE_deform.hh" #include "BKE_geometry_set.hh" #include "BKE_grease_pencil.hh" #include "BKE_lib_query.hh" @@ -100,8 +101,7 @@ static void blend_read(BlendDataReader *reader, ModifierData *md) static int ensure_vertex_group(const StringRefNull name, ListBase &vertex_group_names) { - int def_nr = BLI_findstringindex( - &vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.c_str()); if (def_nr < 0) { bDeformGroup *defgroup = MEM_cnew(__func__); STRNCPY(defgroup->name, name.c_str()); @@ -115,8 +115,7 @@ static int ensure_vertex_group(const StringRefNull name, ListBase &vertex_group_ static bool target_vertex_group_available(const StringRefNull name, const ListBase &vertex_group_names) { - const int def_nr = BLI_findstringindex( - &vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.c_str()); if (def_nr < 0) { return false; } diff --git a/source/blender/modifiers/intern/MOD_grease_pencil_weight_proximity.cc b/source/blender/modifiers/intern/MOD_grease_pencil_weight_proximity.cc index 8f959d62225..aa838d6369b 100644 --- a/source/blender/modifiers/intern/MOD_grease_pencil_weight_proximity.cc +++ b/source/blender/modifiers/intern/MOD_grease_pencil_weight_proximity.cc @@ -21,6 +21,7 @@ #include "RNA_access.hh" #include "BKE_curves.hh" +#include "BKE_deform.hh" #include "BKE_geometry_set.hh" #include "BKE_grease_pencil.hh" #include "BKE_lib_query.hh" @@ -127,8 +128,7 @@ static float get_distance_factor(float3 target_pos, static int ensure_vertex_group(const StringRefNull name, ListBase &vertex_group_names) { - int def_nr = BLI_findstringindex( - &vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.c_str()); if (def_nr < 0) { bDeformGroup *defgroup = MEM_cnew(__func__); STRNCPY(defgroup->name, name.c_str()); @@ -142,8 +142,7 @@ static int ensure_vertex_group(const StringRefNull name, ListBase &vertex_group_ static bool target_vertex_group_available(const StringRefNull name, const ListBase &vertex_group_names) { - const int def_nr = BLI_findstringindex( - &vertex_group_names, name.c_str(), offsetof(bDeformGroup, name)); + const int def_nr = BKE_defgroup_name_index(&vertex_group_names, name.c_str()); if (def_nr < 0) { return false; }