first look at the code:
class USkeletalMesh* UMyManager::DoMerge(USkeletalMesh* RootMesh, TArray BodyParts)
{
TArray<USkeletalMesh*> Meshes;
for (auto PartInfo : BodyParts)
{
Meshes.Add(PartInfo.Mesh);
}
Meshes.RemoveAll([](USkeletalMesh* Mesh) -> bool {return Mesh == nullptr; });
auto Target = NewObject<USkeletalMesh>(this, NAME_None, RF_Transient, RootMesh);
TArray<FSkelMeshMergeSectionMapping> InForceSectionMapping;
FSkeletalMeshMerge merger(Target, Meshes, InForceSectionMapping, 0);
merger.DoMerge();
this->MergeClothingAssets(Meshes, Target);
return Target;
}
void UMyManager::MergeClothingAssets(const TArray& ArySkeletalMesh, USkeletalMesh* NewSkeletalMesh)
{
if (ArySkeletalMesh.Num() == 0 || NewSkeletalMesh == nullptr)
{
return;
}
NewSkeletalMesh->ClothingAssets.Reset();
TArray<UMaterialInterface*> AryMaterialCloth;
TArray<int32> AryClothAsset;
TArray<int32> AryClothSubmesh;
TArray<int32> AryIgnoreIndex;
for (int32 Index = 0; Index < ArySkeletalMesh.Num(); Index++)
{
bool IsIgnore = false;
for (int32 CurIgnoreIndex = 0; CurIgnoreIndex < AryIgnoreIndex.Num(); ++CurIgnoreIndex)
{
if (Index == CurIgnoreIndex)
{
IsIgnore = true;
break;
}
}
if (IsIgnore)
{
continue;
}
USkeletalMesh* CurMesh = ArySkeletalMesh[Index];
this->ClothingAssetsIsUnique(Index, CurMesh, ArySkeletalMesh, AryIgnoreIndex);
//ClothingAssets Array Merge
for (int32 ClothAssetIndex = 0; ClothAssetIndex < CurMesh->ClothingAssets.Num(); ++ClothAssetIndex)
{
NewSkeletalMesh->ClothingAssets.Add(CurMesh->ClothingAssets[ClothAssetIndex]);
//
for (int32 LODIndex = 0; LODIndex < CurMesh->LODInfo.Num(); LODIndex++)
{
FSkeletalMeshResource* Resource = CurMesh->GetImportedResource();
check(Resource->LODModels.IsValidIndex(LODIndex));
FStaticLODModel& LODModel = Resource->LODModels[LODIndex];
int32 NumSections = LODModel.Sections.Num();
for (int32 SecIdx = 0; SecIdx < NumSections; SecIdx++)
{
uint16 MaterialIndex = LODModel.Sections[SecIdx].MaterialIndex;
uint16 ChunkIdx = LODModel.Sections[SecIdx].ChunkIndex;
if (LODModel.Chunks[ChunkIdx].CorrespondClothAssetIndex != INDEX_NONE)
{
UE_LOG(LogInit, Error, TEXT("CorrespondClothSectionIndex = %d"), LODModel.Sections[SecIdx].CorrespondClothSectionIndex);
UMaterialInterface* Material = CurMesh->Materials[MaterialIndex].MaterialInterface;
AryMaterialCloth.Add(Material);
AryClothAsset.Add(ClothAssetIndex);
AryClothSubmesh.Add(LODModel.Chunks[ChunkIdx].ClothAssetSubmeshIndex);
}
}
}
}
}
for (int32 MaterialIndex = 0; MaterialIndex < AryMaterialCloth.Num(); ++MaterialIndex)
{
for (int32 LODIndex = 0; LODIndex < NewSkeletalMesh->LODInfo.Num(); LODIndex++)
{
FSkeletalMeshResource* Resource = NewSkeletalMesh->GetImportedResource();
if (Resource->LODModels.IsValidIndex(LODIndex))
{
FStaticLODModel& LODModel = Resource->LODModels[LODIndex];
int32 NumSections = LODModel.Sections.Num();
for (int32 SecIdx = 0; SecIdx < NumSections; SecIdx++)
{
uint16 CurMaterialIndex = LODModel.Sections[SecIdx].MaterialIndex;
UMaterialInterface* CurMaterial = NewSkeletalMesh->Materials[CurMaterialIndex].MaterialInterface;
if (CurMaterial == AryMaterialCloth[MaterialIndex])
{
uint16 ChunkIdx = LODModel.Sections[SecIdx].ChunkIndex;
UE_LOG(LogInit, Error, TEXT("CorrespondClothAssetIndex = %d, set = %d ,LOD = %d,ChunkIdx = %d"), LODModel.Chunks[ChunkIdx].CorrespondClothAssetIndex,
AryClothAsset[MaterialIndex], LODIndex, ChunkIdx);
/*ApexClothingUtils::ImportClothingSectionFromClothingAsset(
NewSkeletalMesh,
LODIndex,
SecIdx,
AryClothAsset[MaterialIndex],
AryClothSubmesh[MaterialIndex]
);*/
LODModel.Chunks[ChunkIdx].SetClothSubmeshIndex(AryClothAsset[MaterialIndex], AryClothSubmesh[MaterialIndex]);
ApexClothingUtils::ReImportClothingSectionFromClothingAsset(NewSkeletalMesh, LODIndex, SecIdx);
}
}
}
}
}
when I open the editor , check the
,
Why the Cloth Assets is None,I sure set the CorrespondClothAssetIndex = 0,
}