// 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 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