From 06271dd6693bd9e84e7f175513df9c2b1d0edc30 Mon Sep 17 00:00:00 2001 From: Tahir Akhlaq Date: Wed, 18 Oct 2017 13:26:06 +0100 Subject: [PATCH] fixed issue with missing objects --- src/tools/pcb_reader/lgb.h | 11 +++++---- src/tools/pcb_reader/main.cpp | 44 +++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/tools/pcb_reader/lgb.h b/src/tools/pcb_reader/lgb.h index d783c36f..9de026ff 100644 --- a/src/tools/pcb_reader/lgb.h +++ b/src/tools/pcb_reader/lgb.h @@ -169,7 +169,7 @@ struct LGB_GROUP parent = parentStruct; header = *reinterpret_cast(buf + offset); name = std::string( buf + offset + header.groupNameOffset ); - entries.resize( header.entryCount ); + //entries.resize( header.entryCount ); //std::cout << name << std::endl; auto entriesOffset = offset + header.entriesOffset; for( auto i = 0; i < header.entryCount; ++i ) @@ -179,19 +179,20 @@ struct LGB_GROUP try { auto type = *reinterpret_cast(buf + entryOffset); - LGB_MODEL_ENTRY* entry; if( type == LgbEntryType::BgParts ) { - entries[i] = std::make_shared( buf, entryOffset ); + entries.push_back(std::make_shared( buf, entryOffset )); } + /* else if( type == LgbEntryType::Gimmick ) { - entries[i] = std::make_shared( buf, entryOffset ); + //entries[i] = std::make_shared( buf, entryOffset ); } else { - entries[i] = nullptr; + //entries[i] = nullptr; } + */ } catch( std::exception& e ) { diff --git a/src/tools/pcb_reader/main.cpp b/src/tools/pcb_reader/main.cpp index 1a655888..81ac0ebd 100644 --- a/src/tools/pcb_reader/main.cpp +++ b/src/tools/pcb_reader/main.cpp @@ -303,7 +303,7 @@ int main( int argc, char* argv[] ) index.index[1] + max_index + 1, index.index[2] + max_index + 1 ); } - //std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl; +// std::cout << std::to_string( index.unknown[0] )<< " " << std::to_string( index.unknown[1] )<< " " << std::to_string( index.unknown[2]) << std::endl; } max_index += entry.data.vertices.size() + entry.data.vertices_i16.size(); } @@ -315,34 +315,42 @@ int main( int argc, char* argv[] ) pushVerts( pcbFiles[fileName], fileName ); } std::cout << "Writing obj file " << "\n"; - std::cout << bgLgb.groups.size() << " entries " << "\n"; + std::cout << bgLgb.groups.size() << " groups " << "\n"; + uint32_t totalGroups = 0; + uint32_t totalGroupEntries = 0; for( const auto& group : bgLgb.groups ) { + //std::cout << "\t" << group.name << " Size " << group.header.entryCount << "\n"; + totalGroups++; for( const auto pEntry : group.entries ) { - if( !pEntry ) - continue; - auto pBgParts = dynamic_cast(pEntry.get()); - if( pBgParts && pBgParts->collisionFileName.empty() ) + + auto& fileName = pBgParts->collisionFileName; + if( pBgParts ) { - pBgParts->collisionFileName = pBgParts->modelFileName; - boost::replace_all( pBgParts->collisionFileName, "bgparts", "collision" ); - boost::replace_all( pBgParts->collisionFileName, ".mdl", ".pcb" ); - //std::cout << pBgParts->collisionFileName << " renamed\n"; + if ( fileName.empty() ) + fileName = pBgParts->modelFileName; + boost::replace_all( fileName, "bgparts", "collision" ); + boost::replace_all( fileName, ".mdl", ".pcb" ); } - if( !pBgParts || pBgParts->collisionFileName.empty() ) - //|| std::find( stringList.begin(), stringList.end(), pBgParts->collisionFileName ) != stringList.end() ) + + if( !pBgParts || fileName.empty() ) continue; - auto it = pcbFiles.find( pBgParts->collisionFileName ); - if( it == pcbFiles.end() ) { - loadPcbFile( pBgParts->collisionFileName ); - //std::cout << "\t\tLoaded PCB File " << pBgParts->collisionFileName << "\n"; + const auto& it = pcbFiles.find( fileName ); + if( it == pcbFiles.end() ) + { + loadPcbFile( fileName ); + //std::cout << "\t\tLoaded PCB File " << pBgParts->collisionFileName << "\n"; + } } + const auto& it = pcbFiles.find( fileName ); if( it != pcbFiles.end() ) { + totalGroupEntries++; + //std::cout << pBgParts->collisionFileName << "\n"; const auto* scale = &pBgParts->header.scale; @@ -350,10 +358,12 @@ int main( int argc, char* argv[] ) const auto* translation = &pBgParts->header.translation; const auto& pcb_file = it->second; - pushVerts( pcb_file, pBgParts->collisionFileName, scale, rotation, translation ); + pushVerts( pcb_file, fileName, scale, rotation, translation ); } } } + std::cout << "\n\nLoaded " << pcbFiles.size() << " PCB Files \n"; + std::cout << "Total Groups " << totalGroups << " Total entries " << totalGroupEntries << "\n"; } std::cout << "Finished exporting " << zoneName << " in " << std::chrono::duration_cast(std::chrono::system_clock::now() - startTime).count() << " seconds\n";