Files
UnrealEngineUWP/Engine/Source/Runtime/SkeletalMeshDescription/Private/SkeletalMeshOperations.cpp
halfdan ingvarsson 038676468f Fix compiler errors in new clang on macOS.
#jira UE-154036
#rnx
#preflight 628e6445f622d972b58cb184

[CL 20368031 by halfdan ingvarsson in ue5-main branch]
2022-05-25 13:36:02 -04:00

49 lines
2.1 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "SkeletalMeshOperations.h"
#include "SkeletalMeshAttributes.h"
#include "BoneWeights.h"
DEFINE_LOG_CATEGORY(LogSkeletalMeshOperations);
#define LOCTEXT_NAMESPACE "SkeletalMeshOperations"
//Add specific skeletal mesh descriptions implementation here
void FSkeletalMeshOperations::AppendSkinWeight(const FMeshDescription& SourceMesh, FMeshDescription& TargetMesh, FSkeletalMeshAppendSettings& AppendSettings)
{
TRACE_CPUPROFILER_EVENT_SCOPE_STR("FSkeletalMeshOperations::AppendSkinWeight");
FSkeletalMeshConstAttributes SourceSkeletalMeshAttributes(SourceMesh);
FSkeletalMeshAttributes TargetSkeletalMeshAttributes(TargetMesh);
TargetSkeletalMeshAttributes.Register();
FSkinWeightsVertexAttributesConstRef SourceVertexSkinWeights = SourceSkeletalMeshAttributes.GetVertexSkinWeights();
FSkinWeightsVertexAttributesRef TargetVertexSkinWeights = TargetSkeletalMeshAttributes.GetVertexSkinWeights();
TargetMesh.SuspendVertexIndexing();
for (const FVertexID SourceVertexID : SourceMesh.Vertices().GetElementIDs())
{
const FVertexID TargetVertexID = FVertexID(AppendSettings.SourceVertexIDOffset + SourceVertexID.GetValue());
FVertexBoneWeightsConst SourceBoneWeights = SourceVertexSkinWeights.Get(SourceVertexID);
TArray<UE::AnimationCore::FBoneWeight> TargetBoneWeights;
const int32 InfluenceCount = SourceBoneWeights.Num();
for (int32 InfluenceIndex = 0; InfluenceIndex < InfluenceCount; ++InfluenceIndex)
{
const FBoneIndexType SourceBoneIndex = SourceBoneWeights[InfluenceIndex].GetBoneIndex();
if(AppendSettings.SourceRemapBoneIndex.IsValidIndex(SourceBoneIndex))
{
UE::AnimationCore::FBoneWeight& TargetBoneWeight = TargetBoneWeights.AddDefaulted_GetRef();
TargetBoneWeight.SetBoneIndex(AppendSettings.SourceRemapBoneIndex[SourceBoneIndex]);
TargetBoneWeight.SetRawWeight(SourceBoneWeights[InfluenceIndex].GetRawWeight());
}
}
TargetVertexSkinWeights.Set(TargetVertexID, TargetBoneWeights);
}
TargetMesh.ResumeVertexIndexing();
}
#undef LOCTEXT_NAMESPACE