Kim Kulling 2017-10-02 09:33:51 +02:00
parent 1c76962c98
commit 3f4663e369
2 changed files with 15 additions and 4 deletions

View File

@ -261,6 +261,7 @@ OpenGEXImporter::OpenGEXImporter()
, m_nodeChildMap()
, m_meshCache()
, m_mesh2refMap()
, m_material2refMap()
, m_ctx( nullptr )
, m_metrics()
, m_currentNode( nullptr )
@ -482,7 +483,10 @@ void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
|| m_tokenType == Grammar::CameraNodeToken ) {
m_currentNode->mName.Set( name.c_str() );
} else if( m_tokenType == Grammar::MaterialToken ) {
aiString aiName;
aiName.Set( name );
m_currentMaterial->AddProperty( &aiName, AI_MATKEY_NAME );
m_material2refMap[ name ] = m_materialCache.size() - 1;
}
}
}
@ -1050,7 +1054,6 @@ void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pSc
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
} else if( prop->m_value->getString() == Grammar::SpecularPowerTextureToken ) {
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_SPECULAR( 0 ) );
} else if( prop->m_value->getString() == Grammar::EmissionTextureToken ) {
m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_EMISSIVE( 0 ) );
} else if( prop->m_value->getString() == Grammar::OpacyTextureToken ) {
@ -1166,7 +1169,7 @@ void OpenGEXImporter::resolveReferences() {
if( nullptr != currentRefInfo ) {
aiNode *node( currentRefInfo->m_node );
if( RefInfo::MeshRef == currentRefInfo->m_type ) {
for( size_t i = 0; i < currentRefInfo->m_Names.size(); i++ ) {
for( size_t i = 0; i < currentRefInfo->m_Names.size(); ++i ) {
const std::string &name( currentRefInfo->m_Names[ i ] );
ReferenceMap::const_iterator it( m_mesh2refMap.find( name ) );
if( m_mesh2refMap.end() != it ) {
@ -1175,7 +1178,14 @@ void OpenGEXImporter::resolveReferences() {
}
}
} else if( RefInfo::MaterialRef == currentRefInfo->m_type ) {
// ToDo!
for ( size_t i = 0; i < currentRefInfo->m_Names.size(); ++i ) {
const std::string name( currentRefInfo->m_Names[ i ] );
ReferenceMap::const_iterator it( m_material2refMap.find( name ) );
if ( m_material2refMap.end() != it ) {
unsigned int matIdx = static_cast< unsigned int >( m_material2refMap[ name ] );
m_currentMesh->mMaterialIndex = matIdx;
}
}
} else {
throw DeadlyImportError( "Unknown reference info to resolve." );
}

View File

@ -185,6 +185,7 @@ private:
std::vector<aiMesh*> m_meshCache;
typedef std::map<std::string, size_t> ReferenceMap;
std::map<std::string, size_t> m_mesh2refMap;
std::map<std::string, size_t> m_material2refMap;
ODDLParser::Context *m_ctx;
MetricInfo m_metrics[ MetricInfo::Max ];