[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43915] trunk/blender/source/blender: Patch #30050 by Juha M?\195?\164ki-Kanto (kanttori)

Domino Marama domino at dominodesigns.info
Sun Feb 5 17:19:33 CET 2012


Revision: 43915
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43915
Author:   domino
Date:     2012-02-05 16:19:28 +0000 (Sun, 05 Feb 2012)
Log Message:
-----------
Patch #30050 by Juha M?\195?\164ki-Kanto (kanttori)

Fixes for Collada exporter.
Adds Second Life compatibility for armatures
Adds objects parentinverse to exported transform if it's non-identity
Fix mismatch between add_inv_bind_mats and add_joints_source accessor counts
Fix bone exports in world space should be local space

Modified Paths:
--------------
    trunk/blender/source/blender/collada/AnimationExporter.cpp
    trunk/blender/source/blender/collada/AnimationExporter.h
    trunk/blender/source/blender/collada/ArmatureExporter.cpp
    trunk/blender/source/blender/collada/DocumentExporter.cpp
    trunk/blender/source/blender/collada/ExportSettings.h
    trunk/blender/source/blender/collada/TransformWriter.cpp
    trunk/blender/source/blender/collada/collada.cpp
    trunk/blender/source/blender/collada/collada.h
    trunk/blender/source/blender/makesrna/intern/rna_scene_api.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/collada/AnimationExporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/AnimationExporter.cpp	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/AnimationExporter.cpp	2012-02-05 16:19:28 UTC (rev 43915)
@@ -773,6 +773,27 @@
 			copy_m4_m4(mat, pchan->pose_mat);
 		UnitConverter converter;
 
+		// SECOND_LIFE_COMPATIBILITY
+		// AFAIK animation to second life is via BVH, but no
+		// reason to not have the collada-animation be correct
+		if(export_settings->second_life)
+		{
+			float temp[4][4];
+			copy_m4_m4(temp, bone->arm_mat);
+			temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+			invert_m4(temp);
+
+			mult_m4_m4m4(mat, mat, temp);
+
+			if(bone->parent)
+			{
+				copy_m4_m4(temp, bone->parent->arm_mat);
+				temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+
+				mult_m4_m4m4(mat, temp, mat);
+			}
+		}
+
 		float outmat[4][4];
 		converter.mat4_to_dae(outmat,mat);
 

Modified: trunk/blender/source/blender/collada/AnimationExporter.h
===================================================================
--- trunk/blender/source/blender/collada/AnimationExporter.h	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/AnimationExporter.h	2012-02-05 16:19:28 UTC (rev 43915)
@@ -83,7 +83,9 @@
 
 public:
 
-	AnimationExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) { this->sw = sw; }
+	AnimationExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings):
+			COLLADASW::LibraryAnimations(sw), export_settings(export_settings)
+			{ this->sw = sw; }
 	
 
 	void exportAnimations(Scene *sce);
@@ -92,6 +94,7 @@
 	void operator() (Object *ob); 
 	
 protected:
+	const ExportSettings *export_settings;
 
 	void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material *ma = NULL);
 

Modified: trunk/blender/source/blender/collada/ArmatureExporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/ArmatureExporter.cpp	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/ArmatureExporter.cpp	2012-02-05 16:19:28 UTC (rev 43915)
@@ -221,10 +221,33 @@
 		mult_m4_m4m4(mat, invpar, pchan->pose_mat);
 	}
 	else {
-		// get world-space from armature-space
-		mult_m4_m4m4(mat, ob_arm->obmat, pchan->pose_mat);
+		copy_m4_m4(mat, pchan->pose_mat);
+		// Why? Joint's localspace is still it's parent node
+		//get world-space from armature-space
+		//mult_m4_m4m4(mat, ob_arm->obmat, pchan->pose_mat);
 	}
 
