[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34542] trunk/blender/source/blender/ collada: First step towards having a 2-pass reading of COLLADA .dae files.

Nathan Letwory nathan at letworyinteractive.com
Fri Jan 28 13:56:31 CET 2011


Revision: 34542
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34542
Author:   jesterking
Date:     2011-01-28 12:56:30 +0000 (Fri, 28 Jan 2011)
Log Message:
-----------
First step towards having a 2-pass reading of COLLADA .dae files.

Modified Paths:
--------------
    trunk/blender/source/blender/collada/DocumentImporter.cpp
    trunk/blender/source/blender/collada/DocumentImporter.h

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp	2011-01-28 08:51:15 UTC (rev 34541)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp	2011-01-28 12:56:30 UTC (rev 34542)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -120,22 +120,37 @@
 //public:
 
 	/** Constructor. */
-	DocumentImporter::DocumentImporter(bContext *C, const char *filename) : mFilename(filename), mContext(C),
-												armature_importer(&unit_converter, &mesh_importer, &anim_importer, CTX_data_scene(C)),
-												mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
-												anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C)) {}
+	DocumentImporter::DocumentImporter(bContext *C, const char *filename) :
+		mImportStage(General),
+		mFilename(filename),
+		mContext(C),
+		armature_importer(&unit_converter, &mesh_importer, &anim_importer, CTX_data_scene(C)),
+		mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
+		anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
+	{}
 
 	/** Destructor. */
 	DocumentImporter::~DocumentImporter() {}
 
 	bool DocumentImporter::import()
 	{
+		/** TODO Add error handler (implement COLLADASaxFWL::IErrorHandler */
 		COLLADASaxFWL::Loader loader;
 		COLLADAFW::Root root(&loader, this);
 
-		// XXX report error
 		if (!root.loadDocument(mFilename))
 			return false;
+		
+		/** TODO set up scene graph and such here */
+		
+		mImportStage = Controller;
+		
+		COLLADASaxFWL::Loader loader2;
+		COLLADAFW::Root root2(&loader2, this);
+		
+		if (!root2.loadDocument(mFilename))
+			return false;
+		
 
 		return true;
 	}
