[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25001] branches/soc-2009-chingachgook/ source/blender: COLLADA branch: bone animation import works!

Arystanbek Dyussenov arystan.d at gmail.com
Sun Nov 29 15:38:50 CET 2009


Revision: 25001
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25001
Author:   kazanbas
Date:     2009-11-29 15:38:50 +0100 (Sun, 29 Nov 2009)

Log Message:
-----------
COLLADA branch: bone animation import works!

Here's the doc describing how it works: http://wiki.blender.org/index.php/User:Kazanbas/Collada_Animation_Import

Here's a video showing it at work: http://vimeo.com/7877617

Modified Paths:
--------------
    branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_texture.h
    branches/soc-2009-chingachgook/source/blender/blenkernel/intern/texture.c
    branches/soc-2009-chingachgook/source/blender/blenlib/BLI_util.h
    branches/soc-2009-chingachgook/source/blender/blenlib/intern/util.c
    branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/collada_internal.h

Modified: branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_texture.h
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_texture.h	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_texture.h	2009-11-29 14:38:50 UTC (rev 25001)
@@ -62,7 +62,7 @@
 void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size);
 
 void default_tex(struct Tex *tex);
-struct Tex *add_texture(char *name);
+struct Tex *add_texture(const char *name);
 void default_mtex(struct MTex *mtex);
 struct MTex *add_mtex(void);
 struct Tex *copy_texture(struct Tex *tex);

Modified: branches/soc-2009-chingachgook/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenkernel/intern/texture.c	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/blenkernel/intern/texture.c	2009-11-29 14:38:50 UTC (rev 25001)
@@ -518,7 +518,7 @@
 
 /* ------------------------------------------------------------------------- */
 
-Tex *add_texture(char *name)
+Tex *add_texture(const char *name)
 {
 	Tex *tex;
 

Modified: branches/soc-2009-chingachgook/source/blender/blenlib/BLI_util.h
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenlib/BLI_util.h	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/blenlib/BLI_util.h	2009-11-29 14:38:50 UTC (rev 25001)
@@ -61,7 +61,7 @@
 void BLI_join_dirfile(char *string, const char *dir, const char *file);
 void BLI_getlastdir(const char* dir, char *last, int maxlen);
 int BLI_testextensie(const char *str, const char *ext);
-void BLI_uniquename(struct ListBase *list, void *vlink, char defname[], char delim, short name_offs, short len);
+void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
 void BLI_newname(char * name, int add);
 int BLI_stringdec(char *string, char *kop, char *start, unsigned short *numlen);
 void BLI_stringenc(char *string, char *kop, char *start, unsigned short numlen, int pic);

Modified: branches/soc-2009-chingachgook/source/blender/blenlib/intern/util.c
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenlib/intern/util.c	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/blenlib/intern/util.c	2009-11-29 14:38:50 UTC (rev 25001)
@@ -223,7 +223,7 @@
  *	defname: the name that should be used by default if none is specified already
  *	delim: the character which acts as a delimeter between parts of the name
  */
-void BLI_uniquename(ListBase *list, void *vlink, char defname[], char delim, short name_offs, short len)
+void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len)
 {
 	Link *link;
 	char tempname[128];

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-11-29 14:38:50 UTC (rev 25001)
@@ -673,7 +673,7 @@
 			copy_m4_m4(local, mat);
 		}
 
