Wednesday 12 November 2008

fixedSession5

//colourCode - CodeSet 5
//npuckett - 2008 www.colourcodedarch.blogspot.com

proc string newRamp()
{
//create a new material and attach a ramp to its colour output
string $shader = `shadingNode -asShader lambert`;
string $ramp = `shadingNode -asTexture ramp`;
string $place = `shadingNode -asUtility place2dTexture`;
connectAttr ($place+".outUV") ($ramp+".uv");
connectAttr ($place+".outUvFilterSize") ($ramp+".uvFilterSize");
connectAttr -force ($ramp+".outColor") ($shader+".color");

removeMultiInstance -break true ($ramp+".colorEntryList[1]");
setAttr ($ramp+".colorEntryList[2].color") -type double3 0 0 0 ;
setAttr ($ramp+".colorEntryList[2].position") 1;
setAttr ($ramp+".colorEntryList[0].position") 0;
setAttr ($ramp+".colorEntryList[0].color") -type double3 1 1 1 ;
return $ramp;
}







//show colour values on the surface
int $totX = 10;
int $totZ = 10;
//change the name of the controller to correspond to the ones that you have
float $scale = 0.1;
string $controller = "ramp1";
string $surface = "plane1";

for ($x=0;$x<=$totX;$x++)
{
for ($z=0;$z<=$totZ;$z++)
{
float $you = ((1.0/$totX)*$x);
float $vee = ((1.0/$totZ)*$z);
//use colorAtPoint to return the value of the colour
float $heights[] = `colorAtPoint -u $you -v $vee $controller`;
float $position[] = `pointOnSurface -p -u $you -v $vee $surface`;
string $hInfo[] = `textCurves -ch 0 -f "Arial-Regular" -t $heights[0]`;
scale -r $scale $scale $scale $hInfo[0];
move -a $position[0] $position[1] $position[2] $hInfo[0];
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///create a grid
proc boxGrid(int $totalX, int $totalZ, float $factor)
{
//create the grid of boxes
for($x=0;$x<=$totalX;$x++)
{
for($z=0;$z<=$totalZ;$z++)
{
string $name = ("box_"+$x+"_"+$z);
polyCube -n $name;
move -r ($x*$factor) 0 ($z*$factor);
}
}
}
boxGrid(20,20,2.5);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///moving a system of boxes using the colour value
int $totX = 20;
int $totZ = 20;
//change the name of the controllers to correspond to the ones that you have
string $controller = "ramp1";
//the name of the object system being affected
string $baseName = "box";
float $factor = 5;
for ($x=0;$x<$totX;$x++)
{
for ($z=0;$z<$totZ;$z++)
{
//the U and V values are the texture's internal coordinate system
//it runs from 0 -> 1 in both directions
//this is how we define a specific point on the texture to sample from
float $you = ((1.0/$totX)*$x);
float $vee = ((1.0/$totZ)*$z);
//use colorAtPoint to return the value of the colour
float $heights[] = `colorAtPoint -u $you -v $vee $controller`;
//since we used a set naming system the boxes name matches up to the
//coordinates that we sample on the texture
string $name = ($baseName+"_"+$x+"_"+$z);
//use the value from the texture to move the boxes
move -r 0 ($heights[0]*$factor) 0 $name;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//animate the movement
int $totX = 20;
int $totZ = 20;
//change the name of the controllers to correspond to the ones that you have
string $controller = "ramp2";
//the name of the object system being affected
string $baseName = "box";
float $factor = 50;
for ($x=0;$x<$totX;$x++)
{
for ($z=0;$z<$totZ;$z++)
{
//the U and V values are the texture's internal coordinate system
//it runs from 0 -> 1 in both directions
//this is how we define a specific point on the texture to sample from
float $you = ((1.0/$totX)*$x);
float $vee = ((1.0/$totZ)*$z);
//use colorAtPoint to return the value of the colour
float $heights[] = `colorAtPoint -u $you -v $vee $controller`;
//since we used a set naming system the boxes name matches up to the
//coordinates that we sample on the texture
string $name = ($baseName+"_"+$x+"_"+$z);
//use the value from the texture to set the keyframe value
setKeyframe -at translateY -v 0 -t 1 $name;
setKeyframe -at translateY -v ($heights[0]*$factor) -t (($x+1)+($x*$z)) $name;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//using 2 inputs
//animate the movement
int $totX = 20;
int $totZ = 20;
//change the name of the controllers to correspond to the ones that you have
string $controller = "file2";
string $controller2 = "ramp1";
//the name of the object system being affected
string $baseName = "box";
float $factor = 20;
float $timeFactor = 200;
for ($x=0;$x<$totX;$x++)
{
for ($z=0;$z<$totZ;$z++)
{
//the U and V values are the texture's internal coordinate system
//it runs from 0 -> 1 in both directions
//this is how we define a specific point on the texture to sample from
float $you = ((1.0/$totX)*$x);
float $vee = ((1.0/$totZ)*$z);
//use colorAtPoint to return the value of the colour
float $heights[] = `colorAtPoint -u $you -v $vee $controller`;
float $time[] = `colorAtPoint -u $you -v $vee $controller2`;
//since we used a set naming system the boxes name matches up to the
//coordinates that we sample on the texture
string $name = ($baseName+"_"+$x+"_"+$z);
//use the value from the texture to set the keyframe value
setKeyframe -at scaleY -v 0 -t 1 $name;
setKeyframe -at scaleY -v ($heights[0]*$factor) -t ($time[0]*$timeFactor) $name;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//controlling the output range
//using 2 inputs
//animate the movement
int $totX = 10;
int $totZ = 12;
//change the name of the controllers to correspond to the ones that you have
string $controller = "ramp1";
string $controller = "ramp2";
//the name of the object system being affected
string $baseName = "box";
float $factor = 5;
float $timeFactor = 20;

float $outputMin = -30;
float $outputMax =30;
float $timeMin = 30;
float $timeMax = 300;

for ($x=0;$x<$totX;$x++)
{
for ($z=0;$z<$totZ;$z++)
{
//the U and V values are the texture's internal coordinate system
//it runs from 0 -> 1 in both directions
//this is how we define a specific point on the texture to sample from
float $you = ((1.0/$totX)*$x);
float $vee = ((1.0/$totZ)*$z);
//use colorAtPoint to return the value of the colour
float $cVal[] = `colorAtPoint -u $you -v $vee $controller`;
float $time[] = `colorAtPoint -u $you -v $vee $controller2`;
//since we used a set naming system the boxes name matches up to the
//coordinates that we sample on the texture
float $adjCval = $outputMin + ((($cVal[0]-0)/(1-0)) * ($outputMax-$outputMin));
float $adjTval = $outputMin + ((($time[0]-0)/(1-0)) * ($outputMax-$outputMin));
string $name = ($baseName+"_"+$x+"_"+$z);
//use the value from the texture to set the keyframe value
setKeyframe -at translateY -v 0 -t 1 $name;
setKeyframe -at translateY -v $adjCVal -t $adjTval $name;
}
}

1 comment:

George Vizor said...

Hi,
Im having real trouble getting this script to work- its keeps saying no object matches Ramp1! please help
thanks
George