Browse Source

OgreImporter: Continue cleanup.

Jonne Nauha 11 years ago
parent
commit
6c51fa2072
3 changed files with 30 additions and 34 deletions
  1. 13 12
      code/OgreImporter.cpp
  2. 3 8
      code/OgreImporter.hpp
  3. 14 14
      code/OgreMesh.cpp

+ 13 - 12
code/OgreImporter.cpp

@@ -110,12 +110,12 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
 		throw DeadlyImportError("Root node is not <mesh> but <" + string(reader->getNodeName()) + ">");
 	
 	// Node names
-	string nnSharedGeometry = "sharedgeometry";
-	string nnVertexBuffer   = "vertexbuffer";
-	string nnSubMeshes      = "submeshes";
-	string nnSubMesh        = "submesh";
-	string nnSubMeshNames   = "submeshnames";
-	string nnSkeletonLink   = "skeletonlink";
+	const string nnSharedGeometry = "sharedgeometry";
+	const string nnVertexBuffer   = "vertexbuffer";
+	const string nnSubMeshes      = "submeshes";
+	const string nnSubMesh        = "submesh";
+	const string nnSubMeshNames   = "submeshnames";
+	const string nnSkeletonLink   = "skeletonlink";
 
 	// -------------------- Shared Geometry --------------------
 	// This can be used to share geometry between submeshes
@@ -123,7 +123,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
 	NextNode(reader.get());
 	if (CurrentNodeNameEquals(reader, nnSharedGeometry))
 	{
-		DefaultLogger::get()->debug("Reading shader geometry");
+		DefaultLogger::get()->debug("Reading shared geometry");
 		unsigned int NumVertices = GetAttribute<unsigned int>(reader.get(), "vertexcount");
 
 		NextNode(reader.get());
@@ -147,15 +147,16 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass
 
 		// Just a index in a array, we add a mesh in each loop cycle, so we get indicies like 0, 1, 2 ... n;
 		// so it is important to do this before pushing the mesh in the vector!
+		/// @todo Not sure if this really is needed, refactor out if possible.
 		submesh->MaterialIndex = subMeshes.size();
 
 		subMeshes.push_back(boost::shared_ptr<SubMesh>(submesh));
 
-		// Load the Material:
-		aiMaterial* MeshMat = LoadMaterial(submesh->MaterialName);
-		
-		// Set the Material:
-		materials.push_back(MeshMat);
+		/** @todo What is the correct way of handling empty ref here.
+			Does Assimp require there to be a valid material index for each mesh,
+			even if its a dummy material. */
+		aiMaterial* material = LoadMaterial(submesh->MaterialName);
+		materials.push_back(material);
 	}
 
 	if (subMeshes.empty())

+ 3 - 8
code/OgreImporter.hpp

@@ -5,10 +5,6 @@
 
 #include <vector>
 
-/** @todo Read Vertex Colors
-    @todo Read multiple TexCoords
-*/
-
 namespace Assimp
 {
 namespace Ogre
@@ -63,10 +59,9 @@ struct SubMesh
 	}
 };
 
-// ------------------------------------------------------------------------------------------------
-///	\class	OgreImporter
-///	\brief	Importer for Ogre mesh, skeleton and material formats.
-// ------------------------------------------------------------------------------------------------
+/**	Importer for Ogre mesh, skeleton and material formats.
+	@todo Support vertex colors
+	@todo Support multiple TexCoords (this is already done??) */
 class OgreImporter : public BaseImporter
 {
 public:

+ 14 - 14
code/OgreMesh.cpp

@@ -73,11 +73,11 @@ void OgreImporter::ReadSubMesh(const unsigned int submeshIndex, SubMesh &submesh
 	NextNode(reader);
 	string currentNodeName = reader->getNodeName();
 
-	string nnFaces           = "faces";
-	string nnFace            = "face";
-	string nnGeometry        = "geometry";
-	string nnBoneAssignments = "boneassignments";
-	string nnVertexBuffer    = "vertexbuffer";
+	const string nnFaces           = "faces";
+	const string nnFace            = "face";
+	const string nnGeometry        = "geometry";
+	const string nnBoneAssignments = "boneassignments";
+	const string nnVertexBuffer    = "vertexbuffer";
 
 	bool quadWarned = false;
 
@@ -165,14 +165,14 @@ void OgreImporter::ReadVertexBuffer(SubMesh &submesh, XmlReader *reader, const u
 	if (!submesh.HasPositions)
 		throw DeadlyImportError("Vertex buffer does not contain positions!");
 
-	string nnVertex        = "vertex";
-	string nnPosition      = "position";
-	string nnNormal        = "normal";
-	string nnTangent       = "tangent";
-	string nnBinormal      = "binormal";
-	string nnTexCoord      = "texcoord";
-	string nnColorDiffuse  = "colour_diffuse";
-	string nnColorSpecular = "colour_specular";
+	const string nnVertex        = "vertex";
+	const string nnPosition      = "position";
+	const string nnNormal        = "normal";
+	const string nnTangent       = "tangent";
+	const string nnBinormal      = "binormal";
+	const string nnTexCoord      = "texcoord";
+	const string nnColorDiffuse  = "colour_diffuse";
+	const string nnColorSpecular = "colour_specular";
 	
 	bool warnBinormal = true;
 	bool warnColorDiffuse = true;
@@ -299,7 +299,7 @@ void OgreImporter::ReadBoneWeights(SubMesh &submesh, XmlReader *reader)
 	submesh.Weights.resize(submesh.Positions.size());
 
 	unsigned int numRead = 0;
-	string nnVertexBoneAssignment = "vertexboneassignment";
+	const string nnVertexBoneAssignment = "vertexboneassignment";
 
 	NextNode(reader);
 	while(CurrentNodeNameEquals(reader, nnVertexBoneAssignment))