Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Letwory <nathan@letworyinteractive.com>2011-01-28 15:56:30 +0300
committerNathan Letwory <nathan@letworyinteractive.com>2011-01-28 15:56:30 +0300
commit7769c003853a5238135b763c748ed8db2b77b4d9 (patch)
treeada4f8cdd3c8d66fdc8af40f5fdf06e6d344516c /source/blender/collada
parent037920caffe113c6ab9546ac426965fd5891e58c (diff)
First step towards having a 2-pass reading of COLLADA .dae files.
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/DocumentImporter.cpp63
-rw-r--r--source/blender/collada/DocumentImporter.h56
2 files changed, 89 insertions, 30 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index 6dbffd5232c..fef1285ae52 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -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);
}
diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h
index a2c5e664623..114c2839d49 100644
--- a/source/blender/collada/DocumentImporter.h
+++ b/source/blender/collada/DocumentImporter.h
@@ -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,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
};