[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48727] branches/soc-2012-bratwurst/source /blender: - bf_assimp: add settings parameter to bassimp_import().
Alexander Gessler
alexander.gessler at gmx.net
Sun Jul 8 16:10:30 CEST 2012
Revision: 48727
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48727
Author: aramis_acg
Date: 2012-07-08 14:10:29 +0000 (Sun, 08 Jul 2012)
Log Message:
-----------
- bf_assimp: add settings parameter to bassimp_import(). Settings include a reportlist to report to plus some assimp-specific stuff (triangulation, unit scaling etc) . Not all settings are implemented yet and they are also not yet offered in the GUI.
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h
branches/soc-2012-bratwurst/source/blender/fbx/bfbx.cpp
branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c
Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp 2012-07-08 14:10:29 UTC (rev 48727)
@@ -49,6 +49,7 @@
#include "BKE_mesh.h"
#include "BKE_library.h"
#include "BKE_context.h"
+#include "BKE_report.h"
}
@@ -58,12 +59,13 @@
using namespace Assimp;
-SceneImporter::SceneImporter(const char* path, bContext& C)
+SceneImporter::SceneImporter(const char* path, bContext& C, const bassimp_import_settings& settings)
: path(path)
, C(C)
, scene()
, out_scene(CTX_data_scene(&C))
, armature()
+, settings(settings)
{
}
@@ -84,13 +86,19 @@
void SceneImporter::error(const char* what) const
{
- std::cerr << "bassimp error: " << what << std::endl;
+ if(!settings.reports) {
+ return;
+ }
+ BKE_reportf(settings.reports,RPT_ERROR,"bassimp error: %s",what);
}
void SceneImporter::verbose(const char* what) const
{
- std::cout << "bassimp verbose: " << what << std::endl;
+ if(!settings.reports) {
+ return;
+ }
+ BKE_reportf(settings.reports,RPT_INFO,"bassimp verbose: %s",what);
}
@@ -100,15 +108,49 @@
}
+const bassimp_import_settings& SceneImporter::get_settings() const
+{
+ return settings;
+}
+
+
+void SceneImporter::configure_importer()
+{
+ if (settings.nolines) {
+ importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,aiPrimitiveType_LINE | aiPrimitiveType_POINT);
+ }
+
+ // do not generate skeleton meshes, Blender's armature viz does the same job much better
+ importer.SetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES,1);
+}
+
+
unsigned int SceneImporter::get_assimp_flags() const
{
- return aiProcess_JoinIdenticalVertices;
+ unsigned int flags = aiProcess_JoinIdenticalVertices;
+
+ if (settings.nolines) {
+ flags |= aiProcess_SortByPType;
+
+ }
+
+ if (settings.triangulate) {
+ flags |= aiProcess_Triangulate;
+ }
+
+#ifdef _DEBUG
+ flags |= aiProcess_ValidateDataStructure;
+#endif
+
+ return flags;
}
bool SceneImporter::import()
{
const unsigned int postprocessing_flags = get_assimp_flags();
+ configure_importer();
+
if(!importer.ReadFile(path, postprocessing_flags)) {
error(("failed to import file, assimp error message is\'" + std::string(importer.GetErrorString()) + "\'").c_str());
@@ -116,7 +158,7 @@
return false;
}
- verbose("import successful");
+ verbose((std::string("assimp import successful: ") + get_file_path()).c_str());
scene = importer.GetScene();
return true;
}
Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-07-08 14:10:29 UTC (rev 48727)
@@ -27,7 +27,8 @@
#ifndef INCLUDED_SCENE_IMPORTER_H
#define INCLUDED_SCENE_IMPORTER_H
-#include "bassimp_shared.h"
+#include "bassimp_shared.h"
+#include "bassimp.h"
#include <set>
#include <map>
@@ -70,8 +71,11 @@
typedef std::map<Object*, MeshVector> ObjectToMeshMap;
ObjectToMeshMap meshes_by_object;
+ const bassimp_import_settings settings;
+
private:
+ void configure_importer();
unsigned int get_assimp_flags() const;
void convert_materials();
@@ -94,7 +98,7 @@
public:
- SceneImporter(const char* path, bContext& C);
+ SceneImporter(const char* path, bContext& C, const bassimp_import_settings& settings);
~SceneImporter();
bool import();
@@ -104,6 +108,7 @@
void error(const char* what) const;
void verbose(const char* what) const;
+ const bassimp_import_settings& get_settings() const;
const char* get_file_path() const;
const MaterialImporter& get_material(unsigned int idx) const;
Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp 2012-07-08 14:10:29 UTC (rev 48727)
@@ -84,12 +84,21 @@
}
- int bassimp_import(bContext *C, const char *filepath)
+ int bassimp_import(bContext *C, const char *filepath, const bassimp_import_settings* settings)
{
assert(C);
assert(filepath);
- bassimp::SceneImporter imp(filepath,*C);
+ bassimp_import_settings defaults;
+ if (!settings) {
+ defaults.enableAssimpLog = 0;
+ defaults.reports = NULL;
+ defaults.nolines = 0;
+ defaults.triangulate = 0;
+ settings = &defaults;
+ }
+
+ bassimp::SceneImporter imp(filepath,*C,*settings);
return imp.import() != 0 && imp.apply() != 0;
}
Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp.h 2012-07-08 14:10:29 UTC (rev 48727)
@@ -29,6 +29,7 @@
struct bContext;
struct Scene;
+struct ReportList;
#ifdef __cplusplus
extern "C" {
@@ -41,10 +42,38 @@
void bassimp_query_import_file_extensions(const char* out[], int dim);
- /* import/export functions
- * both return 1 on success, 0 on error
+ /* assimp import settings */
+ typedef struct bassimp_import_settings
+ {
+ /* reportlist to write reports to or NULL for silent mode */
+ ReportList* reports;
+
+ /* enable (1) or disable (0) assimp's own logging.
+ * This only works if a non-NULL ReportList is given */
+ int enableAssimpLog;
+
+ /* run assimp's triangulation postprocessor on imported meshes */
+ int triangulate;
+
+ /* drop line and point meshes - in many cases these are
+ * artifacts and have no further use*/
+ int nolines;
+
+ /* scale input scene to fit into (-maximum_size,maximum_size) cube*/
+ int unit_scaling;
+
+ /* if unit_scaling is on (1), this specifies the size to which
+ * the scene is scaled to */
+ float maximum_size;
+
+ } bassimp_import_settings;
+
+
+
+ /* import a scene using assimp. settings are optional.
+ * returns 1 on success, 0 on error
*/
- int bassimp_import(bContext *C, const char *filepath);
+ int bassimp_import(bContext *C, const char *filepath, const bassimp_import_settings* settings);
//int bassimp_export(Scene *sce, const char *filepath, int selected, int apply_modifiers);
#ifdef __cplusplus
}
Modified: branches/soc-2012-bratwurst/source/blender/fbx/bfbx.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/fbx/bfbx.cpp 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/fbx/bfbx.cpp 2012-07-08 14:10:29 UTC (rev 48727)
@@ -41,7 +41,13 @@
assert(C);
assert(filepath);
- bassimp::SceneImporter imp(filepath,*C);
+ bassimp_import_settings defaults;
+ defaults.enableAssimpLog = 0;
+ defaults.reports = NULL;
+ defaults.nolines = 0;
+ defaults.triangulate = 0;
+
+ bassimp::SceneImporter imp(filepath,*C,defaults);
return imp.import() != 0 && imp.apply() != 0;
}
Modified: branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c 2012-07-08 13:03:09 UTC (rev 48726)
+++ branches/soc-2012-bratwurst/source/blender/windowmanager/intern/wm_operators.c 2012-07-08 14:10:29 UTC (rev 48727)
@@ -2166,6 +2166,7 @@
/* function used for WM_OT_save_mainfile too */
static int wm_assimp_import_exec(bContext *C, wmOperator *op)
{
+ bassimp_import_settings settings;
char filename[FILE_MAX];
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -2174,10 +2175,17 @@
}
RNA_string_get(op->ptr, "filepath", filename);
- if (bassimp_import(C, filename)) return OPERATOR_FINISHED;
- BKE_report(op->reports, RPT_ERROR, "Errors found during importing. Please see console for error log.");
+ settings.reports = op->reports;
+ settings.triangulate = 0;
+ settings.nolines = 0;
+ settings.enableAssimpLog = 1;
+ if (bassimp_import(C, filename, &settings)) {
+ return OPERATOR_FINISHED;
+ }
+
+ BKE_report(op->reports, RPT_ERROR, "Errors found during importing");
return OPERATOR_FINISHED;
}
More information about the Bf-blender-cvs
mailing list