For this project I created a MEL script that will generate geometry resembling coral. There are variables within the script that allow the branch angle and height to be altered, therefore allowing for countless possibilities of shapes and sizes for different coral pieces.
THE CODE
Creating this MEL script was super challenging, and I might have bit off more than I could chew for the timeframe I had to complete this project. I ran into a lot of obstacles that I had to hurdle, and while I am not 100% pleased with outcome, I did learn a lot about MEL and I hope to push this code further to achieve the look I want.


In order to achieve an organic look and feel to the branches of the coral, I used a l-system; which is essentially creating complex shapes by repetition. The most common example of a l-system would be a fractal, for instance a Koch snowflake. I borrowed code from Malcom Kesson, who created a l-system that utilizes and works primarily with vectors. He aims the vectors on the Y axis, and then places them randomly on a  circle.
After this is finished, I began the coralGeneration proc, which is the main procedure that governs the overall look and appearance of the coral. I was still relying on Malcom Kesson's structure from his l-system to achieve the curves, but I created code that would extrude along those curves to create geometry for our coral. These curves are made, and then by using recursion, are randomly placed upward; branching off into into our l-system.
This was all going smoothly, but the tricky part was getting the NURBS circles to orient themselves along the curves in order to create a good base for future extrusion. I had rotated them manually, but if the user wanted to increase the coral's branch angle, they would end up with some wonky geometry. So I ended up putting in an aim constraint to get the circles positioned on the curves in order to allow for proper extrusion, no matter the angle.
This process was then repeated a second time for recursion, thus allowing for an organic, branching coral.
GUI DESIGN & MOCK-UP
The main variables of input for this code are as followed; here is a visual of the command line in my coral generation script.
The main variables to pay attention to are the $angle and $len. The $angle variable determines the angle, or spread of the coral, and the $len variable will determine the length/height of the coral. The other two are still important, but less so in comparision; with $begin determining the point of origin for the generation, and $dir determining on which axis the generation grows. I would want the gui to be fairly simple and intuitive, consisting of sliders to easily scrub between variables to pinpoint the look of coral the user wants to achieve rather quickly.
GUI CODE
I ended up with a GUI that is functional and prompts the user to enter the height of their coral and the desired angle of the branches. I originally wanted to incorporate two parameters that would allows the user to define the axis of growth as well as the origin point for the coral's base. I ran into some trouble with vectors and incorporating them into the GUI global proc, so I hard-coded in the origin (0, 0, 0) and the axis of growth, Y. I am still toying with it because I would love to have those parameters in the GUI, but I think this is just as functional since the user can alter both of those parameters after the coral is created.
I used sliders to let the user alter the branch angle and branch length, I would like to implement a realtime display of the changes being made before pressing generate. I need to do more research on the argument because it was being a little tricky. Commented out in yellow is the structure I created for the origin and growth direction parameters. I would like to come back to those and get them working, but I was having issues setting the vectors up in the doCoralGUI proc.

The doCoralGUI proc uses query to determine the value that the user inputs; it then takes that information and plugs it into the coralGeneration proc. As you can see I have hardcoded the $begin and $dir variables for now until I can get them up and running.
CONCLUSION
I really enjoy coding, and I'm glad I finally got to delve into the world of MEL. I am proud of how much I learned and what I was able to accomplish, especially considering how much I had to battle with this code to wrangle it into the shape it is in now. While I am pleased with the current results, I want to take this coral generation script and improve it. There are a lot of things I have been toying with that did not make it into this final submission due to time. For instance, I would love to seal up the ends of the polygons to have a watertight mesh, that is something that is bothering me. I also tried to merge the curves together so that I could end up with one fluid extrusions, but I ran into some roadblocks there; due to the fact that the branches need to remain separate or you won't get a branching effect. So that idea is and was a bit of brainteaser, I'll have to think about that a little bit more. I have tried several different things but all have sent me back to the drawing board scratching my head. I would also love to add a materials variable to this code. I experimented with a few things but unfortunately didn't have any luck, I need to do a little bit more research so that I can add that in.

Overall I am happy with how this turned out, even if it had me kicking and screaming while pulling some hair out. But hey, such is the joys of coding. I look forward to exploring MEL and hopefully Python too!
Back to Top