From 72b535f0aca302f1d9ea49f345faf2a6db699640 Mon Sep 17 00:00:00 2001 From: HarrievG Date: Sun, 19 Jun 2022 01:26:16 +0200 Subject: [PATCH] - Fixed bsp/worldspawn scene node traversal --- neo/idlib/MapFile.cpp | 5 ++++- neo/idlib/gltfParser.cpp | 1 + neo/renderer/Model_gltf.cpp | 24 ++++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/neo/idlib/MapFile.cpp b/neo/idlib/MapFile.cpp index 280eb7bd..f7ef3189 100644 --- a/neo/idlib/MapFile.cpp +++ b/neo/idlib/MapFile.cpp @@ -33,6 +33,9 @@ If you have questions concerning this license or the applicable additional terms #include "../renderer/Image.h" + +idCVar gltf_MapSceneName( "gltf_MapSceneName", "Scene", CVAR_SYSTEM , "Scene to use when d-mapping a gltf/glb" ); + /* =============== FloatCRC @@ -1671,7 +1674,7 @@ bool idMapFile::Parse( const char* filename, bool ignoreRegion, bool osPath ) else if( isGTLF ) { gltfParser->Load( fullName ); - idMapEntity::GetEntities( gltfParser->currentAsset, entities, gltfParser->currentAsset->GetSceneId( "Scene" ) ); + idMapEntity::GetEntities( gltfParser->currentAsset, entities, gltfParser->currentAsset->GetSceneId( gltf_MapSceneName.GetString() ) ); } else { diff --git a/neo/idlib/gltfParser.cpp b/neo/idlib/gltfParser.cpp index 5932ba6d..5e93b11a 100644 --- a/neo/idlib/gltfParser.cpp +++ b/neo/idlib/gltfParser.cpp @@ -1987,6 +1987,7 @@ bool GLTF_Parser::loadGLB( idStr filename ) } Parse(); + delete file; return true; } diff --git a/neo/renderer/Model_gltf.cpp b/neo/renderer/Model_gltf.cpp index 5085a5e3..95eb047f 100644 --- a/neo/renderer/Model_gltf.cpp +++ b/neo/renderer/Model_gltf.cpp @@ -316,6 +316,25 @@ void ProcessSceneNode( idMapEntity* newEntity, gltfNode* node, idMat4& trans, gl newEntity->epairs.Set( "origin", origin.ToString() ); } +void Map_AddMeshes( idMapEntity* _Entity, gltfNode* _Node, idMat4& _Trans, gltfData* _Data ) +{ + gltfData::ResolveNodeMatrix( _Node ); + idMat4 curTrans = _Trans * _Node->matrix; + + if( _Node->mesh != -1 ) + { + for( auto prim : _Data->MeshList( )[_Node->mesh]->primitives ) + { + _Entity->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, _Data, curTrans ) ); + } + } + + for( auto& child : _Node->children ) + { + Map_AddMeshes( _Entity, _Data->NodeList( )[child], curTrans, _Data ); + } +}; + int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneID ) { idMapEntity* worldspawn = new( TAG_IDLIB_GLTF ) idMapEntity(); @@ -341,10 +360,7 @@ int idMapEntity::GetEntities( gltfData* data, EntityListRef entities, int sceneI // account all meshes starting with "worldspawn." or "BSP" in the name if( idStr::Icmpn( node->name, "BSP", 3 ) == 0 || idStr::Icmpn( node->name, "worldspawn.", 11 ) == 0 ) { - for( auto prim : data->MeshList()[node->mesh]->primitives ) - { - worldspawn->AddPrimitive( MapPolygonMesh::ConvertFromMeshGltf( prim, data , mat4_identity ) ); - } + Map_AddMeshes( worldspawn, node, mat4_identity, data ); } else {