From 1191322abeee02557f5a6b0d9ddc38e7ba1b5e7f Mon Sep 17 00:00:00 2001 From: LJW-Dev <48092720+LJW-Dev@users.noreply.github.com> Date: Sun, 19 Apr 2026 19:23:54 +0800 Subject: [PATCH] feat: minor bug fixes --- src/ObjLoading/Game/T6/BSP/BSPCreator.cpp | 55 +++++++++---------- .../Game/T6/BSP/Linker/MapEntsLinker.cpp | 4 +- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp index 174f41b4..2935adc3 100644 --- a/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp +++ b/src/ObjLoading/Game/T6/BSP/BSPCreator.cpp @@ -463,20 +463,16 @@ namespace size_t materialIndex; if (primitive.material) - { - size_t originalMaterialIdx = *primitive.material; - if (node.extras && node.extras->contains("flags")) - { - bool isNoDrawFlagSet = false; - materialIndex = createMaterialWithFlags(originalMaterialIdx, node.extras->at("flags"), isNoDrawFlagSet); - if (isNoDrawFlagSet && m_is_world_gfx) - continue; // noDraw flag doesn't work, so remove the surface from the graphics data instead - } - else - materialIndex = originalMaterialIdx; - } + materialIndex = *primitive.material; else materialIndex = m_emptyMaterialIndex; + if (node.extras && node.extras->contains("flags")) + { + bool isNoDrawFlagSet = false; + materialIndex = createMaterialWithFlags(materialIndex, node.extras->at("flags"), isNoDrawFlagSet); + if (isNoDrawFlagSet && m_is_world_gfx) + continue; // noDraw flag doesn't work, so remove the surface from the graphics data instead + } BSPSurface surface; CreateSurface(accessorsForVertex, nodeMatrix, materialIndex, false, surface); @@ -856,24 +852,15 @@ namespace assert(node.extras->contains("classname")); BSPEntity entity; - bool doesClassContainModel = false; - for (auto& element : node.extras->items()) + std::string classname = node.extras->at("classname"); + if (node.mesh && (classname.starts_with("trigger_") || !classname.compare("info_volume") || !classname.compare("script_brushmodel"))) { - std::string key = element.key(); - if (!key.compare("origin") || !key.compare("angles") || !key.compare("flags")) - continue; + if (node.extras->contains("model")) + { + con::error("Node {} cannot have a model property when its class is a trigger, info_volume or script_brushmodel"); + return false; + } - if (!key.compare("model")) - doesClassContainModel = true; - - BSPEntityEntry entry; - entry.key = key; - entry.value = element.value(); - entity.entries.emplace_back(entry); - } - - if (node.mesh && !doesClassContainModel) - { if (m_is_world_gfx) entity.modelIndex = addScriptTerrainModel(jRoot, node, nodeMatrix); else @@ -882,6 +869,18 @@ namespace else entity.modelIndex = 0; + for (auto& element : node.extras->items()) + { + std::string key = element.key(); + if (!key.compare("origin") || !key.compare("angles") || !key.compare("flags")) + continue; + + BSPEntityEntry entry; + entry.key = key; + entry.value = element.value(); + entity.entries.emplace_back(entry); + } + Eigen::Vector4f position(0, 0, 0, 1.0f); Eigen::Vector4f transformedPosition = nodeMatrix * position; entity.origin.x = transformedPosition.x(); diff --git a/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.cpp b/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.cpp index 548cff22..943b773e 100644 --- a/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.cpp +++ b/src/ObjLoading/Game/T6/BSP/Linker/MapEntsLinker.cpp @@ -159,11 +159,13 @@ namespace entityString.append("{\n"); entityString.append(std::format("\"origin\" \"{}\"\n", BSP::BSPUtil::convertVec3ToString(origin))); - entityString.append(std::format("\"angles\" \"{}\"\n", BSP::BSPUtil::convertVec3ToString(angles))); + for (auto& entry : entity.entries) entityString.append(std::format("\"{}\" \"{}\"\n", entry.key, entry.value)); if (entity.modelIndex != 0) entityString.append(std::format("\"model\" \"*{}\"\n", entity.modelIndex)); + else // entities with generated models can't have rotation data + entityString.append(std::format("\"angles\" \"{}\"\n", BSP::BSPUtil::convertVec3ToString(angles))); entityString.append("}\n"); }