Hi all,
I’m currently trying to update the rest pose of the skeleton of my character to make it match some shape change.
To do this, I’m using the following code where MeshCmp is a USkeletalMeshComponenent and MyOffsets and MyBoneNames are my inputs.
TArray<FVector> MyOffsets;
TArray<FName> MyBoneNames;
FReferenceSkeleton NewSkeletonRef;
FReferenceSkeleton RefSkeleton = MeshCmp->SkeletalMesh->Skeleton->GetReferenceSkeleton();
TArray<FMeshBoneInfo> SkelRefBonesInfo = RefSkeleton.GetRefBoneInfo();
FReferenceSkeletonModifier SkeletonModifier(NewSkeletonRef, MeshCmp->SkeletalMesh->Skeleton);
TArray<FTransform> BonesRestBonesTr = RefSkeleton.GetRefBonePose();
for (int j = 0; j < MyOffsets.Num(); j++)
{
FTransform boneTransform;
int32 SkeletonIndex = RefSkeleton.FindBoneIndex(MyBoneNames[j]);
if (SkeletonIndex >= 0)
{
// get rest bone for this bone
FTransform boneRestTr = BonesRestBonesTr[SkeletonIndex];
boneTransform.SetLocation(boneRestTr.GetLocation() + (MyOffsets[j] * Value));
boneTransform.SetRotation(boneRestTr.GetRotation());
// update pose transform
FMeshBoneInfo boneInfo;
boneInfo.ExportName = SkelRefBonesInfo[SkeletonIndex].ExportName;
boneInfo.Name = SkelRefBonesInfo[SkeletonIndex].Name;
boneInfo.ParentIndex = SkelRefBonesInfo[SkeletonIndex].ParentIndex;
SkeletonModifier.Add(boneInfo, boneTransform);
}
}
This kind of works since my skeleton rest pose is indeed modified as expected by it is modified for all characters using the same skeletal mesh.
Since most of my characters use the same base skeletal mesh, it’s not what I’m after.
So my question is : how could I modify the rest pose of the skeleton only for the instance of the given skeletal mesh component?
Thanks for your help.