diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 9dd2197a7..b80c4738d 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -217,6 +217,7 @@ OpenGEXImporter::OpenGEXImporter() , m_ctx( NULL ) , m_currentNode( NULL ) , m_currentMesh( NULL ) +, m_currentMaterial( NULL ) , m_nodeStack() , m_unresolvedRefStack() { // empty @@ -722,14 +723,62 @@ void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene * } } +//------------------------------------------------------------------------------------------------ +static void getColorRGBA( aiColor3D *pColor, Value *data ) { + if( NULL == pColor || NULL == data ) { + return; + } + + pColor->r = data->getFloat(); + data = data->getNext(); + pColor->g = data->getFloat(); + data = data->getNext(); + pColor->b = data->getFloat(); + data = data->getNext(); +} + +//------------------------------------------------------------------------------------------------ +enum ColorType { + NoneColor = 0, + DiffuseColor +}; + +//------------------------------------------------------------------------------------------------ +static ColorType getColorType( Identifier *id ) { + const int res(strncmp("diffuse", id->m_buffer, id->m_len ) ); + if( 0 == res ) { + return DiffuseColor; + } + + return NoneColor; +} + //------------------------------------------------------------------------------------------------ void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ) { + m_currentMaterial = new aiMaterial; + m_materialCache.push_back( m_currentMaterial ); + + handleNodes( node, pScene ); } //------------------------------------------------------------------------------------------------ void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) { + if( NULL == node ) { + return; + } + Property *colorProp = node->getProperties(); + if( NULL != colorProp ) { + if( NULL != colorProp->m_id ) { + ColorType type( getColorType( colorProp->m_primData ) ); + if( type == DiffuseColor ) { + aiColor3D *col = new aiColor3D; + getColorRGBA( col, node->getValue() ); + m_currentMaterial->AddProperty( col, 1, AI_MATKEY_COLOR_DIFFUSE ); + } + } + } } //------------------------------------------------------------------------------------------------ diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index f5c328ff7..0d0d8f2f5 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -174,6 +174,8 @@ private: aiNode *m_currentNode; VertexContainer m_currentVertices; aiMesh *m_currentMesh; + aiMaterial *m_currentMaterial; + std::vector m_materialCache; std::vector m_nodeStack; std::vector m_unresolvedRefStack; };