mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-01 06:27:26 +00:00
chore: set proper flags and data for animated models
This commit is contained in:
@@ -540,6 +540,15 @@ namespace T5
|
||||
XSurfaceCollisionTree* collisionTree;
|
||||
};
|
||||
|
||||
enum XSurfaceFlag
|
||||
{
|
||||
XSURFACE_FLAG_QUANTIZED = 0x1,
|
||||
XSURFACE_FLAG_SKINNED = 0x2,
|
||||
XSURFACE_FLAG_CONSTANT_COLOR = 0x4,
|
||||
XSURFACE_FLAG_DEFORMED = 0x80,
|
||||
XSURFACE_FLAG_STREAMED = 0x8000,
|
||||
};
|
||||
|
||||
struct XSurfaceTri
|
||||
{
|
||||
uint16_t i[3];
|
||||
|
@@ -2743,6 +2743,14 @@ namespace T6
|
||||
float transWeight;
|
||||
};
|
||||
|
||||
enum XSurfaceFlag
|
||||
{
|
||||
XSURFACE_FLAG_QUANTIZED = 0x1,
|
||||
XSURFACE_FLAG_SKINNED = 0x2,
|
||||
XSURFACE_FLAG_CONSTANT_COLOR = 0x4,
|
||||
XSURFACE_FLAG_DEFORMED = 0x80,
|
||||
};
|
||||
|
||||
struct XSurfaceVertexInfo
|
||||
{
|
||||
int16_t vertCount[4];
|
||||
|
@@ -72,6 +72,9 @@ namespace
|
||||
auto* xmodel = m_memory.Alloc<XModel>();
|
||||
xmodel->name = m_memory.Dup(assetName.c_str());
|
||||
|
||||
m_materials.clear();
|
||||
m_surfaces.clear();
|
||||
|
||||
AssetRegistration<AssetXModel> registration(assetName, xmodel);
|
||||
if (!LoadFromFile(*file.m_stream, *xmodel, context, registration))
|
||||
{
|
||||
@@ -340,6 +343,12 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Dirty hack, this is not necessarly always related to the name
|
||||
if (strstr(xmodel.name, "viewhands"))
|
||||
{
|
||||
memset(xmodel.trans, 0, sizeof(float) * 4 * (xmodel.numBones - xmodel.numRootBones));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -730,10 +739,18 @@ 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;
|
||||
|
||||
if (maxWeightCount == 0) // XModel is rigid
|
||||
{
|
||||
CreateVertListData(surface, xmodelToCommonVertexIndexLookup, common);
|
||||
}
|
||||
else if (maxWeightCount < std::extent_v<decltype(XSurfaceVertexInfo::vertCount)> + 1)
|
||||
{
|
||||
CreateVertsBlendData(surface, xmodelToCommonVertexIndexLookup, common);
|
||||
#if defined(FEATURE_T5) || defined(FEATURE_T6)
|
||||
surface.flags |= XSURFACE_FLAG_SKINNED | XSURFACE_FLAG_DEFORMED;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << std::format("Models must not have vertices that are influenced by more than {} bones\n",
|
||||
@@ -916,6 +933,24 @@ namespace
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(FEATURE_T5) || defined(FEATURE_T6)
|
||||
static bool HasAnySkinnedSurfs(const XModel& xmodel)
|
||||
{
|
||||
for (auto lodIndex = 0u; lodIndex < xmodel.numLods; lodIndex++)
|
||||
{
|
||||
const auto& lod = xmodel.lodInfo[lodIndex];
|
||||
for (auto surfIndex = lod.surfIndex; surfIndex < lod.numsurfs; surfIndex++)
|
||||
{
|
||||
const auto& surf = xmodel.surfs[lod.surfIndex + surfIndex];
|
||||
if (surf.flags & XSURFACE_FLAG_DEFORMED)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CreateXModelFromJson(const JsonXModel& jXModel, XModel& xmodel, AssetCreationContext& context, AssetRegistration<AssetXModel>& registration)
|
||||
{
|
||||
constexpr auto maxLods = std::extent_v<decltype(XModel::lodInfo)>;
|
||||
@@ -964,6 +999,10 @@ namespace
|
||||
else
|
||||
xmodel.collLod = -1;
|
||||
|
||||
#if defined(FEATURE_T5) || defined(FEATURE_T6)
|
||||
xmodel.lodRampType = HasAnySkinnedSurfs(xmodel) ? XMODEL_LOD_RAMP_SKINNED : XMODEL_LOD_RAMP_RIGID;
|
||||
#endif
|
||||
|
||||
if (jXModel.physPreset)
|
||||
{
|
||||
auto* physPreset = context.LoadDependency<AssetPhysPreset>(jXModel.physPreset.value());
|
||||
|
@@ -282,7 +282,7 @@ namespace
|
||||
|
||||
void AddXModelMaterials(XModelCommon& out, DistinctMapper<Material*>& materialMapper, const XModel* model)
|
||||
{
|
||||
for (auto surfaceMaterialNum = 0; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++)
|
||||
for (auto surfaceMaterialNum = 0u; surfaceMaterialNum < model->numsurfs; surfaceMaterialNum++)
|
||||
{
|
||||
Material* material = model->materialHandles[surfaceMaterialNum];
|
||||
if (materialMapper.Add(material))
|
||||
|
Reference in New Issue
Block a user