@@ -155,6 +170,10 @@
 	/** This method is called after the last write* method. No other methods will be called after this.*/
 	void DocumentImporter::finish()
 	{
+		if(mImportStage!=General)
+			return;
+			
+		/** TODO Break up and put into 2-pass parsing of DAE */
 		std::vector<const COLLADAFW::VisualScene*>::iterator it;
 		for (it = vscenes.begin(); it != vscenes.end(); it++) {
 			PointerRNA sceneptr, unit_settings;
@@ -439,6 +458,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeVisualScene ( const COLLADAFW::VisualScene* visualScene ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		// this method called on post process after writeGeometry, writeMaterial, etc.
 
 		// for each <node> in <visual_scene>:
@@ -459,6 +481,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		Scene *sce = CTX_data_scene(mContext);
 
 		const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes();
@@ -474,6 +499,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeGeometry ( const COLLADAFW::Geometry* geom ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		return mesh_importer.write_geometry(geom);
 	}
 
@@ -481,6 +509,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		const std::string& str_mat_id = cmat->getOriginalId();
 		Material *ma = add_material((char*)str_mat_id.c_str());
 		
@@ -655,6 +686,8 @@
 	
 	bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect ) 
 	{
+		if(mImportStage!=General)
+			return true;
 		
 		const COLLADAFW::UniqueId& uid = effect->getUniqueId();
 		if (uid_effect_map.find(uid) == uid_effect_map.end()) {
@@ -682,6 +715,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		Camera *cam = NULL;
 		std::string cam_id, cam_name;
 		
@@ -794,6 +830,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeImage( const COLLADAFW::Image* image ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		// XXX maybe it is necessary to check if the path is absolute or relative
 	    const std::string& filepath = image->getImageURI().toNativePath();
 		const char *filename = (const char*)mFilename.c_str();
@@ -816,6 +855,9 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/
 	bool DocumentImporter::writeLight( const COLLADAFW::Light* light ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		Lamp *lamp = NULL;
 		std::string la_id, la_name;
 		
@@ -911,6 +953,9 @@
 	// this function is called only for animations that pass COLLADAFW::validate
 	bool DocumentImporter::writeAnimation( const COLLADAFW::Animation* anim ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		// return true;
 		return anim_importer.write_animation(anim);
 	}
@@ -918,6 +963,9 @@
 	// called on post-process stage after writeVisualScenes
 	bool DocumentImporter::writeAnimationList( const COLLADAFW::AnimationList* animationList ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		// return true;
 		return anim_importer.write_animation_list(animationList);
 	}
@@ -932,6 +980,9 @@
 	// this is called on postprocess, before writeVisualScenes
 	bool DocumentImporter::writeController( const COLLADAFW::Controller* controller ) 
 	{
+		if(mImportStage!=General)
+			return true;
+			
 		return armature_importer.write_controller(controller);
 	}
 

Modified: trunk/blender/source/blender/collada/DocumentImporter.h
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.h	2011-01-28 08:51:15 UTC (rev 34541)
+++ trunk/blender/source/blender/collada/DocumentImporter.h	2011-01-28 12:56:30 UTC (rev 34542)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -46,32 +46,15 @@
 struct Main;
 struct bContext;
 
+/** Importer class. */
 class DocumentImporter : COLLADAFW::IWriter
 {
- private:
-    
-	std::string mFilename;
-
-    bContext *mContext;
-
-    UnitConverter unit_converter;
-    ArmatureImporter armature_importer;
-    MeshImporter mesh_importer;
-    AnimationImporter anim_importer;
-
-    std::map<COLLADAFW::UniqueId, Image*> uid_image_map;
-    std::map<COLLADAFW::UniqueId, Material*> uid_material_map;
-    std::map<COLLADAFW::UniqueId, Material*> uid_effect_map;
-    std::map<COLLADAFW::UniqueId, Camera*> uid_camera_map;
-    std::map<COLLADAFW::UniqueId, Lamp*> uid_lamp_map;
-    std::map<Material*, TexIndexTextureArrayMap> material_texture_mapping_map;
-    std::map<COLLADAFW::UniqueId, Object*> object_map;
-    std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> node_map;
-    std::vector<const COLLADAFW::VisualScene*> vscenes;
-    std::vector<Object*> libnode_ob;
-
-    std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> root_map; // find root joint by child joint uid, for bone tree evaluation during resampling
  public:
+	//! Enumeration to keep denote the stage of import
+	enum ImportStage {
+		General,		//!< First pass to collect all data except controller
+		Controller,		//!< Second pass to collect controller data
+	};
 	/** Constructor */
 	DocumentImporter(bContext *C, const char *filename);
 
@@ -134,7 +117,32 @@
 
 	bool writeKinematicsScene(const COLLADAFW::KinematicsScene*);
 
+ private:
+ 
+	/** Current import stage we're in. */
+	ImportStage mImportStage;
+	std::string mFilename;
 
+    bContext *mContext;
+
+    UnitConverter unit_converter;
+    ArmatureImporter armature_importer;
+    MeshImporter mesh_importer;
+    AnimationImporter anim_importer;
+
+    std::map<COLLADAFW::UniqueId, Image*> uid_image_map;
+    std::map<COLLADAFW::UniqueId, Material*> uid_material_map;
+    std::map<COLLADAFW::UniqueId, Material*> uid_effect_map;
+    std::map<COLLADAFW::UniqueId, Camera*> uid_camera_map;
+    std::map<COLLADAFW::UniqueId, Lamp*> uid_lamp_map;
+    std::map<Material*, TexIndexTextureArrayMap> material_texture_mapping_map;
+    std::map<COLLADAFW::UniqueId, Object*> object_map;
+    std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> node_map;
+    std::vector<const COLLADAFW::VisualScene*> vscenes;
+    std::vector<Object*> libnode_ob;
+
+    std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> root_map; // find root joint by child joint uid, for bone tree evaluation during resampling
+
 };
 
 #endif




More information about the Bf-blender-cvs mailing list