-		TransformBase::decompose(local, loc, rot, size);
+		TransformBase::decompose(local, loc, rot, NULL, size);
 		
 		/*
 		// this code used to create a single <rotate> representing object rotation

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-11-29 06:10:26 UTC (rev 25000)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-11-29 14:38:50 UTC (rev 25001)
@@ -1,3 +1,7 @@
+// TODO:
+// * name imported objects
+// * import object rotation as euler
+
 #include "COLLADAFWRoot.h"
 #include "COLLADAFWIWriter.h"
 #include "COLLADAFWStableHeaders.h"
@@ -51,6 +55,7 @@
 #include "BLI_util.h"
 #include "BKE_displist.h"
 #include "BLI_math.h"
+#include "BKE_scene.h"
 }
 #include "BKE_armature.h"
 #include "BKE_mesh.h"
@@ -91,6 +96,7 @@
 #include <float.h>
 
 // #define COLLADA_DEBUG
+#define ARMATURE_TEST
 
 char *CustomData_get_layer_name(const struct CustomData *data, int type, int n);
 
@@ -132,8 +138,10 @@
 		return "SPLINE";
 	case COLLADAFW::Geometry::GEO_TYPE_CONVEX_MESH:
 		return "CONVEX_MESH";
+	case COLLADAFW::Geometry::GEO_TYPE_UNKNOWN:
+	default:
+		return "UNKNOWN";
 	}
-	return "UNKNOWN";
 }
 
 // works for COLLADAFW::Node, COLLADAFW::Geometry
@@ -196,41 +204,16 @@
 
 			switch(type) {
 			case COLLADAFW::Transformation::TRANSLATE:
-				{
-					COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm;
-					COLLADABU::Math::Vector3& t = tra->getTranslation();
-
-					unit_m4(cur);
-					cur[3][0] = (float)t[0];
-					cur[3][1] = (float)t[1];
-					cur[3][2] = (float)t[2];
-				}
+				dae_translate_to_mat4(tm, cur);
 				break;
 			case COLLADAFW::Transformation::ROTATE:
-				{
-					COLLADAFW::Rotate *ro = (COLLADAFW::Rotate*)tm;
-					COLLADABU::Math::Vector3& raxis = ro->getRotationAxis();
-					float angle = (float)(ro->getRotationAngle() * M_PI / 180.0f);
-					float axis[] = {raxis[0], raxis[1], raxis[2]};
-					float quat[4];
-					float rot_copy[3][3];
-					float mat[3][3];
-					axis_angle_to_quat(quat, axis, angle);
-					
-					quat_to_mat4( cur,quat);
-				}
+				dae_rotate_to_mat4(tm, cur);
 				break;
 			case COLLADAFW::Transformation::SCALE:
-				{
-					COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale();
-					float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
-					size_to_mat4( cur,size);
-				}
+				dae_scale_to_mat4(tm, cur);
 				break;
 			case COLLADAFW::Transformation::MATRIX:
-				{
-					unit_converter->mat4_from_dae(cur, ((COLLADAFW::Matrix*)tm)->getMatrix());
-				}
+				dae_matrix_to_mat4(tm, cur);
 				break;
 			case COLLADAFW::Transformation::LOOKAT:
 			case COLLADAFW::Transformation::SKEW:
@@ -251,6 +234,42 @@
 			}
 		}
 	}
+
+	void dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
+	{
+		COLLADAFW::Rotate *ro = (COLLADAFW::Rotate*)tm;
+		COLLADABU::Math::Vector3& axis = ro->getRotationAxis();
+		float angle = (float)(ro->getRotationAngle() * M_PI / 180.0f);
+		float ax[] = {axis[0], axis[1], axis[2]};
+		// float quat[4];
+		// axis_angle_to_quat(quat, axis, angle);
+		// quat_to_mat4(m, quat);
+		axis_angle_to_mat4(m, ax, angle);
+	}
+
+	void dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
+	{
+		COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm;
+		COLLADABU::Math::Vector3& t = tra->getTranslation();
+
+		unit_m4(m);
+
+		m[3][0] = (float)t[0];
+		m[3][1] = (float)t[1];
+		m[3][2] = (float)t[2];
+	}
+
+	void dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
+	{
+		COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale();
+		float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
+		size_to_mat4(m, size);
+	}
+
+	void dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
+	{
+		unit_converter->dae_matrix_to_mat4(m, ((COLLADAFW::Matrix*)tm)->getMatrix());
+	}
 };
 
 // only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid
@@ -264,7 +283,7 @@
 class AnimationImporterBase
 {
 public:
-	virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
+	// virtual void change_eul_to_quat(Object *ob, bAction *act) = 0;
 };
 
 class ArmatureImporter : private TransformReader
@@ -390,7 +409,7 @@
 			for (int i = 0; i < weight.getValuesCount(); i++)
 				weights.push_back(get_float_value(weight, i));
 
-			unit_converter->mat4_from_dae(bind_shape_matrix, skin->getBindShapeMatrix());
+			unit_converter->dae_matrix_to_mat4(bind_shape_matrix, skin->getBindShapeMatrix());
 		}
 			
 		void free()
@@ -407,7 +426,7 @@
 		void add_joint(const COLLADABU::Math::Matrix4& matrix)
 		{
 			JointData jd;
-			unit_converter->mat4_from_dae(jd.inv_bind_mat, matrix);
+			unit_converter->dae_matrix_to_mat4(jd.inv_bind_mat, matrix);
 			joint_data.push_back(jd);
 		}
 
@@ -481,7 +500,7 @@
 		void link_armature(bContext *C, Object *ob, std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid,
 						   TransformReader *tm)
 		{
-			tm->decompose(bind_shape_matrix, ob->loc, ob->rot, ob->size);
+			tm->decompose(bind_shape_matrix, ob->loc, ob->rot, NULL, ob->size);
 
 			ob->parent = ob_arm;
 			ob->partype = PARSKEL;
@@ -708,6 +727,7 @@
 		}
 	}
 
+#if 0
 	void set_euler_rotmode()
 	{
 		// just set rotmode = ROT_MODE_EUL on pose channel for each joint
@@ -738,6 +758,7 @@
 			}
 		}
 	}
+#endif
 
 	Object *get_empty_for_leaves()
 	{
@@ -820,7 +841,7 @@
 
 		set_leaf_bone_shapes(ob_arm);
 
-		set_euler_rotmode();
+		// set_euler_rotmode();
 	}
 	
 
@@ -992,6 +1013,7 @@
 		BLI_snprintf(joint_path, count, "pose.bones[\"%s\"]", get_joint_name(node));
 	}
 	
+#if 0
 	void fix_animation()
 	{
 		/* Change Euler rotation to Quaternion for bone animation */
