A Custom Flower Generator Using Dynamic Meshes In Unity
Recently I had some free time and had the idea to make this. It’s my first time dynamically creating a mesh in code.
Design and Inspiration:
I have no idea what made me think of making this, but I just had the idea all of a sudden.
After watching a few YT videos by Brackeys and Code Monkey, I had a general idea how to create the meshes.
From there I just trial-and-error-ed my way to create the petal, then dynamically duplicated it in 360 degrees using some bullet hell code from a recent project.
After that, just duplicate everything for the 2nd layer of petals.
The generator uses 3 Animation Curves from Unity to control the width, height, and depth/length of each petal. The width and height of each vertices in the petal is calculated based on how far, from start to end, along the depth the vertices is.
The code:
Note: This is my first time making custom meshes with code, so there’s probably many ways to improve this code.
CreateShape():
Each petal has 17 vertices, specified by the “_detail” int variable, which equals the number of vertices along the length minus 1.
Don’t ask why I did it that way. ¯\_( ͡• ͜ʖ ͡•)_/¯
UpdateMesh():
Start():
Update():
The result is a pretty good looking procedural flower generator; Easily customized to almost any requirements.