/*=========================================================== Curve Animation v0.5 By Yi-Ming Chu =============================================================*/ ///////////////////////////////////// // main window ///////////////////////////////////// string $windowMain; //declare main window string $groupVar[]; //componment tags for storing L-system variables clear $groupVar; string $switch; if (`window -exists $windowMain`) { deleteUI $windowMain; } $windowMain = `window -title "Sprial Space Curves Creator" -iconName "Sprial Curves" -minimizeButton true -width 400 -height 300 -titleBar true -sizeable true`; columnLayout -h 300 -adjustableColumn true; // image -height 50 -width 400 // -image ((`internalVar -userBitmapsDir`) + "/curvecreator.jpg") // -annotation "Sprial Space Curves Creator"; rowLayout -numberOfColumns 3 -columnWidth 1 200 -columnAttach3 "both" "both" "both" -columnAlign2 "left" "center" "center"; text -label "Spiral Space Curve Creator" -fn "boldLabelFont" -align "center"; button -label "Reset Tool" -command ("resetVar($groupVar, $switch)"); //button -label "Tool Help" -command ("showHelpWin"); setParent ..; separator -height 10 -style "in"; columnLayout -adjustableColumn true; frameLayout -label "Variables for Curves" -labelAlign "top" -borderStyle "etchedIn"; columnLayout -columnWidth 400; $groupVar[0] = `intSliderGrp -label "Number of Curves" -field true -min 1 -max 10 -fieldMinValue 1 -fieldMaxValue 100 -step 1 -value 3`; $groupVar[1] = `intSliderGrp -label "Segment of A Curve" -field true -min 1 -max 10 -fieldMinValue 1 -fieldMaxValue 100 -value 100`; $groupVar[2] = `floatSliderGrp -label "Width of Root" -field true -min 0.0 -max 2.0 -fieldMinValue 0.0 -fieldMaxValue 10 -value 0.1`; setParent ..; setParent ..; $switch = `checkBoxGrp -numberOfCheckBoxes 2 -label "Animation Switch" -labelArray2 "Apply RenerMan curve" "Animate curves"`; separator -height 10 -style "in"; setParent ..; $windowMainWidth = `window -q -w $windowMain`; rowLayout -numberOfColumns 3 -columnWidth3 ($windowMainWidth/3) ($windowMainWidth/3) ($windowMainWidth/3) -columnAttach3 "both" "both" "both" -columnAlign3 "center" "center" "center"; button -label "Create" -command ("getVariable($groupVar, $switch); deleteUI -window " + $windowMain); button -label "Apply" -command ("getVariable($groupVar, $switch)"); button -label "Close" -command ("deleteUI -window " + $windowMain); showWindow $windowMain; ////////////////////////////////////////// // Reset Variables ////////////////////////////////////////// global proc resetVar(string $groupVar[], string $switch) { intSliderGrp -edit -value 3 $groupVar[0]; intSliderGrp -edit -value 100 $groupVar[1]; floatSliderGrp -edit -value 0.1 $groupVar[2]; checkBoxGrp -edit -valueArray2 0 0 $switch; } ////////////////////////////////////////// /// Read the values from the controlors /// then make a test. ////////////////////////////////////////// global proc getVariable(string $groupVar[], string $switch) { //declare variables int $tenNum; //total number of curves int $segNum; //segment of a single curve float $rRoot; //width value for Renderman curve and spiral int $switchRM; //switch for apply PRMAN curve int $switchAnime; //switch for apply animation $tenNum = `intSliderGrp -q -value $groupVar[0]`; $segNum = `intSliderGrp -q -value $groupVar[1]`; $rRoot = `floatSliderGrp -q -value $groupVar[2]`; $switchRM = `checkBoxGrp -q -value1 $switch`; $switchAnime = `checkBoxGrp -q -value2 $switch`; select -all; delete; //=====Interpret the main tree structure spaceCurve($tenNum, $segNum, $rRoot, $switchRM, $switchAnime); } ///////////////////////////////////// // main function ///////////////////////////////////// global proc spaceCurve(int $tenNum, int $segNum, float $rRoot, int $switchRM, int $switchAnime) { string $oring = "curve -d 3 -p 0 0 0 "; string $mcurve = ""; for ($j = 1; $j <= $tenNum; $j++){ for ($i = 1; $i <= $segNum; $i++){ $mcurve += " -p " + (sin($i+90)/$i) + " " + (cos($i+90)/$i) + " " + (-$rRoot*$i/100); } eval($oring + $mcurve); //attach Renderman curves if ($switchRM == 1) { addAttr -ln basewidth -at double -dv $rRoot ("|curve" + $j); setAttr -e -keyable true ("|curve" + $j + ".basewidth"); addAttr -ln topwidth -at double -dv ($rRoot/100) ("|curve" + $j); setAttr -e -keyable true ("|curve" + $j + ".topwidth"); MtorApplyCurves; } $mcurve = ""; } //set keyfram on cvs of curves if ($switchAnime == 1) { for ($j = 1; $j <= $tenNum; $j++) { currentTime 0; setKeyframe ({"curve" + ($tenNum-$j+1) + ".cv[0:" + $segNum + "]"}); for($i = 1; $i < $segNum; $i++) { select -r ("curve" + ($tenNum-$j+1) + ".cv[" + $i + ":"+ $segNum + "]"); currentTime ($i*$j*0.1); rotate -r 0 0 10; move -r -moveX (log($i)/($i*$j)) -moveY (0.01) -moveZ 0; scale -r 1.1 1.1 1.1; setKeyframe ({"curve" + ($tenNum-$j+1) + ".cv[" + $i +":"+ $segNum + "]"}); } select -r ("curve"+$j); move -r 0.1 (0.1) 0; } } else if ($switchAnime == 0) { for ($j = 1; $j <= $tenNum; $j++) { for($i = 1; $i < $segNum; $i++) { select -r ("curve" + ($tenNum-$j+1) + ".cv[" + $i + ":"+ $segNum + "]"); rotate -r 0 0 10; move -r -moveX (log($i)/($i*$j)) -moveY (0.01) -moveZ 0; scale -r 1.1 1.1 1.1; } select -r ("curve"+$j); move -r 0.1 (0.1) 0; } } }