Skip to content

Commit

Permalink
Fixed LODMaterialMap for UE4 SkeletalMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
gildor2 committed Nov 14, 2021
1 parent c60461a commit 6d95fc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Unreal/UnrealMesh/UnMesh4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,16 +2092,19 @@ void USkeletalMesh4::ConvertMesh()
const FSkelMeshSection4 &S = SrcLod.Sections[Sec];
CMeshSection *Dst = new (Lod->Sections) CMeshSection;

// remap material for LOD
// Remap material for LOD
// In comment for LODMaterialMap, INDEX_NONE means "no remap", so let's use this logic here.
// Actually, INDEX_NONE in LODMaterialMap seems hides the mesh section in game.
// Reference: FSkeletalMeshSceneProxy
int MaterialIndex = S.MaterialIndex;
if (Info.LODMaterialMap.IsValidIndex(MaterialIndex))
MaterialIndex = Info.LODMaterialMap[MaterialIndex];
if (MaterialIndex < 0) // UE4 using Clamp(0, Materials.Num()), not Materials.Num()-1
MaterialIndex = 0;
if (Info.LODMaterialMap.IsValidIndex(Sec) && Materials.IsValidIndex(Info.LODMaterialMap[Sec]))
{
MaterialIndex = Info.LODMaterialMap[Sec];
}

Dst->Material = Materials.IsValidIndex(MaterialIndex) ? Materials[MaterialIndex].Material : NULL;
Dst->Material = Materials.IsValidIndex(MaterialIndex) ? Materials[MaterialIndex].Material : NULL;
Dst->FirstIndex = S.BaseIndex;
Dst->NumFaces = S.NumTriangles;
Dst->NumFaces = S.NumTriangles;
}

unguard; // ProcessSections
Expand Down
Binary file modified umodel.exe
Binary file not shown.

0 comments on commit 6d95fc7

Please sign in to comment.