Importer base for Chingiz.
authorArystanbek Dyussenov <arystan.d@gmail.com>
Wed, 17 Jun 2009 11:16:18 +0000 (11:16 +0000)
committerArystanbek Dyussenov <arystan.d@gmail.com>
Wed, 17 Jun 2009 11:16:18 +0000 (11:16 +0000)
13 files changed:
config/linux2-config.py
source/blender/collada/DocumentExporter.h
source/blender/collada/DocumentImporter.cpp [new file with mode: 0644]
source/blender/collada/DocumentImporter.h [new file with mode: 0644]
source/blender/collada/SConscript
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_edit.c
source/blender/editors/space_info/info_header.c
source/blender/windowmanager/intern/wm_operators.c
tools/Blender.py
tools/btools.py

index 2bcad700b42ccffbfa7cade611dfda127aa07d87..71cc7e7bc5bd536cd9e486ef922b0b875003d140 100644 (file)
@@ -170,6 +170,9 @@ BF_OPENCOLLADA_LIBPATH = '/usr/lib'
 BF_PCRE = ''
 BF_PCRE_LIB = 'pcre'
 BF_PCRE_LIBPATH = '/usr/lib'
 BF_PCRE = ''
 BF_PCRE_LIB = 'pcre'
 BF_PCRE_LIBPATH = '/usr/lib'
+BF_EXPAT = '/usr'
+BF_EXPAT_LIB = 'expat'
+BF_EXPAT_LIBPATH = '/usr/lib'
 
 ##
 CC = 'gcc'
 
 ##
 CC = 'gcc'
