2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-25 02:51:43 +00:00

chore: imitate game xmodel behaviour in always having even tri count

This commit is contained in:
Jan Laupetin
2026-05-04 19:15:08 +02:00
parent 8a791816ed
commit a128fbeb5e
@@ -9,12 +9,16 @@
#if GAME == "IW3"
#define FEATURE_IW3
#define EVEN_TRI_COUNT
#elif GAME == "IW4"
#define FEATURE_IW4
#define EVEN_TRI_COUNT
#elif GAME == "IW5"
#define FEATURE_IW5
#define EVEN_TRI_COUNT
#elif GAME == "T5"
#define FEATURE_T5
#define EVEN_TRI_COUNT
#elif GAME == "T6"
#define FEATURE_T6
#endif
@@ -26,6 +30,7 @@
#include JSON_HEADER
#include "Asset/AssetRegistration.h"
#include "Utils/Alignment.h"
#include "Utils/Logging/Log.h"
#include "Utils/QuatInt16.h"
#include "Utils/StringUtils.h"
@@ -723,7 +728,14 @@ namespace
}
surface.triCount = static_cast<uint16_t>(commonObject.m_faces.size());
#ifdef EVEN_TRI_COUNT
// Some games round up to an even tri count
const auto allocatedTriCount = utils::Align<unsigned>(surface.triCount, 2);
surface.triIndices = m_memory.Alloc<XSurfaceTri>(allocatedTriCount);
#else
surface.triIndices = m_memory.Alloc<XSurfaceTri>(surface.triCount);
#endif
xmodelToCommonVertexIndexLookup.reserve(static_cast<size_t>(surface.triCount) * std::extent_v<decltype(XModelFace::vertexIndex)>);
for (auto faceIndex = 0u; faceIndex < surface.triCount; faceIndex++)
@@ -816,6 +828,18 @@ namespace
}
}
#ifdef EVEN_TRI_COUNT
// The game makes sure to allows have an even triCount
// If the triCount is uneven, an additional tri is added that uses the last vertex three times
if (allocatedTriCount > surface.triCount)
{
assert(allocatedTriCount == surface.triCount + 1);
surface.triIndices[allocatedTriCount - 1].i[0] = surface.triIndices[surface.triCount - 1].i[2];
surface.triIndices[allocatedTriCount - 1].i[1] = surface.triIndices[surface.triCount - 1].i[2];
surface.triIndices[allocatedTriCount - 1].i[2] = surface.triIndices[surface.triCount - 1].i[2];
}
#endif
return true;
}