Create A Cube from vertex information

Quite new to lumberyard,

I want to create a mesh at runtime with my own vertex information, currently just a cube for testing,
for what i’m creating I’ve made a LUA script to generate the vertex information already, I was just wondering how I would go about creating the actual mesh and attaching it to the mesh component of an entity.

Would I have to create my own entity component in c++ and build a mesh from there (and if so how do I start) or is there an easier way in lua.

Any advice on how to continue would be appreciated :slight_smile:

Hi @Calvin,

Welcome to the Lumberyard Forum! I hope I can be of some assistance :slight_smile:

I think trying to do what you’re describing is quite a low-level operation which as far as I’m aware isn’t easily exposed through the Mesh Component. The general approach is to create an asset in a separate DCC tool and then import it and set the Mesh Component to point to that asset.

We now support a way to create simple custom geometry directly inside the Lumberyard Editor with a component called White Box. This allows you to create simple level geometry for prototyping levels (the tool is in an early stage at the moment but it might be useful to have a play around with).

If you’re interested in checking out how we actually get the vertices to render you can take a look at WhiteBoxLegacyRenderMesh.cpp. This uses an IRenderNode interface to convert the White Box data into a renderable mesh. I wouldn’t recommend trying to create something like this yourself but it may be useful as a reference. The Mesh Component does something very similar behind the scenes.

You might also be able to actually use the White Box Tool API directly to create a custom mesh (you can check out the unit tests to see how we call AddVertex and AddFace etc…) and there are examples of doing this in Python too (have a look for some Python files in the White Box Gem, that’s how we create some of the other starter shapes in the Editor).

I hope that hasn’t overloaded you with too much information. Let us know how you get on and I’ll see if I can offer any more advice.



Hey Tom,

Thanks, I’ve checked out whitebox and kind of understand enough of API it to generate a mesh with my own vertices, but I’m still battling with other lumberyard things, so I was just wondering how I would expose or get the whiteBoxMeshComponent and the whiteBoxMesh into an LUA script so I can set the vertices and indices there (as they are currently being generated there for custom map generation)

Thanks for letting me know about WhiteBox it really helps :slight_smile:

1 Like

Hey @Calvin,

No worries at all! I’m glad it was some help.

I’m afraid the White Box Tool itself can only be edited at edit time and not runtime so is not exposed to Lua at this time (Lua is runtime only). The White Box Tool is however exposed to Python which can be used at edit time (but not runtime… sorry it’s all a bit confusing :see_no_evil:).

If you checkout dev/Gems/WhiteBox/Editor/Scripts/ you can see some Python scripts that generate meshes at edit time. You can run them in the Editor by using pyRunFile from the console and the absolute path for one of those files (a relative one might work but I can’t quite remember off the top of my head).


pyRunFile C:\Lumberyard\dev\Gems\WhiteBox\Editor\Scripts\

Aside: One neat trick you can use is to cd to that folder and then run where | clip to copy the full path to you clipboard without faffing about in Windows Explorer.

For something like custom map generation (sounds cool btw!) you would most likely need to roll your own solution similar to what we did internally with White Box in LegacyRenderMeshComponent, but being brutally honest I wouldn’t recommend this.

I take it you want to generate a grid and then use noise or some such to generate a terrain? Is that right? You might be able to repurpose the existing terrain system in Lumberyard to do this which might be easiest.

There’s also interesting things on the horizon we can’t really talk about at the moment but that might help with what you’re asking about a little down the line…

Let me know if you have any more questions!

Best of luck! :slight_smile:



1 Like

Hey Tom,

Honestly hearing what you told me about it being edit time only kind of defeats the purpose I’m trying to achieve as most of the meshes I’m trying to generate involves dynamic angles and circular geometry that I’d like to change, however maybe I can stick to generating static maps using python at edit time, its better than nothing right now :slight_smile:

Yeah I’m nowhere near experienced enough to try my own solution.

I did try using the terrain but unfortunately since I’m working with a circular grid it became quite distorted trying to use the terrains square grid setup, your guess was pretty close, except the circular grid style which complicates things.

Oh nice, I’ll be looking forward to see the upcoming features but for now I think I’m at a loss, I’ll have to think of another way to try achieve dynamic maps, but for now, being able to at least generate the maps at edit time is a big step forward into testing.

Thanks for all the help, its been much appreciated. I’ll try checking out the python scripts and see if I can get that working, but looking at it I shouldn’t run into any major issues changing it up.

Thanks again!

1 Like

Hi @Calvin you may also be interested in my DynamicMesh gem
and ProceduralMesh gem

The DynamicMesh gem has a component (DynamicMesh) that accepts an array of verticies, indices and tangents and creates a rendernode and assigns a material to it. You can update it at edit or run time. The ProceduralMesh gem has some examples of creating various shapes using the DynamicMesh component.

Hmmm just realized I haven’t thrown a license file in there or a README but it’ll be MIT.