First step towards having a 2-pass reading of COLLADA .dae files.
authorNathan Letwory <nathan@letworyinteractive.com>
Fri, 28 Jan 2011 12:56:30 +0000 (12:56 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Fri, 28 Jan 2011 12:56:30 +0000 (12:56 +0000)
source/blender/collada/DocumentImporter.cpp
source/blender/collada/DocumentImporter.h

index 6dbffd5232c0ef18a03fc59d5611612d5849a047..fef1285ae52ffc7d18c9e6ed00e887b853960f60 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -120,22 +120,37 @@ private:
 //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 @@ private:
        /** 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 @@ private:
                @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 @@ private:
                @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 @@ private:
                @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 @@ private:
                @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 @@ private:
        
        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 @@ private:
                @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 @@ private:
                @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 @@ private:
                @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 @@ private:
        // 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 @@ private:
        // 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 @@ private:
        // 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);
        }
 
index a2c5e664623359d84e1c6e8a13df44337908884a..114c2839d4923fdfa9dbccfc146fc97a63d99d1e 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
 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,6 +117,31 @@ class DocumentImporter : COLLADAFW::IWriter
 
        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
 
 };