add nodestack to deal with node hierarchy.

Signed-off-by: Kim Kulling <kim.kulling@googlemail.com>
pull/502/head
Kim Kulling 2015-03-18 21:37:57 +01:00
parent 05208a5014
commit f15d62194b
2 changed files with 59 additions and 1 deletions

View File

@ -176,6 +176,7 @@ OpenGEXImporter::OpenGEXImporter()
, m_mesh2refMap() , m_mesh2refMap()
, m_ctx( NULL ) , m_ctx( NULL )
, m_currentNode( NULL ) , m_currentNode( NULL )
, m_nodeStack()
, m_unresolvedRefStack() { , m_unresolvedRefStack() {
// empty // empty
} }
@ -214,6 +215,8 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce
bool success( myParser.parse() ); bool success( myParser.parse() );
if( success ) { if( success ) {
m_ctx = myParser.getContext(); m_ctx = myParser.getContext();
pScene->mRootNode = new aiNode;
pScene->mRootNode->mName.Set( filename );
handleNodes( m_ctx->m_root, pScene ); handleNodes( m_ctx->m_root, pScene );
} }
@ -401,8 +404,12 @@ void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) { void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) {
m_currentNode = new aiNode; aiNode *newNode = new aiNode;
pushNode( newNode, pScene );
m_currentNode = newNode;
handleNodes( node, pScene ); handleNodes( node, pScene );
popNode();
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -413,6 +420,10 @@ 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;
// todo: child nodes?
handleNodes( node, pScene );
} }
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@ -444,6 +455,48 @@ void OpenGEXImporter::resolveReferences() {
} }
} }
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
ai_assert( NULL != pScene );
if( NULL != node ) {
if( m_nodeStack.empty() ) {
node->mParent = pScene->mRootNode;
} else {
aiNode *parent( m_nodeStack.back() );
ai_assert( NULL != parent );
node->mParent = parent;
}
m_nodeStack.push_back( node );
}
}
//------------------------------------------------------------------------------------------------
aiNode *OpenGEXImporter::popNode() {
if( m_nodeStack.empty() ) {
return NULL;
}
aiNode *node( top() );
m_nodeStack.pop_back();
return node;
}
//------------------------------------------------------------------------------------------------
aiNode *OpenGEXImporter::top() const {
if( m_nodeStack.empty() ) {
return NULL;
}
return m_nodeStack.back();
}
//------------------------------------------------------------------------------------------------
void OpenGEXImporter::clearNodeStack() {
m_nodeStack.clear();
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
} // Namespace OpenGEX } // Namespace OpenGEX

View File

@ -109,6 +109,10 @@ protected:
void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene ); void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene );
void handleMaterial( ODDLParser::DDLNode *node, aiScene *pScene ); void handleMaterial( ODDLParser::DDLNode *node, aiScene *pScene );
void resolveReferences(); void resolveReferences();
void pushNode( aiNode *node, aiScene *pScene );
aiNode *popNode();
aiNode *top() const;
void clearNodeStack();
private: private:
struct RefInfo { struct RefInfo {
@ -130,6 +134,7 @@ private:
ODDLParser::Context *m_ctx; ODDLParser::Context *m_ctx;
MetricInfo m_metrics[ MetricInfo::Max ]; MetricInfo m_metrics[ MetricInfo::Max ];
aiNode *m_currentNode; aiNode *m_currentNode;
std::vector<aiNode*> m_nodeStack;
std::vector<RefInfo*> m_unresolvedRefStack; std::vector<RefInfo*> m_unresolvedRefStack;
}; };