+	// SECOND_LIFE_COMPATIBILITY
+	if(export_settings->second_life)
+	{
+		// Remove rotations vs armature from transform
+		// parent_rest_rot * mat * irest_rot
+		float temp[4][4];
+		copy_m4_m4(temp, bone->arm_mat);
+		temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+		invert_m4(temp);
+
+		mult_m4_m4m4(mat, mat, temp);
+
+		if(bone->parent)
+		{
+			copy_m4_m4(temp, bone->parent->arm_mat);
+			temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+
+			mult_m4_m4m4(mat, temp, mat);
+		}
+	}
+
 	TransformWriter::add_node_transform(node, mat,NULL );
 }
 
@@ -341,10 +364,16 @@
 {
 	std::string source_id = controller_id + BIND_POSES_SOURCE_ID_SUFFIX;
 
+	int totjoint = 0;
+	for (bDeformGroup *def = (bDeformGroup*)defbase->first; def; def = def->next) {
+		if (is_bone_defgroup(ob_arm, def))
+			totjoint++;
+	}
+
 	COLLADASW::FloatSourceF source(mSW);
 	source.setId(source_id);
 	source.setArrayId(source_id + ARRAY_ID_SUFFIX);
-	source.setAccessorCount(BLI_countlist(defbase));
+	source.setAccessorCount(totjoint); //BLI_countlist(defbase));
 	source.setAccessorStride(16);
 	
 	source.setParameterTypeName(&COLLADASW::CSWC::CSW_VALUE_TYPE_FLOAT4x4);
@@ -366,16 +395,27 @@
 
 	for (bDeformGroup *def = (bDeformGroup*)defbase->first; def; def = def->next) {
 		if (is_bone_defgroup(ob_arm, def)) {
-
 			bPoseChannel *pchan = get_pose_channel(pose, def->name);
 
 			float mat[4][4];
 			float world[4][4];
 			float inv_bind_mat[4][4];
 
-			// make world-space matrix, arm_mat is armature-space
-			mult_m4_m4m4(world, ob_arm->obmat, pchan->bone->arm_mat);
-			
+			// SECOND_LIFE_COMPATIBILITY
+			if(export_settings->second_life)
+			{
+				// Only translations, no rotation vs armature
+				float temp[4][4];
+				unit_m4(temp);
+				copy_v3_v3(temp[3], pchan->bone->arm_mat[3]);
+				mult_m4_m4m4(world, ob_arm->obmat, temp);
+			}
+			else
+			{
+				// make world-space matrix, arm_mat is armature-space
+				mult_m4_m4m4(world, ob_arm->obmat, pchan->bone->arm_mat);
+			}
+
 			invert_m4_m4(mat, world);
 			converter.mat4_to_dae(inv_bind_mat, mat);
 

Modified: trunk/blender/source/blender/collada/DocumentExporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentExporter.cpp	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/DocumentExporter.cpp	2012-02-05 16:19:28 UTC (rev 43915)
@@ -257,7 +257,7 @@
 	}
 
 	// <library_animations>
-	AnimationExporter ae(&sw);
+	AnimationExporter ae(&sw, this->export_settings);
 	ae.exportAnimations(sce);
 
 	// <library_controllers>

Modified: trunk/blender/source/blender/collada/ExportSettings.h
===================================================================
--- trunk/blender/source/blender/collada/ExportSettings.h	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/ExportSettings.h	2012-02-05 16:19:28 UTC (rev 43915)
@@ -31,6 +31,7 @@
 {
  public:
  bool selected;
+ bool second_life;
  char *filepath;
 };
 

Modified: trunk/blender/source/blender/collada/TransformWriter.cpp
===================================================================
--- trunk/blender/source/blender/collada/TransformWriter.cpp	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/TransformWriter.cpp	2012-02-05 16:19:28 UTC (rev 43915)
@@ -59,6 +59,7 @@
 
 void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob)
 {
+	/*
 	float rot[3], loc[3], scale[3];
 
 	if (ob->parent) {
@@ -91,6 +92,27 @@
 	}
 
 	add_transform(node, loc, rot, scale);
+	*/
+
+	/* Using parentinv should allow use of existing curves */
+	// If parentinv is identity don't add it.
+	bool add_parinv = false;
+	for(int i = 0; i < 16; ++i)
+	{
+		float f = (i%4 == i/4) ? 1.0f : 0.0f ;
+		if(ob->parentinv[i%4][i/4] != f) add_parinv = true;
+	}
+
+	// Eat this 3ds Max et friends
+	if(add_parinv)
+	{
+		double dmat[4][4];
+		UnitConverter converter;
+		converter.mat4_to_dae_double(dmat, ob->parentinv);
+		node.addMatrix("parentinverse", dmat);
+	}
+
+	add_transform(node, ob->loc, ob->rot, ob->size);
 }
 
 void TransformWriter::add_node_transform_identity(COLLADASW::Node& node)

Modified: trunk/blender/source/blender/collada/collada.cpp
===================================================================
--- trunk/blender/source/blender/collada/collada.cpp	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/collada.cpp	2012-02-05 16:19:28 UTC (rev 43915)
@@ -49,11 +49,12 @@
 		return 0;
 	}
 
