/* ------------------------------------------------------------------------------------- \\\\\\\\___________________blendShapeFieldWithAttractors_v1__________________//////// //////// \\\\\\\\ ------------------------------------------------------------------------------------- > 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: 14.12.2009: added a UI > XXL version: 19.5.2011: added a 3rd dimention (z) to the array. > Last modified on 19.5.2011. Tested on Maya 2011. > 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 space locators as the target objects and name them attractor1, // attractor2 etc. //4. RUN the script. //in the generated UI //5. enter the # of rows, # of clms, x step and y step values. //6. enter the # of blendShapes value. It HAS to be equal to the number of // target objects. //7. hit 'create field'. //8. select each locator. in the attribute editor adjust the range values. //----------------------------------------------------------------------------------- proc blendField (){ //specify the number of rows int $nRows = `intSliderGrp -q -v numRows`; //specify the number of columns int $nCols = `intSliderGrp -q -v numClms`; int $nLev = `intSliderGrp -q -v numLvs`; //specify the number of blendShapes 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`; float $z = `floatSliderGrp -q -v zStep`; //add a range attribute to the locators for ($k=0; $k<$bSh; $k++){ string $locName = "attractor" + ($k+1); select -r $locName; addAttr -shortName rn -longName range -defaultValue 10.0 -minValue 0.001 -maxValue 200; } for ($i=0; $i<$nRows; $i++){ for ($j=0; $j<$nCols; $j++){ for ($k=0; $k<$nLev; $k++){ //select theSeed, duplicate it and move it to its new position select -cl; select -r theSeed; string $newName; $newName = "myDupl" + $i + "_" +$j +"_" +$k; duplicate -rr -name $newName; move ($x*$i) ($y*$j) ($z*$k); //create name for the blendshape string $blendName = "blendShape" +$i + "_" + $j + "_" + $k; //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 distance, the name, and the attractors string $distanceName = "distance" + $i + "_" + $j + "_" + $k + "_" + $m; string $expresName = "expression" + $i + "_" + $j + "_" + $k + "_" + $m; string $attracName = "attractor" + ($m+1); //create the distanceNode createNode distanceBetween -n $distanceName; //connect the attractors and the new objects to the 2 points of the 2 distance nodes eval ("connectAttr -f " + $attracName + ".translate " + $distanceName + ".point1"); eval ("connectAttr -f " + $newName + ".translate " + $distanceName + ".point2"); //create the expression connecting the distance to the blendshape value expression -o $blendName -s ("theTarget" + ($m+1) + " = clamp(0,1,1-" + $distanceName + ".distance/" + $attracName + ".range)") -n $expresName; } } } } } global proc constructblendWin () { if (`window -exists blendWindow`) { deleteUI blendWindow; } window -width 400 -height 300 -title "blendShapeFieldWithAttractors_v1" -sizeable true blendWindow; 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 clms(z)" -field true -fieldStep 1 -sliderStep 1 -value 3 -fieldMinValue 2 -fieldMaxValue 100 numLvs; 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; floatSliderGrp -label "z step" -field true -fieldStep 0.1 -sliderStep 0.1 -value 1 -fieldMinValue 0 -fieldMaxValue 100 zStep; //create button button -label "Create Field" -command "blendField" 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; } constructblendWin;