2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-06-06 08:42:35 +00:00

fix: better ignore/allow for meshes and classes when loading gltf

This commit is contained in:
LJW-Dev
2026-04-29 17:21:11 +08:00
committed by Jan Laupetin
parent d411855cc2
commit c227779ac4
+11 -8
View File
@@ -214,6 +214,7 @@ namespace
Eigen::Matrix4f& nodeMatrix, Eigen::Matrix4f& nodeMatrix,
size_t materialIndex, size_t materialIndex,
bool convertWorldToLocalPos, bool convertWorldToLocalPos,
const gltf::JsonNode& node,
BSPSurface& out_surface) BSPSurface& out_surface)
{ {
// clang-format off // clang-format off
@@ -270,7 +271,7 @@ namespace
throw GltfLoadException("Index count must be dividable by 3 for triangles"); throw GltfLoadException("Index count must be dividable by 3 for triangles");
const auto faceCount = indexCount / 3u; const auto faceCount = indexCount / 3u;
if (faceCount > UINT16_MAX) if (faceCount > UINT16_MAX)
throw GltfLoadException(std::format("Face count ({}) exceeded the UINT16_MAX", faceCount)); throw GltfLoadException(std::format("Face count ({}) on node {} exceeded the UINT16_MAX", faceCount, node.name.value_or("unnamed node")));
out_surface.vertexCount = static_cast<uint16_t>(vertexCount); out_surface.vertexCount = static_cast<uint16_t>(vertexCount);
out_surface.triCount = static_cast<uint16_t>(faceCount); out_surface.triCount = static_cast<uint16_t>(faceCount);
@@ -543,7 +544,7 @@ namespace
materialIndex = createMaterialWithFlags(materialIndex, node.extras->at("flags")); materialIndex = createMaterialWithFlags(materialIndex, node.extras->at("flags"));
BSPSurface surface; BSPSurface surface;
CreateSurface(accessorsForVertex, nodeMatrix, materialIndex, false, surface); CreateSurface(accessorsForVertex, nodeMatrix, materialIndex, false, node, surface);
m_curr_bsp_world->staticSurfaces.emplace_back(surface); m_curr_bsp_world->staticSurfaces.emplace_back(surface);
} }
@@ -838,7 +839,7 @@ namespace
materialIndex = m_emptyMaterialIndex; materialIndex = m_emptyMaterialIndex;
BSPSurface surface; BSPSurface surface;
CreateSurface(accessorsForVertex, nodeMatrix, materialIndex, true, surface); CreateSurface(accessorsForVertex, nodeMatrix, materialIndex, true, node, surface);
m_curr_bsp_world->scriptSurfaces.emplace_back(surface); m_curr_bsp_world->scriptSurfaces.emplace_back(surface);
} }
@@ -991,8 +992,10 @@ namespace
{ {
std::string classnameVal = node.extras->at("classname"); std::string classnameVal = node.extras->at("classname");
if ((m_is_world_gfx && !classnameVal.compare("script_brushmodel_gfx")) // make sure only GFX loads script_brushmodel_gfx if ((!m_is_world_gfx && !classnameVal.compare("script_brushmodel_gfx")) // skip GFX brush in collision
|| (!m_is_world_gfx && classnameVal.compare("script_brushmodel_gfx"))) || (m_is_world_gfx && classnameVal.compare("script_brushmodel_gfx"))) // include GFX brush in graphics
return false;
return addClassNode(jRoot, node, nodeMatrix); return addClassNode(jRoot, node, nodeMatrix);
} }
@@ -1022,8 +1025,8 @@ namespace
if (node.extras && node.extras->contains("flags")) if (node.extras && node.extras->contains("flags"))
getSurfaceAndContentFlags(node.extras->at("flags"), surfaceFlags, contentFlags); getSurfaceAndContentFlags(node.extras->at("flags"), surfaceFlags, contentFlags);
if (!m_is_world_gfx bool isNoDraw = (surfaceFlags & BSPFlags::surfaceTypeToFlagMap[BSPFlags::SURF_TYPE_NODRAW].surfaceFlags) != 0;
|| ((surfaceFlags & BSPFlags::surfaceTypeToFlagMap[BSPFlags::SURF_TYPE_NODRAW].surfaceFlags) == 0)) // ignore if gfx mesh has nodraw flag if (!m_is_world_gfx || (m_is_world_gfx && !isNoDraw)) // nodraw flag doesn't set faces to invisible, so remove it from the draw data
return addMeshNode(jRoot, node, nodeMatrix); return addMeshNode(jRoot, node, nodeMatrix);
} }
@@ -1086,7 +1089,7 @@ namespace
material.materialColour.w = 1.0f; material.materialColour.w = 1.0f;
material.surfaceFlags = 0; material.surfaceFlags = 0;
material.contentFlags = 0; material.contentFlags = 1; // all materials start out as solid
if (jsMaterial.extras && jsMaterial.extras->type) if (jsMaterial.extras && jsMaterial.extras->type)
{ {
bool foundType = false; bool foundType = false;