diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-04 13:12:49 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-09-04 13:26:52 +0300 |
commit | f79c748246b075fddf719d2a7a7cbd764f4c5a60 (patch) | |
tree | 29006a3d23db2961d55a43001f1e88e7afe91ef6 /source/blender | |
parent | 52fda9b0dbdc561f905cd691532e361a0254113a (diff) |
Armature: Cheap edit-to-object mode speedup.
`fix_bonelist_roll()` is already recursive, and was calling recursive `BKE_armature_where_is_bone()` twice!
Changed `BKE_armature_where_is_bone()` to controll whether we recurse over children or not.
With full Victor's rig, we gain 16% in `ED_armature_from_edit()` (from 31ms to 26ms).
With a dummy test-case 100 bones chain, we gain 80% in `ED_armature_from_edit()` (from 1.25ms to 0.25ms).
Not crucial, but still worth it. ;)
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_armature.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 15 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_utils.c | 7 |
3 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 2a674e5c2b9..e1885e46b24 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -91,7 +91,7 @@ bool BKE_armature_bone_flag_test_recursive(const struct Bone *bone, int float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float r1, float r2, float rdist); void BKE_armature_where_is(struct bArmature *arm); -void BKE_armature_where_is_bone(struct Bone *bone, struct Bone *prevbone); +void BKE_armature_where_is_bone(struct Bone *bone, struct Bone *prevbone, const bool use_recursion); void BKE_pose_rebuild(struct Object *ob, struct bArmature *arm); void BKE_pose_where_is(struct Scene *scene, struct Object *ob); void BKE_pose_where_is_bone(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra); diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 9bb8726cdb3..639249eab21 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1568,16 +1568,15 @@ void vec_roll_to_mat3(const float vec[3], const float roll, float mat[3][3]) /* recursive part, calculates restposition of entire tree of children */ /* used by exiting editmode too */ -void BKE_armature_where_is_bone(Bone *bone, Bone *prevbone) +void BKE_armature_where_is_bone(Bone *bone, Bone *prevbone, const bool use_recursion) { float vec[3]; /* Bone Space */ sub_v3_v3v3(vec, bone->tail, bone->head); + bone->length = len_v3(vec); vec_roll_to_mat3(vec, bone->roll, bone->bone_mat); - bone->length = len_v3v3(bone->head, bone->tail); - /* this is called on old file reading too... */ if (bone->xwidth == 0.0f) { bone->xwidth = 0.1f; @@ -1599,9 +1598,11 @@ void BKE_armature_where_is_bone(Bone *bone, Bone *prevbone) } /* and the kiddies */ - prevbone = bone; - for (bone = bone->childbase.first; bone; bone = bone->next) { - BKE_armature_where_is_bone(bone, prevbone); + if (use_recursion) { + prevbone = bone; + for (bone = bone->childbase.first; bone; bone = bone->next) { + BKE_armature_where_is_bone(bone, prevbone, use_recursion); + } } } @@ -1613,7 +1614,7 @@ void BKE_armature_where_is(bArmature *arm) /* hierarchical from root to children */ for (bone = arm->bonebase.first; bone; bone = bone->next) { - BKE_armature_where_is_bone(bone, NULL); + BKE_armature_where_is_bone(bone, NULL, true); } } diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index 09284860ec4..82517404334 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -489,8 +489,9 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist) float imat[3][3]; for (curBone = bonelist->first; curBone; curBone = curBone->next) { - /* sets local matrix and arm_mat (restpos) */ - BKE_armature_where_is_bone(curBone, curBone->parent); + /* sets local matrix and arm_mat (restpos). + * Do not recurse into children here, fix_bonelist_roll is already recursive. */ + BKE_armature_where_is_bone(curBone, curBone->parent, false); /* Find the associated editbone */ for (ebone = editbonelist->first; ebone; ebone = ebone->next) @@ -516,7 +517,7 @@ static void fix_bonelist_roll(ListBase *bonelist, ListBase *editbonelist) curBone->roll = -atan2f(difmat[2][0], difmat[2][2]); /* and set restposition again */ - BKE_armature_where_is_bone(curBone, curBone->parent); + BKE_armature_where_is_bone(curBone, curBone->parent, false); } fix_bonelist_roll(&curBone->childbase, editbonelist); } |