Calculating local space position from reference pose on animated mesh

I’m not very good at geometry functions so I’m hoping to get some help here. Thanks in advance.

I’m trying to calculate the local(preskinned) position of a hit on a skeletal mesh. Now if the mesh is locked in its default, reference pose, all I have to do is subtract the ComponentTransform of the skeletal mesh from the ImpactPoint, and I can feed the result directly to my material and it will work well. However, I’m not sure how to get to the same result if the mesh is being animated.

I know I can access the reference skeleton, however, the locations of ref bones are all relative to their parent bone, as opposed to being relative to the skeletal mesh’s root transform. GetBoneTransform() returns the bone’s location relative to the root, which is something I could work with, however, I’m not sure what to do with the reference bones. Different approaches that I’ve tried yielded incorrect results, including the one described via this link: http://www.tomlooman.com/rendering-wounds-on-characters/

According to the aforementioned article, this should have worked:



FTransform SocketTransformWorld = SkeletalMesh->GetSocketTransform(ImpactResult.BoneName, ERelativeTransformSpace::RTS_World);
FReferenceSkeleton RefSkeleton = SkeletalMesh->SkeletalMesh->RefSkeleton;
FTransform RefPoseTransform = RefSkeleton.GetRefBonePose()[RefSkeleton.FindBoneIndex(ImpactResult.BoneName)];
FVector InverseTransformPosition = SocketTransformWorld.InverseTransformPosition(ImpactResult.ImpactPoint);
FVector RefPoseInverseTransformPosition = RefPoseTransform.TransformPosition(InverseTransformPosition);


Except it doesn’t. The final transformed position is not relative to the root bone. So either I’m doing something wrong, or the author forgot to mention something crucial.

Either way, any help would be appreciated, and thanks again.