index 7ae199a5df6093c9ee5c52a925e2944d711e5b5f..1a0c292a3ddb81e715997ff373cb63ac4380a65c 100644 (file)
@@ -1,3 +1,4 @@
+struct Scene;
 
 class DocumentExporter
 {
 
 class DocumentExporter
 {
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
new file mode 100644 (file)
index 0000000..1bffb0f
--- /dev/null
@@ -0,0 +1,238 @@
+#include "COLLADAFWStableHeaders.h"
+#include "COLLADAFWIWriter.h"
+#include "COLLADAFWRoot.h"
+#include "COLLADAFWNode.h"
+#include "COLLADAFWVisualScene.h"
+#include "COLLADAFWInstanceGeometry.h"
+#include "COLLADAFWFileInfo.h"
+#include "COLLADAFWRoot.h"
+#include "COLLADAFWLight.h"
+#include "COLLADAFWImage.h"
+#include "COLLADAFWMaterial.h"
+#include "COLLADAFWGeometry.h"
+#include "COLLADAFWMesh.h"
+
+#include "COLLADASaxFWLLoader.h"
+
+extern "C" 
+{
+#include "BKE_main.h"
+#include "BKE_mesh.h"
+#include "BKE_context.h"
+
+#include "DNA_object_types.h"
+
+#include "ED_object.h"
+
+#include "DocumentImporter.h"
+}
+
+
+/** 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;
+       
+       std::vector<COLLADAFW::VisualScene> mVisualScenes;
+
+       bContext *mContext;
+
+       class UnitConverter
+       {
+       private:
+               COLLADAFW::FileInfo::Unit mUnit;
+               COLLADAFW::FileInfo::UpAxisType mUpAxis;
+       public:
+               UnitConverter(COLLADAFW::FileInfo::UpAxisType upAxis, COLLADAFW::FileInfo::Unit& unit) :
+                       mUpAxis(upAxis), mUnit(unit)
+               {
+               }
+
+               // TODO
+               // convert vector vec from COLLADA format to Blender
+               void convertVec3(float *vec)
+               {
+               }
+               
+               // TODO need also for angle conversion, time conversion...
+       };
+
+public:
+
+       /** Constructor. */
+       Writer(bContext *C, const char *filename) : mContext(C), mFilename(filename) {};
+
+       /** Destructor. */
+       ~Writer() {};
+
+       bool write()
+       {
+               COLLADASaxFWL::Loader loader;
+               COLLADAFW::Root root(&loader, this);
+
+               // XXX report error
+               if (!root.loadDocument(mFilename))
+                       return false;
+       }
+
+       /** This method will be called if an error in the loading process occurred and the loader cannot
+               continue to 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)
+       {
+       }
+
+       /** This is the method called. The writer hast to prepare to receive data.*/
+       virtual void start()
+       {
+       }
+
+       /** This method is called after the last write* method. No other methods will be called after this.*/
+       virtual void finish()
+       {
+               // using mVisualScenes, do:
+               // - write <node> data to Objects: materials, transforms, etc.
+       }
+
+       /** 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 ) 
+       {
+               // XXX take up_axis, unit into account
+               // COLLADAFW::FileInfo::Unit unit = asset->getUnit();
+               // COLLADAFW::FileInfo::UpAxisType upAxis = asset->getUpAxisType();
+
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               // XXX could store the scene id, but do nothing for now
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               // for the sake of clarity link nodes to geometries at a later stage
+               mVisualScenes.push_back(*visualScene);
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               return true;
+       }
+
+       /** 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* geometry ) 
+       {
+               // - create a mesh object
+               // - enter editmode getting editmesh
+               // - write geometry
+               // - exit editmode
+
+               // check geometry->getType() first
+               COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh*)geometry;
+
+               // create a mesh object
+               Object *ob = ED_object_add_type(mContext, OB_MESH);
+               Mesh *me = (Mesh*)ob->data;
+
+               // enter editmode
+               ED_object_enter_editmode(mContext, 0);
+
+               EditMesh *em = BKE_mesh_get_editmesh(me);
+
+               // write geometry
+               // currently only support <triangles>
+
+               BKE_mesh_end_editmesh(me, em);
+
+               // exit editmode
+               ED_object_exit_editmode(mContext, EM_FREEDATA);
+
+               return true;
+       }
+
+       /** 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* material ) 
+       {
+               // TODO: create and store a material.
+               // Let it have 0 users for now.
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               return true;
+       }
+
+       /** 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 ) 
+       {
+               return true;
+       }
+
+       /** When this method is called, the writer must write the Animation.
+               @return The writer should return true, if writing succeeded, false otherwise.*/
+       virtual bool writeAnimation( const COLLADAFW::Animation* animation ) 
+       {
+               return true;
+       }
+
+       /** When this method is called, the writer must write the AnimationList.
+               @return The writer should return true, if writing succeeded, false otherwise.*/
+       virtual bool writeAnimationList( const COLLADAFW::AnimationList* animationList ) 
+       {
+               return true;
+       }
+
+       /** 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* skinControllerData ) 
+       {
+               return true;
+       }
+
+       /** When this method is called, the writer must write the controller.
+               @return The writer should return true, if writing succeeded, false otherwise.*/
+       virtual bool writeController( const COLLADAFW::Controller* Controller ) 
+       {
+               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
new file mode 100644 (file)
index 0000000..5dee101
--- /dev/null
@@ -0,0 +1,8 @@
+struct Main;
+struct bContext;
+
+class DocumentImporter
+{
+ public:
+       void import(bContext *C, const char *filename);
+};
index e417a94b183505da1c656848f5364d6d1c873105..58242775738fc6d51610e34194691b959f928e01 100644 (file)
@@ -4,7 +4,7 @@ Import ('env')
 sources = env.Glob('*.cpp')
 
 # relative paths to include dirs, space-separated, string
 sources = env.Glob('*.cpp')
 
 # relative paths to include dirs, space-separated, string
-incs = '../blenlib ../blenkernel %s/COLLADAStreamWriter/include %s/COLLADABaseUtils/include' % (env['BF_OPENCOLLADA'], env['BF_OPENCOLLADA']) + ' ../makesdna'
+incs = '../blenlib ../blenkernel ../makesdna ../makesrna ../editors/include [OPENCOLLADA]/COLLADAStreamWriter/include [OPENCOLLADA]/COLLADABaseUtils/include [OPENCOLLADA]/COLLADAFramework/include [OPENCOLLADA]/COLLADASaxFrameworkLoader/include '.replace('[OPENCOLLADA]', env['BF_OPENCOLLADA'])
 
 env.BlenderLib ('bf_collada', sources, Split(incs), [], libtype='core', priority=200 )
 
 
 env.BlenderLib ('bf_collada', sources, Split(incs), [], libtype='core', priority=200 )
 
index c53325095f6efecbb27dc84bde2b8bb091093e67..5aed51c0ba2630714c83a5ea13f3c0ca5388ead1 100644 (file)
@@ -1,11 +1,17 @@
-#include <stdio.h>
+#include "BKE_main.h"
 #include "BKE_scene.h"
 #include "BKE_scene.h"
+#include "BKE_context.h"
+
 #include "DocumentExporter.h"
 #include "DocumentExporter.h"
+#include "DocumentImporter.h"
 
 extern "C"
 {
 
 extern "C"
 {
-       int collada_import(Scene *sce, const char *filepath)
+       int collada_import(bContext *C, const char *filepath)
        {
        {
+               DocumentImporter imp;
+               imp.import(C, filepath);
+
                return 1;
        }
 
                return 1;
        }
 
index bf4b21e896c2d65432dc6d159ca5f78b9637d96f..cccca072b40bf9e2a486d36b710356736be1a18f 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef BLENDER_COLLADA_H
 #define BLENDER_COLLADA_H
 
 #ifndef BLENDER_COLLADA_H
 #define BLENDER_COLLADA_H
 
-#include "BKE_scene.h"
+struct bContext;
+struct Scene;
 
 #ifdef __cplusplus
 extern "C" {
 
 #ifdef __cplusplus
 extern "C" {
@@ -9,7 +10,7 @@ extern "C" {
        /*
         * both return 1 on success, 0 on error
         */
        /*
         * both return 1 on success, 0 on error
         */
-       int collada_import(Scene *sce, const char *filepath);
+       int collada_import(bContext *C, const char *filepath);
        int collada_export(Scene *sce, const char *filepath);
 #ifdef __cplusplus
 }
        int collada_export(Scene *sce, const char *filepath);
 #ifdef __cplusplus
 }
index c6277f319bcb0cffb739fef5bc7a73aa9c5efe79..ced726af12f89dee866b15abc64aece9eced640c 100644 (file)
@@ -45,6 +45,7 @@ struct ModifierData;
 /* object_edit.c */
 void ED_operatortypes_object(void);
 void ED_keymap_object(struct wmWindowManager *wm);
 /* object_edit.c */
 void ED_operatortypes_object(void);
 void ED_keymap_object(struct wmWindowManager *wm);
+struct Object *ED_object_add_type(struct bContext *C, int type);
 
        /* send your own notifier for select! */
 void ED_base_object_select(struct Base *base, short mode);
 
        /* send your own notifier for select! */
 void ED_base_object_select(struct Base *base, short mode);
index 15ace3b02b17bdfaa250858ef9225ce4a05c5691..990d982fda273bd915cdea6cabd7e365f8881e79 100644 (file)
@@ -290,6 +290,12 @@ static Object *object_add_type(bContext *C, int type)
        return ob;
 }
 
        return ob;
 }
 
+/* for COLLADA imp/exp */
+Object *ED_object_add_type(bContext *C, int type)
+{
+       return object_add_type(C, type);
+}
+
 /* for object add operator */
 static int object_add_exec(bContext *C, wmOperator *op)
 {
 /* for object add operator */
 static int object_add_exec(bContext *C, wmOperator *op)
 {
index a08b43ab796736d50e9eb3c3db01e9fe1402c0c8..c81d3cc5602b73f776fd18fad84254d89aa36061 100644 (file)
@@ -279,6 +279,7 @@ static void info_filemenu(bContext *C, uiLayout *layout, void *arg_unused)
        // XXX: these should move
        uiItemS(layout);
        uiLayoutContext(layout, WM_OP_INVOKE_AREA);
        // XXX: these should move
        uiItemS(layout);
        uiLayoutContext(layout, WM_OP_INVOKE_AREA);
+       uiItemO(layout, NULL, 0, "WM_OT_collada_import"); 
        uiItemO(layout, NULL, 0, "WM_OT_collada_export"); 
 
 #if 0
        uiItemO(layout, NULL, 0, "WM_OT_collada_export"); 
 
 #if 0
index e9f72e1acb899b41338ea934ffe52927fc4ccb7c..a0f0615e71ae0b2b70df3345799eb9ab8e57375a 100644 (file)
@@ -634,9 +634,9 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        //WM_write_file(C, filename, op->reports);
        collada_export(CTX_data_scene(C), filename);
        
        //WM_write_file(C, filename, op->reports);
        collada_export(CTX_data_scene(C), filename);
        
-       WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL);
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
 
 
-       return 0;
+       return OPERATOR_FINISHED;
 }
 
 static void WM_OT_collada_export(wmOperatorType *ot)
 }
 
 static void WM_OT_collada_export(wmOperatorType *ot)
@@ -653,6 +653,50 @@ static void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
 }
 
        RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
 }
 
+static int wm_collada_import_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       // XXX: temporary
+       RNA_string_set(op->ptr, "filename", "/tmp/test.dae");
+       
+       WM_event_add_fileselect(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
+/* function used for WM_OT_save_mainfile too */
+static int wm_collada_import_exec(bContext *C, wmOperator *op)
+{
+       char filename[FILE_MAX];
+       
+       if(RNA_property_is_set(op->ptr, "filename"))
+               RNA_string_get(op->ptr, "filename", filename);
+       else {
+               BLI_strncpy(filename, G.sce, FILE_MAX);
+               untitled(filename);
+       }
+       
+       //WM_write_file(C, filename, op->reports);
+       collada_import(CTX_data_scene(C), filename);
+       
+       /* WM_event_add_notifier(C, NC_WM|ND_FILESAVE, NULL); */
+
+       return OPERATOR_FINISHED;
+}
+
+static void WM_OT_collada_import(wmOperatorType *ot)
+{
+       ot->name= "Collada Import";
+       ot->idname= "WM_OT_collada_import";
+       
+       ot->invoke= wm_collada_import_invoke;
+       ot->exec= wm_collada_import_exec;
+       ot->poll= WM_operator_winactive;
+       
+       ot->flag= 0;
+       
+       RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+}
+
 
 
 
 
 
 
@@ -1498,6 +1542,7 @@ void wm_operatortype_init(void)
 
        /* XXX: move these */
        WM_operatortype_append(WM_OT_collada_export);
 
        /* XXX: move these */
        WM_operatortype_append(WM_OT_collada_export);
+       WM_operatortype_append(WM_OT_collada_import);
 }
 
 /* default keymap for windows and screens, only call once per WM */
 }
 
 /* default keymap for windows and screens, only call once per WM */
