diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-11-20 17:42:37 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-11-20 17:53:59 +0300 |
commit | 4dc639ac9965f3d0e8b2304363c62d888cdd1dc9 (patch) | |
tree | f0272c9c70e5095dbabf5bce59d07cd8492f1b74 /source/blender/blenkernel/intern/armature_update.c | |
parent | 163be42a9661741757325039909ba81f0701b248 (diff) |
Speedup rigs with multiple objects deformed by bbones
Previously each of the objects which has armature modifier will
request deformation matricies from bbones. Thing is, all those
deformations are the same and do not depend on object which is
being modified. What's even worse is that this calculation is
not cheap.
This change makes it so bbones deformation is calculated once
and stored in the armature object. After this armature modifiers
simply use it.
With a rigs we've got here dependency graph evaluation time
goes down from 0.02 sec to 0.012 sec.
Possible further optimization is to make bbone deformation
calculated at the time when bone is calculated. This will avoid
an extra threaded loop over all bones.
Diffstat (limited to 'source/blender/blenkernel/intern/armature_update.c')
-rw-r--r-- | source/blender/blenkernel/intern/armature_update.c | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index c9e072caa6e..e882b64e8cc 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -585,21 +585,21 @@ BLI_INLINE bPoseChannel *pose_pchan_get_indexed(Object *ob, int pchan_index) void BKE_pose_eval_init(struct Depsgraph *depsgraph, Scene *UNUSED(scene), - Object *ob) + Object *object) { - bPose *pose = ob->pose; + bPose *pose = object->pose; BLI_assert(pose != NULL); - DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob); + DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); - BLI_assert(ob->type == OB_ARMATURE); + BLI_assert(object->type == OB_ARMATURE); /* We demand having proper pose. */ - BLI_assert(ob->pose != NULL); - BLI_assert((ob->pose->flag & POSE_RECALC) == 0); + BLI_assert(object->pose != NULL); + BLI_assert((object->pose->flag & POSE_RECALC) == 0); /* imat is needed for solvers. */ - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(object->imat, object->obmat); /* clear flags */ for (bPoseChannel *pchan = pose->chanbase.first; pchan != NULL; pchan = pchan->next) { @@ -607,6 +607,7 @@ void BKE_pose_eval_init(struct Depsgraph *depsgraph, } pose_pchan_index_create(pose); + armature_cached_bbone_deformation_free_data(object); } void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph, @@ -746,41 +747,68 @@ void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph, BKE_splineik_execute_tree(depsgraph, scene, ob, rootchan, ctime); } -void BKE_pose_eval_cleanup(struct Depsgraph *depsgraph, - Scene *scene, - Object *ob) +/* Common part for both original and proxy armatrues. */ +static void pose_eval_done_common(Object *object) { - bPose *pose = ob->pose; + bPose *pose = object->pose; + UNUSED_VARS_NDEBUG(pose); + BLI_assert(pose != NULL); + armature_cached_bbone_deformation_update(object); +} +static void pose_eval_cleanup_common(Object *object) +{ + bPose *pose = object->pose; BLI_assert(pose != NULL); - - float ctime = BKE_scene_frame_get(scene); /* not accurate... */ - DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob); - BLI_assert(ob->type == OB_ARMATURE); - - /* release the IK tree */ - BIK_release_tree(scene, ob, ctime); - BLI_assert(pose->chan_array != NULL || BLI_listbase_is_empty(&pose->chanbase)); MEM_SAFE_FREE(pose->chan_array); } +void BKE_pose_eval_done(struct Depsgraph *depsgraph, Object *object) +{ + bPose *pose = object->pose; + BLI_assert(pose != NULL); + UNUSED_VARS_NDEBUG(pose); + DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); + BLI_assert(object->type == OB_ARMATURE); + pose_eval_done_common(object); +} + +void BKE_pose_eval_cleanup(struct Depsgraph *depsgraph, + Scene *scene, + Object *object) +{ + bPose *pose = object->pose; + BLI_assert(pose != NULL); + UNUSED_VARS_NDEBUG(pose); + const float ctime = BKE_scene_frame_get(scene); /* not accurate... */ + DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); + BLI_assert(object->type == OB_ARMATURE); + /* Release the IK tree. */ + BIK_release_tree(scene, object, ctime); + pose_eval_cleanup_common(object); +} + void BKE_pose_eval_proxy_init(struct Depsgraph *depsgraph, Object *object) { BLI_assert(ID_IS_LINKED(object) && object->proxy_from != NULL); DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); pose_pchan_index_create(object->pose); + armature_cached_bbone_deformation_free_data(object); } -void BKE_pose_eval_proxy_cleanup(struct Depsgraph *depsgraph, Object *object) +void BKE_pose_eval_proxy_done(struct Depsgraph *depsgraph, Object *object) { BLI_assert(ID_IS_LINKED(object) && object->proxy_from != NULL); DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); + pose_eval_done_common(object); +} - bPose *pose = object->pose; - BLI_assert(pose->chan_array != NULL); - MEM_freeN(pose->chan_array); - pose->chan_array = NULL; +void BKE_pose_eval_proxy_cleanup(struct Depsgraph *depsgraph, Object *object) +{ + BLI_assert(ID_IS_LINKED(object) && object->proxy_from != NULL); + DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); + pose_eval_cleanup_common(object); } void BKE_pose_eval_proxy_copy_bone( |