Revision: 47927
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47927
Author:   aramis_acg
Date:     2012-06-14 23:41:07 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
- bf_assimp: blender now reads the list of supported file extensions directly 
from assimp.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h
    branches/soc-2012-bratwurst/source/blender/editors/space_file/CMakeLists.txt
    branches/soc-2012-bratwurst/source/blender/editors/space_file/filelist.c
    branches/soc-2012-bratwurst/source/blender/imbuf/IMB_imbuf_types.h
    branches/soc-2012-bratwurst/source/blender/imbuf/intern/util.c

Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp       
2012-06-14 22:51:34 UTC (rev 47926)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp       
2012-06-14 23:41:07 UTC (rev 47927)
@@ -26,6 +26,11 @@
 
 #include "SceneImporter.h"
 
+namespace {
+#define MAX_ASSIMP_EXT_TOTAL_LENGTH 512
+       char cached_extensions[MAX_ASSIMP_EXT_TOTAL_LENGTH] = {0};
+}
+
 extern "C"
 {
 #include "BKE_scene.h"
@@ -35,6 +40,46 @@
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
 
+       void bassimp_query_import_file_extensions(const char* out[], int dim)
+       {
+               // XXX: this is a very inconvenient solution (and its not 
re-entrant either).
+               // the problem is that we should return static strings to 
Blender, but 
+               // we can't get take them directly from assimp.
+
+               Assimp::Importer importer;
+
+               aiString ext;
+               importer.GetExtensionList(ext);
+
+               char* buff_cursor = cached_extensions, *buff_end = 
cached_extensions + MAX_ASSIMP_EXT_TOTAL_LENGTH - 1;
+
+               int cnt = 0;
+               bool done = false;
+               for(const char* sz = ext.data, *last = sz+1 /* skip the '*' */; 
!done; ++sz)
+               {
+                       done = !(*sz);
+                       if (*sz == ';' || done) {
+                               const size_t len = static_cast<size_t>(sz-last);
+                               if (buff_cursor + len > buff_end) {
+                                       return;
+                               }
+
+                               memcpy(buff_cursor,last,len);
+                               buff_cursor[len] = '\0';
+
+                               out[cnt++] = buff_cursor;
+
+                               buff_cursor += len+1;
+                               last = sz+2;
+
+                               if(cnt == dim) {
+                                       return;
+                               }
+                       }
+               }
+       }
+
+
        int bassimp_import(bContext *C, const char *filepath)
        {
                bassimp::SceneImporter imp(filepath,C);

Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h 2012-06-14 
22:51:34 UTC (rev 47926)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h 2012-06-14 
23:41:07 UTC (rev 47927)
@@ -33,7 +33,15 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-       /*
+
+       /* list all import file extensions recognized by assimp.
+        * entries should follow the format '.aaa'
+        *  'out' array should be of size dim+1
+        */
+       void bassimp_query_import_file_extensions(const char* out[], int dim);
+
+
+       /* import/export functions
         * both return 1 on success, 0 on error
         */
        int bassimp_import(bContext *C, const char *filepath);

Modified: 
branches/soc-2012-bratwurst/source/blender/editors/space_file/CMakeLists.txt
===================================================================
--- 
branches/soc-2012-bratwurst/source/blender/editors/space_file/CMakeLists.txt    
    2012-06-14 22:51:34 UTC (rev 47926)
+++ 
branches/soc-2012-bratwurst/source/blender/editors/space_file/CMakeLists.txt    
    2012-06-14 23:41:07 UTC (rev 47927)
@@ -78,6 +78,10 @@
        add_definitions(-DWITH_HDR)
 endif()
 
+if(WITH_ASSIMP)
+       add_definitions(-DWITH_ASSIMP)
+endif()
+
 if(WITH_INTERNATIONAL)
        add_definitions(-DWITH_INTERNATIONAL)
 endif()

Modified: 
branches/soc-2012-bratwurst/source/blender/editors/space_file/filelist.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/space_file/filelist.c    
2012-06-14 22:51:34 UTC (rev 47926)
+++ branches/soc-2012-bratwurst/source/blender/editors/space_file/filelist.c    
2012-06-14 23:41:07 UTC (rev 47927)
@@ -80,6 +80,11 @@
 
 #include "filelist.h"
 
+
+#ifdef WITH_ASSIMP
+#      include "../../assimp/bassimp.h"
+#endif
+
 /* max length of library group name within filesel */
 #define GROUP_MAX 32
 
@@ -796,9 +801,21 @@
        else if (BLI_testextensie_array(relname, imb_ext_audio)) {
                return SOUNDFILE;
        } 
-       else if (BLI_testextensie_array(relname, imb_ext_assimp)) {
-               return ASSIMPFILE;
+
+#ifdef WITH_ASSIMP
+       else {
+               
+               // query list of file extensions from assimp
+               if (imb_ext_assimp[0] == NULL) {
+                       
bassimp_query_import_file_extensions(imb_ext_assimp,MAX_ASSIMP_EXT);
+               }
+               
+               if (BLI_testextensie_array(relname, imb_ext_assimp)) {
+                       return ASSIMPFILE;
+               }
        }
+#endif
+
        return 0;
 }
 

Modified: branches/soc-2012-bratwurst/source/blender/imbuf/IMB_imbuf_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/imbuf/IMB_imbuf_types.h  
2012-06-14 22:51:34 UTC (rev 47926)
+++ branches/soc-2012-bratwurst/source/blender/imbuf/IMB_imbuf_types.h  
2012-06-14 23:41:07 UTC (rev 47927)
@@ -219,6 +219,8 @@
 extern const char *imb_ext_image_qt[];
 extern const char *imb_ext_movie[];
 extern const char *imb_ext_audio[];
+
+#define MAX_ASSIMP_EXT 64
 extern const char *imb_ext_assimp[];
 
 #endif

Modified: branches/soc-2012-bratwurst/source/blender/imbuf/intern/util.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/imbuf/intern/util.c      
2012-06-14 22:51:34 UTC (rev 47926)
+++ branches/soc-2012-bratwurst/source/blender/imbuf/intern/util.c      
2012-06-14 23:41:07 UTC (rev 47927)
@@ -151,16 +151,11 @@
        NULL
 };
 
-// XXX: get list from assimp
-const char *imb_ext_assimp[] = {
-       ".3ds",
-       ".obj",
-       ".ms3d",
-       ".x",
-       ".lwo",
-       NULL
-};
+// the actual list will be pulled from assimp at runtime
+// if Blender is built without assimp, this is just a dummy
+const char *imb_ext_assimp[MAX_ASSIMP_EXT+1] = {0};
 
+
 static int IMB_ispic_name(const char *name)
 {
        ImFileType *type;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to