Search Advanced Algorithmic Design
Spring 2007 GSAPP Instructors: Mark Collins (mark@proxyarch.com) Toru Hasegawa (toru@proxyarch.com) Class Time: 8:00-10:00 Thursdays Precept Time: 11:00-1:00 Mondays
designed by proxy link In this tutorial, we will be looking at basic concepts + syntax within MEL. This tutorial assumes a basic familiarity with the Maya interface (Script editor, manipulating views, etc) - all of the scripts below can be pasted directly into the script editor and run without any extra files. Basic help with Processing can be found here: Working in MEL, we have to remember that we are not in a true programming environment - instead, it is a means through which we can combine certain fixtures of programming language (loops, variables, etc) and supported Maya commands/object types. It is essentially 'scripting' rather than 'programming'. One great resource to make the transition from modeling to scripting is to see how the creating/editing of objects in Maya echoes to the 'script editor' - everything you can do in Maya has a MEL command associated with it. There are several ways of executing these commands, and particular syntax for employing variables + loops that will allow us to work with MEL commands and recursion. executing commands
//from Hotkey editor (or looking in script editor) CreateNURBSCircle; //Evaluating a command string //Note the '$' in front of variable names - this is standard in MEL string $myString= "CreateNURBSCircle"; eval($createCurve); //Capturing the output (object name) using `` string $myCircleName[] = `CreateNURBSCircle`; print ($myCircleName[0] + "\n"); using recursion to build up a variable for execution
string $createCurve = "curve -d 3 ";
string $myCurve;
for($i=0;$i<12;$i++){
float $random = `rand 3`;
$createCurve = ($createCurve + " -p " + " 0 " + $random + " " + $i);
}
print $createCurve;
eval($createCurve);
![]() Procedures in MEL give us similar functionality to what we have been exploring in Processing with Classes. However, procedures are essentially a set list of commands - in that sense they are not 'objects' (like a class) but rather 'scripts' - series of instructions that have been bundled to execute consecutively. They will execute when called, and can 'return' information at the end of their operation. Here we will bundle our curve drawing commands into a procedure that will take a simple 'argument' and return the name of the curve that it created. procedure
syntax
global proc procedureName(argumentType myArgument1,
argumentType myArgument2...){
series of commands....
}
our buildCurve procedure
global proc buildCurve(){
float $startX =4;
string $createCurve = "curve -d 3 ";
string $myCurve;
for($i=0;$i<8;$i++){
float $random = `rand 3`;
$createCurve = ($createCurve + " -p 0 " + $random + " " + $i);
}
$myCurve = `eval($createCurve)`;
print ($myCurve+"\n");
}
buildCurve();
using a return statement and procedure argument
global proc string buildCurve(float $startX){
string $createCurve = "curve -d 3 ";
string $myCurve;
for($i=0;$i<8;$i++){
float $random = `noise<<$startX,0,$i>>`;
$createCurve = ($createCurve+" -p "+$startX+" "+$random+" "+$i);
}
$myCurve = `eval($createCurve)`;
return $myCurve;
}
buildCurve(0);
![]() Once we have established a procedure to draw our lines, we can use another procedure to call it - ultimately producing a series of nested calls that can produce more complex objects. In this case, we will call our 'buildCurve' procedure to produce enough lines for a surface. Also, we can continually capture the information returned by 'buildCurve' and use it to produce a lofted surface. 'buildSurface' procedure
global proc buildSurface(int $totalCurves, float $offset){
string $curveArray[];
for($i=0;$i<$totalCurves;$i++){
$curveArray[$i] = buildCurve($i+$offset);
}
print $curveArray;
}
'buildSurface' w/ automatic lofting
global proc buildSurface(int $totalCurves, float $offset){
string $curveArray[];
for($i=0;$i<$totalCurves;$i++){
$curveArray[$i] = buildCurve($i+$offset);
}
print $curveArray;
select -cl;
for($i=0;$i<size($curveArray);$i++){
select -tgl $curveArray[$i];
}
loftToolScript 4; //from "hotkey" editor
}
![]() proxy is a firm that specializes in design, fabrication, and software applications emerging out of computer driven processes. leveraging the most current technology to make things that are both complex and accessible is what proxy does.
proxyarch.com - link |