Skeletal mesh vertex editing

Hi. I want to get access to vertex data of a mesh (skeletal), so I can use code to rearrange them (position, normals, maybe colors and weights…).

This was very easy in Unity, in UE4 I don’t know what to do :frowning:

I’ve got lots of variations of a particular base-mesh and want to create morph-targets from them (procedurally). I’d also like to do some dynamic deformation effects like “pull vertices to a position based on range” or a distort/noise effect.

Help please!

edit: I also want to change bones/bind-poses procedurally, because some “morphs” actually modify the length of body parts.

I mean, every engine I know has accessable Vertex-Buffers (…) for a given mesh somewhere, that can be read and modified. Where do I find them for UE4’s Skeletal Meshes??

Although I have been working with mesh-buffers in other engines quite a lot, I have never heard about “chunks” before. Is that something I need to understand in order to get to the vertex data?

I’ve tried to find something in the source, but with no luck so far.

What’s also funny: why are there no normals to be found anywhere? When looking at the source, I find “mentions” of positions, vertex-colors, tangents etc., but no normals…

Btw, I don’t necessarily need to create actual UE4 morph-targets. I suspect those are not made for modifications of the bind-poses (skeleton) anyway. So I would just like to read the complete mesh’s vertex data and modify it to a copy of the mesh.

If anyone has links to info/tutorials about these things, that would also be much appreciated. I didn’t find anything, just some tutorial about a procedural static mesh.

Put simply, I want to get read/write access to a skeletal mesh’s:

  • vertices (position, color, weights…)
  • bone-transforms (bind-poses)

… if I could just have one wish for christmas, it would be an answer to this question.

1 Like

Ok, nevermind. I figured it out.

If anyone cares:

  • vertex data can be read and modified inside the SkeletalMeshResource class as chunks (per LOD). Apparently, a chunk is just a sub-mesh that shares a single material, which is what I was looking for. I had thought chunks were something that the engine creates internally for optimization purposes or something…

  • bind-poses for bones can be read and changed inside ReferenceSkeleton (or something like that).

… but I still don’t understand why there aren’t any normals for the chunks’ vertices …

This was very useful. I was wondering if you know how could I use this very same method to add vertices to a skeletalmesh (not just modify existing ones). I’m aware of the LODModels.Add(…) method from a skeletalMeshResource. However, how can I add a new vertex if I only know the coordinates of that vertex but no other info that a FStaticLODModel holds? How can I create the FStaticLODModel object to pass via the .Add() method just using the vertex coordinates?

It’s been a while since I’ve been dealing with this sort of thing. What’s the problem with adding vertices? If I remember correctly, you just need to add indices to the corresponding “sections” (like “chunks”) accordingly and adjust the count/num-integer values inside both.

I know its been while since you posted this, but after you manipulate the vertices? How do you save the data back to the asset? Here is my code, what should i do next?

	USkeletalMesh* DuplicatedMesh = LoadskeletalMeshFromPath("/Game/Characters/Human/Body/F/Mesh/FemaleBase_Baked");
		FSkeletalMeshModel* importedModel = DuplicatedMesh->GetImportedModel();
		FSkeletalMeshLODModel importedModelLod0 = importedModel->LODModels[0];
		TArray<FSkelMeshSection> lod0Sections = importedModelLod0.Sections;
		FSkelMeshSection section = lod0Sections[0];
		//FSoftSkinVertex* DestVertex = section.SoftVertices.GetData();
		auto softVerts = section.SoftVertices;
		for (int32 VertIndex = 0; VertIndex < softVerts.Num(); VertIndex++)
		{
			softVerts[VertIndex].Position  += 100.0f * FVector(3, 5, 2);
		}
		DuplicatedMesh->PostEditChange();
		DuplicatedMesh->PostLoad();

First of all you should use pointers or references (&) throughout, if you don’t want to edit copies of the original data. And then it should be pretty simple. Just save the mesh-assets in the editor. You can do that with code, too (package->save()). What I usually do is to just mark the packages dirty, so I can still choose whether to save them manually or not without overlooking anything. Just call mesh->GetOutermost()->SetDirtyFlag(true). There’s another function that does the same, but, unlike the other, this one also works at runtime/PIE.

And yes, some things have changed since I first posted here. Most importantly, there are no “chunks” anymore, only “sections”. There used to be soft and rigid vertices. Now there’s only soft. And since 4.19 working with skeletal meshes in no-editor builds is a complete mess, because there is now an object called FSkeletalMeshRenderData, which is basically the runtime version of the FSkeletalMeshModel and it obviously wasn’t designed to be edited.

So, if you want to alter meshes dynamically at runtime, you might find this interesting.

Hey i got it working thanks to this, dumb mistake by me not using pointers/refs. Thanks for pointing that out!

Are there any necessary dependencies or anything like that? I have very similar code written out, but it is not recognizing a lot of the types. Like it says that FSkelMeshSection is an undeclared identifier and that several other types are undefined types. It also says that GetImportedModel is not a member of USkeletal mesh even though I looked at the file, and the definition is there.

So after 4.19, how can i edit skeletal mesh in runtime without editor. FSkeletalMeshRenderData seems not to be editable.