Saturday, September 19, 2009

MEL

I just finished another DT course: Intro to MEL, which is about Maya's Embedded Language for making little scripts and customizing the program.
Say you want a quick way to hide some attributes for all objects that are selected... well Maya doesn't come with a single button to do that, but you can make one! And create new marking menus, which are almost like mouse gestures in a way (if you haven't used Maya before). So the main project was to create some pretty little flowers entirely using MEL. Here they are:


Ew... a jpeg... but the png's screw up the transparency for some reason and blogger only accepts jpegs, pngs, bmps, and gifs. I'll try a bmp next time.

All the texturing, modelling and everything was done with this little script:

global proc flowerMaker () {

int $numPetals = `rand 10 15`;
$createShader = 1;


//check for petal shader
string $shaders[] = `ls -mat`;
for ($myNode in $shaders){
if ($myNode == "petalColor")
$createShader = 0;
}

switch ($createShader){
case 0:
print "Shader exists\n";
break;
case 1:
//build shader network
shadingNode -asShader lambert -n "petalColor";
shadingNode -asTexture ramp -n "petalRamp";
sets -renderable true -noSurfaceShader true
-empty -n petalColorSG;

connectAttr -f petalColor.outColor petalColorSG.surfaceShader;
connectAttr petalRamp.outColor petalColor.color;


setAttr "petalRamp.colorEntryList[3].color" -type double3 1 0 0;
setAttr "petalRamp.colorEntryList[3].position" 1;

setAttr "petalRamp.colorEntryList[2].color" -type double3 1 1 0;
setAttr "petalRamp.colorEntryList[2].position" .5;

setAttr "petalRamp.colorEntryList[1].color" -type double3 1 0 0;
setAttr "petalRamp.colorEntryList[1].position" 0;

setAttr petalRamp.type 8;


//build core shader network
shadingNode -asShader lambert -n "coreColor";

sets -renderable true -noSurfaceShader true
-empty -n coreColorSG;

connectAttr -f coreColor.outColor coreColorSG.surfaceShader;

setAttr "coreColor.color" -type double3 0.5 0.222 0.028;

break;
}



//create flower core
sphere -ax 0 1 0 -n "core";
string $myCore[] = `ls -sl`;
scale 1 .5 1;
move 0 .2 0;

//connects to core shader network
select $myCore[0];
pickWalk -d down;
string $myCoreShape[] = `ls -sl`;
sets -edit -forceElement coreColorSG $myCoreShape[0];



// build the petal
sphere -ax 0 1 0;
move 0 0 -1.6;
scale .7 .3 1.7;
FreezeTransformations;
ResetTransformations;

string $myPetal[] = `ls -sl`;
parent $myPetal $myCore;

//connects to shader network
select $myPetal[0];
pickWalk -d down;
string $myPetalShape[] = `ls -sl`;
sets -edit -forceElement petalColorSG $myPetalShape[0];



//move the tip of the petal
select ($myPetal[0] + ".cv[3] [7]");
move -r 0 1.5 0;

//move center of petal down
//U loop
for ($uCV = 5; $uCV <= 6; $uCV++){
//V loop
for ($vCV = 0; $vCV <= 7; $vCV++){
select ($myPetal[0] + ".cv[" + $uCV + "] [" + $vCV + "]");
move -r 0 -.3 0;

}
}
//closed the loops



//duplicate petals
select $myPetal[0];
float $degreeApart = (360 / $numPetals);

for ($i = 1; $i < $numPetals; $i++){
duplicate;
rotate -r 0 $degreeApart 0;

// randomly rotate the petals
float $petalRX = `rand -10 10`;
float $petalRY = `rand -10 10`;
float $petalRZ = `rand -10 10`;

FreezeTransformations;
rotate $petalRX $petalRY $petalRZ;

}


select $myCore;
rename "Flower0";

}

That creates one flower... yeah, so it would be easier to just make it by hand, but this really taught me a lot about MEL's syntax and commands and different things you can do with it.
I think I'm going to work through another modelling tutorial project next, so hopefully that goes okay.

I also am going to be doing a directed study at UVic to learn some Maya and stuff, so that should be fun. I'll keep you posted on that too.

Later,
Stuart

2 comments:

  1. That's amazing you can do that simply with code. It's like the matrix where they look at the screens of falling green symbols and can"see" what's going on in the matrix... or something like that...

    ReplyDelete
  2. Thanks... yeah it's kinda fun. I'm gonna do another MEL tutorial after I do a couple other ones first, but looking forward to it. I like computer animation and I like coding, so obviously I like the combination.

    ReplyDelete