Add support for up to 65536 skeleton bones in skinned meshes

https://forum.flaxengine.com/t/import-fbx-with-bones-more-than-256/1196
This commit is contained in:
Wojtek Figat
2025-01-08 18:48:50 +01:00
parent 1f294605a3
commit 3505b8971b
6 changed files with 123 additions and 8 deletions

View File

@@ -396,8 +396,27 @@ bool SkinnedModel::SetupSkeleton(const Array<SkeletonNode>& nodes, const Array<S
// Validate input
if (nodes.Count() <= 0 || nodes.Count() > MAX_uint16)
return true;
if (bones.Count() <= 0 || bones.Count() > MODEL_MAX_BONES_PER_MODEL)
return true;
if (bones.Count() <= 0)
{
if (bones.Count() > 255)
{
for (auto& lod : LODs)
{
for (auto& mesh : lod.Meshes)
{
auto* vertexLayout = mesh.GetVertexLayout();
VertexElement element = vertexLayout ? vertexLayout->FindElement(VertexElement::Types::BlendIndices) : VertexElement();
if (element.Format == PixelFormat::R8G8B8A8_UInt)
{
LOG(Warning, "Cannot use more than 255 bones if skinned model uses 8-bit storage for blend indices in vertices.");
return true;
}
}
}
}
if (bones.Count() > MODEL_MAX_BONES_PER_MODEL)
return true;
}
auto model = this;
if (!model->IsVirtual())
return true;
@@ -557,7 +576,7 @@ bool SkinnedModel::LoadHeader(ReadStream& stream, byte& headerVersion)
lod._model = this;
lod._lodIndex = lodIndex;
stream.Read(lod.ScreenSize);
// Meshes
uint16 meshesCount;
stream.Read(meshesCount);
@@ -579,7 +598,7 @@ bool SkinnedModel::LoadHeader(ReadStream& stream, byte& headerVersion)
return true;
}
mesh.SetMaterialSlotIndex(materialSlotIndex);
// Bounds
BoundingBox box;
stream.Read(box);