[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47904] branches/soc-2012-bratwurst/source /blender/assimp: - bf_assimp: proper coordinate space conversion.
Alexander Gessler
alexander.gessler at gmx.net
Thu Jun 14 16:43:44 CEST 2012
Revision: 47904
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47904
Author: aramis_acg
Date: 2012-06-14 14:43:37 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
- bf_assimp: proper coordinate space conversion. Output scenes will now use Blender's coordinate system (even though the conversion is so far only applied to the root transform).
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt
branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
Added Paths:
-----------
branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.cpp
branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.h
Modified: branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt 2012-06-14 14:19:05 UTC (rev 47903)
+++ branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt 2012-06-14 14:43:37 UTC (rev 47904)
@@ -60,6 +60,9 @@
ImageImporter.cpp
ImageImporter.h
+
+ SceneOrientation.cpp
+ SceneOrientation.h
)
if(WITH_BUILDINFO)
Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp 2012-06-14 14:19:05 UTC (rev 47903)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp 2012-06-14 14:43:37 UTC (rev 47904)
@@ -31,6 +31,7 @@
#include "SceneImporter.h"
#include "MeshImporter.h"
#include "MaterialImporter.h"
+#include "SceneOrientation.h"
#include "bassimp_internal.h"
@@ -124,6 +125,9 @@
return false;
}
+ handle_coordinate_space();
+ handle_scale();
+
convert_materials();
const aiNode* nd = scene->mRootNode;
@@ -134,6 +138,27 @@
}
+void SceneImporter::handle_scale()
+{
+ // XXX make this configurable
+}
+
+
+void SceneImporter::handle_coordinate_space()
+{
+ // note: the const_cast is definitely a hack to avoid creating a copy
+ // of the assimp scene. Assimp does not allow manipulating its
+ // data structure (for good reasons) - scaling and rotating, however,
+ // just changes a few float values and is thus totally safe.
+ SceneRotator rot = SceneRotator(const_cast<aiScene*>(scene));
+
+ // blender uses right-handed z-up, y-into-screen coordinate system,
+ // assimp uses right-handled z-out-of-screen, z-up. All we need to
+ // do is a 90 degrees rotation around x.
+ rot.rotate_90deg_xpositive();
+}
+
+
void SceneImporter::convert_materials()
{
materials.resize(scene->mNumMaterials);
Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-06-14 14:19:05 UTC (rev 47903)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-06-14 14:43:37 UTC (rev 47904)
@@ -57,6 +57,9 @@
Object* convert_camera(const aiCamera& cam) const;
Object* convert_mesh(const std::vector<const aiMesh*>& in_meshes, const char* name) const;
+ void handle_scale();
+ void handle_coordinate_space();
+
public:
SceneImporter(const char* path, bContext *C);
Added: branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.cpp (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.cpp 2012-06-14 14:43:37 UTC (rev 47904)
@@ -0,0 +1,101 @@
+/*
+ * ***** 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): Alexander Gessler
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/assimp/SceneImporter.cpp
+ * \ingroup assimp
+ */
+
+#include <cassert>
+#include <math.h>
+
+#include "SceneOrientation.h"
+
+
+namespace bassimp {
+
+ using namespace Assimp;
+
+
+SceneScaler::SceneScaler(aiScene* sc)
+ : sc(sc)
+ , deepScale()
+{
+
+}
+
+
+void SceneScaler::use_deep_scaling(bool doit)
+{
+ deepScale = doit;
+}
+
+
+void SceneScaler::scale(float s)
+{
+ assert(fabs(s) > 1e-7f && "zero scaling specified");
+ assert(s > 0.0f && "negative scaling specified");
+ assert(!deepScale && "deepScale not yet implemented");
+
+ aiMatrix4x4& m = sc->mRootNode->mTransformation;
+ m.a1 *= s;
+ m.a2 *= s;
+ m.a3 *= s;
+
+ m.b1 *= s;
+ m.b2 *= s;
+ m.b3 *= s;
+
+ m.c1 *= s;
+ m.c2 *= s;
+ m.c3 *= s;
+
+ m.d1 *= s;
+ m.d2 *= s;
+ m.d3 *= s;
+}
+
+
+SceneRotator::SceneRotator(aiScene* sc)
+: sc(sc)
+, deepRotate()
+{
+
+}
+
+
+void SceneRotator::use_deep_rotation(bool doit)
+{
+ deepRotate = doit;
+}
+
+
+void SceneRotator::rotate_90deg_xpositive()
+{
+ assert(!deepRotate && "deepRotate not yet implemented");
+
+ aiMatrix4x4 rot;
+ aiMatrix4x4::RotationX(AI_MATH_HALF_PI,rot);
+ sc->mRootNode->mTransformation = sc->mRootNode->mTransformation * rot;
+}
+
+
+}
Added: branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.h (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneOrientation.h 2012-06-14 14:43:37 UTC (rev 47904)
@@ -0,0 +1,88 @@
+/*
+ * ***** 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): Alexander Gessler.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file SceneOrientation.h
+ * \ingroup assimp
+ */
+
+#ifndef INCLUDED_SCENE_ORIENTATION_H
+#define INCLUDED_SCENE_ORIENTATION_H
+
+#include "bassimp_shared.h"
+
+namespace bassimp {
+
+ // utility class to apply uniform scalings to the imported assimp scene.
+ // All scaling is done in-place.
+ class SceneScaler
+ {
+ private:
+
+ aiScene* sc;
+ bool deepScale;
+
+ public:
+ SceneScaler(aiScene* sc);
+
+ public:
+
+ // enabling deep scale means that the scaling operation will
+ // be applied recursively to the entire scene and not just
+ // embedded in the root node.
+ void use_deep_scaling(bool doit);
+
+ // apply a specific relative scaling to the scene. This function
+ // can be invoked multiple times on a scene.
+ void scale(float s);
+ };
+
+
+ // utility class to rotate imported assimp scenes. This is needed
+ // to transform them to Blender's internal coordinate space.
+ // All rotations are done in-place.
+ class SceneRotator
+ {
+ private:
+
+ aiScene* sc;
+ bool deepRotate;
+
+ public:
+
+ SceneRotator(aiScene* sc);
+
+ public:
+
+ // enabling deep rotate means that the rotation operation will
+ // be applied recursively to the entire scene and not just
+ // embedded in the root node.
+ void use_deep_rotation(bool doit);
+
+ // rotate the scene by 90 degrees on the x-axis. This is
+ // hard-coded to this angle in order to avoid precision
+ // issues.
+ void rotate_90deg_xpositive();
+ };
+}
+
+#endif
+
More information about the Bf-blender-cvs
mailing list