Modify Skeleton Mesh Vertex Position Runtime

Hello everyone,
I’m working on a project that need to change Specified Skeleton Mesh Vertex Position At Runtime. In fact i want to replace some vertex position(may be a head) with new positions(Get from assimp).
1. I konw procedural component can do it, but if it is possible to make animation with procedural component cause i need the vertex-replaced mesh to play animation.
2.World Position oOfset can change vertex positions, but how can i use it on certern vertex.

Any ideas will help me, thanks!

1 Like

First I try to modify float number in GetSkeletalMeshComponent()->GetSkeletalMeshResource()->LODModels[0].VertexBufferGPUSkin.GetVertexPtr(i)->Position,And after i really change them nothing happen to the mesh(it looks like before).
Then I try to modify GetSkeletalMeshComponent()->GetSkeletalMeshResource()->LODModels[0].Sections[0].SoftVertices , but it is a const value So i have no ideas .

Ok, I have just worked it out.Here is the code, it do jobs that change vertex position in skeleton mesh file forever.

Make sure the Skeletalmesh1 is what is using in the custom skeletonmesh component.

I delete something unuserful but it still seems Redundant。

.h

UCLASS(meta = (BlueprintSpawnableComponent))
class MYPROJECT37_API AModelTransformSM : public ASkeletalMeshActor
{
GENERATED_BODY()

UFUNCTION(BlueprintCallable, Category = "My Test Library")
USkeletalMesh *  TestGetSkeletalMeshData4(USkeletalMesh * SkeletalMesh1);

};

.cpp

USkeletalMesh * AModelTransformSM::TestGetSkeletalMeshData4(USkeletalMesh * SkeletalMesh1) {

FStaticLODModel& LODModel = SkeletalMesh1->GetImportedResource()->LODModels[0];

for (uint32 i = 0; i < LODModel.VertexBufferGPUSkin.GetNumVertices() / 2; i++)
{
	FVector TempVec = LODModel.VertexBufferGPUSkin.GetVertexPositionFast(i);

	if (LODModel.VertexBufferGPUSkin.GetUseFullPrecisionUVs())
	{
		FVector position1 = ((TGPUSkinVertexFloat16Uvs<MAX_TEXCOORDS>*)(LODModel.VertexBufferGPUSkin.GetVertexPtr(i)))->Position;
		position1.X += 20;
		position1.Y += 30;
		position1.Z += 30;
		((TGPUSkinVertexFloat16Uvs<MAX_TEXCOORDS>*)(LODModel.VertexBufferGPUSkin.GetVertexPtr(i)))->Position = position1;
	}
	else
	{
		FVector position1 = ((TGPUSkinVertexFloat32Uvs<MAX_TEXCOORDS>*)(LODModel.VertexBufferGPUSkin.GetVertexPtr(i)))->Position;
		position1.X += 20;
		position1.Y += 30;
		position1.Z += 30;
		((TGPUSkinVertexFloat32Uvs<MAX_TEXCOORDS>*)(LODModel.VertexBufferGPUSkin.GetVertexPtr(i)))->Position = position1;
	}
}

LODModel.VertexBufferGPUSkin.InitRHI();
SkeletalMesh1->PostEditChange();
GetSkeletalMeshComponent()->PostEditChange();

GetSkeletalMeshComponent()->MarkRenderStateDirty();
GetSkeletalMeshComponent()->MarkRenderDynamicDataDirty();
GetSkeletalMeshComponent()->MarkRenderTransformDirty();

return SkeletalMesh1;
}

bp

2 Likes

great

VertexBufferGPUSkin has been moved in ue 5.3.0. How to edit skeletal mesh position in runtime at 5.3 version