Extract Vectors from Fluid
back to Proxy.wiki Revision 1.0
For Maya 8.5 - paste below into script editor. Make sure that it has not added "Pasted from proxyarch.com/wiki" to bottom. Highlight the pasted script and press ctrl-enter with your fluid container selected.
/*------------------------------------
extractVectorsFromFluid();
For Maya 8.5
Produces vector lines of fluid force
Prompts for a scaling factor
Written by Mark Collins 2007
-------------------------------------*/
global proc extractVectorsFromFluid(){
string $text;
string $result = `promptDialog
-title "Extract Vectors from Fluid"
-message "Scale of Vector Lines"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
if ($result == "OK") {
$text = `promptDialog -query -text`; }
float $scale = float($text);
string $fluid[] = `ls -sl`;
string $shape[] = `listRelatives`;
if(`gmatch $shape[0] "*hape*"` == 1){
float $sizes[] = `getAttr ($shape[0]+".resolution")`;
for($i=0;$i<$sizes[0];$i++){
for($j=0;$j<$sizes[1];$j++){
for($k=0;$k<$sizes[2];$k++){
float $v[] = `getFluidAttr -at "velocity" -xi $i -yi $j -zi $k $fluid[0]`;
float $p[] = `fluidVoxelInfo -xi $i -yi $j -zi $k -vc $fluid[0]`;
float $perp[] = { ($v[1]*-1), $v[0], 0};
curve -d 1 -p $p[0] $p[1] $p[2]
-p ($p[0]+$v[0]*$scale) ($p[1]+$v[1]*$scale) ($p[2]+$v[2]*$scale)
-n "vectorCurve1" ; //MAIN CURVE
curve -d 1 -p ($p[0]+$v[0]*$scale) ($p[1]+$v[1]*$scale) ($p[2]+$v[2]*$scale)
-p ($p[0]+$v[0]*$scale+$v[0]*$scale*-.25+$perp[0]*-.025)
($p[1]+$v[1]*$scale+$v[1]*$scale*-.25+$perp[1]*-.025)
($p[2]+$v[2]*$scale+$v[2]*$scale*-.25+$perp[2]*-.025)
-n "vectorCurve1"; //FIRST ARM
curve -d 1 -p ($p[0]+$v[0]*$scale) ($p[1]+$v[1]*$scale) ($p[2]+$v[2]*$scale)
-p ($p[0]+$v[0]*$scale+$v[0]*$scale*-.25+$perp[0]*.025)
($p[1]+$v[1]*$scale+$v[1]*$scale*-.25+$perp[1]*.025)
($p[2]+$v[2]*$scale+$v[2]*$scale*-.25+$perp[2]*.025)
-n "vectorCurve1"; //FIRST ARM
}}}
}
else{
print ("[ERROR] Does not appear to be a valid fluid. Select a fluid first!\n");
}
}
extractVectorsFromFluid();