November 14, 2013 Workshop 18 Notes
MEL EXAMPLES
CreatePolygonCube;
setToolTo CreatePolyCubeCtx;
polyCube -ch on -o on -w 3.739708 -h 2.49654 -d 3.577945 -cuv 4 ;
// Result: pCube1 polyCube1 //
Select and repaste the command editing the values, and hit the
“enter” key
CreatePolygonCube;
polyCube -ch on -o on -w 1 -h 1 -d 1 ;
// Result: pCube2 polyCube2 //
//create a float variable $r using the rand() command by typing
float $r;
$r = rand(10);
//Edit the cube and use the random number for the cube size
//CreatePolygonCube;
polyCube -w $r -h $r -d $r -ax 0 1 0;
float $r, $Gx, $Gy, $Gz;
$r = rand(10);
string $Name[];
//CreatePolygonCube;
$Name = `polyCube -w $r -h $r -d $r -ax 0 1 0`;
$Gx = gauss(10);
$Gy = gauss(10);
$Gz = gauss(10);
move $Gx $Gy $Gz $Name;
Highlight in scrip editor and keep entering enter key and see
results.
float $r, $Gx, $Gy, $Gz;
int $counter=1;
while ($counter++ < 10) {
$r = rand(10);
string $Name[];
//CreatePolygonCube;
$Name =
`polyCube -w $r -h $r -d $r -sx 1 -sy 1 -sz 1 -ax 0 1 0 `;
$Gx =
gauss(10);
$Gy =
gauss(10);
$Gz =
gauss(10);
move $Gx $Gy $Gz $Name;
}
float $x, $y, $z;
for ($cube in `ls -sl`){
$x =
gauss(1);
$y =
gauss(1);
$z =
gauss(1);
move $x $y $z $cube;
};
float $x, $y, $z;
for ($cube in `ls -sl`){
$x =
gauss(1);
$y =
gauss(1);
$z =
gauss(1);
move $x $y
$z $cube;
if
($y > 1) { scale 2 2 2 $cube; }
};
ctrl/ctrl-a on one of the cubes an open attribute editor
select pCubeShape (e.g., pCubeShape5) and the Render Stats section.
Uncheck cast shadows yields
setAttr "pCubeShape5.castsShadows" 0;
try using the followwing code for a selected set of cubes:
for ($cube in `ls -sl`){
setAttr ($cube+".castsShadows") 0;
}
**********************
14. For a particle, after creating an emitter, use expressions editor
under Translate Y attribute box to create the following expression:
particle1.translateY = 10 * sin(deg_to_rad(sqrt(pow(particle1.translateX,2) + pow(particle1.translateZ,2)) + frame));
*****************
15. Writing a procedure for a ball {WE WILL CONTINUE BY REVISITING THIS
EXAMPLE]
global proc string moveball2(vector $pt){
float $px = $pt.x;
float $py = $pt.y;
float $pz = $pt.z;
string $balls[1] = `sphere -p $px $py $pz`;
string $myball = $balls[0];
expression -o $myball -s "tz = sin(deg_to_rad(frame)) * 10;";
return $myball;
}
//test 1
vector $pt = <<4, 4, 0>>;
moveball2($pt);
//test 2
vector $pt = <<2, 2, 0>>;
moveball2($pt);
//Procedure to create array of moving spheres
global proc string makeballs(int $rows, int $cols) {
float $spaced = 4.0;
float $xpos = -1 * $cols * 0.5 * $spaced;
float $ypos = -1 * $rows * 0.5 * $spaced;
float $zpos = 0.0;
vector $pt = <<$xpos, $ypos, $zpos>>;
int $i = 0;
int $ii = 0;
while ($i < $rows) {
while ($ii < $cols) {
$pt = <<$xpos,
$ypos, $zpos>>;
moveball2($pt);
$xpos = $xpos + $spaced;
$ii = $ii + 1;
print("inner loop \n");
print("x val & y
val " + $xpos + " " + $ypos + "\n");
}
print("outer loop \n");
$ii = 0;
$i = $i + 1;
$xpos = -1 * $cols * 0.5 * $spaced;
$ypos = $ypos + $spaced;
}
return "done";
};
makeballs(2,2);
makeballs(20, 20);
***************************************************
VARIED HEIGHTS BY DISTANCE FROM ORIGIN
global proc string moveball3(vector $pt){
float $px = $pt.x;
float $py = $pt.y;
float $pz = $pt.z;
string $balls[1] = `sphere -p 0 0 0 -r 1`;
move -r $px $py $pz ;
string $myball = $balls[0];
expression -o $myball -s "ty = 10.0 * sin (deg_to_rad (15 * (sqrt
(pow (tx, 2) + pow (tz, 2))) + frame));";
return $myball;
}
global proc string makeballs(int $rows, int $cols) {
float $spaced = 4.0;
float $xpos = -1 * $cols * 0.5 * $spaced;
float $ypos = -1 * $rows * 0.5 * $spaced;
float $zpos = 0.0;
vector $pt = <<$xpos, $ypos, $zpos>>;
int $i = 0;
int $ii = 0;
while ($i < $rows) {
while ($ii < $cols) {
moveball3($pt);
//change procedure in examples below ... makeplanes
$xpos = $xpos + $spaced;
$pt = <<$xpos,
$ypos, $zpos>>;
$ii = $ii + 1;
//print("inner loop
\n");
}
$ii = 0;
$i = $i + 1;
$xpos = -1 * $cols * 0.5 * $spaced;
$zpos = $zpos + $spaced;
}
return "done";
}
***************************************************
WITH PLANES
global proc string moveplane(vector $pt, float $spaced){
float $px = $pt.x;
float $py = $pt.y;
float $pz = $pt.z;
string $planes[1] = `nurbsPlane -p 0 0 0 -ax 0 1 0 -w $spaced -lr 1 -d
3 -u 1 -v 1 -ch 1`;
move -r $px $py $pz ;
string $myplane = $planes[0];
expression -o $myplane -s "ty = 10.0 * sin (deg_to_rad (15 * (sqrt
(pow (tx, 2) + pow (tz, 2))) + frame));";
return $myplane;
}
global proc string makeplanes(int $rows, int $cols) {
float $spaced = 4.0;
float $xpos = -1 * $cols * 0.5 * $spaced;
float $ypos = -1 * $rows * 0.5 * $spaced;
float $zpos = 0.0;
vector $pt = <<$xpos, $ypos, $zpos>>;
int $i = 0;
int $ii = 0;
while ($i < $rows) {
while ($ii < $cols) {
moveplane($pt,
$spaced);//change procedure from example above ... makeballs
$xpos = $xpos + $spaced;
$pt = <<$xpos,
$ypos, $zpos>>;
$ii = $ii + 1;
//print("inner loop
\n");
}
$ii = 0;
$i = $i + 1;
$xpos = -1 * $cols * 0.5 * $spaced;
$zpos = $zpos + $spaced;
}
return "done";
};
makeplanes(20, 20);