implementation for mesh resolving.

Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>
pull/502/head
Kim Kulling 2015-03-17 14:25:40 +01:00
parent 0d5a2ce4c1
commit 59633d172f
1 changed files with 92 additions and 7 deletions

View File

@ -162,12 +162,21 @@ namespace OpenGEX {
USE_ODDLPARSER_NS USE_ODDLPARSER_NS
//------------------------------------------------------------------------------------------------
OpenGEXImporter::RefInfo::RefInfo( aiNode *node, Type type, std::vector<std::string> &names )
: m_node( node )
, m_type( type )
, m_Names( names ) {
// empty
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
OpenGEXImporter::OpenGEXImporter() OpenGEXImporter::OpenGEXImporter()
: m_meshCache() : m_meshCache()
, m_mesh2refMap() , m_mesh2refMap()
, m_ctx( NULL ) , m_ctx( NULL )
, m_currentNode( NULL ) { , m_currentNode( NULL )
, m_unresolvedRefStack() {
// empty // empty
} }
@ -246,7 +255,12 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
break; break;
case Grammar::MaterialRefToken: case Grammar::MaterialRefToken:
handleMaterialRefNode( *it, pScene );
break;
case Grammar::MetricKeyToken: case Grammar::MetricKeyToken:
break;
case Grammar::GeometryNodeToken: case Grammar::GeometryNodeToken:
handleGeometryNode( *it, pScene ); handleGeometryNode( *it, pScene );
break; break;
@ -256,12 +270,27 @@ void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
break; break;
case Grammar::TransformToken: case Grammar::TransformToken:
break;
case Grammar::MeshToken: case Grammar::MeshToken:
break;
case Grammar::VertexArrayToken: case Grammar::VertexArrayToken:
break;
case Grammar::IndexArrayToken: case Grammar::IndexArrayToken:
break;
case Grammar::MaterialToken: case Grammar::MaterialToken:
handleMaterial( *it, pScene );
break;
case Grammar::ColorToken: case Grammar::ColorToken:
break;
case Grammar::TextureToken: case Grammar::TextureToken:
break;
default: default:
break; break;
} }
@ -290,7 +319,7 @@ void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
if( Value::ddl_float == val->m_type ) { if( Value::ddl_float == val->m_type ) {
m_metrics[ type ].m_floatValue = val->getFloat(); m_metrics[ type ].m_floatValue = val->getFloat();
} else if( Value::ddl_int32 == val->m_type ) { } else if( Value::ddl_int32 == val->m_type ) {
m_metrics[ type ].m_floatValue = val->getInt32(); m_metrics[ type ].m_intValue = val->getInt32();
} else if( Value::ddl_string == val->m_type ) { } else if( Value::ddl_string == val->m_type ) {
m_metrics[type].m_stringValue = std::string( val->getString() ); m_metrics[type].m_stringValue = std::string( val->getString() );
} else { } else {
@ -322,6 +351,24 @@ void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
} }
} }
//------------------------------------------------------------------------------------------------
static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
ai_assert( NULL != node );
Reference *ref = node->getReferences();
if( NULL != ref ) {
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
Name *currentName( ref->m_referencedName[ i ] );
if( NULL != currentName && NULL != currentName->m_id ) {
const std::string name( currentName->m_id->m_buffer );
if( !name.empty() ) {
names.push_back( name );
}
}
}
}
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) { void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) { if( NULL == m_currentNode ) {
@ -329,11 +376,26 @@ void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
return; return;
} }
Reference *ref = node->getReferences(); std::vector<std::string> objRefNames;
if( NULL != ref ) { getRefNames( node, objRefNames );
for( size_t i = 0; i < ref->m_numRefs; i++ ) { m_currentNode->mNumMeshes = objRefNames.size();
Name *currentName( ref->m_referencedName[ i ] ); m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
} if( !objRefNames.empty() ) {
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
}
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
if( NULL == m_currentNode ) {
throw DeadlyImportError( "No parent node for name." );
return;
}
std::vector<std::string> matRefNames;
getRefNames( node, matRefNames );
if( !matRefNames.empty() ) {
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MaterialRef, matRefNames ) );
} }
} }
@ -351,12 +413,35 @@ void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
// store name to reference relation // store name to reference relation
m_mesh2refMap[ node->getName() ] = idx; m_mesh2refMap[ node->getName() ] = idx;
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleMaterial( ODDLParser::DDLNode *node, aiScene *pScene ) {
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::resolveReferences() { void OpenGEXImporter::resolveReferences() {
if( m_unresolvedRefStack.empty() ) {
return;
}
RefInfo *currentRefInfo( NULL );
for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) {
currentRefInfo = *it;
if( NULL != currentRefInfo ) {
aiNode *node( currentRefInfo->m_node );
if( RefInfo::MeshRef == currentRefInfo->m_type ) {
for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
const std::string &name(currentRefInfo->m_Names[ i ] );
unsigned int meshIdx = m_mesh2refMap[ name ];
node->mMeshes[ i ] = meshIdx;
}
} else if( RefInfo::MaterialRef == currentRefInfo->m_type ) {
// ToDo
}
}
}
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------