fix loading 3D uvs from obj
parent
ef270225ac
commit
9a533d826a
|
@ -281,6 +281,8 @@ struct Model {
|
||||||
std::string m_strActiveGroup;
|
std::string m_strActiveGroup;
|
||||||
//! Vector with generated texture coordinates
|
//! Vector with generated texture coordinates
|
||||||
std::vector<aiVector3D> m_TextureCoord;
|
std::vector<aiVector3D> m_TextureCoord;
|
||||||
|
//! Maximum dimension of texture coordinates
|
||||||
|
unsigned int m_TextureCoordDim;
|
||||||
//! Current mesh instance
|
//! Current mesh instance
|
||||||
Mesh *m_pCurrentMesh;
|
Mesh *m_pCurrentMesh;
|
||||||
//! Vector with stored meshes
|
//! Vector with stored meshes
|
||||||
|
@ -296,6 +298,7 @@ struct Model {
|
||||||
m_pDefaultMaterial(NULL),
|
m_pDefaultMaterial(NULL),
|
||||||
m_pGroupFaceIDs(NULL),
|
m_pGroupFaceIDs(NULL),
|
||||||
m_strActiveGroup(""),
|
m_strActiveGroup(""),
|
||||||
|
m_TextureCoordDim(0),
|
||||||
m_pCurrentMesh(NULL)
|
m_pCurrentMesh(NULL)
|
||||||
{
|
{
|
||||||
// empty
|
// empty
|
||||||
|
|
|
@ -442,7 +442,7 @@ void ObjFileImporter::createVertexArray(const ObjFile::Model* pModel,
|
||||||
// Allocate buffer for texture coordinates
|
// Allocate buffer for texture coordinates
|
||||||
if ( !pModel->m_TextureCoord.empty() && pObjMesh->m_uiUVCoordinates[0] )
|
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 ];
|
pMesh->mTextureCoords[ 0 ] = new aiVector3D[ pMesh->mNumVertices ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,8 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
|
||||||
} else if (*m_DataIt == 't') {
|
} else if (*m_DataIt == 't') {
|
||||||
// read in texture coordinate ( 2D or 3D )
|
// read in texture coordinate ( 2D or 3D )
|
||||||
++m_DataIt;
|
++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') {
|
} else if (*m_DataIt == 'n') {
|
||||||
// Read in normal vector definition
|
// Read in normal vector definition
|
||||||
++m_DataIt;
|
++m_DataIt;
|
||||||
|
@ -296,7 +297,7 @@ size_t ObjFileParser::getNumComponentsInDataDefinition() {
|
||||||
return numComponents;
|
return numComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
size_t ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
||||||
size_t numComponents = getNumComponentsInDataDefinition();
|
size_t numComponents = getNumComponentsInDataDefinition();
|
||||||
ai_real x, y, z;
|
ai_real x, y, z;
|
||||||
if( 2 == numComponents ) {
|
if( 2 == numComponents ) {
|
||||||
|
@ -320,6 +321,7 @@ void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
|
||||||
}
|
}
|
||||||
point3d_array.push_back( aiVector3D( x, y, z ) );
|
point3d_array.push_back( aiVector3D( x, y, z ) );
|
||||||
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
|
||||||
|
return numComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
|
void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ protected:
|
||||||
/// Get the number of components in a line.
|
/// Get the number of components in a line.
|
||||||
size_t getNumComponentsInDataDefinition();
|
size_t getNumComponentsInDataDefinition();
|
||||||
/// Stores the vector
|
/// Stores the vector
|
||||||
void getVector( std::vector<aiVector3D> &point3d_array );
|
size_t getVector( std::vector<aiVector3D> &point3d_array );
|
||||||
/// Stores the following 3d vector.
|
/// Stores the following 3d vector.
|
||||||
void getVector3( std::vector<aiVector3D> &point3d_array );
|
void getVector3( std::vector<aiVector3D> &point3d_array );
|
||||||
/// Stores the following homogeneous vector as a 3D vector
|
/// Stores the following homogeneous vector as a 3D vector
|
||||||
|
|
Loading…
Reference in New Issue