diff --git a/src/ObjLoading/XModel/LoaderXModel.cpp.template b/src/ObjLoading/XModel/LoaderXModel.cpp.template index 993077f4..a4fc9a41 100644 --- a/src/ObjLoading/XModel/LoaderXModel.cpp.template +++ b/src/ObjLoading/XModel/LoaderXModel.cpp.template @@ -725,15 +725,34 @@ namespace } } - constexpr auto maxVertices = std::numeric_limits::max(); - if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVertices) - { - con::error("Lod exceeds limit of {} vertices", maxVertices); - return false; - } - 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(std::numeric_limits::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(std::numeric_limits::max()), + static_cast(std::numeric_limits>::max())); + + if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVerticesForAnimated) + { + con::error("Lod exceeds limit of {} vertices for animated models", maxVerticesForAnimated); + return false; + } + } + surface.baseVertIndex = static_cast(vertexOffset); surface.vertCount = static_cast(xmodelToCommonVertexIndexLookup.size()); surface.verts0 = m_memory.Alloc(surface.vertCount); @@ -748,11 +767,7 @@ namespace if (!common.m_bone_weight_data.weights.empty()) { - // 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; - - if (maxWeightCount <= 1) // XModel is rigid + if (modelIsRigid) { CreateVertListData(surface, xmodelToCommonVertexIndexLookup, common); }