Mel
From DreamsteepWiki
Aarons original fractal tree in melscript dated to November 10,2001
global int $stackNum = 0;
global string $leafName = "leaf";
global string $barkName = "wood";
global string $curveName = "stack0_level1_branch1_ring1";
global string $jointName = "joint";
global string $splineName = "handle";
global string $name = "";
global int $loftState = 1;
global int $leafState = 0;
global int $leafScalState = 0;
global int $leafRotState = 0;
global int $boneState = 1;
global int $springState = 0;
global int $leafcount = 1;
global int $branchOffPoint = 0;
///////////////////////////////////////////////////////////////////////////////
proc nwscn ()
{
file -f -new;
modelEditor -e -grid 0 modelPanel4;
global int $stackNum;
$stackNum = 0;
sets -n delKurve;
sets -n leafSet;
sets -n branchSet;
createDisplayLayer -n leaves;
createDisplayLayer -n branches;
createDisplayLayer -n skeleton;
createDisplayLayer -n IK_handles;
}
nwscn;
proc rstscn ()
{
warning "NOT YET BUDDY";
}
proc cleanUp ()
{
global int $leafState;
select delKurve;
delete;
if ($leafState ==1){
select `textField -q -tx crntLeaf`;
delete;
select leafSet;
layerBarAssignObjects leaves;
}
select branchSet;
layerBarAssignObjects branches;
}
proc abt ()
{
//address of tutorial
//bio of me
}
proc renam ()
{
string $list[] = `ls -sl`;
int $size = size($list);
int $a = 0;
for ($a = 0;$a<=$size;$a++)
{
select $list[$a];
rename (`textField -q -tx renField` + $a);
}
}
proc skelFix ()
{
int $a =1;
int $b = $a - 1;
for ($a =1;$a < `intField -q -v stckNumField`;$a++)
{
//skel1stack0_level1_branch1_ring1
parent ("skel1stack" + $a + "_level1_branch1_ring1")
("skel1stack" + $b + "_level1_branch1_ring1");
}
}
proc putLeaf ()
{
global string $name;
//USED FOR THIS PURPOSE
//DONT FORGET TO RESET
global int $leafCount;
global int $leafScalState;
global int $leafRotState;
float $leafPos[3];
float $leafRot[3];
//for ($a=1;$a<$multiLeaf;$a++)
//{
select `textField -q -tx crntLeaf`;
sets -add leafSet;
duplicate;
$leafCount++;
if ($leafScalState == 1){scale -r ($leafCount * `floatField -q -v leafScaField`);}
$leafRot = `xform -q -ws -ro $name`;
$leafPos = `xform -q -ws -t $name`;
move -ws $leafPos[0] $leafPos[1] $leafPos[2];
if ($leafRotState == 1) { rotate -r -os ($leafRot[1]+`floatField -q -v lfRotyField`)
($leafRot[0]+ `floatField -q -v lfRotxField`)
($leafRot[2]+ `floatField -q -v lfRotzField`);}
else { rotate -r -os $leafRot[0] $leafRot[1] $leafRot[2];}
//}
}
///////////////////////////////////////////////////////////////////////////////
string $windNam = "NURBIVOR_5_KEITH_LEGG_SEPTEMBER_2001";
modelEditor -e -grid 0 modelPanel4;
if (`window -ex $windNam`) deleteUI $windNam;
window -menuBar true -widthHeight 200 100 -title $windNam $windNam;
paneLayout -configuration "vertical2" "ROOT";
paneLayout -configuration "horizontal3" "leftpane";
scrollLayout -horizontalScrollBarThickness 4
-verticalScrollBarThickness 4;
rowColumnLayout -numberOfColumns 1;
checkBox -label "LEAVES" -v 0 -onc "$leafState = 1;" -ofc "$leafState = 0;";
checkBox -label "INSTANCE" "instancebox";
checkBox -label "LEAFSCALING" -v 0 -onc "$leafScalState =1" -ofc "$leafScalState = 0";
checkBox -label "LEAFROTATION"-v 0 -onc "$leafRotState =1" -ofc "$leafRotState = 0";
checkBox -label "MULTIBRANCHSCALING";
checkBox -label "VTX RANDOMNESS";
checkBox -label "KNOT RANDOMNESS";
checkBox -label "LEAF RANDOMNESS";
checkBox -label "CURVATURE";
checkBox -label "BONES" -v 0 -onc "$boneState = 1" -ofc "$boneState = 0";
checkBox -label "IK";
checkBox -label "SPLINE IK";
checkBox -label "SOFTBODY" "sofbodbox";
checkBox -label "SPRINGS" -onc "$springState = 1" -ofc "$springState = 0";
checkBox -label "LOFT" -v 1 -onc "$loftState = 1" -ofc "$loftState = 0";
checkBox -label "GRID" -onc "modelEditor -e -grid 1 modelPanel4" -ofc "modelEditor -e -grid 0 modelPanel4" gridBox;
setParent ..;setParent ..;
scrollLayout -horizontalScrollBarThickness 16
-verticalScrollBarThickness 16;
rowColumnLayout -numberOfColumns 3;
text "DEPTH";
intField -v 3 -step 1 -min 1 -max 10 -cc "intSlider -e -v `intField -q -v depthField` depthSlid" "depthField";
intSlider -v 3 -step 1 -min 1 -max 10 -cc "intField -e -v `intSlider -q -v depthSlid` depthField" "depthSlid";
text "STACK NUM";
intField -v 1 -step 1 -min 1 -max 50 -cc "intSlider -e -v `intField -q -v stckNumField` stckNumSlid" "stckNumField";
intSlider -v 1 -step 1 -min 1 -max 50 -cc "intField -e -v `intSlider -q -v stckNumSlid` stckNumField" "stckNumSlid";
text "DIAMETER";
floatField -v 2 -step 1 -min 1 -max 20 -cc "floatSlider -e -v `floatField -q -v diaField` diaSlid" "diaField";
floatSlider -v 2 -step 1 -min 1 -max 20 -cc "floatField -e -v `floatSlider -q -v diaSlid` diaField" "diaSlid";
text "SPAN NUMBER";
intField -v 8 -step 1 -min 1 -max 20 -cc "intSlider -e -v `intField -q -v stNumField` stNumSlid" "stNumField";
intSlider -v 8 -step 1 -min 1 -max 20 -cc "intField -e -v `intSlider -q -v stNumSlid` stNumField" "stNumSlid";
text "SPAN HEIGHT";
floatField -v 3 -step 1 -min .1 -max 20 -cc "floatSlider -e -v `floatField -q -v stackField` stackSlid" "stackField";
floatSlider -v 3 -step 1 -min .1 -max 20 -cc "floatField -e -v `floatSlider -q -v stackSlid` stackField" "stackSlid";
text "BRANCH SCALE FACTOR";
floatField -v .9 -min .5 -max 1.5 -cc "floatSlider -e -v `floatField -q -v branField` branSlid" "branField";
floatSlider -v .9 -min .5 -max 1.5 -cc "floatField -e -v `floatSlider -q -v branSlid` branField" "branSlid";
text "LEAF SCALE FACTOR";
floatField -v 1 -min 0 -max 1 -cc "floatSlider -e -v `floatField -q -v leafScaField` leafScaSlid" "leafScaField";
floatSlider -v 1 -min 0 -max 1 -cc "floatField -e -v `floatSlider -q -v leafScaSlid` leafScaField" "leafScaSlid";
text "LEAF CUTOFF";
intField -v 2 -step 1 -min 1 -max 30 -cc "intSlider -e -v `intField -q -v leafDepField` leafDepSlid" "leafDepField";
intSlider -v 2 -step 1 -min 1 -max 30 -cc "intField -e -v `intSlider -q -v leafDepSlid` leafDepField" "leafDepSlid";
text "RANDOM FACTOR";
floatField -v 1 -min 0 -max 1 -cc "floatSlider -e -v `floatField -q -v ranFacField` ranFacSlid" "ranFacField";
floatSlider -v 1 -min 0 -max 1 -cc "floatField -e -v `floatSlider -q -v ranFacSlid` ranFacField" "ranFacSlid";
text "BRANCHOFF 1";
intField -v 4 -step 1 -min 1 -max 50 -cc "intSlider -e -v `intField -q -v bo1Field` bo1Slid" "bo1Field";
intSlider -v 4 -step 1 -min 1 -max 50 -cc "intField -e -v `intSlider -q -v bo1Slid` bo1Field" "bo1Slid";
text "B1 ROTATE X";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b1RotxField` b1RotxSlid " "b1RotxField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b1RotxSlid` b1RotxField " "b1RotxSlid";
text "B1 ROTATE Y";
floatField -v 180 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b1RotyField` b1RotySlid " "b1RotyField";
floatSlider -v 180 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b1RotySlid` b1RotyField " "b1RotySlid";
text "B1 ROTATE Z";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b1RotzField` b1RotzSlid " "b1RotzField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b1RotzSlid` b1RotzField " "b1RotzSlid";
text "BRANCHOFF 2";
intField -v 4 -step 1 -min 1 -max 50 -cc "intSlider -e -v `intField -q -v bo2Field` bo2Slid" "bo2Field";
intSlider -v 4 -step 1 -min 1 -max 50 -cc "intField -e -v `intSlider -q -v bo2Slid` bo2Field" "bo2Slid";
text "B2 ROTATE X";
floatField -v -45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b2RotxField` b2RotxSlid " "b2RotxField";
floatSlider -v -45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b2RotxSlid` b2RotxField " "b2RotxSlid";
text "B2 ROTATE Y";
floatField -v -45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b2RotyField` b2RotySlid " "b2RotyField";
floatSlider -v -45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b2RotySlid` b2RotyField " "b2RotySlid";
text "B2 ROTATE Z";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b2RotzField` b2RotzSlid " "b2RotzField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b2RotzSlid` b2RotzField " "b2RotzSlid";
text "BRANCHOFF 3";
intField -v 5 -step 1 -min 1 -max 50 -cc "intSlider -e -v `intField -q -v bo3Field` bo3Slid" "bo3Field";
intSlider -v 5 -step 1 -min 1 -max 50 -cc "intField -e -v `intSlider -q -v bo3Slid` bo3Field" "bo3Slid";
text "B3 ROTATE X";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b3RotxField` b3RotxSlid " "b3RotxField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b3RotxSlid` b3RotxField " "b3RotxSlid";
text "B3 ROTATE Y";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b3RotyField` b3RotySlid " "b3RotyField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b3RotySlid` b3RotyField " "b3RotySlid";
text "B3 ROTATE Z";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v b3RotzField` b3RotzSlid " "b3RotzField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v b3RotzSlid` b3RotzField " "b3RotzSlid";
text "LEAF ROTATE X";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v lfRotxField` lfRotxSlid " "lfRotxField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v lfRotxSlid` lfRotxField " "lfRotxSlid";
text "LEAF ROTATE Y";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v lfRotyField` lfRotySlid " "lfRotyField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v lfRotySlid` lfRotyField " "lfRotySlid";
text "LEAF ROTATE X";
floatField -v 45 -step .1 -min -360 -max 360 -cc "floatSlider -e -v `floatField -q -v lfRotzField` lfRotzSlid " "lfRotzField";
floatSlider -v 45 -step .1 -min -360 -max 360 -cc "floatField -e -v `floatSlider -q -v lfRotzSlid` lfRotzField " "lfRotzSlid";
setParent ..;setParent ..;
scrollLayout -horizontalScrollBarThickness 4
-verticalScrollBarThickness 4;
rowColumnLayout -numberOfColumns 2;
text "CURRENT CURVE";textField -tx $curveName "crntCurve";
text "CURRENT LEAF";textField -tx $leafName "crntLeaf";
text "LEAF TEXTURE";textField " ";
text "RENAME NAME";textField "renField";
text "SOFT BODY NAME";textField " ";
text "SPRING SYSTEM NAME";textField " ";
setParent -top;
scrollLayout -horizontalScrollBarThickness 16
-verticalScrollBarThickness 16;
rowColumnLayout -numberOfColumns 1;
button -label "BUILD CURVE" -command "makeCurve";
button -label "CHOOSE CURVE" -command "selcurve";
button -label "BUILD LEAF" -command "makeLeaf";
button -label "CHOOSE LEAF" -command "selLeaf";
button -label "CHOOSE LF TX";
button -label "BUILD TREE" -command "frac";
button -label "FIX SKELETON" -command "skelFix";
button -label "RENAME" -command "renam";
button -label "EXPORT SCRIPT";
button -label "CHOOSE ELEMENT";
button -label "ABOUT" -command "abt";
button -label "RESET" -command "rstscn";
button -label "NEW SCENE" -command "checkBox -e -v 0 gridBox; nwscn;";
button -label "CLOSE" -command "deleteUI $windNam;";
showWindow;
///////////////////////////////////////////////////////////////////////////////
proc makeCurve()
{
global string $curveName;
cylinder -n "sex" -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360 -r (`floatField -q -v diaField`/2) -hr 2 -d 3 -ut 0 -tol 0.01 -s 8 -nsp 10 -ch 1; objectMoveCommand;
select -r sex.u[0] ;
duplicateCurve -ch 0 -rn 0 -local 0 "sex.u[0]";
rename $curveName;
sets -add delKurve;
move -rpr 0 0 0 ;
xform -cp;
FreezeTransformations;
select -r sex;
delete;
}
proc selcurve()
{
string $list[] = `ls -sl`;
string $current = $list[0];
int $size = size ($list);
if ($size <= 0) {warning"NOTHING SELECTED";}
if ($size >= 2) {warning"PLEASE SELECT ONLY ONE CURVE";}
if ($size == 1)
{
textField -e -tx $current crntCurve;
select -cl;select `textField -q -tx crntCurve`;
rename "stack0_level1_branch1_ring1";
sets -add branchSet;
}
}
///////////////////////////////////////////////////////////////////////////////
proc makeLeaf()
{
global string $leafName;
polyCreateFacet -ch on -tx 1 -s 1 -p 0 0 0 -p -1 0 -1
-p -1 0 -3 -p 0 0 -4 -p 1 0 -3 -p 1 0 -1 ;
rename $leafName;
sets -add leafSet;
}
proc selLeaf()
{
string $list[] = `ls -sl`;
string $temp = $list[0];
int $size = size ($list);
if ($size <= 0) {warning"NOTHING SELECTED";}
if ($size >= 2) {warning"PLEASE SELECT ONLY ONE OBJECT";}
if ($size == 1)
{
textField -e -tx $temp crntLeaf;
}
}
///////////////////////////////////////////////////////////////////////////////
//TREE/LEVEL/BRANCH/RING
proc makeTree (int $level,int $branch,float $angleX,float $angleY,float $angleZ)
{
int $depth = `intField -q -v depthField`;
int $stackHeight = `intField -q -v stNumField`;
global int $branchOffPoint;
global int $ntree;
global int $branchIndex;
global int $stackNum;
global int $loftState;
global int $boneState;
global int $leafState;
global int $leafCount;
global string $barkName;
global string $jointName;
global string $splineName;
global string $lastCurve;
string $list[] = `ls -sl`;
string $current = $list[0];
float $jointPos[3];
string $jointRoot;
string $splineRoot;
global string $name;
if ($level > $depth) {return;}
if ($branch > 1)
{
select $name;
duplicate;
$name = "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring1";
rename ($name);
rotate -r -os 0 ($angleY) 0;
rotate -r -os ($angleX) 0 0;
rotate -r -os 0 0 ($angleZ);
}
select $name;
for ($a=1;$a<$stackHeight;$a++)
{
xform -cp;
duplicate;
rename $name;
scale -r `floatField -q -v branField` `floatField -q -v branField` `floatField -q -v branField`;
move -r -os 0 `floatField -q -v stackField` 0;
}
select -cl;
//THIS IS WHERE I RESET FOR SCALING
$leafCount = 1;
for ($a=$stackHeight;$a>`intField -q -v leafDepField`;$a--)
{
//if ($a < `intField -q -v leafDepField`)
// {
$name = "stack" + $stackNum + "_level" +$level + "_branch" + $branch + "_ring" + $a;
if ($leafState ==1) {putLeaf;}
// }
}
for ($a=1;$a<=$stackHeight;$a++)
{
$name = "stack" + $stackNum + "_level" +$level + "_branch" + $branch + "_ring" + $a;
select -add $name;
}
if ($loftState ==1)
{
loft -ch 0 -n ($barkName + "level" +$level + "_branch" + $branch);
sets -add branchSet;
select -cl;
}
$branchIndex++;
// jointRoot is local, jointName is global
// we set jointRoot to the current name before we change it
// so that it will contain the previous joint
$jointRoot = $jointName;
int $curRing = 0;
if ($level == $depth) // if at the end
{
$curRing = `intField -q -v stNumField`;
}
else // not at the end
{
$branchOffPoint = `intField -q -v bo1Field`;
$curRing = $branchOffPoint;
}
$name = "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $curRing;
$jointPos = `xform -q -ws -t $name`;
$jointName = "skel1" + "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $curRing;
select -cl;
if ($boneState ==1) {joint -p $jointPos[0] $jointPos[1] $jointPos[2] -n $jointName;parent $jointName $jointRoot;}
if ($level != $depth) // if not at the end
{
// sets up jointRoot for parenting after the recursive call.
// we don't want to do this if it's the last one
$jointRoot = $jointName;
}
// ***** recursive call #1 *****
makeTree ($level +1,$branchIndex,`floatField -q -v b1RotxField`,
`floatField -q -v b1RotyField`,`floatField -q -v b1RotzField`);
if (($level != $depth))
{
$branchOffPoint = `intField -q -v bo2Field`;
$name = "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointName = "skel1" + "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointPos = `xform -q -ws -t $name`;
if (`intField -q -v bo1Field` != `intField -q -v bo2Field`) // same branchpoint at 1 and 2
{
select -cl;
if ($boneState ==1)
{
joint -p $jointPos[0] $jointPos[1] $jointPos[2] -n $jointName;
parent $jointName $jointRoot;
}
$jointRoot = $jointName;
} // END if (`intField...
} // END if (($level != $depth))
// ***** recursive call #2 *****
makeTree ($level +1,$branchIndex,`floatField -q -v b2RotxField`,
`floatField -q -v b2RotyField`,`floatField -q -v b2RotzField`);
if ($level != $depth)
{
$branchOffPoint = `intField -q -v bo3Field`;
$name = "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointName = "skel1" + "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointPos = `xform -q -ws -t $name`;
if (`intField -q -v bo2Field` != `intField -q -v bo3Field`) // same branchpoint at 2 and 3
{
select -cl;
if ($boneState ==1)
{
joint -p $jointPos[0] $jointPos[1] $jointPos[2] -n $jointName;
parent $jointName $jointRoot;
}
$jointRoot = $jointName;
} // END if (`intField...
} // END if (($level != $depth))
// ***** recursive call #3 *****
makeTree ($level +1,$branchIndex,`floatField -q -v b3RotxField`,
`floatField -q -v b3RotyField`,`floatField -q -v b3RotzField`);
if ($level != $depth)
{
$branchOffPoint = `intField -q -v stNumField`;
$name = "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointName = "skel1" + "stack" + $stackNum + "_level" + $level + "_branch" + $branch + "_ring" + $branchOffPoint;
$jointPos = `xform -q -ws -t $name`;
select -cl;
if ($boneState ==1)
{
joint -p $jointPos[0] $jointPos[1] $jointPos[2] -n $jointName;
parent $jointName $jointRoot;
}
$jointRoot = $jointName;
} // END if (($level != $depth))
} // END proc makeTree()
proc frac ()
{
global string $name;
global int $boneState;
global int $stackNum;
global int $branchIndex;
global string $jointName;
global string $curveName;
global int $branchIndex = 1;
global int $branchOffPoint;
string $locName = "stack" + $stackNum + "_level1_branch1_ring";
float $jointPos[3];
int $a =0;
select -cl;
for ($a=1;$a<(`intField -q -v stckNumField` +1);$a++)
{
$name = "stack" + $stackNum + "_level1_branch1_ring1";
if ($boneState == 1)
{
$jointPos = `xform -q -ws -t $name`;
$jointName = "skel1" + $name;
select -cl;
joint -p $jointPos[0] $jointPos[1] $jointPos[2] -n $jointName;
}
$branchOffPoint = `intField -q -v bo1Field`;
string $locName = "stack" + $stackNum + "_level1_branch1_ring";
makeTree (1,1,1,1,1);
select ($locName + `intField -q -v stNumField`);
$stackNum++;
rename ("stack" + $stackNum + "_level1_branch1_ring1");
}
cleanUp;
}

