[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49814] branches/soc-2012-bratwurst/source /blender/collada: [COLLADA]Morph Controller Import.

Sukhitha Jayathilake pr.jayathilake at gmail.com
Sat Aug 11 20:07:01 CEST 2012


Revision: 49814
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49814
Author:   phabtar
Date:     2012-08-11 18:07:01 +0000 (Sat, 11 Aug 2012)
Log Message:
-----------
[COLLADA]Morph Controller Import.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
    branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h

Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp	2012-08-11 16:25:31 UTC (rev 49813)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp	2012-08-11 18:07:01 UTC (rev 49814)
@@ -649,9 +649,47 @@
 		skin_by_data_uid[data_uid].set_controller(co);
 	}
 	// morph controller
-	else {
-		// shape keys? :)
-		fprintf(stderr, "Morph controller is not supported yet.\n");
+	else if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_MORPH) {
+		COLLADAFW::MorphController *co = (COLLADAFW::MorphController *)controller;
+		// to be able to find geom id by controller id
+		geom_uid_by_controller_uid[skin_id] = co->getSource();
+
+		COLLADAFW::UniqueIdArray& morphTargetIds = co->getMorphTargets();
+		COLLADAFW::FloatOrDoubleArray& morphWeights = co->getMorphWeights();
+        
+		//Prereq: all the geometries must be imported and mesh objects must be made
+		Object *source_ob = this->mesh_importer->get_object_by_geom_uid(co->getSource());
+		Mesh *source_me = (Mesh*) source_ob->data;
+		float *weight;
+
+		for ( int i = 0 ; i < morphTargetIds.getCount() ; i++ ){
+			//better to have a seperate map of morph objects, 
+			//This'll do for now since only mesh morphing is imported
+			Object *ob = this->mesh_importer->get_object_by_geom_uid(morphTargetIds[i]);
+			if(ob){
+				Mesh *me = (Mesh*)ob->data;
+				Key *key = ob_get_key(source_ob);
+				KeyBlock *kb;
+				int newkey = 0;
+
+				if (key == NULL) {
+					key = source_me->key = add_key((ID *)me);
+					key->type = KEY_RELATIVE;
+					newkey = 1;
+				}
+
+				kb = add_keyblock_ctime(key, morphTargetIds[i].toAscii().c_str(), FALSE);
+				mesh_to_key(me, kb);
+				weight =  morphWeights.getFloatValues()[i].getData();
+				kb->curval = *weight;
+				
+				//free object since it is added as shape key
+				BKE_object_free(ob);
+			}
+			else 
+				fprintf(stderr, "Morph target geometry not found.\n");
+		} 
+//		fprintf(stderr, "Morph controller is not supported yet.\n");
 	}
 
 	return true;

Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h	2012-08-11 16:25:31 UTC (rev 49813)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h	2012-08-11 18:07:01 UTC (rev 49814)
@@ -29,13 +29,16 @@
 
 #include "COLLADAFWNode.h"
 #include "COLLADAFWUniqueId.h"
+#include "COLLADAFWMorphController.h"
 
 extern "C" {
 #include "BKE_context.h"
+#include "BKE_key.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_key_types.h"
 
 #include "ED_armature.h"
 }




More information about the Bf-blender-cvs mailing list