index d649edbab119391744421c98c344338cdcac6e07..3368411d28670c3f5cfa76cf588175390bbe842b 100644 (file)
@@ -150,6 +150,7 @@ def setup_staticlibs(lenv):
        if lenv['WITH_BF_COLLADA']:
                libincs += Split(lenv['BF_OPENCOLLADA_LIBPATH'])
                libincs += Split(lenv['BF_PCRE_LIBPATH'])
        if lenv['WITH_BF_COLLADA']:
                libincs += Split(lenv['BF_OPENCOLLADA_LIBPATH'])
                libincs += Split(lenv['BF_PCRE_LIBPATH'])
+        libincs += Split(lenv['BF_EXPAT_LIBPATH'])
 
 
        return statlibs, libincs
 
 
        return statlibs, libincs
@@ -198,6 +199,7 @@ def setup_syslibs(lenv):
        if lenv['WITH_BF_COLLADA']:
                syslibs.append(lenv['BF_OPENCOLLADA_LIB'])
                syslibs.append(lenv['BF_PCRE_LIB'])
        if lenv['WITH_BF_COLLADA']:
                syslibs.append(lenv['BF_OPENCOLLADA_LIB'])
                syslibs.append(lenv['BF_PCRE_LIB'])
+        syslibs.append(lenv['BF_EXPAT_LIB'])
 
 
        syslibs += lenv['LLIBS']
 
 
        syslibs += lenv['LLIBS']
