2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-12-19 08:51:50 +00:00

fix: update warning for vertex limit to consider rigid and animated limits

This commit is contained in:
Jan Laupetin
2025-12-17 17:22:10 +00:00
parent 1e8ae0ff59
commit d39efa3b6f

View File

@@ -725,15 +725,34 @@ namespace
} }
} }
constexpr auto maxVertices = std::numeric_limits<decltype(XSurface::vertCount)>::max();
if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVertices)
{
con::error("Lod exceeds limit of {} vertices", maxVertices);
return false;
}
ReorderVerticesByWeightCount(xmodelToCommonVertexIndexLookup, surface, common); ReorderVerticesByWeightCount(xmodelToCommonVertexIndexLookup, surface, common);
// Since bone weights are sorted by weight count, the last must have the highest weight count
const auto maxWeightCount = common.m_vertex_bone_weights[xmodelToCommonVertexIndexLookup[xmodelToCommonVertexIndexLookup.size() - 1]].weightCount;
const auto modelIsRigid = maxWeightCount <= 1;
if (modelIsRigid)
{
constexpr auto maxVerticesForRigid = static_cast<size_t>(std::numeric_limits<decltype(XSurface::vertCount)>::max());
if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVerticesForRigid)
{
con::error("Lod exceeds limit of {} vertices for rigid models", maxVerticesForRigid);
return false;
}
}
else
{
constexpr auto maxVerticesForAnimated =
std::min(static_cast<size_t>(std::numeric_limits<decltype(XSurface::vertCount)>::max()),
static_cast<size_t>(std::numeric_limits<std::remove_extent_t<decltype(XSurfaceVertexInfo::vertCount)>>::max()));
if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVerticesForAnimated)
{
con::error("Lod exceeds limit of {} vertices for animated models", maxVerticesForAnimated);
return false;
}
}
surface.baseVertIndex = static_cast<uint16_t>(vertexOffset); surface.baseVertIndex = static_cast<uint16_t>(vertexOffset);
surface.vertCount = static_cast<uint16_t>(xmodelToCommonVertexIndexLookup.size()); surface.vertCount = static_cast<uint16_t>(xmodelToCommonVertexIndexLookup.size());
surface.verts0 = m_memory.Alloc<GfxPackedVertex>(surface.vertCount); surface.verts0 = m_memory.Alloc<GfxPackedVertex>(surface.vertCount);
@@ -748,11 +767,7 @@ namespace
if (!common.m_bone_weight_data.weights.empty()) if (!common.m_bone_weight_data.weights.empty())
{ {
// Since bone weights are sorted by weight count, the last must have the highest weight count if (modelIsRigid)
const auto maxWeightCount =
common.m_vertex_bone_weights[xmodelToCommonVertexIndexLookup[xmodelToCommonVertexIndexLookup.size() - 1]].weightCount;
if (maxWeightCount <= 1) // XModel is rigid
{ {
CreateVertListData(surface, xmodelToCommonVertexIndexLookup, common); CreateVertListData(surface, xmodelToCommonVertexIndexLookup, common);
} }