//////////////////////////////////////////////////////////////////////////////////// // Script: mmCurveDistribute 1.0 // // Description: distributes a number of instances of an objects along a curve.// // Useful to create all kinds of chains or treads. // // Author: Manuel Macha | www.manuelmacha.de |manuel@manuelmacha.de // //////////////////////////////////////////////////////////////////////////////////// //****************************************************************************** global proc mmInstanceAlongCurve() { string $motionPath; currentTime 1; string $group = `group -empty -name "instancedObjects"`; addAttr -ln objScale -at double -dv 1 $group; setAttr -e -keyable true ($group + ".objScale"); connectControl objScaleFloatSlider ($group + ".objScale") ; string $curve = `textField -q -text curveTextField`; string $object = `textField -q -text objectTextField`; int $noOfInstances = `intField -q -value noInstancesIntField`; float $instances = `intField -q -value noInstancesIntField`; float $spacing = 1 / $instances; int $worldUpTypeId = `optionMenuGrp -query -select worldUpTypeOptionMenuGrp`; string $worldTypeObjectUp = `textFieldButtonGrp -query -text objectUpTextFieldGrp`; for ($i = 1; $i < $noOfInstances + 1; $i++) { string $null = `group -empty -name ("null" + $i)`; string $newInstance[] = `instance $object`; parent $newInstance[0] $null; connectAttr -f ($group + ".objScale") ($null + ".scaleX"); connectAttr -f ($group + ".objScale") ($null + ".scaleY"); connectAttr -f ($group + ".objScale") ($null + ".scaleZ"); if ($worldUpTypeId == 2 || $worldUpTypeId == 3) { $motionPath = `pathAnimation -fractionMode true -follow true -followAxis x -upAxis y -worldUpType ($worldUpTypeId - 1) -worldUpVector 1 0 0 -inverseUp false -inverseFront false -worldUpObject $worldTypeObjectUp -bank false -startTimeU 1 -endTimeU 1 $curve $null`; } else { $motionPath = `pathAnimation -fractionMode true -follow true -followAxis x -upAxis y -worldUpType ($worldUpTypeId - 1) -worldUpVector 1 0 0 -inverseUp false -inverseFront false -bank false -startTimeU 1 -endTimeU 1 $curve $null`; } setAttr ($motionPath + ".uValue") ($spacing * $i); parent $null $group; } } //******************************************************* global proc mmSelectCurve() { string $objInSel[] = `ls -sl`; select -r $objInSel[0]; string $selNode[] = `pickWalk -d down`; select -r $objInSel[0]; if (`nodeType $selNode[0]` == "nurbsCurve") { textField -edit -text $selNode[0] curveTextField; } else { print "\\\\Error: Please select a nurbsCurve"; } } //******************************************************* global proc mmSelectObject() { string $objInSel[] = `ls -sl`; textField -edit -text $objInSel[0] objectTextField; } //******************************************************* global proc mmSelectWorldUpObject() { string $objInSel[] = `ls -sl`; textFieldButtonGrp -edit -text $objInSel[0] objectUpTextFieldGrp; } //******************************************************* global proc mmDistributeCurve() { if (`window -exists "mmCurveInstanceUI"`) { deleteUI mmCurveInstanceUI; } else { int $width = 265; int $height = 350; window -width $width -height $height mmCurveInstanceUI; columnLayout -width $width mmCurveInstanceUIcolumnLayout; text -label "select the curve:"; textField -width $width -text "" curveTextField; button -width $width -label "select" -command mmSelectCurve; separator -width $width; optionMenuGrp -width $width -columnWidth2 (ceil($width * 0.35)) (ceil($width * 0.65)) -label "World Up Type" worldUpTypeOptionMenuGrp; menuItem -label "Scene Up" ; menuItem -label "Object Up" ; menuItem -label "Object Rotation Up" ; menuItem -label "Vector" ; menuItem -label "Normal" ; setParent ..; textFieldButtonGrp -width $width -columnAlign3 "left" "left" "left" -columnWidth3 (ceil($width * 0.35)) (ceil($width * 0.5)) (ceil($width * 0.15)) -label "World Up Object" -buttonLabel "Select" -buttonCommand mmSelectWorldUpObject -text "" objectUpTextFieldGrp; separator -width $width; text -label "select object to instance along curve:"; textField -width $width -text "" objectTextField; button -width $width -label "select" -command mmSelectObject; separator -width $width; text -label "number of instances:"; intField -width $width -minValue 1 -value 10 noInstancesIntField; button -width $width -label "Instance " -command mmInstanceAlongCurve; separator -width $width; text -label "objectScale:"; floatSlider -width $width -minValue -10 -maxValue 10 -value 1 objScaleFloatSlider; separator -width $width; button -width $width -height 18 -align "left" -label "mmCurveDistribute v1.0 - help and tutorial -> www.manuelmacha.de/scripts" -annotation "mmCurveDistribute v1.0 - help and tutorial -> www.manuelmacha.de/scripts" -command "system(\"load http://www.manuelmacha.de/scripts.html\")"; showWindow mmCurveInstanceUI; window -edit -width ($width + 9) -height $height mmCurveInstanceUI; } } mmDistributeCurve;