From 50b43f76e12e269be8bb7e5985115bc0e5d4d1b7 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Thu, 5 Oct 2017 12:51:08 +0300 Subject: [PATCH] OpenGEXImporter: Copy materials to scene --- code/OpenGEXImporter.cpp | 14 ++++++++++++++ code/OpenGEXImporter.h | 1 + 2 files changed, 15 insertions(+) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index 7073a5e..47e3e3e 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -322,6 +322,7 @@ void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pSce copyMeshes( pScene ); copyCameras( pScene ); copyLights( pScene ); + copyMaterials( pScene ); resolveReferences(); createNodeTree( pScene ); } @@ -1159,6 +1160,19 @@ void OpenGEXImporter::copyLights( aiScene *pScene ) { } //------------------------------------------------------------------------------------------------ +void OpenGEXImporter::copyMaterials( aiScene *pScene ) { + ai_assert( nullptr != pScene ); + + if ( m_materialCache.empty() ) { + return; + } + + pScene->mNumMaterials = static_cast(m_materialCache.size()); + pScene->mMaterials = new aiMaterial*[ pScene->mNumMaterials ]; + std::copy( m_materialCache.begin(), m_materialCache.end(), pScene->mMaterials ); +} + +//------------------------------------------------------------------------------------------------ void OpenGEXImporter::resolveReferences() { if( m_unresolvedRefStack.empty() ) { return; diff --git a/code/OpenGEXImporter.h b/code/OpenGEXImporter.h index aefd9ef..c0cde57 100644 --- a/code/OpenGEXImporter.h +++ b/code/OpenGEXImporter.h @@ -133,6 +133,7 @@ protected: void copyMeshes( aiScene *pScene ); void copyCameras( aiScene *pScene ); void copyLights( aiScene *pScene ); + void copyMaterials( aiScene *pScene ); void resolveReferences(); void pushNode( aiNode *node, aiScene *pScene ); aiNode *popNode(); -- 2.7.4