diff --git a/neo/idlib/gltfParser.cpp b/neo/idlib/gltfParser.cpp index 0bc5ef6f..0c218b5a 100644 --- a/neo/idlib/gltfParser.cpp +++ b/neo/idlib/gltfParser.cpp @@ -1948,7 +1948,7 @@ bool GLTF_Parser::loadGLB( idStr filename ) unsigned int chunk_type = 0; // 4 bytes unsigned int chunk_length = 0; // 4 bytes byte* data = nullptr; - gltfData* dataCache = gltfData::Data( filename ); + gltfData* dataCache = gltfData::Data( filename, true ); currentAsset = dataCache; int chunkCount = 0; @@ -2074,21 +2074,18 @@ bool GLTF_Parser::Parse() bool GLTF_Parser::Load( idStr filename ) { - //seriously fix this; proper gltf data cache. - //.. and destroy it properly too!! - static idStr lastFile = ""; - //next line still has to be fixed. - //gfx is not updated on command - common->SetRefreshOnPrint( true ); + //.. and destroy data !! - if( lastFile == filename ) + gltfData* data = gltfData::Data( filename ); + currentFile = filename; + if( data != nullptr ) { - common->Warning( "Did not parse %s again", filename.c_str() ); + currentAsset = data; return true; } - lastFile = filename; - currentFile = filename; + + common->SetRefreshOnPrint( true ); if( filename.CheckExtension( ".glb" ) ) { if( !loadGLB( filename ) ) @@ -2104,7 +2101,7 @@ bool GLTF_Parser::Load( idStr filename ) common->FatalError( "Failed to read file" ); } - gltfData* data = gltfData::Data( filename ); + data = gltfData::Data( filename , true ); data->FileName( filename ); byte* dataBuff = data->AddData( length ); currentAsset = data; diff --git a/neo/idlib/gltfProperties.h b/neo/idlib/gltfProperties.h index ca2c67c2..c8293dc2 100644 --- a/neo/idlib/gltfProperties.h +++ b/neo/idlib/gltfProperties.h @@ -793,18 +793,26 @@ public: static idHashIndex fileDataHash; static idList dataList; - //add data from filename - static gltfData* Data( idStr& fileName ) + //add data for filename + static gltfData* Data( idStr& fileName, bool create = false ) { - dataList.AssureSizeAlloc( dataList.Num() + 1, idListNewElement ); - dataList[dataList.Num() - 1]->FileName( fileName ); - fileDataHash.Add( fileDataHash.GenerateKey( fileName ), dataList.Num() - 1 ); - return dataList[dataList.Num() - 1]; - } - //find data; - static gltfData* Data( const char* filename ) - { - return dataList[fileDataHash.First( fileDataHash.GenerateKey( filename ) )]; + int key = fileDataHash.GenerateKey( fileName ); + int index = fileDataHash.GetFirst( key ); + + if( create && index == -1 ) + { + index = dataList.Num( ); + dataList.AssureSizeAlloc( index + 1, idListNewElement ); + dataList[index]->FileName( fileName ); + fileDataHash.Add( fileDataHash.GenerateKey( fileName ), index ); + } + + if( !create && index < 0 ) + { + return nullptr; + } + + return dataList[index]; } static const idList& DataList() { diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 578b3698..e3302223 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -163,18 +163,7 @@ void idRenderModelGLTF::InitFromFile( const char* fileName ) model_state = DM_STATIC; gltfManager::ExtractIdentifier( gltfFileName, meshID, meshName ); - - if( gltfParser->currentFile.Length() ) - { - if( gltfParser->currentAsset && gltfParser->currentFile != gltfFileName ) - { - common->FatalError( "multiple GLTF file loading not supported" ); - } - } - else - { - gltfParser->Load( gltfFileName ); - } + gltfParser->Load( gltfFileName ); timeStamp = fileSystem->GetTimestamp( gltfFileName ); data = gltfParser->currentAsset; @@ -275,6 +264,12 @@ bool idRenderModelGLTF::LoadBinaryModel( idFile* file, const ID_TIME_T sourceTim hasAnimations = false; fileExclusive = false; // not written. root = nullptr; + + if( !idRenderModelStatic::LoadBinaryModel( file, sourceTimeStamp ) ) + { + return false; + } + unsigned int magic = 0; file->ReadBig( magic ); @@ -607,18 +602,7 @@ idFile_Memory* idRenderModelGLTF::GetAnimBin( idStr animName , const ID_TIME_T idStr gltfFileName = idStr( animName ); idStr name; gltfManager::ExtractIdentifier( gltfFileName, id, name ); - - if( gltfParser->currentFile.Length( ) ) - { - if( gltfParser->currentAsset && gltfParser->currentFile != gltfFileName ) - { - common->FatalError( "multiple GLTF file loading not supported" ); - } - } - else - { - gltfParser->Load( gltfFileName ); - } + gltfParser->Load( gltfFileName ); gltfData* data = gltfParser->currentAsset;