[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39506] branches/soc-2011-pepper/source/ blender/collada: Animation export id bone animation + armature importer cleanup.

Sukhitha Jayathilake pr.jayathilake at gmail.com
Wed Aug 17 22:15:41 CEST 2011


Revision: 39506
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39506
Author:   phabtar
Date:     2011-08-17 20:15:40 +0000 (Wed, 17 Aug 2011)
Log Message:
-----------
Animation export id bone animation + armature importer cleanup.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
    branches/soc-2011-pepper/source/blender/collada/ArmatureImporter.cpp

Modified: branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp	2011-08-17 19:00:07 UTC (rev 39505)
+++ branches/soc-2011-pepper/source/blender/collada/AnimationExporter.cpp	2011-08-17 20:15:40 UTC (rev 39506)
@@ -66,6 +66,7 @@
 			//transform matrix export for bones are temporarily disabled here.
 			if ( ob->type == OB_ARMATURE )
 			{
+				if (!ob->data) return;
 				bArmature *arm = (bArmature*)ob->data;
 				for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
 					write_bone_animation_matrix(ob, bone);
@@ -363,10 +364,18 @@
 		bArmature *arm = (bArmature*)ob_arm->data;
 		int flag = arm->flag;
 		std::vector<float> fra;
-		char prefix[256];
+		//char prefix[256];
 
-		BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name);
+		FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
+		while(fcu)
+		{
+			std::string bone_name = getObjectBoneName(ob_arm,fcu);
+			int val = BLI_strcasecmp((char*)bone_name.c_str(),bone->name);
+			if(val==0) break;
+			fcu = fcu->next;
+		}
 
+		if(!(fcu)) return; 
 		bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
 		if (!pchan)
 			return;

Modified: branches/soc-2011-pepper/source/blender/collada/ArmatureImporter.cpp
===================================================================
--- branches/soc-2011-pepper/source/blender/collada/ArmatureImporter.cpp	2011-08-17 19:00:07 UTC (rev 39505)
+++ branches/soc-2011-pepper/source/blender/collada/ArmatureImporter.cpp	2011-08-17 20:15:40 UTC (rev 39506)
@@ -93,16 +93,16 @@
 
 	EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node));
 	totbone++;
-    
+	
 	bPoseChannel *pchan  =  get_pose_channel(ob_arm->pose, (char*)bc_get_joint_name(node));
 
 	if (parent) bone->parent = parent;
-    float ax[3];
+
 	float angle = 0;
 
 	// get world-space
 	if (parent){
-       	mul_m4_m4m4(mat, obmat, parent_mat);
+		mul_m4_m4m4(mat, obmat, parent_mat);
 
 	}
 	else {
@@ -116,7 +116,7 @@
 	// set head
 	copy_v3_v3(bone->head, mat[3]);
    
-    
+	
 	// set tail, don't set it to head because 0-length bones are not allowed
 	float vec[3] = {0.0f, 0.5f, 0.0f};
 	add_v3_v3v3(bone->tail, bone->head, vec);
@@ -127,7 +127,7 @@
 		
 		// not setting BONE_CONNECTED because this would lock child bone location with respect to parent
 		// bone->flag |= BONE_CONNECTED;
-    
+	
 		// XXX increase this to prevent "very" small bones?
 		const float epsilon = 0.000001f;
 
@@ -166,6 +166,10 @@
 
 	float mat[4][4];
 
+	// TODO rename from Node "name" attrs later
+	EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
+	totbone++;
+
 	if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) {
 		// get original world-space matrix
 		invert_m4_m4(mat, joint_inv_bind_mat);
@@ -182,12 +186,14 @@
 			mul_m4_m4m4(mat, obmat, parent_mat);
 		else
 			copy_m4_m4(mat, obmat);
+
+		float loc[3], size[3], rot[3][3] , angle;
+		mat4_to_loc_rot_size( loc, rot, size, obmat);
+		mat3_to_vec_roll(rot, NULL, &angle );
+		bone->roll=angle;
 	}
 
-	// TODO rename from Node "name" attrs later
-	EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
-	totbone++;
-
+	
 	if (parent) bone->parent = parent;
 
 	// set head
@@ -264,8 +270,8 @@
 	leaf.bone = bone;
 	copy_m4_m4(leaf.mat, mat);
 	BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name));
-    
- 	TagsMap::iterator etit;
+	
+	TagsMap::iterator etit;
 	ExtraTags *et = 0;
 	etit = uid_tags_map.find(node->getUniqueId().toAscii());
 	if(etit !=  uid_tags_map.end())
@@ -277,7 +283,7 @@
 	et->setData("tip_y",&y);
 	et->setData("tip_z",&z);
 	float vec[3] = {x,y,z};
-    copy_v3_v3(leaf.bone->tail, leaf.bone->head);
+	copy_v3_v3(leaf.bone->tail, leaf.bone->head);
 	add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec);
 	leaf_bones.push_back(leaf);
 }
@@ -292,7 +298,7 @@
 
 		// pointing up
 		float vec[3] = {0.0f, 0.0f, 1.0f};
-        
+		
 		mul_v3_fl(vec, leaf_bone_length);
 
 		copy_v3_v3(leaf.bone->tail, leaf.bone->head);
@@ -396,10 +402,10 @@
 {
 	std::vector<COLLADAFW::Node*>::iterator ri;
 	//if there is an armature created for root_joint next root_joint
-  	for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
+	for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
 			if ( get_armature_for_joint(*ri) != NULL ) continue;
-	    
-        //add armature object for current joint
+		
+		//add armature object for current joint
 		//Object *ob_arm = add_object(scene, OB_ARMATURE);
 
 		Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()];
@@ -413,7 +419,7 @@
 		   TODO:
 		   check if bones have already been created for a given joint
 		*/
-     leaf_bone_length = FLT_MAX;
+	 leaf_bone_length = FLT_MAX;
 		create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm);
 
 		//fix_leaf_bones();
@@ -545,7 +551,7 @@
 	DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB|OB_RECALC_DATA);
 
 	// set_leaf_bone_shapes(ob_arm);
-    // set_euler_rotmode();
+	// set_euler_rotmode();
 }
 
 
@@ -572,7 +578,7 @@
 
 	// get world-space
 	if (parentname){
-       	mul_m4_m4m4(mat, obmat, parent_mat);
+		mul_m4_m4m4(mat, obmat, parent_mat);
 		bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parentname);
 
 		mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
@@ -581,12 +587,12 @@
 	else {
 		copy_m4_m4(mat, obmat);
 		 float invObmat[4][4];
-       invert_m4_m4(invObmat, ob_arm->obmat);
-       mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
+	   invert_m4_m4(invObmat, ob_arm->obmat);
+	   mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
 	  
 	}
 		
-     mat4_to_axis_angle(ax,&angle,mat);
+	 mat4_to_axis_angle(ax,&angle,mat);
 	   pchan->bone->roll = angle;
 	
 
@@ -651,10 +657,9 @@
 		// free memory stolen from SkinControllerData
 		skin.free();
 	}
-    
+	
 	//for bones without skins
 	create_armature_bones();
-
 }
 
 #if 0
@@ -761,7 +766,7 @@
 
 void ArmatureImporter::set_tags_map(TagsMap & tagsMap)
 {
-    this->uid_tags_map = tagsMap;
+	this->uid_tags_map = tagsMap;
 }
 
 void ArmatureImporter::get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count)




More information about the Bf-blender-cvs mailing list