[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54411] trunk/blender/source/blender: [ #33437](partial fix) Collada: importing a scene changes units.
Gaia Clary
gaia.clary at machinimatrix.org
Sat Feb 9 17:19:31 CET 2013
Revision: 54411
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54411
Author: gaiaclary
Date: 2013-02-09 16:19:30 +0000 (Sat, 09 Feb 2013)
Log Message:
-----------
[#33437](partial fix) Collada: importing a scene changes units. Added an option to disable unit settings during import.
Modified Paths:
--------------
trunk/blender/source/blender/collada/CMakeLists.txt
trunk/blender/source/blender/collada/DocumentImporter.cpp
trunk/blender/source/blender/collada/DocumentImporter.h
trunk/blender/source/blender/collada/collada.cpp
trunk/blender/source/blender/collada/collada.h
trunk/blender/source/blender/editors/io/io_collada.c
Added Paths:
-----------
trunk/blender/source/blender/collada/ImportSettings.cpp
trunk/blender/source/blender/collada/ImportSettings.h
Modified: trunk/blender/source/blender/collada/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/collada/CMakeLists.txt 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/collada/CMakeLists.txt 2013-02-09 16:19:30 UTC (rev 54411)
@@ -57,6 +57,7 @@
EffectExporter.cpp
ErrorHandler.cpp
ExportSettings.cpp
+ ImportSettings.cpp
ExtraHandler.cpp
ExtraTags.cpp
GeometryExporter.cpp
@@ -84,6 +85,7 @@
EffectExporter.h
ErrorHandler.h
ExportSettings.h
+ ImportSettings.h
ExtraHandler.h
ExtraTags.h
GeometryExporter.h
Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp 2013-02-09 16:19:30 UTC (rev 54411)
@@ -99,9 +99,9 @@
// creates empties for each imported bone on layer 2, for debugging
// #define ARMATURE_TEST
-DocumentImporter::DocumentImporter(bContext *C, const char *filename) :
+DocumentImporter::DocumentImporter(bContext *C, const ImportSettings *import_settings) :
+ import_settings(import_settings),
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)),
@@ -131,6 +131,7 @@
// deselect all to select new objects
BKE_scene_base_deselect_all(CTX_data_scene(mContext));
+ std::string mFilename = std::string(this->import_settings->filepath);
const std::string encodedFilename = bc_url_encode(mFilename);
if (!root.loadDocument(encodedFilename)) {
fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n");
@@ -188,30 +189,42 @@
Scene *sce = CTX_data_scene(mContext);
// for scene unit settings: system, scale_length
+
RNA_id_pointer_create(&sce->id, &sceneptr);
unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
system = RNA_struct_find_property(&unit_settings, "system");
scale = RNA_struct_find_property(&unit_settings, "scale_length");
-
- switch (unit_converter.isMetricSystem()) {
- case UnitConverter::Metric:
- RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
- break;
- case UnitConverter::Imperial:
- RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
- break;
- default:
- RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
- break;
+
+ if (this->import_settings->import_units) {
+
+ switch (unit_converter.isMetricSystem()) {
+ case UnitConverter::Metric:
+ RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
+ break;
+ case UnitConverter::Imperial:
+ RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
+ break;
+ default:
+ RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
+ break;
+ }
+ float unit_factor = unit_converter.getLinearMeter();
+ RNA_property_float_set(&unit_settings, scale, unit_factor);
+ fprintf(stdout, "Collada: Adjusting Blender units to Importset units: %f.\n", unit_factor);
+
}
- RNA_property_float_set(&unit_settings, scale, unit_converter.getLinearMeter());
-
+ else {
+ // TODO: add automatic scaling for the case when Blender units
+ // and import units are set to different values.
+ }
+
+ // Write nodes to scene
const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
-
for (unsigned int i = 0; i < roots.getCount(); i++) {
write_node(roots[i], NULL, sce, NULL, false);
}
+ // update scene
Main *bmain = CTX_data_main(mContext);
DAG_scene_sort(bmain, sce);
DAG_ids_flush_update(bmain, 0);
@@ -974,7 +987,7 @@
// 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();
+ const char *filename = (const char *)filepath.c_str();
char dir[FILE_MAX];
char full_path[FILE_MAX];
Modified: trunk/blender/source/blender/collada/DocumentImporter.h
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.h 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/collada/DocumentImporter.h 2013-02-09 16:19:30 UTC (rev 54411)
@@ -47,6 +47,7 @@
#include "ArmatureImporter.h"
#include "ControllerExporter.h"
#include "MeshImporter.h"
+#include "ImportSettings.h"
@@ -63,7 +64,7 @@
Controller, //!< Second pass to collect controller data
};
/** Constructor */
- DocumentImporter(bContext *C, const char *filename);
+ DocumentImporter(bContext *C, const ImportSettings *import_settings);
/** Destructor */
~DocumentImporter();
@@ -137,10 +138,10 @@
private:
+ const ImportSettings *import_settings;
/** Current import stage we're in. */
ImportStage mImportStage;
- std::string mFilename;
bContext *mContext;
Added: trunk/blender/source/blender/collada/ImportSettings.cpp
===================================================================
--- trunk/blender/source/blender/collada/ImportSettings.cpp (rev 0)
+++ trunk/blender/source/blender/collada/ImportSettings.cpp 2013-02-09 16:19:30 UTC (rev 54411)
@@ -0,0 +1,27 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Gaia Clary.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/collada/ExportSettings.cpp
+ * \ingroup collada
+ */
+
+#include "ImportSettings.h"
Added: trunk/blender/source/blender/collada/ImportSettings.h
===================================================================
--- trunk/blender/source/blender/collada/ImportSettings.h (rev 0)
+++ trunk/blender/source/blender/collada/ImportSettings.h 2013-02-09 16:19:30 UTC (rev 54411)
@@ -0,0 +1,39 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Gaia Clary
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ExportSettings.h
+ * \ingroup collada
+ */
+
+#ifndef __IMPORTSETTINGS_H__
+#define __IMPORTSETTINGS_H__
+
+#include "collada.h"
+
+struct ImportSettings {
+public:
+ bool import_units;
+
+ char *filepath;
+};
+
+#endif
Modified: trunk/blender/source/blender/collada/collada.cpp
===================================================================
--- trunk/blender/source/blender/collada/collada.cpp 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/collada/collada.cpp 2013-02-09 16:19:30 UTC (rev 54411)
@@ -31,6 +31,7 @@
#include "DocumentExporter.h"
#include "DocumentImporter.h"
#include "ExportSettings.h"
+#include "ImportSettings.h"
extern "C"
{
@@ -42,9 +43,17 @@
#include "BLI_path_util.h"
#include "BLI_linklist.h"
-int collada_import(bContext *C, const char *filepath)
+int collada_import(bContext *C,
+ const char *filepath,
+ int import_units)
{
- DocumentImporter imp(C, filepath);
+
+ ImportSettings import_settings;
+ import_settings.filepath = (char *)filepath;
+
+ import_settings.import_units = import_units != 0;
+
+ DocumentImporter imp(C, &import_settings);
if (imp.import()) return 1;
return 0;
Modified: trunk/blender/source/blender/collada/collada.h
===================================================================
--- trunk/blender/source/blender/collada/collada.h 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/collada/collada.h 2013-02-09 16:19:30 UTC (rev 54411)
@@ -46,7 +46,10 @@
/*
* both return 1 on success, 0 on error
*/
-int collada_import(bContext *C, const char *filepath);
+int collada_import(bContext *C,
+ const char *filepath,
+ int import_units);
+
int collada_export(Scene *sce,
const char *filepath,
int apply_modifiers,
Modified: trunk/blender/source/blender/editors/io/io_collada.c
===================================================================
--- trunk/blender/source/blender/editors/io/io_collada.c 2013-02-09 15:49:20 UTC (rev 54410)
+++ trunk/blender/source/blender/editors/io/io_collada.c 2013-02-09 16:19:30 UTC (rev 54411)
@@ -308,20 +308,49 @@
static int wm_collada_import_exec(bContext *C, wmOperator *op)
{
char filename[FILE_MAX];
+ int import_units;
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
return OPERATOR_CANCELLED;
}
+ /* Options panel */
+ import_units = RNA_boolean_get(op->ptr, "import_units");
+
RNA_string_get(op->ptr, "filepath", filename);
- if (collada_import(C, filename)) return OPERATOR_FINISHED;
-
+ if (collada_import( C,
+ filename,
+ import_units)) {
+ return OPERATOR_FINISHED;
+ }
+ else {
BKE_report(op->reports, RPT_ERROR, "Errors found during parsing COLLADA document (see console for details)");
+ return OPERATOR_CANCELLED;
+ }
+}
- return OPERATOR_FINISHED;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list