Monday, December 3, 2012

Flower Petals with Expressions

This is my second melscript revision. It essentially does the same thing as the last one, but it adjusts the bend resistance and lift over time with an expression, in order to give a more leafy quality.

//Clean Up
SelectAll;
doDelete;


// User Definitions
string $currentSelection[];
string $myTurbulence[];
string $myAir[];

//Set Up Background
polyPlane -w 1 -h 1 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;
move -2.076 -4.896 7.866;
rotate 0 0 90;
scale 9 1 16;
sets -e -forceElement surfaceShader1SG;
$currentSelection = `ls -selection`;
select -r (($currentSelection[0]) + ".map[0:3]");
polyEditUV -pu 0.5 -pv 0.5 -a 90 ;
polyEditUV -pu 0.5 -pv 0.5 -su -1 -sv 1 ;

//Create Fields
turbulence -pos 0 0 0 -m 6 -att 0 -f 1 -phaseX 0 -phaseY 0 -phaseZ 0 -noiseLevel 0 -noiseRatio 0.707  -mxd -1  -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ;
$myTurbulence = `ls -selection`;
air -pos 0 0 0 -m 15 -att 0 -dx 0 -dy -.75 -dz 1 -s 5 -iv 1 -iro 1 -vco 0 -es 0  -mxd 20  -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ;
$myAir = `ls -selection`;

//Create petals For Loop
for( $i=0; $i<10; $i++)
{
    //create plane
    polyPlane -w .25 -h .5 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1;
    move -r (rand(-1,1)) (rand(-1,1)) (rand(-1,1));
    rotate (rand(0,360)) (rand(0,360)) (rand(0,360));
    sets -e -forceElement flowerPetalTexture2SG;
 
    //Adjust NCloth settings
    createNCloth 0;
    $currentSelection = `ls -selection`;
    setAttr (($currentSelection[0]) + ".drag") (rand(.05, 5));
    setAttr (($currentSelection[0]) + ".pointMass") (rand(.1, 2));
    setAttr (($currentSelection[0]) + ".lift") (rand(.1, 2));
    setAttr (($currentSelection[0]) + ".bendResistance") 10;
    setAttr (($currentSelection[0]) + ".stretchResistance") (rand(1, 200));
    expression -string (($currentSelection[0]) + ".drag = (rand(.05, 5)); \n" + ($currentSelection[0]) + ".pointMass = (rand(.1, 2)); \n" + ($currentSelection[0]) + ".lift = (rand(.1,2)); \n");
 
    //Attach Fields
    connectDynamic -f $myAir $currentSelection;
    connectDynamic -f $myTurbulence $currentSelection;
 
    select -r $currentSelection nucleus1 ;
    setAttr "nucleus1.gravity" 0;
}



Flower Petals with Mel Script

I was attempting to use mel script to create an aesthetically pleasing piece.

The background is a matte painting, but the flower petals are all created dynamically through mel script.

To create the petals through mel script, I use a For Loop to create each petal.
1. Create plane.
2. Set starting position and rotation randomly.
3. Turn plane into NCloth.
4. Attach plane to fields.

I was trying to integrate NCloth, which Im pretty new at into melscript, and I think it turned out pretty well. One thing I would like to adjust in the future is the lighting on the petals. The color isn't quite right when its in the shadows. The movement is pretty close to what I was looking for though.

Here is the mel script and a playblast. Enjoy!




//Clean Up
SelectAll;
doDelete;


// User Definitions
string $currentSelection[];
string $myTurbulence[];
string $myAir[];

//Set Up Background
polyPlane -w 1 -h 1 -sx 1 -sy 1 -ax 0 1 0 -cuv 2 -ch 1;
move -2.076 -4.896 7.866;
rotate 0 0 90;
scale 9 1 16;
sets -e -forceElement surfaceShader1SG;
$currentSelection = `ls -selection`;
select -r (($mySelection[0]) + ".map[0:3]");
polyEditUV -pu 0.5 -pv 0.5 -a 90 ;
polyEditUV -pu 0.5 -pv 0.5 -su -1 -sv 1 ;