@@ -1002,6 +1024,23 @@
 			anim_importer->change_eul_to_quat(ob, ob->adt->action);
 		}
 	}
+#endif
+
+	// gives a world-space mat
+	bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint)
+	{
+		std::map<COLLADAFW::UniqueId, SkinInfo>::iterator it;
+		bool found = false;
+		for (it = skin_by_data_uid.begin(); it != skin_by_data_uid.end(); it++) {
+			SkinInfo& skin = it->second;
+			if ((found = skin.get_joint_inv_bind_matrix(m, joint))) {
+				invert_m4(m);
+				break;
+			}
+		}
+
+		return found;
+	}
 };
 
 class MeshImporter : public MeshImporterBase
@@ -1080,6 +1119,9 @@
 					
 				}
 				break;
+			case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:	
+			default:
+				fprintf(stderr, "MeshImporter.getUV(): unknown data type\n");
 			}
 		}
 	};
@@ -1320,7 +1362,7 @@
 	int count_new_tris(COLLADAFW::Mesh *mesh, Mesh *me)
 	{
 		COLLADAFW::MeshPrimitiveArray& prim_arr = mesh->getMeshPrimitives();
-		int i, j, k;
+		int i, j;
 		int tottri = 0;
 		
 		for (i = 0; i < prim_arr.getCount(); i++) {
@@ -1730,11 +1772,14 @@
 	ArmatureImporter *armature_importer;
 	Scene *scene;
 
-	std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > uid_fcurve_map;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list