diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-04 18:44:07 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-12-06 12:21:32 +0300 |
commit | 284f106c91679a0c750f5c701e382f265412d58e (patch) | |
tree | 718174e43d52419112a398327f744501964907b2 /source/blender | |
parent | 0cd2303e676ec9f5f45be98083a734924e5f8c0f (diff) |
Depsgraph: begin use of RNAPathKey instead of re-implemented checks in driver variables
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_relations.cc | 31 | ||||
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_relations.h | 36 |
2 files changed, 43 insertions, 24 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 18298218e91..f2d1dd43438 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -962,8 +962,8 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) fcu->rna_path ? fcu->rna_path : "", fcu->array_index); bPoseChannel *pchan = NULL; - const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + const RNAPathKey self_key(id, rna_path); /* Create dependency between driver and data affected by it. */ /* - direct property relationship... */ @@ -1142,31 +1142,14 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) add_relation(target_key, driver_key, "Target -> Driver"); } else if (dtar->rna_path && strstr(dtar->rna_path, "pose.bones[")) { - /* Workaround for ensuring that local bone transforms don't end - * up having to wait for pose eval to finish (to prevent cycles). - */ - Object *object = (Object *)dtar->id; - char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, - "pose.bones["); - bPoseChannel *target_pchan = - BKE_pose_channel_find_name(object->pose, bone_name); - if (bone_name != NULL) { - MEM_freeN(bone_name); - bone_name = NULL; + RNAPathKey variable_key(dtar->id, dtar->rna_path); + if (RNA_pointer_is_null(&variable_key.ptr)) { + continue; } - if (target_pchan != NULL) { - if (dtar->id == id && - pchan != NULL && - STREQ(pchan->name, target_pchan->name)) - { - continue; - } - OperationKey bone_key(dtar->id, - DEG_NODE_TYPE_BONE, - target_pchan->name, - DEG_OPCODE_BONE_LOCAL); - add_relation(bone_key, driver_key, "RNA Bone -> Driver"); + if (is_same_bone_dependency(variable_key, self_key)) { + continue; } + add_relation(variable_key, driver_key, "RNA Bone -> Driver"); } else { if (dtar->id == id) { diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h index 68762043e5e..e61cd95cb96 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h @@ -31,6 +31,7 @@ #pragma once #include <cstdio> +#include <cstring> #include "intern/depsgraph_types.h" @@ -43,6 +44,7 @@ #include "BLI_string.h" #include "intern/nodes/deg_node.h" +#include "intern/nodes/deg_node_component.h" #include "intern/nodes/deg_node_operation.h" struct Base; @@ -266,6 +268,9 @@ protected: bool needs_animdata_node(ID *id); + template <typename KeyFrom, typename KeyTo> + bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to); + private: /* State which never changes, same for the whole builder time. */ Main *bmain_; @@ -378,4 +383,35 @@ DepsNodeHandle DepsgraphRelationBuilder::create_node_handle( return DepsNodeHandle(this, get_node(key), default_name); } +/* Rig compatibility: we check if bone is using local transform as a variable + * for driver on itself and ignore those relations to avoid "false-positive" + * dependency cycles. + */ +template <typename KeyFrom, typename KeyTo> +bool DepsgraphRelationBuilder::is_same_bone_dependency(const KeyFrom& key_from, + const KeyTo& key_to) +{ + /* Get operations for requested keys. */ + DepsNode *node_from = get_node(key_from); + DepsNode *node_to = get_node(key_to); + if (node_from == NULL || node_to == NULL) { + return false; + } + OperationDepsNode *op_from = node_from->get_exit_operation(); + OperationDepsNode *op_to = node_to->get_entry_operation(); + if (op_from == NULL || op_to == NULL) { + return false; + } + /* We are only interested in relations like BONE_DONE -> BONE_LOCAL... */ + if (!(op_from->opcode == DEG_OPCODE_BONE_DONE && + op_to->opcode == DEG_OPCODE_BONE_LOCAL)) { + return false; + } + /* ... BUT, we also need to check if it's same bone. */ + if (!STREQ(op_from->owner->name, op_to->owner->name)) { + return false; + } + return true; +} + } // namespace DEG |