Last year I wanted to learn how to procedurally generate meshes in Unreal, so I put together a few quick tests of my own. This got some interest from people here so I decided to clean it up and release it for free!
I really hope this will be useful to others who also want to play with geometry generation in Unreal.
The purpose of this project is to provide examples on how to generate geometry in code, from simple cubes to more complex geometry generated from fractal algorithms.
I would love for this to become a community project, so I will accept pull requests for new samples as well as any corrections to my code. I’m also willing to add contributors directly if anyone is interested!
Please note that I wrote the code to be readable, trying my best to explain each step along the way. There are many ways this code could be optimized to run better, but I wanted to keep things simple in the first few examples.
There is a lot of code duplication between the different examples which I felt was OK for the first few classes, but I will refactor some of the common functions into a utility class soon.
Update: I recently converted the example from using Epic’s ProceduralMeshComponent to Koderz’s excellent RuntimeMeshComponent.
All corrections, contributions etc are of course welcome! I’m still new to rendering in UE4 and ultimately want to convert some of this to using RHI calls myself (UPrimitiveComponent, PrimitiveSceneProxy etc).
I would love to hear what you have planned! I’ve been thinking about writing my own version of it, or going a completely different route.
What’s been bothering me lately:
The variables holding the generated data (mesh sections) aren’t marked as Transient. So if you offer editor support (not just generate on BeginPLay), all the mesh data is saved along with your map. I got around this by making the whole component Transient, causing issues with transforms among others.
No easy way to update mesh data once generated, so currently I need to re-create the mesh on every frame. We need a way to set a mesh as static (once generated) or dynamic. Perhaps allow updating the Vertices buffer, as long as length and indexes remain the same?
A way to export the meshes to static mesh assets. Antidamage posted a way to do this I plan on utilizing once I need it.
Well, if you’re interested, I’m in the Unreal Slack much of the day almost every day. (I’m in Eastern US, so not sure what timezone you’re in)
You pretty much listed some of the same things that bug me. The only one I hadn’t thought of was the mesh data getting saved, but I can probably solve that. I have far faster updates already done, as well as generally better render performance, and a few other things. I planned on supporting static mesh -> PMC, but not sure about the other way around.
What I suspect is happening here is not everyone being familiar with how Git submodules work? The example project is directly referencing a couple of plugins, and you can see the references pointing at specific SHAs here:
A submodule is like a sub-project, a way for a Git project to directly reference and use another Git repo. Unfortunately they aren’t super straight forward to work with…