diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 8f9a359ae..4172ae97b 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -176,6 +176,7 @@ OpenGEXImporter::OpenGEXImporter() , m_mesh2refMap() , m_ctx( NULL ) , m_currentNode( NULL ) +, m_nodeStack() , m_unresolvedRefStack() { // empty } @@ -214,6 +215,8 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce bool success( myParser.parse() ); if( success ) { m_ctx = myParser.getContext(); + pScene->mRootNode = new aiNode; + pScene->mRootNode->mName.Set( filename ); handleNodes( m_ctx->m_root, pScene ); } @@ -401,8 +404,12 @@ void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene //------------------------------------------------------------------------------------------------ void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) { - m_currentNode = new aiNode; + aiNode *newNode = new aiNode; + pushNode( newNode, pScene ); + m_currentNode = newNode; handleNodes( node, pScene ); + + popNode(); } //------------------------------------------------------------------------------------------------ @@ -413,6 +420,10 @@ void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) { // store name to reference relation 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 diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index 0bc2378b7..13154e06d 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -109,6 +109,10 @@ protected: void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene ); void handleMaterial( ODDLParser::DDLNode *node, aiScene *pScene ); void resolveReferences(); + void pushNode( aiNode *node, aiScene *pScene ); + aiNode *popNode(); + aiNode *top() const; + void clearNodeStack(); private: struct RefInfo { @@ -130,6 +134,7 @@ private: ODDLParser::Context *m_ctx; MetricInfo m_metrics[ MetricInfo::Max ]; aiNode *m_currentNode; + std::vector m_nodeStack; std::vector m_unresolvedRefStack; };