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
path: root/source
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2013-02-09 20:19:30 +0400
committerGaia Clary <gaia.clary@machinimatrix.org>2013-02-09 20:19:30 +0400
commitf34d1d55850cd82fbae843ffafa7115dab0e0eeb (patch)
treef01c7b58dc5a66639d4e554ba206e1752d4fada8 /source
parent555bcc3298a564cb678c9f31ba6bded86d58bab6 (diff)
[#33437](partial fix) Collada: importing a scene changes units. Added an option to disable unit settings during import.
Diffstat (limited to 'source')
-rw-r--r--source/blender/collada/CMakeLists.txt2
-rw-r--r--source/blender/collada/DocumentImporter.cpp47
-rw-r--r--source/blender/collada/DocumentImporter.h5
-rw-r--r--source/blender/collada/ImportSettings.cpp27
-rw-r--r--source/blender/collada/ImportSettings.h39
-rw-r--r--source/blender/collada/collada.cpp13
-rw-r--r--source/blender/collada/collada.h5
-rw-r--r--source/blender/editors/io/io_collada.c44
8 files changed, 157 insertions, 25 deletions
diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt
index 7f389346a81..326ca2b9937 100644
--- a/source/blender/collada/CMakeLists.txt
+++ b/source/blender/collada/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC
EffectExporter.cpp
ErrorHandler.cpp
ExportSettings.cpp
+ ImportSettings.cpp
ExtraHandler.cpp
ExtraTags.cpp
GeometryExporter.cpp
@@ -84,6 +85,7 @@ set(SRC
EffectExporter.h
ErrorHandler.h
ExportSettings.h
+ ImportSettings.h
ExtraHandler.h
ExtraTags.h
GeometryExporter.h
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index a234d85bc6f..7437401ed09 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -99,9 +99,9 @@ extern "C" {
// 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 @@ bool DocumentImporter::import()
// 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 @@ void DocumentImporter::finish()
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);
+
+ }
+ else {
+ // TODO: add automatic scaling for the case when Blender units
+ // and import units are set to different values.
}
- RNA_property_float_set(&unit_settings, scale, unit_converter.getLinearMeter());
-
- const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
+ // 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 @@ 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();
- 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];
diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h
index 7e3476fb7e0..76d16f38a0c 100644
--- a/source/blender/collada/DocumentImporter.h
+++ b/source/blender/collada/DocumentImporter.h
@@ -47,6 +47,7 @@
#include "ArmatureImporter.h"
#include "ControllerExporter.h"
#include "MeshImporter.h"
+#include "ImportSettings.h"
@@ -63,7 +64,7 @@ public:
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 @@ public:
private:
+ const ImportSettings *import_settings;
/** Current import stage we're in. */
ImportStage mImportStage;
- std::string mFilename;
bContext *mContext;
diff --git a/source/blender/collada/ImportSettings.cpp b/source/blender/collada/ImportSettings.cpp
new file mode 100644
index 00000000000..74607787f25
--- /dev/null
+++ b/source/blender/collada/ImportSettings.cpp
@@ -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"
diff --git a/source/blender/collada/ImportSettings.h b/source/blender/collada/ImportSettings.h
new file mode 100644
index 00000000000..3f3a9fb354e
--- /dev/null
+++ b/source/blender/collada/ImportSettings.h
@@ -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
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index ef34c55bbe6..1aff0f166ba 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -31,6 +31,7 @@
#include "DocumentExporter.h"
#include "DocumentImporter.h"
#include "ExportSettings.h"
+#include "ImportSettings.h"
extern "C"
{
@@ -42,9 +43,17 @@ extern "C"
#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;
diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h
index a02e3e007ae..587dc37b7db 100644
--- a/source/blender/collada/collada.h
+++ b/source/blender/collada/collada.h
@@ -46,7 +46,10 @@ struct Scene;
/*
* 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,
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index f53672b7092..0982b4f034e 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -308,18 +308,47 @@ void WM_OT_collada_export(wmOperatorType *ot)
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;
}
- RNA_string_get(op->ptr, "filepath", filename);
- if (collada_import(C, filename)) return OPERATOR_FINISHED;
+ /* Options panel */
+ import_units = RNA_boolean_get(op->ptr, "import_units");
+ RNA_string_get(op->ptr, "filepath", filename);
+ 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;
+ }
+}
+
+static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
+{
+ uiLayout *box, *row;
+
+ /* Import Options: */
+ box = uiLayoutBox(layout);
+ row = uiLayoutRow(box, FALSE);
+ uiItemL(row, IFACE_("Import Data Options:"), ICON_MESH_DATA);
- return OPERATOR_FINISHED;
+ row = uiLayoutRow(box, FALSE);
+ uiItemR(row, imfptr, "import_units", 0, NULL, ICON_NONE);
+}
+
+static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
+{
+ PointerRNA ptr;
+
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+ uiCollada_importSettings(op->layout, &ptr);
}
void WM_OT_collada_import(wmOperatorType *ot)
@@ -332,7 +361,16 @@ void WM_OT_collada_import(wmOperatorType *ot)
ot->exec = wm_collada_import_exec;
ot->poll = WM_operator_winactive;
+ //ot->flag |= OPTYPE_PRESET;
+
+ ot->ui = wm_collada_import_draw;
+
WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_OPENFILE,
WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
+
+ RNA_def_boolean(ot->srna,
+ "import_units", 0, "Import Units",
+ "If enabled use Units as defined in Collada Import, else keep Blender's current Units settings. ");
+
}
#endif