diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 5ff9db68c..a2d9f2cc7 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -281,6 +281,8 @@ struct Model { std::string m_strActiveGroup; //! Vector with generated texture coordinates std::vector m_TextureCoord; + //! Maximum dimension of texture coordinates + unsigned int m_TextureCoordDim; //! Current mesh instance Mesh *m_pCurrentMesh; //! Vector with stored meshes @@ -296,6 +298,7 @@ struct Model { m_pDefaultMaterial(NULL), m_pGroupFaceIDs(NULL), m_strActiveGroup(""), + m_TextureCoordDim(0), m_pCurrentMesh(NULL) { // empty diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 814180c81..549956474 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -442,7 +442,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel, // Allocate buffer for texture coordinates if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] ) { - pMesh->mNumUVComponents[ 0 ] = 2; + pMesh->mNumUVComponents[ 0 ] = pModel->m_TextureCoordDim; pMesh->mTextureCoords[ 0 ] = new aiVector3D[ pMesh->mNumVertices ]; } diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index d303cb8b9..a8509b583 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -151,7 +151,8 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { } else if (*m_DataIt == 't') { // read in texture coordinate ( 2D or 3D ) ++m_DataIt; - getVector( m_pModel->m_TextureCoord ); + size_t dim = getVector(m_pModel->m_TextureCoord); + m_pModel->m_TextureCoordDim = std::max(m_pModel->m_TextureCoordDim, (unsigned int)dim); } else if (*m_DataIt == 'n') { // Read in normal vector definition ++m_DataIt; @@ -296,7 +297,7 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() { return numComponents; } -void ObjFileParser::getVector( std::vector &point3d_array ) { +size_t ObjFileParser::getVector( std::vector &point3d_array ) { size_t numComponents = getNumComponentsInDataDefinition(); ai_real x, y, z; if( 2 == numComponents ) { @@ -320,6 +321,7 @@ void ObjFileParser::getVector( std::vector &point3d_array ) { } point3d_array.push_back( aiVector3D( x, y, z ) ); m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); + return numComponents; } void ObjFileParser::getVector3( std::vector &point3d_array ) { diff --git a/code/ObjFileParser.h b/code/ObjFileParser.h index e00382f4c..a8961452d 100644 --- a/code/ObjFileParser.h +++ b/code/ObjFileParser.h @@ -96,7 +96,7 @@ protected: /// Get the number of components in a line. size_t getNumComponentsInDataDefinition(); /// Stores the vector - void getVector( std::vector &point3d_array ); + size_t getVector( std::vector &point3d_array ); /// Stores the following 3d vector. void getVector3( std::vector &point3d_array ); /// Stores the following homogeneous vector as a 3D vector