//Create Fields
turbulence -pos 0 0 0 -m 6 -att 0 -f 1 -phaseX 0 -phaseY 0 -phaseZ 0 -noiseLevel 0 -noiseRatio 0.707  -mxd -1  -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ;
$myTurbulence = `ls -selection`;
air -pos 0 0 0 -m 15 -att 0 -dx 0 -dy -.75 -dz 1 -s 5 -iv 1 -iro 1 -vco 0 -es 0  -mxd 20  -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5 ;
$myAir = `ls -selection`;

//Create petals For Loop
for( $i=0; $i<10; $i++)
{
    //create plane
    polyPlane -w .25 -h .5 -sx 10 -sy 10 -ax 0 1 0 -cuv 2 -ch 1;
    move -r (rand(-1,1)) (rand(-1,1)) (rand(-1,1));
    rotate (rand(0,360)) (rand(0,360)) (rand(0,360));
    sets -e -forceElement flowerPetalTexture2SG;
   
    //Adjust NCloth settings
    createNCloth 0;
    $currentSelection = `ls -selection`;
    setAttr (($currentSelection[0]) + ".drag") (rand(.05, 5));
    setAttr (($currentSelection[0]) + ".pointMass") (rand(.1, 2));
    setAttr (($currentSelection[0]) + ".bendResistance") (rand(.1, 2));
    setAttr (($currentSelection[0]) + ".stretchResistance") (rand(1, 200));
   
    //Attach Fields
    connectDynamic -f $myAir $currentSelection;
    connectDynamic -f $myTurbulence $currentSelection;
   
    select -r $currentSelection nucleus1 ;
    setAttr "nucleus1.gravity" 0;
}




Monday, November 26, 2012

Randomized cube script

I was attempting to do a spiraling column of cubes, and this is the script that I came up with. Enjoy!



cleanUp();
buildCubes();


//CLEAN UP
global proc cleanUp()
{
SelectAll;
doDelete;
}



//BUILD OBJECTS - make a random sized cube
global proc buildCubes()
{

    float $spacing = 3;
    float $blockSpacing = 27;
    float $cubeSizeX;
    float $cubeSizeY;
    float $cubeSizeZ;
    int $cubeArrayNum = 0;
    string $cubeArrayName[];
    string $cubeArray[];
   
    //for loop
    for ( $blockHeight=1; $blockHeight<10; $blockHeight++)
    {
        for ( $blockDepth=1; $blockDepth<10; $blockDepth++)
        {
            for ( $blockWidth=1; $blockWidth<10; $blockWidth++)
            {
                $cubeSizeX= rand(3);
                $cubeSizeY= rand(3);
                $cubeSizeZ= rand(3);
           
                polyCube -width $cubeSizeX -height $cubeSizeY -depth $cubeSizeZ;
                move -r ($spacing * $blockWidth) ($spacing * $blockHeight) ($spacing * $blockDepth);
                rotate -r (rand(0,360)) (rand(0,360)) (rand(0,360)) ;
                $cubeArrayName = `ls -selection`;
                $cubeArray[$cubeArrayNum] = $cubeArrayName[0];
                $cubeArrayNum++;
            }
        }
    }
    select $cubeArray;
    group -name cubeArray;
    for ( $i=1; $i<5; $i++)
            {
                duplicate;
                move -r 0 $blockSpacing 0;
                rotate -r 0 15 0;
                $cubeArrayName = `ls -selection`;
                $cubeArray[$cubeArrayNum] = $cubeArrayName[0];
                $cubeArrayNum++;
            }
}

Adjustments

Here are some adjustments that I made. I tried to allow the skull to be the main focus of the composition, and I adjusted the cluster of texture that distracted from the eyes.

I was struggling to make the rim light in Maya, so hopefully I can work on that a bit.