Marching squares implemented in Bevy, with a mesh that updates every frame! Egui is used for an interactive settings menu.
Rather than trying to read my pile of spaghetti code, I recommend watching this video
by The Coding Train.
When it comes to implementing Lerping (which is not covered in the video), you can use an inverse lerp
function with your two points' values as a and b, and your threshold as the "value" argument. It will return a t
value, representing how far along the threshold is between your two values. You can then use this to move mesh points around.
I found this project useful in learning procedural mesh generation in general. The "positions" describe all of the vertices, and the indicies describe which vertices are used to create each triangle. This allows rendering a quad with only 4 vertices instead of 6, for example, as some vertices are reused. When it came to spawning the mesh, I followed this bevy example that spawned a default quad mesh.
If you want to update the mesh, remember to query for a Mesh2dHandle
instead of a Handle<Mesh>
, this just being an annoying inconsistency between 2D and 3D in Bevy.