-	int collada_export(Scene *sce, const char *filepath, int selected)
+	int collada_export(Scene *sce, const char *filepath, int selected, int second_life)
 	{
 		ExportSettings export_settings;
 		
 		export_settings.selected = selected != 0;
+		export_settings.second_life = second_life != 0;
 		export_settings.filepath = (char *)filepath;
 
 		/* annoying, collada crashes if file cant be created! [#27162] */

Modified: trunk/blender/source/blender/collada/collada.h
===================================================================
--- trunk/blender/source/blender/collada/collada.h	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/collada/collada.h	2012-02-05 16:19:28 UTC (rev 43915)
@@ -37,7 +37,7 @@
 	 * both return 1 on success, 0 on error
 	 */
 	int collada_import(bContext *C, const char *filepath);
-	int collada_export(Scene *sce, const char *filepath, int selected);
+	int collada_export(Scene *sce, const char *filepath, int selected, int second_life);
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/blender/source/blender/makesrna/intern/rna_scene_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_scene_api.c	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/makesrna/intern/rna_scene_api.c	2012-02-05 16:19:28 UTC (rev 43915)
@@ -84,9 +84,9 @@
 /* don't remove this, as COLLADA exporting cannot be done through operators in render() callback. */
 #include "../../collada/collada.h"
 
-static void rna_Scene_collada_export(Scene *scene, const char *filepath, int selected)
+static void rna_Scene_collada_export(Scene *scene, const char *filepath, int selected, int second_life)
 {
-	collada_export(scene, filepath, selected);
+	collada_export(scene, filepath, selected, second_life);
 }
 
 #endif
@@ -110,10 +110,11 @@
 #ifdef WITH_COLLADA
 	/* don't remove this, as COLLADA exporting cannot be done through operators in render() callback. */
 	func= RNA_def_function(srna, "collada_export", "rna_Scene_collada_export");
-	RNA_def_string(func, "filepath", "", FILE_MAX, "File Path", "File path to write Collada file");
-	parm= RNA_def_boolean(func, "selected", 0, "Export only selected", "Export only selected elements");
+	parm= RNA_def_string(func, "filepath", "", FILE_MAX, "File Path", "File path to write Collada file");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 	RNA_def_property_subtype(parm, PROP_FILEPATH); /* allow non utf8 */
+	parm= RNA_def_boolean(func, "selected", 0, "Export only selected", "Export only selected elements");
+	parm= RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
 	RNA_def_function_ui_description(func, "Export to collada file");
 #endif
 }

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-02-05 16:05:36 UTC (rev 43914)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-02-05 16:19:28 UTC (rev 43915)
@@ -2135,7 +2135,7 @@
 static int wm_collada_export_exec(bContext *C, wmOperator *op)
 {
 	char filename[FILE_MAX];
-	int selected;
+	int selected, second_life;
 	
 	if(!RNA_struct_property_is_set(op->ptr, "filepath")) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list