[Bf-blender-cvs] [f79c748] master: Armature: Cheap edit-to-object mode speedup.

Bastien Montagne noreply at git.blender.org
Fri Sep 4 12:28:59 CEST 2015


Commit: f79c748246b075fddf719d2a7a7cbd764f4c5a60
Author: Bastien Montagne
Date:   Fri Sep 4 12:12:49 2015 +0200
Branches: master
https://developer.blender.org/rBf79c748246b075fddf719d2a7a7cbd764f4c5a60

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. ;)

===================================================================

M	source/blender/blenkernel/BKE_armature.h
M	source/blender/blenkernel/intern/armature.c
M	source/blender/editors/armature/armature_utils.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index 2a674e5..e1885e4 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 9bb8726..639249e 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 0928486..8251740 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);
 	}




More information about the Bf-blender-cvs mailing list