From 21dcf7b46dd507190c62c80e0ded007e5281bcec Mon Sep 17 00:00:00 2001 From: LJW-Dev <48092720+LJW-Dev@users.noreply.github.com> Date: Wed, 11 Feb 2026 17:14:37 +0800 Subject: [PATCH] WIP unique tree for each material type --- .../Game/T6/BSP/Linker/ClipMapLinker.cpp | 22 ++++++++++++++++++- .../Game/T6/BSP/Linker/ClipMapLinker.h | 3 +-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp index 22d41530..1d9fc1cd 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.cpp @@ -212,6 +212,26 @@ namespace BSP if (leafObjectCount > highestLeafObjectCount) highestLeafObjectCount = leafObjectCount; + std::vector uniqueMaterials; + for (size_t objIdx = 0; objIdx < leafObjectCount; objIdx++) + { + int partitionIdx = tree->leaf->getObject(objIdx)->partitionIndex; + unsigned materialIndex = partitionToMaterialMap[partitionIdx]; + bool foundIdx = false; + for (unsigned int uniqueMat : uniqueMaterials) + { + if (uniqueMat == materialIndex) + { + foundIdx = true; + break; + } + } + if (!foundIdx) + uniqueMaterials.emplace_back(materialIndex); + } + + con::info("{} {}", uniqueMaterials.size(), uniqueMaterials[0]); + // BO2 has a maximum limit of 128 children per AABB tree (essentially), // so this is fixed by adding multiple parent AABB trees that hold 128 children each size_t result = leafObjectCount / BSPGameConstants::MAX_AABB_TREE_CHILDREN; @@ -533,7 +553,7 @@ namespace BSP partitionVec.emplace_back(partition); - partitionToSurfaceMap.emplace_back(surfIdx); + partitionToMaterialMap.emplace_back(surface.materialIndex); } } clipMap->partitionCount = static_cast(partitionVec.size()); diff --git a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.h b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.h index 5597b7e4..a4f5f19c 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.h +++ b/src/ObjLoading/Game/T6/BSP/Linker/ClipMapLinker.h @@ -31,8 +31,7 @@ namespace BSP std::vector leafVec; std::vector AABBTreeVec; size_t highestLeafObjectCount = 0; - std::vector partitionToSurfaceMap; - std::vector surfaceToMaterialMap; + std::vector partitionToMaterialMap; void addAABBTreeFromLeaf(clipMap_t* clipMap, BSPTree* tree, size_t* out_parentCount, size_t* out_parentStartIndex); int16_t loadBSPNode(clipMap_t* clipMap, BSPTree* tree); bool loadBSPTree(clipMap_t* clipMap, BSPData* bsp);