[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48101] branches/soc-2012-bratwurst/source /blender/assimp: - bf_assimp: import skinning data / deform groups.
Alexander Gessler
alexander.gessler at gmx.net
Wed Jun 20 01:24:32 CEST 2012
Revision: 48101
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48101
Author: aramis_acg
Date: 2012-06-19 23:24:27 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------
- bf_assimp: import skinning data / deform groups. Some more file-tuning and fixes will follow, but feature-wise this makes anim import via assimp complete.
- bf_assimp: refactor for const-correctness and add some more assertions to check inputs.
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
branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
branches/soc-2012-bratwurst/source/blender/assimp/bassimp_internal.cpp
Added Paths:
-----------
branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.cpp
branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.h
Modified: branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt 2012-06-19 23:08:16 UTC (rev 48100)
+++ branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt 2012-06-19 23:24:27 UTC (rev 48101)
@@ -72,6 +72,9 @@
AnimEvaluator.cpp
AnimEvaluator.h
+
+ SkinImporter.cpp
+ SkinImporter.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-19 23:08:16 UTC (rev 48100)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp 2012-06-19 23:24:27 UTC (rev 48101)
@@ -34,6 +34,7 @@
#include "SceneOrientation.h"
#include "ArmatureImporter.h"
#include "AnimationImporter.h"
+#include "SkinImporter.h"
#include "bassimp_internal.h"
@@ -57,11 +58,11 @@
using namespace Assimp;
-SceneImporter::SceneImporter(const char* path, bContext *C)
+SceneImporter::SceneImporter(const char* path, bContext& C)
: path(path)
, C(C)
, scene()
-, out_scene(CTX_data_scene(C))
+, out_scene(CTX_data_scene(&C))
, armature()
{
}
@@ -115,8 +116,7 @@
return false;
}
- verbose("import ok");
-
+ verbose("import successful");
scene = importer.GetScene();
return true;
}
@@ -150,6 +150,7 @@
convert_node(*scene->mRootNode,NULL);
convert_armature();
+ convert_skin();
convert_animations();
verbose("conversion to blender Scene ok");
@@ -195,6 +196,19 @@
}
+void SceneImporter::convert_skin()
+{
+ if (!has_bones || !armature) {
+ return;
+ }
+
+ SkinImporter imp(C,*armature);
+ for (ObjectToMeshMap::const_iterator it = meshes_by_object.begin(), end = meshes_by_object.end(); it != end; ++it) {
+ imp.link_armature(*(*it).first,(*it).second);
+ }
+}
+
+
void SceneImporter::convert_animations()
{
for (int i = 0; i < scene->mNumAnimations; ++i)
@@ -309,6 +323,7 @@
// attach meshes
if (in_node.mNumMeshes) {
+
// XXX join meshes on their name -- for each list of meshes we create a blender mesh
std::vector<const aiMesh*> in_meshes;
for (unsigned int i = 0, c = in_node.mNumMeshes; i < c; ++i) {
@@ -319,6 +334,9 @@
if(obj != NULL) {
objects_done.push_back(obj);
++meshes;
+
+ // store object->mesh mapping, we later need it to be able to assign skins
+ meshes_by_object[obj] = in_meshes;
}
}
}
@@ -409,14 +427,14 @@
// set parent (unless this is root)
if(out_parent) {
- util_set_parent(&anchor, out_parent ,C, true);
+ util_set_parent(&anchor, out_parent ,&C, true);
}
for (ObjectVector::iterator it = objects_done.begin(), end = objects_done.end() - 1; it != end; ++it) {
Object& obj = **it;
set_identity_transform(obj);
- util_set_parent(&obj,&anchor,C,true);
+ util_set_parent(&obj,&anchor,&C,true);
}
// recursively convert child nodes
Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-06-19 23:08:16 UTC (rev 48100)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h 2012-06-19 23:24:27 UTC (rev 48101)
@@ -20,7 +20,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file SceneExporter.h
+/** \file SceneImporter.h
* \ingroup assimp
*/
@@ -41,7 +41,7 @@
private:
const char* path;
- bContext *C;
+ bContext& C;
Scene* out_scene;
Assimp::Importer importer;
@@ -66,6 +66,10 @@
typedef std::map<const aiNode*, Object*> NodeToObjectMap;
NodeToObjectMap objects_by_node;
+ typedef std::vector<const aiMesh*> MeshVector;
+ typedef std::map<Object*, MeshVector> ObjectToMeshMap;
+ ObjectToMeshMap meshes_by_object;
+
private:
unsigned int get_assimp_flags() const;
@@ -73,6 +77,7 @@
void convert_materials();
void convert_animations();
void convert_armature();
+ void convert_skin();
void convert_node(const aiNode& in_node, Object* out_parent);
void convert_node_transform(const aiNode& node_in, Object& out_obj) const;
@@ -89,7 +94,7 @@
public:
- SceneImporter(const char* path, bContext *C);
+ SceneImporter(const char* path, bContext& C);
~SceneImporter();
bool import();
Added: branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.cpp (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.cpp 2012-06-19 23:24:27 UTC (rev 48101)
@@ -0,0 +1,125 @@
+/*
+ * ***** 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/MeshImporter.cpp
+ * \ingroup assimp
+ */
+
+#include <cassert>
+#include <set>
+
+#include "SkinImporter.h"
+#include "bassimp_internal.h"
+
+extern "C" {
+# include "BKE_object.h"
+# include "DNA_armature_types.h"
+# include "DNA_modifier_types.h"
+# include "ED_mesh.h"
+# include "ED_object.h"
+# include "BKE_action.h"
+# include "BLI_listbase.h"
+# include "BLI_math.h"
+}
+
+namespace bassimp {
+
+SkinImporter::SkinImporter(bContext& C, const Object& ob_armature)
+: C(C)
+, bmain(*CTX_data_main(&C))
+, scene(*CTX_data_scene(&C))
+, ob_armature(ob_armature)
+, armature(*static_cast<bArmature*>(ob_armature.data))
+{
+
+}
+
+
+SkinImporter::~SkinImporter()
+{
+
+}
+
+
+void SkinImporter::link_armature(Object& ob, const std::vector<const aiMesh*>& meshes)
+{
+ ModifierData* const md = ED_object_modifier_add(NULL, &bmain, &scene, &ob, NULL, eModifierType_Armature);
+ ArmatureModifierData *amd = (ArmatureModifierData *)md;
+ amd->object = const_cast<Object*>(&ob_armature);
+
+ //copy_m4_m4(ob->obmat, bind_shape_matrix);
+ //BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
+
+ util_set_parent(&ob, const_cast<Object*>(&ob_armature), &C, true);
+ amd->deformflag = ARM_DEF_VGROUP;
+
+ // create all vertex groups that we need
+ std::vector<const aiBone*> groups;
+ std::set<std::string> groups_set;
+ unsigned int count = 0;
+
+ for (std::vector<const aiMesh*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
+ const aiMesh& m = **it;
+ for (unsigned int i = 0; i < m.mNumBones; ++i) {
+ const aiBone& b = *m.mBones[i];
+
+ std::set<std::string>::const_iterator it = groups_set.find(b.mName.C_Str());
+ if (it == groups_set.end()) {
+ groups.push_back(&b);
+ }
+ }
+ }
+
+ for (std::vector<const aiBone*>::const_iterator it = groups.begin(); it != groups.end(); ++it) {
+ ED_vgroup_add_name(&ob, (*it)->mName.C_Str());
+ }
+
+ unsigned int vert_offset = 0;
+ for (std::vector<const aiMesh*>::const_iterator it = meshes.begin(); it != meshes.end(); ++it) {
+ const aiMesh& m = **it;
+ for (unsigned int i = 0; i < m.mNumBones; ++i) {
+ const aiBone& b = *m.mBones[i];
+
+ unsigned int index = groups.size();
+ for (std::vector<const aiBone*>::const_iterator it = groups.begin(); it != groups.end(); ++it) {
+ if (*it == &b) {
+ index = std::distance<std::vector<const aiBone*>::const_iterator>(groups.begin(),it);
+ break;
+ }
+ }
+
+ assert(index <= groups.size());
+ bDeformGroup& def = *static_cast<bDeformGroup*>(BLI_findlink(&ob.defbase, index));
+
+ for (unsigned int j = 0; j < b.mNumWeights; ++j) {
+ const aiVertexWeight& v = b.mWeights[j];
+
+ ED_vgroup_vert_add(&ob, &def, v.mVertexId + vert_offset, v.mWeight, WEIGHT_REPLACE);
+ }
+ }
+
+ vert_offset += m.mNumVertices;
+ }
+}
+
+}
+
Added: branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.h (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SkinImporter.h 2012-06-19 23:24:27 UTC (rev 48101)
@@ -0,0 +1,58 @@
+/*
+ * ***** 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 SkinImporter.h
+ * \ingroup assimp
+ */
+
+#ifndef INCLUDED_SKIN_IMPORTER_H
+#define INCLUDED_SKIN_IMPORTER_H
+
+#include "bassimp_shared.h"
+
+
+namespace bassimp {
+
+class SkinImporter
+{
+private:
+
+ bContext& C;
+ Main& bmain;
+ Scene& scene;
+
+ const Object& ob_armature;
+ const bArmature& armature;
+
+public:
+
+ SkinImporter(bContext& C, const Object& ob_armature);
+ ~SkinImporter();
+
+public:
+
+ void link_armature(Object& obj, const std::vector<const aiMesh*>& meshes);
+};
+
+}
+
+#endif
Modified: branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp 2012-06-19 23:08:16 UTC (rev 48100)
+++ branches/soc-2012-bratwurst/source/blender/assimp/bassimp.cpp 2012-06-19 23:24:27 UTC (rev 48101)
@@ -24,6 +24,7 @@
* \ingroup assimp
*/
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list