Browse Source

- Bugfix : Fix build of Obj-FileImporter ( this is currently only a work-around, loader is leaking memory, I am working on it ).
- Update : Merge fixes from GitHub, thanks to Riku Palomäki ( more fixes will merged soon ).

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1213 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

kimmi 13 years ago
parent
commit
b724ac5c2c
3 changed files with 17 additions and 9 deletions
  1. 9 2
      code/BaseImporter.cpp
  2. 2 2
      code/BaseImporter.h
  3. 6 5
      code/ObjFileData.h

+ 9 - 2
code/BaseImporter.cpp

@@ -110,7 +110,8 @@ void BaseImporter::SetupProperties(const Importer* /*pImp*/)
 	const std::string&	pFile,
 	const std::string&	pFile,
 	const char**		tokens, 
 	const char**		tokens, 
 	unsigned int		numTokens,
 	unsigned int		numTokens,
-	unsigned int		searchBytes /* = 200 */)
+	unsigned int		searchBytes /* = 200 */,
+	bool				tokensSol /* false */)
 {
 {
 	ai_assert(NULL != tokens && 0 != numTokens && 0 != searchBytes);
 	ai_assert(NULL != tokens && 0 != numTokens && 0 != searchBytes);
 	if (!pIOHandler)
 	if (!pIOHandler)
@@ -142,7 +143,13 @@ void BaseImporter::SetupProperties(const Importer* /*pImp*/)
 		for (unsigned int i = 0; i < numTokens;++i)	{
 		for (unsigned int i = 0; i < numTokens;++i)	{
 			ai_assert(NULL != tokens[i]);
 			ai_assert(NULL != tokens[i]);
 
 
-			if (::strstr(buffer,tokens[i]))	{
+
+			const char* r = strstr(buffer,tokens[i]);
+			if (!r) 
+				continue;
+			// We got a match, either we don't care where it is, or it happens to
+			// be in the beginning of the file / line
+			if (!tokensSol || r == buffer || r[-1] == '\r' || r[-1] == '\n') {
 				DefaultLogger::get()->debug(std::string("Found positive match for header keyword: ") + tokens[i]);
 				DefaultLogger::get()->debug(std::string("Found positive match for header keyword: ") + tokens[i]);
 				return true;
 				return true;
 			}
 			}

+ 2 - 2
code/BaseImporter.h

@@ -271,8 +271,8 @@ public: // static utilities
 		const std::string&	file,
 		const std::string&	file,
 		const char** tokens, 
 		const char** tokens, 
 		unsigned int numTokens,
 		unsigned int numTokens,
-		unsigned int searchBytes = 200);
-
+		unsigned int searchBytes = 200,
+		bool tokensSol = false);
 
 
 	// -------------------------------------------------------------------
 	// -------------------------------------------------------------------
 	/** @brief Check whether a file has a specific file extension
 	/** @brief Check whether a file has a specific file extension

+ 6 - 5
code/ObjFileData.h

@@ -58,7 +58,7 @@ struct Material;
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 //!	\struct	Face
 //!	\struct	Face
-//!	\brief	Datastructure for a simple obj-face, descripes discredisation and materials
+//!	\brief	Data structure for a simple obj-face, describes discredit,l.ation and materials
 struct Face
 struct Face
 {
 {
 	typedef std::vector<unsigned int> IndexArray;
 	typedef std::vector<unsigned int> IndexArray;
@@ -96,8 +96,10 @@ struct Face
 	{	
 	{	
 		delete m_pVertices;
 		delete m_pVertices;
 		m_pVertices = NULL;
 		m_pVertices = NULL;
+
 		delete m_pNormals;
 		delete m_pNormals;
 		m_pNormals = NULL;
 		m_pNormals = NULL;
+
 		delete m_pTexturCoords;
 		delete m_pTexturCoords;
 		m_pTexturCoords = NULL;
 		m_pTexturCoords = NULL;
 	}
 	}
@@ -162,7 +164,7 @@ struct Material
 	aiColor3D ambient;
 	aiColor3D ambient;
 	//!	Diffuse color
 	//!	Diffuse color
 	aiColor3D diffuse;
 	aiColor3D diffuse;
-	//!	Speculao color
+	//!	Specular color
 	aiColor3D specular;
 	aiColor3D specular;
 	//!	Alpha value
 	//!	Alpha value
 	float alpha;
 	float alpha;
@@ -228,7 +230,6 @@ struct Mesh
 		{
 		{
 			delete *it;
 			delete *it;
 		}
 		}
-
 	}
 	}
 };
 };
 
 
@@ -259,7 +260,7 @@ struct Model
 	std::vector<aiVector3D> m_Vertices;
 	std::vector<aiVector3D> m_Vertices;
 	//!	vector with all generated normals
 	//!	vector with all generated normals
 	std::vector<aiVector3D> m_Normals;
 	std::vector<aiVector3D> m_Normals;
-	//!	Groupmap
+	//!	Group map
 	GroupMap m_Groups;
 	GroupMap m_Groups;
 	//!	Group to face id assignment
 	//!	Group to face id assignment
 	std::vector<unsigned int> *m_pGroupFaceIDs;
 	std::vector<unsigned int> *m_pGroupFaceIDs;
@@ -309,7 +310,7 @@ struct Model
 		m_Groups.clear();
 		m_Groups.clear();
 
 
 		for ( std::map<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) {
 		for ( std::map<std::string, Material*>::iterator it = m_MaterialMap.begin(); it != m_MaterialMap.end(); ++it ) {
-			delete it->second;
+//			delete it->second;
 		}
 		}
 	}
 	}
 };
 };