From 17d8650d2d5ecd034a2409bf32c5c559a897ae8b Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Wed, 30 Apr 2025 09:18:34 +0200 Subject: [PATCH] Fix #137398: Transforming editbones can propagate wrong envelope radii When tweaking envelope radii of (connected) envelope bones, we dont always make sure that corresponding head and tail radii are in sync. Using the `Bone Size` tool should take care of this (and it works to some extend) but tweaking the radii through the sidepanel UI or the Properties Editor (through RNA), then corresponding heads and tails radii get out of sync. Once we are in such unfortunate situation, then code in the transform system's `recalcData_edit_armature` fails with wrong assumptions, it propagates radii from children to parents which are unexpected / not in use. So one thing to do would be to add this syncing of radii to `rna_Armature_editbone_transform_update`. This alone would solve the "problem" in new files. For existing files that are already out of sync we add versioning that corrects this on file load Pull Request: https://projects.blender.org/blender/blender/pulls/137599 --- .../blender/blenkernel/BKE_blender_version.h | 2 +- .../blenloader/intern/versioning_400.cc | 18 ++++++++++++++++++ source/blender/makesrna/intern/rna_armature.cc | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 1b6fdb86da6..bcbe3edf693 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -27,7 +27,7 @@ /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 56 +#define BLENDER_FILE_SUBVERSION 57 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index 3ba3f0043b0..05e46b93911 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -9953,6 +9953,24 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain) version_convert_sculpt_planar_brushes(bmain); } + /* Enforce that bone envelope radii match for parent and connected children. */ + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 57)) { + LISTBASE_FOREACH (bArmature *, arm, &bmain->armatures) { + blender::animrig::ANIM_armature_foreach_bone(&arm->bonebase, [](Bone *bone) { + if (bone->parent && (bone->flag & BONE_CONNECTED)) { + bone->rad_head = bone->parent->rad_tail; + } + }); + if (arm->edbo) { + LISTBASE_FOREACH (EditBone *, ebone, arm->edbo) { + if (ebone->parent && (ebone->flag & BONE_CONNECTED)) { + ebone->rad_head = ebone->parent->rad_tail; + } + } + } + } + } + /* Always run this versioning (keep at the bottom of the function). Meshes are written with the * legacy format which always needs to be converted to the new format on file load. To be moved * to a subversion check in 5.0. */ diff --git a/source/blender/makesrna/intern/rna_armature.cc b/source/blender/makesrna/intern/rna_armature.cc index 2a0d939fa22..bdd28e41b74 100644 --- a/source/blender/makesrna/intern/rna_armature.cc +++ b/source/blender/makesrna/intern/rna_armature.cc @@ -1035,12 +1035,14 @@ static void rna_Armature_editbone_transform_update(Main *bmain, Scene *scene, Po /* update our parent */ if (ebone->parent && ebone->flag & BONE_CONNECTED) { copy_v3_v3(ebone->parent->tail, ebone->head); + ebone->parent->rad_tail = ebone->rad_head; } /* update our children if necessary */ for (child = static_cast(arm->edbo->first); child; child = child->next) { if (child->parent == ebone && (child->flag & BONE_CONNECTED)) { copy_v3_v3(child->head, ebone->tail); + child->rad_head = ebone->rad_tail; } }