From ed57fac879a980fb6c71ceffd57b59d7b61d88ff Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 8 Apr 2015 20:43:55 +0200 Subject: [PATCH] create node tree Signed-off-by: Kim Kulling --- code/OpenGEXImporter.cpp | 53 ++++++++++++++++++++++++++++++++++------ code/OpenGEXImporter.h | 9 +++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 2b8fd207f..8454ae1f2 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -211,6 +211,8 @@ OpenGEXImporter::RefInfo::~RefInfo() { //------------------------------------------------------------------------------------------------ OpenGEXImporter::OpenGEXImporter() : m_meshCache() +, m_root( NULL ) +, m_nodeChildMap() , m_mesh2refMap() , m_ctx( NULL ) , m_currentNode( NULL ) @@ -261,6 +263,7 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce copyMeshes( pScene ); resolveReferences(); + createNodeTree( pScene ); } //------------------------------------------------------------------------------------------------ @@ -724,6 +727,16 @@ void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pS } +//------------------------------------------------------------------------------------------------ +void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) { + +} + +//------------------------------------------------------------------------------------------------ +void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) { + +} + //------------------------------------------------------------------------------------------------ void OpenGEXImporter::copyMeshes( aiScene *pScene ) { if( m_meshCache.empty() ) { @@ -756,7 +769,7 @@ void OpenGEXImporter::resolveReferences() { if( m_mesh2refMap.end() != it ) { unsigned int meshIdx = m_mesh2refMap[ name ]; node->mMeshes[ i ] = meshIdx; - node->mNumMeshes++; + //node->mNumMeshes++; } } } else if( RefInfo::MaterialRef == currentRefInfo->m_type ) { @@ -769,13 +782,21 @@ void OpenGEXImporter::resolveReferences() { } //------------------------------------------------------------------------------------------------ -void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) { - -} - -//------------------------------------------------------------------------------------------------ -void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) { +void OpenGEXImporter::createNodeTree( aiScene *pScene ) { + if( NULL == m_root ) { + return; + } + if( m_root->m_children.empty() ) { + return; + } + size_t i( 0 ); + pScene->mRootNode->mNumChildren = m_root->m_children.size(); + pScene->mRootNode->mChildren = new C_STRUCT aiNode*[ pScene->mRootNode->mNumChildren ]; + for( ChildInfo::NodeList::iterator it = m_root->m_children.begin(); it != m_root->m_children.end(); it++ ) { + pScene->mRootNode->mChildren[ i ] = *it; + i++; + } } //------------------------------------------------------------------------------------------------ @@ -783,12 +804,30 @@ void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) { ai_assert( NULL != pScene ); if( NULL != node ) { + ChildInfo *info( NULL ); if( m_nodeStack.empty() ) { node->mParent = pScene->mRootNode; + NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) ); + if( m_nodeChildMap.end() == it ) { + info = new ChildInfo; + m_root = info; + m_nodeChildMap[ node->mParent ] = info; + } else { + info = it->second; + } + info->m_children.push_back( node ); } else { aiNode *parent( m_nodeStack.back() ); ai_assert( NULL != parent ); node->mParent = parent; + NodeChildMap::iterator it( m_nodeChildMap.find( node->mParent ) ); + if( m_nodeChildMap.end() == it ) { + info = new ChildInfo; + m_nodeChildMap[ node->mParent ] = info; + } else { + info = it->second; + } + info->m_children.push_back( node ); } m_nodeStack.push_back( node ); } diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index f1b608a4b..f5c328ff7 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -120,6 +120,7 @@ protected: aiNode *popNode(); aiNode *top() const; void clearNodeStack(); + void createNodeTree( aiScene *pScene ); private: struct VertexContainer { @@ -156,6 +157,14 @@ private: RefInfo &operator = ( const RefInfo & ); }; + struct ChildInfo { + typedef std::list NodeList; + std::list m_children; + }; + ChildInfo *m_root; + typedef std::map NodeChildMap; + NodeChildMap m_nodeChildMap; + std::vector m_meshCache; typedef std::map ReferenceMap; std::map m_mesh2refMap;