|
Step 3 is easy after the last step, in this step all we are going to do is to use a variable to make the number of floors the script makes easily changable. $i = 0; //loop through while $i is less that ten and create some cubes while($i < 10){ polyCube; scale 10 .1 1; move 0 $i $i; $i++; } Step 2 The second step in this step is to take the loop from step 1 and wrap it inside of a procedure. To create a procedure, just surround the loop with a procedure declaration. Place the statement 'proc stair(){' at the beginning and '}' at the end. This defines it as a procedure named 'stair()' (the parthesis will be explained later in the tutorial). When you copy-and-paste this script into the MEL scripting window, nothing will happen on the screen. However, once you have cut-and-paste the script, you will have a new function called 'stair()' that you can execute. Once you copy-and-paste, type 'stair();' into the MEL scripting window and it will create a stair. proc stair(){ //create a function called 'stair()' that will perform the loop //loop through while $i is less that ten and create some cubes $i = 0; while($i < 10){ polyCube; scale 10 .1 1; move 0 $i $i; $i++; } } If you add the word 'global' before your procedure declaration, then if you save it to a file you can use the files as a function library. Add a 'global' declararion before the 'proc' statement and save your script as a text-only file called 'stair.mel'. To load the stair function at any time, choose 'Source Script' from the 'File' menu in the MEL Scripting window and select you file. Step 3 Now that you have defined your 'stair' procedure, you can refine its definition by providing for 'arguments'. 'Arguments' allow you to feed information or varaibles into your function so that it can have different behaviors. These arguments are the variables that come between the parenthesis when you call a procedure. In this step you will redefine your function so that the number of stairs is variable. To do this change the function declaration to be 'global proc stair(float $numberofsteps)', this tells the function that is will receive a variable (which will be a floating point decimal) and that number will define how many steps should be in the stairs. Use the '$numberofsteps" variable inside of the function to limit the iterations of the loop.
/hi, // //i attached some mel-code which could help. it swaps uv position between 2 or 3 uvs/vertices. //you can also select a face - and all vertices are swaped. HTH. // //chris // //====================================================== string $convertCmd = `PolySelectConvert 4`; string $uvData[] = `ls -sl -fl`; string $uvTransfer[]; string $uvNew[]; int $u = 1; int $plusCount; int $uvCount; float $uvPosition[]; //just get the position of the UVs stored in $uvTransfer... for ($selIndex = 0; $selIndex < size($uvData); $selIndex++) This introduction to the Maya Embeded Language (MEL) introduces some simple MEL commands as well as the basic programming concepts of variables and loops. Variables are abstract signifiers that can be used to represent numbers, words (strings), decimals or just about anything else. The power of variables is that they are just that - variable. By using variables you are able to treat general conditions, instead of the specific. For example you can write a program that will create a building of any height, instead a specific height like 10 feet. Using variables means that you can use your MEL scripts in variety of different situations, This tutorial covers the basics of making your own MEL procedures, MEL procedures allow you to define your own language in MEL, creating your own commands instead of using the built in commands like 'move', 'rotate' and 'polyCube'. The power of being able to make your own procedures is the ablity to create a simple interface to a vast array of functionality and decision making. MEL procedures do this by allowing you to take a series of complicated commands, group them together and give them a name. In this simple tutorial we are going to create a new MEL procedures called 'stair', this procedure will perform all of the calculations necessary to create a set of stairs based on height, number of steps and starting location. Once you have made this function, you can save it to a file and source it whenever you start Maya. If you do that, you can use it over and over again, wherever you need a staircase. Step 1 |
| w_w_w___.j_a__va_2__s.c_o___m_ | Contact Us |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |