[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48702] branches/soc-2012-bratwurst/extern /assimp/code: - ext_assimp: merge https://github.com/acgessler/ assimp-gsoc2012-fbx - this pulls in lots of bugfixes for the fbx importer.

Alexander Gessler alexander.gessler at gmx.net
Sat Jul 7 04:07:38 CEST 2012


Revision: 48702
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48702
Author:   aramis_acg
Date:     2012-07-07 02:07:33 +0000 (Sat, 07 Jul 2012)
Log Message:
-----------
- ext_assimp: merge https://github.com/acgessler/assimp-gsoc2012-fbx - this pulls in lots of bugfixes for the fbx importer. 

Modified Paths:
--------------
    branches/soc-2012-bratwurst/extern/assimp/code/FBXConverter.cpp
    branches/soc-2012-bratwurst/extern/assimp/code/FBXDocument.cpp
    branches/soc-2012-bratwurst/extern/assimp/code/FBXDocument.h
    branches/soc-2012-bratwurst/extern/assimp/code/FBXModel.cpp
    branches/soc-2012-bratwurst/extern/assimp/code/FBXProperties.cpp

Modified: branches/soc-2012-bratwurst/extern/assimp/code/FBXConverter.cpp
===================================================================
--- branches/soc-2012-bratwurst/extern/assimp/code/FBXConverter.cpp	2012-07-07 01:49:09 UTC (rev 48701)
+++ branches/soc-2012-bratwurst/extern/assimp/code/FBXConverter.cpp	2012-07-07 02:07:33 UTC (rev 48702)
@@ -91,14 +91,6 @@
 			}
 		}
 
-		// dummy root node
-		out->mRootNode = new aiNode();
-		out->mRootNode->mNumMeshes = static_cast<unsigned int>(meshes.size());
-		out->mRootNode->mMeshes = new unsigned int[meshes.size()];
-		for(unsigned int i = 0; i < out->mRootNode->mNumMeshes; ++i) {
-			out->mRootNode->mMeshes[i] = i;
-		}
-
 		TransferDataToScene();
 	}
 
@@ -117,7 +109,7 @@
 	void ConvertRootNode() 
 	{
 		out->mRootNode = new aiNode();
-		out->mRootNode->mName.Set("Model::RootNode");
+		out->mRootNode->mName.Set("RootNode");
 
 		// root has ID 0
 		ConvertNodes(0L, *out->mRootNode);
@@ -151,10 +143,18 @@
 		
 			if(model) {
 				aiNode* nd = new aiNode();
-				nd->mName.Set(model->Name());
+				nodes.push_back(nd);
+
+				// strip Model:: prefix
+				std::string name = model->Name();
+				if(name.substr(0,7) == "Model::") {
+					name = name.substr(7);
+				}
+
+				nd->mName.Set(name);
 				nd->mParent = &parent;
 
-				// XXX handle transformation
+				ConvertTransformation(*model,*nd);
 
 				ConvertModel(*model, *nd);
 				ConvertNodes(model->ID(), *nd);
@@ -171,6 +171,46 @@
 
 
 	// ------------------------------------------------------------------------------------------------
+	void ConvertTransformation(const Model& model, aiNode& nd)
+	{
+		const PropertyTable& props = model.Props();
+
+		bool ok;
+		
+		aiVector3D Translation = PropertyGet<aiVector3D>(props,"Lcl Translation",ok);
+		if(!ok) {
+			Translation = aiVector3D(0.0f,0.0f,0.0f);
+		}
+
+		aiVector3D Scaling = PropertyGet<aiVector3D>(props,"Lcl Scaling",ok);
+		if(!ok) {
+			Scaling = aiVector3D(1.0f,1.0f,1.0f);
+		}
+
+		// XXX euler angles, radians, xyz order?
+		aiVector3D Rotation = PropertyGet<aiVector3D>(props,"Lcl Rotation",ok);
+		if(!ok) {
+			Rotation = aiVector3D(0.0f,0.0f,0.0f);
+		}
+
+		aiMatrix4x4 temp;
+		nd.mTransformation = aiMatrix4x4::Scaling(Scaling,temp);
+		if(fabs(Rotation.x) > 1e-6f) {
+			nd.mTransformation *= aiMatrix4x4::RotationX(Rotation.x,temp);
+		}
+		if(fabs(Rotation.y) > 1e-6f) {
+			nd.mTransformation *= aiMatrix4x4::RotationY(Rotation.y,temp);
+		}
+		if(fabs(Rotation.z) > 1e-6f) {
+			nd.mTransformation *= aiMatrix4x4::RotationZ(Rotation.z,temp);
+		}
+		nd.mTransformation.a4 = Translation.x;
+		nd.mTransformation.b4 = Translation.y;
+		nd.mTransformation.c4 = Translation.z;
+	}
+
+
+	// ------------------------------------------------------------------------------------------------
 	void ConvertModel(const Model& model, aiNode& nd)
 	{
 		const std::vector<const Geometry*>& geos = model.GetGeometry();
@@ -183,11 +223,7 @@
 			const MeshGeometry* const mesh = dynamic_cast<const MeshGeometry*>(geo);
 			if(mesh) {
 				std::vector<unsigned int>& indices = ConvertMesh(*mesh, model);
-
-				// mesh indices are shifted by 1 and 0 entries are failed conversions -
-				// XXX maybe log how many conversions went wrong?
-				std::remove(indices.begin(),indices.end(),0);
-				std::transform(indices.begin(),indices.end(),std::back_inserter(meshes), std::bind2nd(std::minus<unsigned int>(),1) );
+				std::copy(indices.begin(),indices.end(),std::back_inserter(meshes) );
 			}
 			else {
 				FBXImporter::LogWarn("ignoring unrecognized geometry: " + geo->Name());
@@ -211,7 +247,7 @@
 
 		MeshMap::const_iterator it = meshes_converted.find(&mesh);
 		if (it != meshes_converted.end()) {
-			temp.push_back((*it).second + 1);
+			std::copy((*it).second.begin(),(*it).second.end(),std::back_inserter(temp));
 			return temp;
 		}
 
@@ -222,11 +258,6 @@
 			return temp;
 		}
 
-		aiMesh* out_mesh = new aiMesh();
-		meshes.push_back(out_mesh);
-
-		meshes_converted[&mesh] = static_cast<unsigned int>(meshes.size()-1);
-
 		// one material per mesh maps easily to aiMesh. Multiple material 
 		// meshes need to be split.
 		const std::vector<unsigned int>& mindices = mesh.GetMaterialIndices();
@@ -234,20 +265,44 @@
 			const unsigned int base = mindices[0];
 			BOOST_FOREACH(unsigned int index, mindices) {
 				if(index != base) {
-					return ConvertMeshMultiMaterial(out_mesh, mesh, model);
+					return ConvertMeshMultiMaterial(mesh, model);
 				}
 			}
 		}
 
 		// faster codepath, just copy the data
-		temp.push_back(ConvertMeshSingleMaterial(out_mesh, mesh, model));
+		temp.push_back(ConvertMeshSingleMaterial(mesh, model));
 		return temp;
 	}
 
 
 	// ------------------------------------------------------------------------------------------------
-	unsigned int ConvertMeshSingleMaterial(aiMesh* out_mesh, const MeshGeometry& mesh, const Model& model)	
+	aiMesh* SetupEmptyMesh(const MeshGeometry& mesh, unsigned int material_index)
 	{
+		aiMesh* const out_mesh = new aiMesh();
+		meshes.push_back(out_mesh);
+		meshes_converted[&mesh].push_back(static_cast<unsigned int>(meshes.size()-1));
+
+		// set name
+		std::string name = mesh.Name();
+		if (name.substr(0,10) == "Geometry::") {
+			name = name.substr(10);
+		}
+
+		if(name.length()) {
+			out_mesh->mName.Set(name);
+		}
+
+		return out_mesh;
+	}
+
+
+	// ------------------------------------------------------------------------------------------------
+	unsigned int ConvertMeshSingleMaterial(const MeshGeometry& mesh, const Model& model)	
+	{
+		const std::vector<unsigned int>& mindices = mesh.GetMaterialIndices();
+		aiMesh* const out_mesh = SetupEmptyMesh(mesh,mindices.size() ? mindices[0] : static_cast<unsigned int>(-1)); 
+
 		const std::vector<aiVector3D>& vertices = mesh.GetVertices();
 		const std::vector<unsigned int>& faces = mesh.GetFaceIndexCounts();
 
@@ -353,7 +408,6 @@
 			std::copy(colors.begin(),colors.end(),out_mesh->mColors[i]);
 		}
 
-		const std::vector<unsigned int>& mindices = mesh.GetMaterialIndices();
 		if(mindices.empty()) {
 			FBXImporter::LogError("no material assigned to mesh, setting default material");
 			out_mesh->mMaterialIndex = GetDefaultMaterial();
@@ -362,12 +416,12 @@
 			ConvertMaterialForMesh(out_mesh,model,mesh,mindices[0]);
 		}
 
-		return static_cast<unsigned int>(meshes.size());
+		return static_cast<unsigned int>(meshes.size() - 1);
 	}
 
 
 	// ------------------------------------------------------------------------------------------------
-	std::vector<unsigned int> ConvertMeshMultiMaterial(aiMesh* out_mesh, const MeshGeometry& mesh, const Model& model)	
+	std::vector<unsigned int> ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model)	
 	{
 		const std::vector<unsigned int>& mindices = mesh.GetMaterialIndices();
 		ai_assert(mindices.size());
@@ -376,9 +430,9 @@
 		std::vector<unsigned int> indices;
 
 		BOOST_FOREACH(unsigned int index, mindices) {
-			if(had.find(index) != had.end()) {
+			if(had.find(index) == had.end()) {
 
-				indices.push_back(ConvertMeshMultiMaterial(out_mesh, mesh, model, index));
+				indices.push_back(ConvertMeshMultiMaterial(mesh, model, index));
 				had.insert(index);
 			}
 		}
@@ -388,11 +442,11 @@
 
 
 	// ------------------------------------------------------------------------------------------------
-	unsigned int ConvertMeshMultiMaterial(aiMesh* out_mesh, const MeshGeometry& mesh, const Model& model, unsigned int index)	
+	unsigned int ConvertMeshMultiMaterial(const MeshGeometry& mesh, const Model& model, unsigned int index)	
 	{
+		aiMesh* const out_mesh = SetupEmptyMesh(mesh, index);
+
 		const std::vector<unsigned int>& mindices = mesh.GetMaterialIndices();
-		ai_assert(mindices.size());
-
 		const std::vector<aiVector3D>& vertices = mesh.GetVertices();
 		const std::vector<unsigned int>& faces = mesh.GetFaceIndexCounts();
 
@@ -538,7 +592,7 @@
 		}
 	
 		ConvertMaterialForMesh(out_mesh,model,mesh,index);
-		return static_cast<unsigned int>(meshes.size());
+		return static_cast<unsigned int>(meshes.size() - 1);
 	}
 
 
@@ -602,10 +656,19 @@
 
 		aiString str;
 
-		// set material name
-		str.Set(material.Name());
-		out_mat->AddProperty(&str,AI_MATKEY_NAME);
+		// stip Material:: prefix
+		std::string name = material.Name();
+		if(name.substr(0,10) == "Material::") {
+			name = name.substr(10);
+		}
 
+		// set material name if not empty - this could happen
+		// and there should be no key for it in this case.
+		if(name.length()) {
+			str.Set(name);
+			out_mat->AddProperty(&str,AI_MATKEY_NAME);
+		}
+
 		// shading stuff and colors
 		SetShadingPropertiesCommon(out_mat,props);
 	
@@ -837,7 +900,8 @@
 	typedef std::map<const Material*, unsigned int> MaterialMap;
 	MaterialMap materials_converted;
 
-	typedef std::map<const Geometry*, unsigned int> MeshMap;
+
+	typedef std::map<const Geometry*, std::vector<unsigned int> > MeshMap;
 	MeshMap meshes_converted;
 
 	aiScene* const out;

Modified: branches/soc-2012-bratwurst/extern/assimp/code/FBXDocument.cpp
===================================================================
--- branches/soc-2012-bratwurst/extern/assimp/code/FBXDocument.cpp	2012-07-07 01:49:09 UTC (rev 48701)
+++ branches/soc-2012-bratwurst/extern/assimp/code/FBXDocument.cpp	2012-07-07 02:07:33 UTC (rev 48702)
@@ -468,6 +468,12 @@
 : parser(parser)
 , settings(settings)
 {
+	// cannot use array default initialization syntax because vc8 fails on it
+	for (unsigned int i = 0; i < 7; ++i) {
+		creationTimeStamp[i] = 0;
+	}
+
+	ReadHeader();
 	ReadPropertyTemplates();
 
 	// this order is important, connections need parsed objects to check
@@ -488,6 +494,38 @@
 
 
 // ------------------------------------------------------------------------------------------------
+void Document::ReadHeader()
+{
+	// read ID objects from "Objects" section
+	const Scope& sc = parser.GetRootScope();
+	const Element* const ehead = sc["FBXHeaderExtension"];
+	if(!ehead || !ehead->Compound()) {
+		DOMError("no FBXHeaderExtension dictionary found");
+	}
+
+	const Scope& shead = *ehead->Compound();
+	fbxVersion = ParseTokenAsInt(GetRequiredToken(GetRequiredElement(shead,"FBXVersion",ehead),0));
+
+	const Element* const ecreator = shead["Creator"];
+	if(ecreator) {
+		creator = ParseTokenAsString(GetRequiredToken(*ecreator,0));
+	}
+
+	const Element* const etimestamp = shead["CreationTimeStamp"];
+	if(etimestamp && etimestamp->Compound()) {
+		const Scope& stimestamp = *etimestamp->Compound();

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list