From 047081841113da73d7a13886218f5a56cfc62de6 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 24 Apr 2019 16:24:53 +0300 Subject: Fix T59848: precisely represent the dependencies of Armature modifier. When the modifier uses vertex groups, the set of the bones it actually needs is precisely defined by the set of the group names. If envelopes are enabled, this refinement is not available, because any bone can potentially be used. This can be used in the dependency graph construction to allow objects deformed by a part of the armature to be used in constraints on other bones, e.g. for placing cartoon-style face elements on top of the body mesh via Shrinkwrap constraints. Since the list of vertex group names is now used as an input by the dependency graph, adding/removing/renaming groups should now be triggering a graph rebuild. Differential Revision: https://developer.blender.org/D4715 --- source/blender/modifiers/intern/MOD_armature.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c index 6a01b01c0d9..31a1f5207c6 100644 --- a/source/blender/modifiers/intern/MOD_armature.c +++ b/source/blender/modifiers/intern/MOD_armature.c @@ -24,11 +24,13 @@ #include #include "BLI_utildefines.h" +#include "BLI_listbase.h" #include "DNA_armature_types.h" #include "DNA_object_types.h" #include "DNA_mesh_types.h" +#include "BKE_action.h" #include "BKE_editmesh.h" #include "BKE_lattice.h" #include "BKE_library.h" @@ -91,7 +93,26 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte { ArmatureModifierData *amd = (ArmatureModifierData *)md; if (amd->object != NULL) { - DEG_add_object_relation(ctx->node, amd->object, DEG_OB_COMP_EVAL_POSE, "Armature Modifier"); + /* If not using envelopes, create relations to individual bones for more rigging flexibility. */ + if ((amd->deformflag & ARM_DEF_ENVELOPE) == 0 && (amd->object->pose != NULL) && + ELEM(ctx->object->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) { + /* If neither vertex groups nor envelopes are used, the modifier has no bone dependencies. */ + if ((amd->deformflag & ARM_DEF_VGROUP) != 0) { + /* Enumerate groups that match existing bones. */ + LISTBASE_FOREACH (bDeformGroup *, dg, &ctx->object->defbase) { + if (BKE_pose_channel_find_name(amd->object->pose, dg->name) != NULL) { + /* Can't check BONE_NO_DEFORM because it can be animated. */ + DEG_add_bone_relation( + ctx->node, amd->object, dg->name, DEG_OB_COMP_BONE, "Armature Modifier"); + } + } + } + } + /* Otherwise require the whole pose to be complete. */ + else { + DEG_add_object_relation(ctx->node, amd->object, DEG_OB_COMP_EVAL_POSE, "Armature Modifier"); + } + DEG_add_object_relation(ctx->node, amd->object, DEG_OB_COMP_TRANSFORM, "Armature Modifier"); } DEG_add_modifier_to_transform_relation(ctx->node, "Armature Modifier"); -- cgit v1.2.3