/********************************************\ migSurfaceGraph ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ Version 1.0 Author Mika Göös Updated 22.09.2005 Documentation at http://migugi.net/mel/surfaceGraph/ \********************************************/ global proc migSurfaceGraph() { // if(`windowPref -exists surfaceWindow`) // windowPref -remove surfaceWindow; if(`window -exists surfaceWindow`) { deleteUI -window surfaceWindow; } int $animationEnabled = `objExists "SurfaceGraphJob"`; window -title "Input the Surface Function" -sizeable false -wh 298 180 surfaceWindow; columnLayout; separator -h 2 -st "none"; scrollField -w 290 -h 63 -ww true -fn "smallPlainLabelFont" migScriptInput; separator -h 2 -st "none"; progressBar -w 290 -h 20 -pr 0 -max 1000 prBar; separator -h 5 -st "none"; columnLayout -co "left" 50; checkBox -w 290 -al "left" -l "Evaluate when Rendering Animation" -value $animationEnabled -onCommand "migSurfaceGraphEnableAnimation" -offCommand "migSurfaceGraphDisableAnimation"; setParent ..; separator -h 5 -st "none"; frameLayout -w 290 -h 40 -lv false -mw 3 -mh 7 -bs "in" -bgc 0.0 0.06 0.1; rowColumnLayout -numberOfColumns 3 -bgc 0.0 0.06 0.1 -w 200 -cw 1 80 -cs 1 10 -cal 1 "center" -cw 2 80 -cs 2 10 -cal 2 "center" -cw 3 80 -cs 3 10 -cal 3 "center"; button -l "Generate" -c "migSurfaceGraphGenerateSelected"; button -l "Load" -c "migSurfaceGraphLoad"; button -l "Close" -c "deleteUI -window surfaceWindow"; showWindow surfaceWindow; } global proc migSurfaceGraphGenerateAll() { string $time = `currentTime -q`; string $geometry[] = `ls -g`; string $Ps[] = `filterExpand -sm 12 $geometry`; for($P in $Ps) if( attributeExists("GraphAnimate", $P) && `getAttr ($P+".graphAnim")` && attributeExists("GraphFunction", $P) ) { string $input = `getAttr ($P+".graphFunc")`; print ("Generating "+$P+"... "); migSurfaceGraphGenerate($P, $input, $time); print "Done\n"; } } global proc migSurfaceGraphGenerateSelected() { string $Ps[] = `filterExpand -sm 12`; if(size($Ps) != 1) error "Please select one poly object!"; string $Poly = $Ps[0]; string $input = `scrollField -q -text migScriptInput`; if(strip($input) == "") $input = "0"; string $time = `currentTime -q`; if( !attributeExists("GraphAnimate", $Poly) ) addAttr -ln "GraphAnimate" -sn "graphAnim" -at bool -dv 1 -k true -h false $Poly; if( !attributeExists("GraphFunction", $Poly) ) addAttr -ln "GraphFunction" -sn "graphFunc" -dt "string" $Poly; setAttr -type "string" ($Poly+".graphFunc") $input; migSurfaceGraphGenerate($Poly, $input, $time); } // Helper functions // proc float migDistance(float $x, float $y) { return sqrt($x*$x + $y*$y); } proc float migMAX(float $x, float $y) { return $x>$y ? $x:$y; } proc float migMIN(float $x, float $y) { return $x<$y ? $x:$y; } proc string migSubstitute(string $s, string $regexp, string $replace) { string $old; do {$old=$s; $s=`substitute $regexp $s $replace`; } while($old != $s); return $s; } global proc migSurfaceGraphGenerate(string $Poly, string $input, string $time) { /* VARIABLES: x y d fii t CONSTANTS: e pi FUNCTIONS: sqrt sin cos tan asin atan acos min max abs pow log */ $input = substituteAllString($input, "\n", ""); $input = substituteAllString($input, "/", "*1.0/"); $input = substituteAllString($input, "e", `exp(1)`); $input = migSubstitute($input, "pi", 3.1415927); $input = migSubstitute($input, "max", "migMAX"); $input = migSubstitute($input, "min", "migMIN"); $input = migSubstitute($input, "tan", "TAN"); $input = migSubstitute($input, "sqrt", "SQRT"); $input = substituteAllString($input, "t", "("+$time+")"); $input = migSubstitute($input, "TAN", "tan"); $input = migSubstitute($input, "SQRT", "sqrt"); int $i; int $NumVs[] = `polyEvaluate -v $Poly`; for($i=0; $i<$NumVs[0]; $i++) { string $V = ($Poly+".vtx["+$i+"]"); vector $pos = `xform -q -t $V`; float $angle = `angle <<$pos.x, $pos.z, 0>> <<1, 0, 0>>`; if($pos.z < 0) $angle *= -1; float $distance = migDistance($pos.x, $pos.z); string $cmd = $input; $cmd = substituteAllString($cmd, "y", "("+($pos.z)+")"); $cmd = substituteAllString($cmd, "x", "("+($pos.x)+")"); $cmd = substituteAllString($cmd, "d", ""+$distance); $cmd = migSubstitute($cmd, "fii", "("+$angle+")"); float $z = eval ( "float $tmp = "+$cmd ); xform -t ($pos.x) $z ($pos.z) $V; if($i % 200 == 0 && `window -exists surfaceWindow`) { int $pr = $i*1000/$NumVs[0]; progressBar -e -pr $pr prBar; } } if(`window -exists surfaceWindow`) progressBar -e -pr 0 prBar; } global proc migSurfaceGraphEnableAnimation() { if(!`objExists "SurfaceGraphJob"`) { scriptNode -st 5 -n "SurfaceGraphJob" -bs "source migSurfaceGraph; migSurfaceGraphGenerateAll"; print "Animation enabled\n"; } } global proc migSurfaceGraphDisableAnimation() { if(`objExists "SurfaceGraphJob"`) { delete "SurfaceGraphJob"; print "Animation disabled\n"; } } global proc migSurfaceGraphLoad() { string $Ps[] = `filterExpand -sm 12`; if(size($Ps) != 1) error "Please select one poly object to load the function from!"; if( !attributeExists("GraphFunction", $Ps[0]) ) error "No function found from the selected object!"; string $function = `getAttr ($Ps[0]+".graphFunc")`; scrollField -e -text $function migScriptInput; }