From 8a791816ed3215b0b919fe07ece7e376a2b053c0 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 4 May 2026 18:31:12 +0200 Subject: [PATCH] chore: set XSurface deformed property when applicable --- src/Common/Game/IW5/IW5_Assets.h | 5 +++++ src/ObjLoading/XModel/LoaderXModel.cpp.template | 13 ++++++++++--- src/ObjWriting/XModel/XModelDumper.cpp.template | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Common/Game/IW5/IW5_Assets.h b/src/Common/Game/IW5/IW5_Assets.h index ae694a85..e61fb58b 100644 --- a/src/Common/Game/IW5/IW5_Assets.h +++ b/src/Common/Game/IW5/IW5_Assets.h @@ -516,6 +516,11 @@ namespace IW5 typedef tdef_align32(16) XSurfaceTri XSurfaceTri16; + enum XSurfaceFlag + { + XSURFACE_FLAG_DEFORMED = 0x40 + }; + struct XSurface { unsigned char tileMode; diff --git a/src/ObjLoading/XModel/LoaderXModel.cpp.template b/src/ObjLoading/XModel/LoaderXModel.cpp.template index 018ada36..b3332821 100644 --- a/src/ObjLoading/XModel/LoaderXModel.cpp.template +++ b/src/ObjLoading/XModel/LoaderXModel.cpp.template @@ -752,9 +752,16 @@ namespace // 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; + const auto surfaceIsRigid = maxWeightCount <= 1; - if (modelIsRigid) +#if defined(FEATURE_IW3) || defined(FEATURE_IW4) + surface.deformed = !surfaceIsRigid; +#else + if (!surfaceIsRigid) + surface.flags |= XSURFACE_FLAG_DEFORMED; +#endif + + if (surfaceIsRigid) { constexpr auto maxVerticesForRigid = static_cast(std::numeric_limits::max()); if (vertexOffset + xmodelToCommonVertexIndexLookup.size() > maxVerticesForRigid) @@ -790,7 +797,7 @@ namespace if (!common.m_bone_weight_data.weights.empty()) { - if (modelIsRigid) + if (surfaceIsRigid) { CreateVertListData(surface, xmodelToCommonVertexIndexLookup, common); } diff --git a/src/ObjWriting/XModel/XModelDumper.cpp.template b/src/ObjWriting/XModel/XModelDumper.cpp.template index 434750af..06a7ff08 100644 --- a/src/ObjWriting/XModel/XModelDumper.cpp.template +++ b/src/ObjWriting/XModel/XModelDumper.cpp.template @@ -423,6 +423,12 @@ namespace if (surface.vertList) { +#if defined(FEATURE_IW3) || defined(FEATURE_IW4) + assert(!surface.deformed); +#else + assert((surface.flags & XSURFACE_FLAG_DEFORMED) == 0); +#endif + for (auto vertListIndex = 0u; vertListIndex < surface.vertListCount; vertListIndex++) { const auto& vertList = surface.vertList[vertListIndex]; @@ -442,6 +448,12 @@ namespace auto vertsBlendOffset = 0u; if (surface.vertInfo.vertsBlend) { +#if defined(FEATURE_IW3) || defined(FEATURE_IW4) + assert(surface.deformed); +#else + assert((surface.flags & XSURFACE_FLAG_DEFORMED) > 0); +#endif + // 1 bone weight for (auto vertIndex = 0; vertIndex < surface.vertInfo.vertCount[0]; vertIndex++) {