index d82b393d219d7e07b0545b0d7369a2f8da3d304d..d5e9110795e04a7172abeea0b1a6ff1a72f8351f 100755 (executable)
@@ -49,7 +49,7 @@ def validate_arguments(args, bc):
                        'WITH_BF_FREETYPE', 'BF_FREETYPE', 'BF_FREETYPE_INC', 'BF_FREETYPE_LIB', 'BF_FREETYPE_LIBPATH',
                        'WITH_BF_QUICKTIME', 'BF_QUICKTIME', 'BF_QUICKTIME_INC', 'BF_QUICKTIME_LIB', 'BF_QUICKTIME_LIBPATH',
                        'WITH_BF_STATICOPENGL', 'BF_OPENGL', 'BF_OPENGL_INC', 'BF_OPENGL_LIB', 'BF_OPENGL_LIBPATH', 'BF_OPENGL_LIB_STATIC',
                        'WITH_BF_FREETYPE', 'BF_FREETYPE', 'BF_FREETYPE_INC', 'BF_FREETYPE_LIB', 'BF_FREETYPE_LIBPATH',
                        'WITH_BF_QUICKTIME', 'BF_QUICKTIME', 'BF_QUICKTIME_INC', 'BF_QUICKTIME_LIB', 'BF_QUICKTIME_LIBPATH',
                        'WITH_BF_STATICOPENGL', 'BF_OPENGL', 'BF_OPENGL_INC', 'BF_OPENGL_LIB', 'BF_OPENGL_LIBPATH', 'BF_OPENGL_LIB_STATIC',
