ComputeSkinnedPositions() returns incorrect data

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. :slight_smile:

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.

Hi ,

First, I modify your code. ComputeSkinnedPositions returns vertices in component space, not in actor.

auto pCharacter = Cast<ACharacter>(GetPawn());
if (!pCharacter)
	return;

TArray<FVector> MeshVertices;
pCharacter->GetMesh()->ComputeSkinnedPositions(MeshVertices);
	

if (MeshVertices.Num() != 0)
{
	FVector location = pCharacter->GetMesh()->GetComponentLocation();
	FRotator rotation = pCharacter->GetMesh()->GetComponentRotation();

	FRotationTranslationMatrix mat(rotation, location);

	for (int32 i = 0; i < MeshVertices.Num(); i++)
	{
		FVector p = mat.TransformPosition(MeshVertices[i]);
			DrawDebugPoint(GetWorld(),
			p,
			5,
			FColor(255, 0, 0),
			false,
			-1.f,
			0);
	}
}

I checked this code with UE 4.5/4.6. I think these additional points are result of incorrect transformation. Also, make sure it is not trash points in the model.

Hope it helps!

Thanks for the reply, I switched your code over mine, but I still get the incorrect positions. I checked in the persona I don’t see any floating geometry, neither under Maya (my 3D software form where the mesh/rig came from).

I tried with an other model and I get similar results :

I can send the fbx file by PM/e-mail if you want.

It also seems your method is much heavier in computation than mine unfortunately. On a 30K mesh with a call each tick() of the function a go down to 7fps with yours, 30fps with mine.

Did you get this one solved by chance?

Nope, sorry. :confused:
I simply abandoned.