Obj: fix issue 121 - set group names as the mesh names.

pull/607/head
Kim Kulling 2015-07-09 20:15:44 +02:00
parent 891c17ee7b
commit e138a02dd5
4 changed files with 25 additions and 23 deletions

View File

@ -219,10 +219,10 @@ struct Material
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
//! \struct Mesh //! \struct Mesh
//! \brief Data structure to store a mesh //! \brief Data structure to store a mesh
struct Mesh struct Mesh {
{
static const unsigned int NoMaterial = ~0u; static const unsigned int NoMaterial = ~0u;
/// The name for the mesh
std::string m_name;
/// Array with pointer to all stored faces /// Array with pointer to all stored faces
std::vector<Face*> m_Faces; std::vector<Face*> m_Faces;
/// Assigned material /// Assigned material
@ -235,13 +235,14 @@ struct Mesh
unsigned int m_uiMaterialIndex; unsigned int m_uiMaterialIndex;
/// True, if normals are stored. /// True, if normals are stored.
bool m_hasNormals; bool m_hasNormals;
/// Constructor /// Constructor
Mesh() : Mesh( const std::string &name )
m_pMaterial(NULL), : m_name( name )
m_uiNumIndices(0), , m_pMaterial(NULL)
m_uiMaterialIndex( NoMaterial ), , m_uiNumIndices(0)
m_hasNormals(false) , m_uiMaterialIndex( NoMaterial )
{ , m_hasNormals(false) {
memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS); memset(m_uiUVCoordinates, 0, sizeof( unsigned int ) * AI_MAX_NUMBER_OF_TEXTURECOORDS);
} }

View File

@ -289,6 +289,10 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
} }
ai_assert( NULL != pObjMesh ); ai_assert( NULL != pObjMesh );
aiMesh* pMesh = new aiMesh; aiMesh* pMesh = new aiMesh;
if( !pObjMesh->m_name.empty() ) {
pMesh->mName.Set( pObjMesh->m_name );
}
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++)
{ {
ObjFile::Face *const inp = pObjMesh->m_Faces[ index ]; ObjFile::Face *const inp = pObjMesh->m_Faces[ index ];
@ -311,19 +315,16 @@ aiMesh *ObjFileImporter::createTopology( const ObjFile::Model* pModel, const Obj
} }
unsigned int uiIdxCount( 0u ); unsigned int uiIdxCount( 0u );
if ( pMesh->mNumFaces > 0 ) if ( pMesh->mNumFaces > 0 ) {
{
pMesh->mFaces = new aiFace[ pMesh->mNumFaces ]; pMesh->mFaces = new aiFace[ pMesh->mNumFaces ];
if ( pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial ) if ( pObjMesh->m_uiMaterialIndex != ObjFile::Mesh::NoMaterial ) {
{
pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex; pMesh->mMaterialIndex = pObjMesh->m_uiMaterialIndex;
} }
unsigned int outIndex( 0 ); unsigned int outIndex( 0 );
// Copy all data from all stored meshes // Copy all data from all stored meshes
for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) for (size_t index = 0; index < pObjMesh->m_Faces.size(); index++) {
{
ObjFile::Face* const inp = pObjMesh->m_Faces[ index ]; ObjFile::Face* const inp = pObjMesh->m_Faces[ index ];
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) { if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
for(size_t i = 0; i < inp->m_pVertices->size() - 1; ++i) { for(size_t i = 0; i < inp->m_pVertices->size() - 1; ++i) {

View File

@ -440,7 +440,7 @@ void ObjFileParser::getFace(aiPrimitiveType type)
// Assign face to mesh // Assign face to mesh
if ( NULL == m_pModel->m_pCurrentMesh ) { if ( NULL == m_pModel->m_pCurrentMesh ) {
createMesh(); createMesh( "defaultobject" );
} }
// Store the face // Store the face
@ -496,7 +496,7 @@ void ObjFileParser::getMaterialDesc()
m_pModel->m_pCurrentMaterial = (*it).second; m_pModel->m_pCurrentMaterial = (*it).second;
if ( needsNewMesh( strName )) if ( needsNewMesh( strName ))
{ {
createMesh(); createMesh( strName );
} }
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName ); m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName );
} }
@ -585,7 +585,7 @@ void ObjFileParser::getNewMaterial()
// Set new material // Set new material
if ( needsNewMesh( strMat ) ) if ( needsNewMesh( strMat ) )
{ {
createMesh(); createMesh( strMat );
} }
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat ); m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat );
} }
@ -714,7 +714,7 @@ void ObjFileParser::createObject(const std::string &objName)
m_pModel->m_pCurrent->m_strObjName = objName; m_pModel->m_pCurrent->m_strObjName = objName;
m_pModel->m_Objects.push_back( m_pModel->m_pCurrent ); m_pModel->m_Objects.push_back( m_pModel->m_pCurrent );
createMesh(); createMesh( objName );
if( m_pModel->m_pCurrentMaterial ) if( m_pModel->m_pCurrentMaterial )
{ {
@ -725,10 +725,10 @@ void ObjFileParser::createObject(const std::string &objName)
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Creates a new mesh // Creates a new mesh
void ObjFileParser::createMesh() void ObjFileParser::createMesh( const std::string &meshName )
{ {
ai_assert( NULL != m_pModel ); ai_assert( NULL != m_pModel );
m_pModel->m_pCurrentMesh = new ObjFile::Mesh; m_pModel->m_pCurrentMesh = new ObjFile::Mesh( meshName );
m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh ); m_pModel->m_Meshes.push_back( m_pModel->m_pCurrentMesh );
unsigned int meshId = m_pModel->m_Meshes.size()-1; unsigned int meshId = m_pModel->m_Meshes.size()-1;
if ( NULL != m_pModel->m_pCurrent ) if ( NULL != m_pModel->m_pCurrent )

View File

@ -113,9 +113,9 @@ private:
/// Parse object name /// Parse object name
void getObjectName(); void getObjectName();
/// Creates a new object. /// Creates a new object.
void createObject(const std::string &strObjectName); void createObject( const std::string &strObjectName );
/// Creates a new mesh. /// Creates a new mesh.
void createMesh(); void createMesh( const std::string &meshName );
/// Returns true, if a new mesh instance must be created. /// Returns true, if a new mesh instance must be created.
bool needsNewMesh( const std::string &rMaterialName ); bool needsNewMesh( const std::string &rMaterialName );
/// Error report in token /// Error report in token