-                       'WITH_BF_COLLADA', 'BF_COLLADA', 'BF_COLLADA_INC', 'BF_COLLADA_LIB', 'BF_OPENCOLLADA', 'BF_OPENCOLLADA_LIB', 'BF_OPENCOLLADA_LIBPATH', 'BF_PCRE', 'BF_PCRE_LIB', 'BF_PCRE_LIBPATH',
+                       'WITH_BF_COLLADA', 'BF_COLLADA', 'BF_COLLADA_INC', 'BF_COLLADA_LIB', 'BF_OPENCOLLADA', 'BF_OPENCOLLADA_LIB', 'BF_OPENCOLLADA_LIBPATH', 'BF_PCRE', 'BF_PCRE_LIB', 'BF_PCRE_LIBPATH', 'BF_EXPAT', 'BF_EXPAT_LIB', 'BF_EXPAT_LIBPATH',
                        'WITH_BF_PLAYER',
                        'WITH_BF_NOBLENDER',
                        'WITH_BF_BINRELOC',
                        'WITH_BF_PLAYER',
                        'WITH_BF_NOBLENDER',
                        'WITH_BF_BINRELOC',
@@ -319,6 +319,9 @@ def read_opts(cfg, args):
                ('BF_PCRE', 'PCRE base path', ''),
                ('BF_PCRE_LIB', 'PCRE library', ''),
                ('BF_PCRE_LIBPATH', 'PCRE library path', ''),
                ('BF_PCRE', 'PCRE base path', ''),
                ('BF_PCRE_LIB', 'PCRE library', ''),
                ('BF_PCRE_LIBPATH', 'PCRE library path', ''),
+        ('BF_EXPAT', 'Expat base path', ''),
+               ('BF_EXPAT_LIB', 'Expat library', ''),
+               ('BF_EXPAT_LIBPATH', 'Expat library path', ''),
                
                (BoolVariable('WITH_BF_PLAYER', 'Build blenderplayer if true', False)),
                (BoolVariable('WITH_BF_NOBLENDER', 'Do not build blender if true', False)),
                
                (BoolVariable('WITH_BF_PLAYER', 'Build blenderplayer if true', False)),
                (BoolVariable('WITH_BF_NOBLENDER', 'Do not build blender if true', False)),