PDA

View Full Version : Error Grass Code


VHS
09-23-2008, 01:44 PM
Helle there :arteest:
Anyone who can help me get this script working,
it should be some buttons and when you hit it there will be grass




global proc string xxCreateStraw()
{
//Create variables
string $currentCone[];

int $grassType;
float $strawHeight;
float $moveCone;
float $strawBend;
int $strawSubDivY;
int $detail;
float $translateX;
float $translateZ;

float $minX;
float $maxX;
float $minZ;
float $maxZ;

// assign values to variables
// get min and max for X and Z


$minX = `floatFieldGrp -query -value1 grassGen_X_ffGrp`;
$maxX = `floatFieldGrp -query -value2 grassGen_X_ffGrp`;
$minZ = `floatFieldGrp -query -value1 grassGen_Z_ffGrp`;
$maxZ = `floatFieldGrp -query -value2 grassGen_Z_ffGrp`;


$translateX = rand($min,$maxX);
$translateZ = rand($minZ,$maxZ);


// get style and detale for grass.

$grassType = `radioButtonGrp -query -select grassGenTypeRBGrp`;
$detal



//Assign variables
$grassType = 2;
$detail = 2;
$translateX = rand(1,-1);
$translateZ = rand(1,-1);

//Switch for grass type
switch ( $grassType )
{
case 1 :
{
$strawHeight = rand(0.25,0.5);
$strawBend = rand(0.1,0.5);
switch ( $detail )
{
case 1 :
{
$strawSubDivY = 2;
}
break;
case 2 :
{
$strawSubDivY = 4;
}
break;
case 3 :
{
$strawSubDivY = 6;
}
break;
default :
{
$strawSubDivY = 4;
}
break;
}
}
break;
case 2 :
{
$strawHeight = rand(0.75,1.5);
$strawBend = rand(0.25,0.75);
switch ( $detail )
{
case 1 :
{
$strawSubDivY = 3;
}
break;
case 2 :
{
$strawSubDivY = 6;
}
break;
case 3 :
{
$strawSubDivY = 9;
}
break;
default :
{
$strawSubDivY = 5;
}
break;
}
}
break;
case 3 :
{
$strawHeight = rand(1.5,3);
$strawBend = rand(0.25,1);
switch ( $detail )
{
case 1 :
{
$strawSubDivY = 5;
}
break;
case 2 :
{
$strawSubDivY = 10;
}
break;
case 3 :
{
$strawSubDivY = 30;
}
break;
default :
{
$strawSubDivY = 10;
}
break;
}
}
break;
default :
{
$strawHeight = 1;
$strawBend = 0.25;
$strawSubDivY = 5;
}
break;
}

$moveCone = $strawHeight * 0.5;

//Create the cone
polyCone
-radius 0.1
-height $strawHeight
-subdivisionsX 3
-subdivisionsY $strawSubDivY
-subdivisionsZ 0
-axis 0 1 0
-roundCap 0
-createUVs 1
-constructionHistory 0;

$currentCone = `ls -sl`;

//Move and scale cone
move -y $moveCone;
scale -x 0.1;

//Soften and harden
polySoftEdge
-angle 1
-constructionHistory 0;

//Create and move deformer
nonLinear
-type bend
-lowBound -1
-highBound 1
-curvature $strawBend;
move -y 0;
//Reselect and delete history
select -r $currentCone[0];
DeleteHistory;

// Move/rotate straw randomly
xform
-relative
-translation $translateX 0 $translateZ
-rotation 0 `rand(360)` 0;
return $currentCone[0];
}






global proc dsCreateGrass()
{
// Varibles
int $numberOfStraws;
int $squareUnitcount;

float $minX;
float $maxX;
float $minZ;
float $maxZ;

// assign values to variables
$minX = `floatFieldGrp -query -value1 grassGen_X_ffGrp`;
$maxX = `floatFieldGrp -query -value2 grassGen_X_ffGrp`;
$minZ = `floatFieldGrp -query -value1 grassGen_Z_ffGrp`;
$maxZ = `floatFieldGrp -query -value2 grassGen_Z_ffGrp`;

SquareUnitCount = `intFieldGrp -query -value1 grassGenDensityIF`;

$numberOfStraws = 100;

// Loop to create some straws

for { $i=0; $i<$numberOfStraws $i++ }
{
$allTheStraws[$i] = `dsCreateStraw`;
}

select -r $allTheStraws;
polyUnite -ch 0;
}

NaughtyNathan
09-24-2008, 10:52 AM
well what's wrong with it? we can't tell or test it as you've only posted a part of your code... there's no UI creation in it..!

looking at it though, apart from some obvious syntax errors (line 37: $detal ... ?!? and the fact that you reassign the same variable values twice?) you have a very confusing set of nested switch/cases.. I'm not even sure if this is legal is it??! even if you can, I'd advise against it... obfuscation would be an understatement.

don't use switch case here, use the case values (i.e. 1,2,3,etc..) to define the values directly, e.g:

$strawSubDivY = ($detail * 2);

also (for what it's worth on this forum) make sure you enclose your posted code in the [code] tags

:nathaN

CGTalk Moderation
09-24-2008, 10:52 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.