From d1f250c0bc60f3ce7c81e799d345aecb417adbc3 Mon Sep 17 00:00:00 2001 From: Nate Rupsis Date: Fri, 29 Sep 2023 15:31:57 +0200 Subject: [PATCH] FIX #110946: vgroup normalize all check if armature is deforming before normalizing If an armature is present, but not active the group_select_mode defaults to WT_VGROUP_BONE_DEFORM, and throws an error because it can't find any active vertex groups. we're now checking to see if any bone is actively deforming before switching to WT_VGROUP_BONE_DEFORM (else defaulting to WT_VGROUP_ALL) Pull Request: https://projects.blender.org/blender/blender/pulls/112648 --- .../blender/editors/object/object_vgroup.cc | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 55c1675d7dc..a3d228c7eef 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -2888,14 +2888,40 @@ void OBJECT_OT_vertex_group_normalize(wmOperatorType *ot) /** \name Vertex Group Normalize All Operator * \{ */ +/* + * For a given object, determine which target vertex group to normalize. + */ +static eVGroupSelect normalize_vertex_group_target(Object *ob) +{ + /* Default to All Groups. */ + eVGroupSelect target_group = WT_VGROUP_ALL; + + /* If armature is present, and armature is actively deforming the object + (i.e armature modifier isn't disabled) use BONE DEFORM. */ + if (BKE_modifiers_is_deformed_by_armature(ob)) { + + int defgroup_tot = BKE_object_defgroup_count(ob); + bool *defgroup_validmap = BKE_object_defgroup_validmap_get(ob, defgroup_tot); + + for (int i = 0; i < defgroup_tot; i++) { + if (defgroup_validmap[i] == true) { + target_group = WT_VGROUP_BONE_DEFORM; + break; + } + } + MEM_freeN(defgroup_validmap); + } + + return target_group; +} + static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_context(C); - /* If armature is present, default to `Deform Bones` otherwise `All Groups`. */ - RNA_enum_set(op->ptr, - "group_select_mode", - BKE_modifiers_is_deformed_by_armature(ob) ? WT_VGROUP_BONE_DEFORM : WT_VGROUP_ALL); + eVGroupSelect target_group = normalize_vertex_group_target(ob); + + RNA_enum_set(op->ptr, "group_select_mode", target_group); bool lock_active = RNA_boolean_get(op->ptr, "lock_active"); eVGroupSelect subset_type = static_cast(