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:
-rw-r--r--source/blender/collada/DocumentImporter.cpp100
-rw-r--r--source/blender/collada/DocumentImporter.h108
-rw-r--r--source/blender/collada/collada.cpp4
3 files changed, 148 insertions, 64 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index fc3ae1ac8c2..818b78fdd6d 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -30,16 +30,9 @@
#include <algorithm> // sort()
#include "COLLADAFWRoot.h"
-#include "COLLADAFWIWriter.h"
#include "COLLADAFWStableHeaders.h"
-#include "COLLADAFWCamera.h"
#include "COLLADAFWColorOrTexture.h"
-#include "COLLADAFWEffect.h"
-#include "COLLADAFWImage.h"
#include "COLLADAFWIndexList.h"
-#include "COLLADAFWInstanceGeometry.h"
-#include "COLLADAFWLight.h"
-#include "COLLADAFWMaterial.h"
#include "COLLADAFWMeshPrimitiveWithFaceVertexCount.h"
#include "COLLADAFWPolygons.h"
#include "COLLADAFWSampler.h"
@@ -47,6 +40,8 @@
#include "COLLADAFWVisualScene.h"
#include "COLLADAFWArrayPrimitiveType.h"
#include "COLLADAFWLibraryNodes.h"
+#include "COLLADAFWCamera.h"
+#include "COLLADAFWLight.h"
#include "COLLADASaxFWLLoader.h"
@@ -58,7 +53,6 @@
#include "BLI_path_util.h"
#include "BKE_scene.h"
#include "BKE_global.h"
-#include "BKE_object.h"
#include "BKE_material.h"
#include "BKE_utildefines.h"
#include "BKE_image.h"
@@ -77,10 +71,6 @@
#include "DocumentImporter.h"
#include "collada_internal.h"
-#include "TransformReader.h"
-#include "AnimationImporter.h"
-#include "ArmatureImporter.h"
-#include "MeshImporter.h"
#include "collada_utils.h"
@@ -95,8 +85,7 @@
/** Class that needs to be implemented by a writer.
IMPORTANT: The write functions are called in arbitrary order.*/
-class Writer: public COLLADAFW::IWriter
-{
+/*
private:
std::string mFilename;
@@ -118,25 +107,27 @@ private:
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
+ std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> root_map;
+ */
+ // find root joint by child joint uid, for bone tree evaluation during resampling
// animation
// std::map<COLLADAFW::UniqueId, std::vector<FCurve*> > uid_fcurve_map;
// Nodes don't share AnimationLists (Arystan)
// std::map<COLLADAFW::UniqueId, Animation> uid_animated_map; // AnimationList->uniqueId to AnimatedObject map
-public:
+//public:
/** Constructor. */
- Writer(bContext *C, const char *filename) : mFilename(filename), mContext(C),
+ 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)) {}
/** Destructor. */
- ~Writer() {}
+ DocumentImporter::~DocumentImporter() {}
- bool write()
+ bool DocumentImporter::import()
{
COLLADASaxFWL::Loader loader;
COLLADAFW::Root root(&loader, this);
@@ -147,12 +138,8 @@ public:
return true;
}
-
- /** This method will be called if an error in the loading process occurred and the loader cannot
- continue to load. The writer should undo all operations that have been performed.
- @param errorMessage A message containing informations about the error that occurred.
- */
- virtual void cancel(const COLLADAFW::String& errorMessage)
+
+ void DocumentImporter::cancel(const COLLADAFW::String& errorMessage)
{
// TODO: if possible show error info
//
@@ -162,13 +149,10 @@ public:
// The latter sounds better.
}
- /** This is the method called. The writer hast to prepare to receive data.*/
- virtual void start()
- {
- }
+ void DocumentImporter::start(){}
/** This method is called after the last write* method. No other methods will be called after this.*/
- virtual void finish()
+ void DocumentImporter::finish()
{
std::vector<const COLLADAFW::VisualScene*>::iterator it;
for (it = vscenes.begin(); it != vscenes.end(); it++) {
@@ -213,7 +197,7 @@ public:
const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
for (unsigned int i = 0; i < roots.getCount(); i++)
- translate_anim_recursive(roots[i]);
+ translate_anim_recursive(roots[i],NULL,NULL);
}
if (libnode_ob.size()) {
@@ -242,7 +226,7 @@ public:
}
- void translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW::Node *par = NULL, Object *parob = NULL)
+ void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW::Node *par = NULL, Object *parob = NULL)
{
if (par && par->getType() == COLLADAFW::Node::JOINT) {
// par is root if there's no corresp. key in root_map
@@ -273,7 +257,7 @@ public:
/** When this method is called, the writer must write the global document asset.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
+ bool DocumentImporter::writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
{
unit_converter.read_asset(asset);
@@ -282,12 +266,12 @@ public:
/** When this method is called, the writer must write the scene.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeScene ( const COLLADAFW::Scene* scene )
+ bool DocumentImporter::writeScene ( const COLLADAFW::Scene* scene )
{
// XXX could store the scene id, but do nothing for now
return true;
}
- Object *create_camera_object(COLLADAFW::InstanceCamera *camera, Scene *sce)
+ Object* DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera, Scene *sce)
{
const COLLADAFW::UniqueId& cam_uid = camera->getInstanciatedObjectId();
if (uid_camera_map.find(cam_uid) == uid_camera_map.end()) {
@@ -304,7 +288,7 @@ public:
return ob;
}
- Object *create_lamp_object(COLLADAFW::InstanceLight *lamp, Scene *sce)
+ Object* DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Scene *sce)
{
const COLLADAFW::UniqueId& lamp_uid = lamp->getInstanciatedObjectId();
if (uid_lamp_map.find(lamp_uid) == uid_lamp_map.end()) {
@@ -321,7 +305,7 @@ public:
return ob;
}
- Object *create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node)
+ Object* DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node)
{
Object *obn = copy_object(source_ob);
obn->recalc |= OB_RECALC_ALL;
@@ -361,7 +345,7 @@ public:
return obn;
}
- void write_node (COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
+ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
{
Object *ob = NULL;
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
@@ -452,7 +436,7 @@ public:
/** When this method is called, the writer must write the entire visual scene.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeVisualScene ( const COLLADAFW::VisualScene* visualScene )
+ bool DocumentImporter::writeVisualScene ( const COLLADAFW::VisualScene* visualScene )
{
// this method called on post process after writeGeometry, writeMaterial, etc.
@@ -472,7 +456,7 @@ public:
/** When this method is called, the writer must handle all nodes contained in the
library nodes.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes )
+ bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes )
{
Scene *sce = CTX_data_scene(mContext);
@@ -487,14 +471,14 @@ public:
/** When this method is called, the writer must write the geometry.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeGeometry ( const COLLADAFW::Geometry* geom )
+ bool DocumentImporter::writeGeometry ( const COLLADAFW::Geometry* geom )
{
return mesh_importer.write_geometry(geom);
}
/** When this method is called, the writer must write the material.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeMaterial( const COLLADAFW::Material* cmat )
+ bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat )
{
const std::string& str_mat_id = cmat->getOriginalId();
Material *ma = add_material((char*)str_mat_id.c_str());
@@ -506,7 +490,7 @@ public:
}
// create mtex, create texture, set texture image
- MTex *create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma,
+ MTex* DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma,
int i, TexIndexTextureArrayMap &texindex_texarray_map)
{
COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray();
@@ -531,7 +515,7 @@ public:
return ma->mtex[i];
}
- void write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma)
+ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma)
{
COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType();
@@ -668,7 +652,7 @@ public:
/** When this method is called, the writer must write the effect.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeEffect( const COLLADAFW::Effect* effect )
+ bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
{
const COLLADAFW::UniqueId& uid = effect->getUniqueId();
@@ -695,7 +679,7 @@ public:
/** When this method is called, the writer must write the camera.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeCamera( const COLLADAFW::Camera* camera )
+ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
{
Camera *cam = NULL;
std::string cam_id, cam_name;
@@ -807,7 +791,7 @@ public:
/** When this method is called, the writer must write the image.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeImage( const COLLADAFW::Image* image )
+ bool DocumentImporter::writeImage( const COLLADAFW::Image* image )
{
// XXX maybe it is necessary to check if the path is absolute or relative
const std::string& filepath = image->getImageURI().toNativePath();
@@ -829,7 +813,7 @@ public:
/** When this method is called, the writer must write the light.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeLight( const COLLADAFW::Light* light )
+ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
{
Lamp *lamp = NULL;
std::string la_id, la_name;
@@ -924,14 +908,14 @@ public:
}
// this function is called only for animations that pass COLLADAFW::validate
- virtual bool writeAnimation( const COLLADAFW::Animation* anim )
+ bool DocumentImporter::writeAnimation( const COLLADAFW::Animation* anim )
{
// return true;
return anim_importer.write_animation(anim);
}
// called on post-process stage after writeVisualScenes
- virtual bool writeAnimationList( const COLLADAFW::AnimationList* animationList )
+ bool DocumentImporter::writeAnimationList( const COLLADAFW::AnimationList* animationList )
{
// return true;
return anim_importer.write_animation_list(animationList);
@@ -939,30 +923,26 @@ public:
/** When this method is called, the writer must write the skin controller data.
@return The writer should return true, if writing succeeded, false otherwise.*/
- virtual bool writeSkinControllerData( const COLLADAFW::SkinControllerData* skin )
+ bool DocumentImporter::writeSkinControllerData( const COLLADAFW::SkinControllerData* skin )
{
return armature_importer.write_skin_controller_data(skin);
}
// this is called on postprocess, before writeVisualScenes
- virtual bool writeController( const COLLADAFW::Controller* controller )
+ bool DocumentImporter::writeController( const COLLADAFW::Controller* controller )
{
return armature_importer.write_controller(controller);
}
- virtual bool writeFormulas( const COLLADAFW::Formulas* formulas )
+ bool DocumentImporter::writeFormulas( const COLLADAFW::Formulas* formulas )
{
return true;
}
- virtual bool writeKinematicsScene( const COLLADAFW::KinematicsScene* kinematicsScene )
+ bool DocumentImporter::writeKinematicsScene( const COLLADAFW::KinematicsScene* kinematicsScene )
{
return true;
}
-};
-void DocumentImporter::import(bContext *C, const char *filename)
-{
- Writer w(C, filename);
- w.write();
-}
+
+
diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h
index 6a6f1dcb3bc..a2c5e664623 100644
--- a/source/blender/collada/DocumentImporter.h
+++ b/source/blender/collada/DocumentImporter.h
@@ -24,13 +24,117 @@
#ifndef __DOCUMENTIMPORTER_H__
#define __DOCUMENTIMPORTER_H__
+
+#include "COLLADAFWIWriter.h"
+#include "COLLADAFWMaterial.h"
+#include "COLLADAFWEffect.h"
+#include "COLLADAFWColor.h"
+#include "COLLADAFWImage.h"
+#include "COLLADAFWInstanceGeometry.h"
+#include "COLLADAFWController.h"
+#include "COLLADAFWMorphController.h"
+#include "COLLADAFWSkinController.h"
+
+#include "BKE_object.h"
+
+#include "TransformReader.h"
+#include "AnimationImporter.h"
+#include "ArmatureImporter.h"
+#include "MeshImporter.h"
+
+
struct Main;
struct bContext;
-class DocumentImporter
+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:
- void import(bContext *C, const char *filename);
+ /** Constructor */
+ DocumentImporter(bContext *C, const char *filename);
+
+ /** Destructor */
+ ~DocumentImporter();
+
+ /** Function called by blender UI */
+ bool import();
+
+ /** these should not be here */
+ Object* create_camera_object(COLLADAFW::InstanceCamera*, Scene*);
+ Object* create_lamp_object(COLLADAFW::InstanceLight*, Scene*);
+ Object* create_instance_node(Object*, COLLADAFW::Node*, COLLADAFW::Node*, Scene*, bool);
+ void write_node(COLLADAFW::Node*, COLLADAFW::Node*, Scene*, Object*, bool);
+ MTex* create_texture(COLLADAFW::EffectCommon*, COLLADAFW::Texture&, Material*, int, TexIndexTextureArrayMap&);
+ void write_profile_COMMON(COLLADAFW::EffectCommon*, Material*);
+ void translate_anim_recursive(COLLADAFW::Node*, COLLADAFW::Node*, Object*);
+
+ /** This method will be called if an error in the loading process occurred and the loader cannot
+ continue to load. The writer should undo all operations that have been performed.
+ @param errorMessage A message containing informations about the error that occurred.
+ */
+ void cancel(const COLLADAFW::String& errorMessage);
+
+ /** This is the method called. The writer hast to prepare to receive data.*/
+ void start();
+
+ /** This method is called after the last write* method. No other methods will be called after this.*/
+ void finish();
+
+ bool writeGlobalAsset(const COLLADAFW::FileInfo*);
+
+ bool writeScene(const COLLADAFW::Scene*);
+
+ bool writeVisualScene(const COLLADAFW::VisualScene*);
+
+ bool writeLibraryNodes(const COLLADAFW::LibraryNodes*);
+
+ bool writeAnimation(const COLLADAFW::Animation*);
+
+ bool writeAnimationList(const COLLADAFW::AnimationList*);
+
+ bool writeGeometry(const COLLADAFW::Geometry*);
+
+ bool writeMaterial(const COLLADAFW::Material*);
+
+ bool writeEffect(const COLLADAFW::Effect*);
+
+ bool writeCamera(const COLLADAFW::Camera*);
+
+ bool writeImage(const COLLADAFW::Image*);
+
+ bool writeLight(const COLLADAFW::Light*);
+
+ bool writeSkinControllerData(const COLLADAFW::SkinControllerData*);
+
+ bool writeController(const COLLADAFW::Controller*);
+
+ bool writeFormulas(const COLLADAFW::Formulas*);
+
+ bool writeKinematicsScene(const COLLADAFW::KinematicsScene*);
+
+
};
#endif
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index d499249cfa2..d040e99c4b9 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -32,8 +32,8 @@ extern "C"
int collada_import(bContext *C, const char *filepath)
{
- DocumentImporter imp;
- imp.import(C, filepath);
+ DocumentImporter imp (C, filepath);
+ imp.import();
return 1;
}