pull/612/head
Kim Kulling 2015-07-10 01:21:57 +02:00
commit 5a207dbb19
4 changed files with 25 additions and 23 deletions

View File

@ -216,10 +216,10 @@ struct Material
// ------------------------------------------------------------------------------------------------
//! \struct Mesh
//! \brief Data structure to store a mesh
struct Mesh
{
struct Mesh {
static const unsigned int NoMaterial = ~0u;
/// The name for the mesh
std::string m_name;
/// Array with pointer to all stored faces
std::vector<Face*> m_Faces;
/// Assigned material
@ -232,13 +232,14 @@ struct Mesh
unsigned int m_uiMaterialIndex;
/// True, if normals are stored.
bool m_hasNormals;
/// Constructor
Mesh() :
m_pMaterial(NULL),
m_uiNumIndices(0),
m_uiMaterialIndex( NoMaterial ),
m_hasNormals(false)
{
Mesh( const std::string &name )
: m_name( name )
, m_pMaterial(NULL)
, m_uiNumIndices(0)
, m_uiMaterialIndex( NoMaterial )
, m_hasNormals(false) {
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 );
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++)
{
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 );
if ( pMesh->mNumFaces > 0 )
{
if ( pMesh->mNumFaces > 0 ) {
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;
}
unsigned int outIndex( 0 );
// 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 ];
if (inp->m_PrimitiveType == aiPrimitiveType_LINE) {
for(size_t i = 0; i < inp->m_pVertices->size() - 1; ++i) {

View File

@ -439,7 +439,7 @@ void ObjFileParser::getFace(aiPrimitiveType type)
// Assign face to mesh
if ( NULL == m_pModel->m_pCurrentMesh ) {
createMesh();
createMesh( "defaultobject" );
}
// Store the face
@ -495,7 +495,7 @@ void ObjFileParser::getMaterialDesc()
m_pModel->m_pCurrentMaterial = (*it).second;
if ( needsNewMesh( strName ))
{
createMesh();
createMesh( strName );
}
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strName );
}
@ -584,7 +584,7 @@ void ObjFileParser::getNewMaterial()
// Set new material
if ( needsNewMesh( strMat ) )
{
createMesh();
createMesh( strMat );
}
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = getMaterialIndex( strMat );
}
@ -713,7 +713,7 @@ void ObjFileParser::createObject(const std::string &objName)
m_pModel->m_pCurrent->m_strObjName = objName;
m_pModel->m_Objects.push_back( m_pModel->m_pCurrent );
createMesh();
createMesh( objName );
if( m_pModel->m_pCurrentMaterial )
{
@ -724,10 +724,10 @@ void ObjFileParser::createObject(const std::string &objName)
}
// -------------------------------------------------------------------
// Creates a new mesh
void ObjFileParser::createMesh()
void ObjFileParser::createMesh( const std::string &meshName )
{
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 );
unsigned int meshId = m_pModel->m_Meshes.size()-1;
if ( NULL != m_pModel->m_pCurrent )

View File

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