Getting UVs and colors to work with dynamic mesh using FDynamicMesh3

I’ve been working with FDynamicMesh3 for a while now but have just recently got around to working closely with the UVs and colors of the mesh I’ve created. My issue is that no matter what I do, I can’t get the UVs or colors to work. (As I understand it, the color problem should sort itself out if I can solve the UV problem.)

The mesh I’ve created is a flat (2D) circle. Sample: grey tiles are my mesh. I’ve verified that the UV and color buffers in the FDynamicMesh3 object contain the expected values alongside the normal data, but the only indication I have that anything is working is that it’s getting the vertices and triangle data and generating the mesh, but it’s not doing anything with the UV/color/normals.

I read recently someone had managed to get everything to work by using some functions from the FDynamicMeshAttributeSet family (CopyVertexUVsToOverlay and CopyVertexNormalsToOverlay) , but I’ve had no such success. I wrapped the FDynamicMesh3 in a DynamicMeshAttributeSet and tried the functions indicated and there was no change.

If I drag the actor class with my mesh generating code into the editor viewport and use the Modelling mode → AutoUV setting, it takes a few seconds to think and then the checkerboard pattern tells me that the UVs are set and working (but still won’t show my colors).

The only things I can say about my situation that are objectively true:

  • The FDynamicMesh3 data is being successfully placed in the container
  • The vertex and triangle data is being used successfully to render the basic mesh
  • Vertex and triangle data was working both when I was only using FDynamicMesh3, and also since I wrapped it in the FDynamicMeshAttributeSet object.
  • Nothing I have tried programatically, including the recommended functions, has ever worked to produce the outcome I’m expecting (mesh covered in a kaleidoscope of colors).

I need a way to get them to work programatically and would love if any of you have managed to get this to work and could drop a tip or two.

Thanks very much in advance.

2 Likes

After some digging around, this post what ended up solving it for me:

I am doing these (not sure if all of them are necessary)

	FDynamicMesh3 newMesh;
	newMesh.EnableAttributes();
	newMesh.EnableVertexUVs(FVector2f::Zero());
 
// generate vertices with UV logics ....

	UE::Geometry::CopyVertexUVsToOverlay(newMesh, *newMesh.Attributes()->PrimaryUV());

Voila!

2 Likes

Hey, thanks for your post! Sorry it took so long to respond. I have a few other things to test before I can try your solution but if it works I’ll make sure to come back and mark it properly.

Thanks again!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.