Download

Procedural Mesh Examples - free!

Hi everyone!

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.

Download and source code: GitHub - SiggiG/ProceduralMeshDemos: Examples of procedural mesh generation in Unreal 4.

NOTE: All the current code is for Unreal 4.25!

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).

Thanks SiggiG! I’ve done some tests with the ProceduralMesh gen but got stopped up at various points, so this will be very helpful.

Wow, that Sierpinski triangle looks awesome. Nice one

Thanks a lot, I will probably come back to ProceduralMesh and spend some time on this after my current projects!

Made some progress on animating the meshes, will post a couple examples on the Github later tonight.

Keep in mind that this is a very expensive way to do it since the mesh is generated on every frame! I will move away from the ProceduralMeshComponent later on for a more optimal implementation.

Very nice!

Really Cool.
Will take a look

The trees, are they created using a DLA algorithm?

No, but I’m planning on adding that and other algorithms later. What I have there is a simple line division with a random offset of the center point.

This looks like nice project, good work. But the GPL license can’t be used in UE4 by EULA, you should change the license. (MIT, Zlib or other)

Ah thanks for that! The MIT one is probably all I need.

Hey SiggiG, I’ve been working on some serious updates to the PMC and would be interested in seeing what all issues you’ve been running into! That goes for anyone else as well!

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.
  • Using tasks/threading for mesh creation.

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.

I’ve updated all the examples using Koderz’s excellent RuntimeMeshComponent plugin. This is more efficient and faster than the UE4 ProceduralMeshComponent.

Awesome work Koderz, keep it up! :slight_smile:

Hey SiggiG I have trouble getting the plugin to load with 12.5 …says the plugin was made with a different version of the engine and it wont rebuild for me!

Sorry for the slow response here. Hmm this is odd since I’m not providing a pre-built version of the plugin, only the source. I’ll take a look once I’m home.

Any luck, I’m breaking on 12.5 too. I simply can’t open the project if I have the plugin included.

EDIT: Nevermind - I was downloading from the wrong place. First I did the git repo direct, then from a link in the forum - but then I found the stable release (for 12.5 anyway):

Also - I had references to ProceduralMeshComponent in my project, which I pulled out. And I updated the Build file to show too.

Alright, new challenge - how to make these meshes have collisions. I’ve tried adding these sections to the initializer - but maybe I need to do something more.

MeshComponent->SetSimulatePhysics(true);
MeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

Ooh, do i see L-System trees? Looking awsome.

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…

Some info here, but basically after syncing down my example project you need to initialize and then pull the referenced submodules with Git:
https://git-scm.com/book/en/v2/Git-Tools-Submodules

I believe Koderz’s latest version of PMC has proper support for collisions. I’ll try to get my code updated to his latest plugin soon ™.

Well… kinda :slight_smile: I haven’t implemented actual L-system parsing logic here, but it’s something I’m planning on do when I find some free time :slight_smile: