Home

MEL Matrix

MEL (Maya embedded language) is designed to simplify and achieve the complex tasks that are most of the times too tedious to be done with available set of Maya User-interface. For this assignment I wanted to create procedural model based on Koch Fractal system. This system is based on a equilateral triangle which then recursively divide each line segment into three segments of equal length and draws another equilateral triangle on the middle line segment. This process can be repeat to infinity but for this project number of iterations can be decided by the end user.

Technical Breakdowns

Before starting the project professor "Malcom Kesson" shows and explain an example of  procedural modeling based on "Sierpinski triangle", With that thought in mind I started researching about different math functions and algorithms to create procedural shapes and I found "Koch snowflake" fractal. When I initially started thinking about this I had no clue how to  achieve that, although there were several different techniques in my mind but after few email conversations and class sessions professor explained the Lindenmayer's system (L System) which is based on set of rules and axiom. Based on that not only snowflake but unlimited different varieties of patterns can be achieved.

Koch snowflake reference

Initial approach to Koch snowflake

Incorporating Snowflake Pattern with Lsystem into Maya

Since L system works on a specific set of rule and axiom so in this case.

 

RULES:

L  draw a (straight curve) line

<  subsequent rotations are positive

> subsequent rotations are negative

x rotation axis is 'x'

y rotation axis is 'y'

z  rotation axis is 'z'

 

$axiom = "L<zzL<zzL";

$ruleL = "L>zL<zzL>zL";

$angle = 60.0;

 

which means every time when axiom reads L it replaces it with the string in ruleL.

 

Note:

The code and more precise explanation of Lsystem based Koch snowflake is available on professors website :

www.fundza.com/mel/koch/index.html

($axiom, 1)

($axiom, 2)

($axiom, 3)

($axiom, 3)

angle = 90.0

 

ruleL = "L>zxL<zyzL>zL"

 

axiom = "L<zzL<zzL"

 

angle = 17.0

 

ruleL = "L>zxL<zyzL>zL"

 

axiom = "L<zzL<zzL"

($axiom, 3)

($axiom, 3)

 

angle = 90.0

 

$ruleL = ">yL<zL>xL>zL>zL>xL<zL";

 

string $axiom = ">zL";

 

$sph = `sphere -r 0.13`;

$cyl = `cylinder -r 0.05 -ax 0 1 0 -hr 20`;

move -r 0 0.5 0 $cyl;

parent -r $shape $node;

parent -r $cyl[0] $node;

MEL codes:

Koch.mel

preamble.mel

node_utils.mel

How to Run the Code through maya script editor:

 

1- Copy all the codes in the script directory.

2- Open maya script editor load and run koch.mel:

 

it will generate snowflake.mel in the script folder of your project directory.

 

3- In the script editor type:

 

rehash;

source "node_utils.mel";

source "snowflake.mel";

 

Renders

Koch Extension (Branching System)

To create branching effect like a tree, I modify the code "Koch.mel" and introduced 2 conditions with push and pop functions, So it creates branches whenever it receives "}"  "{" characters within the Rule field, also I replaced the curve creation with polycylinder to create the cylinder instead of curves each time .

 

All the three functions addCylinderTo, push and pop are located inside node_utils.mel.

 

So the Radius and Height of the cylinders are control by the string called $hei & $rad which are passing the values to the addCylinderTo function inside node_utls.mel

  else if($c == "L")

   $lines[$line_count++] = "$tnode = addCylindersTo($tnode, $hei ,$rad/100 );\n";

  // print ("$radius is" + $rad + "\n");

  else if($c == "{"){

      $lines[$line_count++] = "push($tnode);\n";

   $scale_invert_stack[$line_count++] = "$lines;\n";

              }

  else if($c == "}" ){

      $lines[$line_count++] = "$tnode = pop();\n";

   $lines_count = " $scale_invert_stack.pop();\n ";

                }

 

   }

 

($axiom,1)

 

 

$angle = 17;

$ruleL = "Ly{>zxL}L{<zxL}L";

$axiom = "L";

 

 

($axiom,2)

 

 

$angle = 17;

$ruleL = "Ly{>zxL}L{<zxL}L";

$axiom = "L";

 

 

($axiom,3)

 

 

$angle = 17;

$ruleL = "Ly{>zxL}L{<zxL}L";

$axiom = "L";

 

 

Final Code with UI

Koch.mel

preamble.mel

node_utils.mel

For the growth effect I animate the Cylinders in Y scale after setting their pivot points at bottom center position.

Conclusion

Its great to get hands on experience in MEL, especially when it comes to achieve something that is challenging in many ways. Thanks to Professor Malcolm Kesson for providing the best of his support throughout the assignment. Now my eyes on the next assignment where we are required to create the user interface inside MEL so that I have more control over the objects.