/* ------------------------------------------------------------------------------------- \\\\\\\\_______________________fluidsToBlendShapes_v.1_______________________//////// //////// \\\\\\\\ ------------------------------------------------------------------------------------- > Written by dimitris gourdoukis. 2009. ------------------------------------------------------------------------------------- > http://object-e.net/ > object.e.architecture@gmail.com ------------------------------------------------------------------------------------- > released under the creative commons license "share alike unported 3.0" > http://creativecommons.org/licenses/by-sa/3.0/ ------------------------------------------------------------------------------------- >>UPDATES: > SKG in Flux version 1: 13.12.2009 first version. > SKG in Flux version 2: 15.12.2009 added a UI Last Modified 15/12/09. Tested on Maya 2009. > Use and modify at your own risk. ------------------------------------------------------------------------------------- */ //BEFORE running the script do: //1. create an object to use a seed and name it theSeed //2. dublicate theSeed up to 10 times and transform the dublicates at will. name // the new objects theTarget1, theTarget2 etc. //3. create as many fluids as the target objects and name them fluidMap1, // fluidMap2 etc. //3a add to the fluid emitter(s) fields etc. this can be done/edited also after you // run the script. //4. RUN the script. //in the generated UI //5. enter the # of rows, # of clms, x step and y step values. those numbers have to // be less or equal to the resolution of the fluid (equal for better results). //6. enter the # of blendShapes value. It HAS to be equal to the number of // target objects and the number of fluid containers. //7. hit 'create field'. //8. the blendShape value of each created object is connected with an expression with // the density of the respective grid cell of the fluid. //----------------------------------------------------------------------------------- proc blendFieldFlu (){ //specify the number of rows int $nRows = `intSliderGrp -q -v numRows`; //specify the number of columns int $nCols = `intSliderGrp -q -v numClms`; //specify the number of fluids int $bSh = `intSliderGrp -q -v numBlen`; //specify the grid step for x and y float $x = `floatSliderGrp -q -v xStep`; float $y = `floatSliderGrp -q -v yStep`; for ($i=0; $i<$nRows; $i++){ for ($j=0; $j<$nCols; $j++){ //select theSeed, duplicate it and move it to its new position select -cl; select -r theSeed; string $newName; $newName = "myDupl" + $i + "_" + $j; duplicate -rr -name $newName; move ($x*$i) ($y*$j) 0; //create name for the blendshape string $blendName = "blendShape" +$i + "_" + $j; //create the blendshape blendShape -name $blendName theTarget1 $newName; //add extra blendShapes for ($n=1; $n<$bSh; $n++){ string $tarN = "theTarget" + ($n+1); blendShape -edit -t $newName ($n+1) $tarN 1.0 $blendName; } for ($m=0; $m<$bSh; $m++){ //create names for the expression and the fluids string $expresName = "expression" + $i + "_" + $j + "_" + $m; string $fluidName = "fluidMap" + ($m+1); //create the expression connecting the density of the fluid to the blendshape value expression -o $blendName -s ("float $g[] = `getFluidAttr -at \"density\" -xi " + $i + " -yi " + $j + " " + $fluidName + "`; \n theTarget" + ($m+1) + " = $g[0];") -n $expresName; } } } } global proc constructFBlendWin () { if (`window -exists fBlendWindow`) { deleteUI fBlendWindow; } window -width 400 -height 250 -title "fluidsToBlendShapes_v.1" -sizeable true fBlendWindow; columnLayout; text -l ""; intSliderGrp -label "# of rows(x)" -field true -fieldStep 1 -sliderStep 1 -value 3 -fieldMinValue 2 -fieldMaxValue 100 numRows; intSliderGrp -label "# of clms(y)" -field true -fieldStep 1 -sliderStep 1 -value 3 -fieldMinValue 2 -fieldMaxValue 100 numClms; intSliderGrp -label "# of blendShapes" -field true -fieldStep 1 -sliderStep 1 -value 3 -fieldMinValue 2 -fieldMaxValue 10 numBlen; floatSliderGrp -label "x step" -field true -fieldStep 0.1 -sliderStep 0.1 -value 1 -fieldMinValue 0 -fieldMaxValue 100 xStep; floatSliderGrp -label "y step" -field true -fieldStep 0.1 -sliderStep 0.1 -value 1 -fieldMinValue 0 -fieldMaxValue 100 yStep; //create button button -label "Create Field" -command "blendFieldFlu" buildIt; setParent ..; //break columnLayout; text -l ""; separator -w 800 -h 4 -backgroundColor 1 0.663 1; text -l "http://object-e.net"; text -l "dimitris gourdoukis. 2009."; showWindow; } constructFBlendWin;