Hello,
With the code posted just below I’m accessing the vertices of the skeletal mesh of my main character. While most of the code work, i get partially incorrect positions and I’m not sure to know why. I’m interested in the best way to retrieve those data properly.
Note : I’m running under UE4 4.5.0.
So, MeshBody in this context is my skeletal mesh component used my Character class in my game project.
The code below come from a function in my character class, called first in the tick() function (before the super:: call).
TArray<FVector> MeshVertices;
MeshBody->ComputeSkinnedPositions( MeshVertices );
if( MeshVertices.Num() != 0 )
{
FVector Pos = FVector(0,0,0);
FVector Origin = GetActorLocation() - FVector(0,0,94);
FRotator Rot = GetActorRotation();
FVector Direction = FVector(0,0,0);
float Distance = 0.0f;
for(int32 i = 0; i < MeshVertices.Num(); i++)
{
Distance = FVector::Dist( FVector(0,0,0), MeshVertices[i] );
Direction = FVector(0,0,0) - MeshVertices[i];
Direction.Normalize();
Direction = Direction.RotateAngleAxis( Rot.Yaw - 90.0f, FVector(0,0,1) );
Pos = FVector(0,0,0) + (Distance * -1 * Direction);
Pos += Origin;
DrawDebugPoint(GetWorld(),
Pos,
5,
FColor(255, 0, 0),
false,
-1.f,
0);
}
}
Below is what I get, you can notice the points floating around while they are missing from the arms/legs of my character. If my skinning was wrong I would have understood, but in this case the mesh displayed on the screen is clean and the data returned by ComputeSkinnedPositions() is not always right.
In T-Pose those incorrect vertices align with X=0, Y=0 and various Z values.