-
-
Save jaidetree/2840060 to your computer and use it in GitHub Desktop.
Kory Dondzila's Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdAutoRigV0.1.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: This is a prototype script. It allows the /// | |
/// user to rig the spine and neck of a character. /// | |
/// The script generates the locators for the user /// | |
/// to place where they want the joints. /// | |
/// /// | |
/// USAGE: Source script then run: autoRigUI(); /// | |
/// /// | |
/// EDITS TO DO: Parts of neck rig not working properly. /// | |
/// /// | |
/// THINGS TO ADD: Procedures to rig; legs, arms, and hands. /// | |
/// /// | |
/// VERSIONS: 0.1 - Oct 26, 2011 - Initial Prototype /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
////////////////////// Procedure: neck ///////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure rigs the neck for the character. // | |
// Creating all the joints, controls and attribute // | |
// connections. // | |
proc neck( string $charTxt, string $neckButton ) | |
{ | |
// Disables the neck button and queries the character name. | |
button -e -en 0 $neckButton; | |
string $charName = `textFieldButtonGrp -q -tx $charTxt`; | |
// Setting up initial variables. | |
string $selJnt[]; | |
string $locators[] = { "neck", "head" }; | |
vector $neckLoc = `getAttr neck_loc.t`; // Gets the new positions of the neck and head locators. | |
vector $headLoc = `getAttr head_loc.t`; | |
string $bindSet = "skinBind_jnts"; | |
string $attrs[] = { ".tx", ".ty", ".tz", ".rx", ".ry", ".rz", ".sx", ".sy", ".sz", ".v" }; | |
string $neckCtrl[]; | |
string $headCtrl; | |
string $bindJnt[]; | |
string $dup[]; | |
string $headWSGrp[]; | |
string $headNSGrp[]; | |
string $headBSGrp[]; | |
string $headTSGrp[]; | |
// Creates neck control joints. | |
$neckCtrl[ 0 ] = `joint -p ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ) -n ( "neck_ctrl" ) -rad 0.5`; | |
$neckCtrl[ 1 ] = `joint -p ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) -n ( "neck_ctrl_end_jnt" ) -rad 0.5`; | |
// Creates the main joints for the neck. | |
select -cl; | |
$selJnt[ 0 ] = `joint -p ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ) -n ( "neck_1_jnt" ) -rad 0.5`; | |
$selJnt[ 1 ] = `joint -p ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) -n ( "neck_end_jnt" ) -rad 0.5`; | |
// Creates the the joints to straighten the neck. | |
select -cl; | |
$bindJnt[ 0 ] = `joint -p ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ) -n ( "neck_curve_base_strait_jnt" ) -rad 0.5`; | |
select -cl; | |
$bindJnt[ 1 ] = `joint -p ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) -n ( "neck_curve_end_strait_jnt" ) -rad 0.5`; | |
// Adds the joints to the select set. | |
sets -e -add $bindSet $bindJnt; | |
// Gets the positions of the neck and head joint. | |
vector $sjPos = ( `joint -q -p $selJnt[ 0 ]` ); | |
vector $ejPos = ( `joint -q -p $selJnt[ 1 ]` ); | |
string $crJnt[]; | |
float $radius = ( `getAttr ( $selJnt[ 0 ] + ".radius" )` ); | |
// Input an integer for the TOTAL number of segments you need, for $seg. | |
int $seg = 3; | |
select -cl; | |
// For loop creates joints in the proper position | |
// and assigns them to an array and parents the first created joint | |
// to the start joint and parents the end joint to the last created joint. | |
for ( $i = $seg; $i > 1; $i-- ) | |
{ | |
int $x = abs ( $i - $seg ); | |
$crJnt[ $x ] = `joint -p ( ( ( ( ( $sjPos.x ) - ( $ejPos.x ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.x ) ) | |
( ( ( ( ( $sjPos.y ) - ( $ejPos.y ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.y ) ) | |
( ( ( ( ( $sjPos.z ) - ( $ejPos.z ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.z ) ) -n ( "neck_" + ( $x + 2 ) + "_jnt" ) -rad $radius`; | |
if ( $x == 0 ) | |
{ | |
// Duplicates the first joint up from the neck. | |
// To be used to straighten the neck. | |
$dup = `duplicate $crJnt[ $x ]`; | |
$bindJnt[ 2 ] = `rename $dup[ 0 ] "neck_curve_mid_strait_jnt"`; | |
parent $crJnt[ $x ] $selJnt[ 0 ]; | |
} | |
if ( ( $x + 1 ) == ( $seg - 1 ) ) | |
{ | |
parent $selJnt[ 1 ] $crJnt[ $x ]; | |
} | |
} | |
// Adds created joints to the select set and orients the joints. | |
sets -e -add $bindSet $crJnt; | |
$bindJnt = { $bindJnt[ 0 ], $bindJnt[ 2 ], $bindJnt[ 1 ] }; | |
parent $bindJnt[ 1 ] $bindJnt[ 0 ]; | |
joint -e -oj xyz -sao zdown -zso -ch $selJnt[ 0 ]; | |
joint -e -oj xyz -sao zdown -zso -ch $bindJnt[ 0 ]; | |
joint -e -oj xyz -sao zdown -zso -ch $neckCtrl[ 0 ]; | |
// Creates the neck control. | |
circle -nr 1 0 0 -n "neck"; | |
parent -add -s neckShape $neckCtrl[ 0 ]; | |
delete neck; | |
$dup = `circle -nr 0 0 1 -n "head_ctrl"`; | |
$headCtrl = $dup[ 0 ]; | |
move -a ( $headLoc.x ) ( ( $headLoc.y ) +0.8 ) ( $headLoc.z ) $headCtrl; | |
move -a ( $headLoc.x) ( $headLoc.y ) ( $headLoc.z ) ( $headCtrl + ".scalePivot" ) ( $headCtrl + ".rotatePivot" ); | |
makeIdentity -a 1 -t 1 $headCtrl; | |
delete -ch $headCtrl; | |
// Distance node uses the head and neck locators. | |
// It is used to control the straightening of the neck. | |
string $neckDist = `distanceDimension -sp ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ) -ep ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z )`; | |
rename "distanceDimension1" "neck_dist"; | |
$neckDist = "neck_distShape"; | |
string $neckStartDist = `rename "neck_loc" "neck_start_dist"`; | |
string $neckEndDist = `rename "head_loc" "neck_end_dist"`; | |
// Spline ik used for controlling the bend in the neck. | |
string $ikHandle[] = `ikHandle -sj $selJnt[ 0 ] -ee $selJnt[ 1 ] -sol ikSplineSolver -n "neck_ikHandle"`; | |
$ikHandle[ 1 ] = `rename $ikHandle[ 1 ] ( $ikHandle[ 0 ] + "_eff" )`; | |
$ikHandle[ 2 ] = `rename $ikHandle[ 2 ] "neck_curve"`; | |
// Creates the curve info node for the neck. | |
string $neckInfo = `arclen -ch 1 $ikHandle[ 2 ]`; | |
$neckInfo = `rename $neckInfo "neck_curveInfo"`; | |
addAttr -at "float" -ln "normalizedScale" $neckInfo; | |
float $neckLengthNorm = `getAttr ( $neckInfo + ".arcLength" )`; | |
select -cl; | |
// Setting up the groups for contraining the head. | |
parent $neckEndDist $bindJnt[ 2 ] $headCtrl; | |
string $headCtrlGrp = `group -n ( $headCtrl + "_grp" ) -p ( $charName + "_ctrl_grp" ) $headCtrl`; | |
xform -os -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headCtrlGrp; | |
$headWSGrp[ 0 ] = `group -n ( $headCtrl + "_world_space_grp" ) -em -p ( $charName + "_ctrl_grp" )`; | |
$headWSGrp[ 1 ] = `group -n ( $headCtrl + "_world_tSpace" ) -em -p $headWSGrp[ 0 ]`; | |
$headWSGrp[ 2 ] = `group -n ( $headCtrl + "_world_oSpace" ) -em -p $headWSGrp[ 0 ]`; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headWSGrp[ 1 ]; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headWSGrp[ 2 ]; | |
// Setting up the groups for contraining the head. | |
string $neckCtrlGrp = `group -n ( $neckCtrl[ 0 ] + "_grp" ) -p ( $charName + "_ctrl_grp" ) $neckCtrl[ 0 ]`; | |
xform -ws -piv 0 0 0 $neckCtrlGrp; | |
$headNSGrp[ 0 ] = `group -n ( $headCtrl + "_neck_space_grp" ) -em -p $neckCtrl[ 1 ]`; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headNSGrp[ 0 ]; | |
$headNSGrp[ 1 ] = `group -n ( $headCtrl + "_neck_tSpace" ) -em -p $headNSGrp`; | |
$headNSGrp[ 2 ] = `group -n ( $headCtrl + "_neck_oSpace" ) -em -p $headNSGrp`; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headNSGrp[ 1 ]; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headNSGrp[ 2 ]; | |
// Setting up the the neck grp and neck DoNotTouch grp. | |
string $neckGrp = `group -n "neck_grp" -p "spine_grp" $selJnt[ 0 ]`; | |
xform -ws -piv 0 0 0 $neckGrp; | |
string $neckDNT = `group -n "neck_doNotTouch_grp" -p $neckGrp $ikHandle[ 0 ] $ikHandle[ 2 ] $neckDist`; | |
xform -ws -piv 0 0 0 $neckDNT; | |
// Setting up the groups for contraining the head. | |
$headBSGrp[ 0 ] = `group -n ( $headCtrl +"_body_space_grp" ) -em -p "upperBody_ctrl"`; | |
$headBSGrp[ 1 ] = `group -n ( $headCtrl +"_body_tSpace" ) -em -p $headBSGrp`; | |
$headBSGrp[ 2 ] = `group -n ( $headCtrl +"_body_oSpace" ) -em -p $headBSGrp`; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headBSGrp[ 1 ]; | |
xform -ws -piv ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ) $headBSGrp[ 2 ]; | |
// Setting up the groups for contraining the head. | |
string $neckStraitGrp = `group -n "neck_curve_strait_grp" -p "torso_ctrl" $bindJnt[ 0 ]`; | |
xform -ws -piv ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ) $neckStraitGrp; | |
string $neckCtrlGrpConst = `group -n ( $neckCtrlGrp + "_const" ) -em -p "torso_ctrl"`; | |
$headTSGrp[ 0 ] = `group -n ( $headCtrl + "_torso_space_grp" ) -em -p "torso_ctrl"`; | |
$headTSGrp[ 1 ] = `group -n ( $headCtrl + "_torso_tSpace" ) -em -p $headTSGrp`; | |
$headTSGrp[ 2 ] = `group -n ( $headCtrl + "_torso_oSpace" ) -em -p $headTSGrp`; | |
xform -ws -piv ( $headLoc.x ) ($headLoc.y ) ( $headLoc.z ) $headTSGrp[ 1 ]; | |
xform -ws -piv ( $headLoc.x ) ($headLoc.y ) ( $headLoc.z ) $headTSGrp[ 2 ]; | |
// Parents the neck locator to the torso control. | |
parent $neckStartDist "torso_ctrl"; | |
// Parent and orient constrains the head ctrl grp. | |
// and parent constrains the neck ctrl grp. | |
string $tSpaceConst[] = `pointConstraint $headNSGrp[ 1 ] $headTSGrp[ 1 ] $headBSGrp[ 1 ] $headWSGrp[ 1 ] $headCtrlGrp`; | |
string $oSpaceConst[] = `orientConstraint $headNSGrp[ 2 ] $headTSGrp[ 2 ] $headBSGrp[ 2 ] $headWSGrp[ 2 ] $headCtrlGrp`; | |
parentConstraint $neckCtrlGrpConst $neckCtrlGrp; | |
// Adding the attributes for the tSpace and oSpace for the head | |
// to the settings grp. | |
string $settings = ( "nahiel_settings_grp" ); | |
addAttr -at enum -en "Neck:Torso:Body:World" -ln "headTSpace" -k 1 $settings; | |
string $tSpace = ( $settings + ".headTSpace" ); | |
addAttr -at enum -en "Neck:Torso:Body:World" -ln "headOSpace" -k 1 $settings; | |
string $oSpace = ( $settings + ".headOSpace" ); | |
// For loop sets driven keys for the head contraints. | |
string $space[] = { "neck", "torso", "body", "world" }; | |
for ( $i = 0; $i < 4; $i++ ) | |
{ | |
setDrivenKeyframe -currentDriver $tSpace -dv $i -v 1 ( "head_ctrl_grp_pointConstraint1.head_ctrl_" + $space[ $i ] + "_tSpaceW" + $i ); | |
for ( $s = 0; $s < 4; $s++ ) | |
{ | |
if ( $s != $i ) | |
setDrivenKeyframe -currentDriver $tSpace -dv $i -v 0 ( "head_ctrl_grp_pointConstraint1.head_ctrl_" + $space[ $s ] + "_tSpaceW" + $s ); | |
} | |
} | |
// For loop sets driven keys for the head contraints. | |
for ( $i = 0; $i < 4; $i++ ) | |
{ | |
setDrivenKeyframe -currentDriver $oSpace -dv $i -v 1 ( "head_ctrl_grp_orientConstraint1.head_ctrl_" + $space[ $i ] + "_oSpaceW" + $i ); | |
for ( $s = 0; $s < 4; $s++ ) | |
{ | |
if ( $s != $i ) | |
setDrivenKeyframe -currentDriver $oSpace -dv $i -v 0 ( "head_ctrl_grp_orientConstraint1.head_ctrl_" + $space[ $s ] + "_oSpaceW" + $s ); | |
} | |
} | |
// Creates the normalized scale multiply/divide node for | |
// the neck curve. | |
string $neckCurveNorm = `shadingNode -au multiplyDivide -n ( $ikHandle[ 2 ] + "_normalizedScale" )`; | |
setAttr ( $neckCurveNorm + ".operation" ) 2; | |
setAttr ( $neckCurveNorm + ".input2X" ) $neckLengthNorm; | |
connectAttr ( $neckInfo + ".arcLength" ) ( $neckCurveNorm + ".input1X" ); | |
connectAttr ( $neckCurveNorm + ".outputX" ) ( $neckInfo + ".normalizedScale" ); | |
// Creates the global scale multiply/divide node for | |
// controlling the scale of the neck joints. | |
string $neckCurveGlobal = `shadingNode -au multiplyDivide -n ( $ikHandle[ 2 ] + "_globalScale" )`; | |
setAttr ( $neckCurveGlobal + ".operation" ) 2; | |
connectAttr ( $neckInfo + ".normalizedScale" ) ( $neckCurveGlobal + ".input1X" ); | |
connectAttr ( $charName + "_global_ctrl.globalScale" ) ( $neckCurveGlobal + ".input2X" ); | |
connectAttr ( $neckCurveGlobal + ".outputX" ) ( $selJnt[ 0 ] + ".scaleX" ); | |
connectAttr ( $neckCurveGlobal + ".outputX" ) ( $crJnt[ 0 ] + ".scaleX" ); | |
connectAttr ( $neckCurveGlobal + ".outputX" ) ( $crJnt[ 1 ] + ".scaleX" ); | |
// Creates the normalized scale multiply/divide node for | |
// controlling the straightening of the neck. | |
string $neckNormScale = `shadingNode -au multiplyDivide -n "neck_normalizedScale"`; | |
setAttr ( $neckNormScale + ".operation" ) 2; | |
connectAttr ( $neckDist + ".distance" ) ( $neckNormScale + ".input1X" ); | |
connectAttr ( $charName + "_global_ctrl.globalScale" ) ( $neckNormScale + ".input2X" ); | |
// Sets driven keys for scaling the straight joints. | |
setDrivenKeyframe -currentDriver ( $neckNormScale + ".input1Y" ) -dv 0.0361 -v 0.1 | |
( $bindJnt[ 0 ] + ".scaleX" ) ( $bindJnt[ 0 ] + ".scaleY" ) ( $bindJnt[ 0 ] + ".scaleZ" ) | |
( $bindJnt[ 2 ] + ".scaleX" ) ( $bindJnt[ 2 ] + ".scaleY" ) ( $bindJnt[ 2 ] + ".scaleZ" ); | |
// Sets driven keys for scaling the straight joints. | |
setDrivenKeyframe -currentDriver ( $neckNormScale + ".input1Y" ) -dv $neckLengthNorm -v 1 | |
( $bindJnt[ 0 ] + ".scaleX" ) ( $bindJnt[ 0 ] + ".scaleY" ) ( $bindJnt[ 0 ] + ".scaleZ" ) | |
( $bindJnt[ 2 ] + ".scaleX" ) ( $bindJnt[ 2 ] + ".scaleY" ) ( $bindJnt[ 2 ] + ".scaleZ" ); | |
// For loop forces the connection between the neck normalized scale | |
// and animation curves for the straight joints. | |
string $scale[] = { "_scaleX", "_scaleY", "_scaleZ" }; | |
for ( $i = 0; $i < 3; $i++ ) | |
{ | |
connectAttr -f ( $neckNormScale + ".outputX" ) ( $bindJnt[ 0 ] + $scale[ $i ] + ".input" ); | |
connectAttr -f ( $neckNormScale + ".outputX" ) ( $bindJnt[ 2 ] + $scale[ $i ] + ".input" ); | |
} | |
// Binds the straight joints to the neck curve. | |
skinCluster $bindJnt[ 0 ] $bindJnt[ 1 ] $bindJnt[ 2 ] $ikHandle[ 2 ]; | |
// Removes inherits transform on the neck curve. | |
setAttr ( $ikHandle[ 2 ] + ".inheritsTransform" ) 0; | |
// Set up the advanced twist controls for the spline ik. | |
setAttr ( $ikHandle[ 0 ] + ".dTwistControlEnable" ) 1; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpType" ) 4; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorY" ) 0; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorEndY" ) 0; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorZ" ) -1; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorEndZ" ) -1; | |
connectAttr ( "torso_ctrl.worldMatrix" ) ( $ikHandle[ 0 ] + ".dWorldUpMatrix" ); | |
connectAttr ( $headCtrl + ".worldMatrix" ) ( $ikHandle[ 0 ] + ".dWorldUpMatrixEnd" ); | |
// Cleans up the neck ctrl. | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( ( $i < 3 ) || ( $i > 5 ) ) setAttr -l 1 -k 0 -cb 0 ( "neck_ctrl" + $attrs[ $i ] ); | |
} | |
// Cleans up the head ctrl. | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( $i > 5 ) setAttr -l 1 -k 0 -cb 0 ( "head_ctrl" + $attrs[ $i ] ); | |
} | |
// Hides nodes that don't need to be seen by the animator. | |
hide $headWSGrp $headBSGrp $headTSGrp $headNSGrp $neckCtrlGrpConst $neckDNT $neckStartDist $neckEndDist; | |
select -cl; | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////////// Procedure: spine ///////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure rigs the spine for the character. // | |
// Creating all the joints, controls and attribute // | |
// connections. // | |
proc spine( string $charTxt, string $spineButton, string $neckButton ) | |
{ | |
// Disables the spine button, enables the neck button and queries the character name. | |
button -e -en 0 $spineButton; | |
button -e -en 1 $neckButton; | |
string $charName = `textFieldButtonGrp -q -tx $charTxt`; | |
// Setting up initial variables. | |
string $selJnt[]; | |
string $locators[] = { "hip", "torso", "global" }; | |
vector $hipLoc = `getAttr hip_loc.t`; | |
vector $torsoLoc = `getAttr torso_loc.t`; | |
vector $globalLoc = `getAttr global_loc.t`; | |
string $bindSet = "skinBind_jnts"; | |
string $attrs[] = { ".tx", ".ty", ".tz", ".rx", ".ry", ".rz", ".sx", ".sy", ".sz", ".v" }; | |
// Spine start and end joints. | |
select -cl; | |
$selJnt[ 0 ] = `joint -p ( $hipLoc.x ) ( $hipLoc.y ) ( $hipLoc.z ) -n ( "spine_1_jnt" ) -rad 0.5`; | |
$selJnt[ 1 ] = `joint -p ( $torsoLoc.x ) ( $torsoLoc.y ) ( $torsoLoc.z ) -n ( "spine_end_jnt" ) -rad 0.5`; | |
// Creates the hip and torso joints and adds them to the select set. | |
select -cl; | |
$selJnt[ 2 ] = `joint -p ( $hipLoc.x ) ( $hipLoc.y ) ( $hipLoc.z ) -n ( $locators[ 0 ] + "_jnt" ) -rad 0.4`; | |
sets -e -add $bindSet $selJnt[ 2 ]; | |
select -cl; | |
$selJnt[ 3 ] = `joint -p ( $torsoLoc.x ) ( $torsoLoc.y ) ( $torsoLoc.z ) -n ( $locators[ 1 ] + "_jnt" ) -rad 0.4`; | |
sets -e -add $bindSet $selJnt[ 3 ]; | |
// gets the positions of the start and end joints. | |
vector $sjPos = ( `joint -q -p $selJnt[ 0 ]` ); | |
vector $ejPos = ( `joint -q -p $selJnt[ 1 ]` ); | |
string $crJnt[]; | |
float $radius = ( `getAttr ( $selJnt[ 0 ] + ".radius" )` ); | |
// Input an integer for the TOTAL number of segments you need, for $seg. | |
int $seg = 6; | |
select -cl; | |
// For loop creates joints in the proper position | |
// and assigns them to an array and parents the first created joint | |
// to the start joint and parents the end joint to the last created joint. | |
for ( $i = $seg; $i > 1; $i-- ) | |
{ | |
int $x = abs ( $i - $seg ); | |
$crJnt[ $x ] = `joint -p ( ( ( ( ( $sjPos.x ) - ( $ejPos.x ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.x ) ) | |
( ( ( ( ( $sjPos.y ) - ( $ejPos.y ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.y ) ) | |
( ( ( ( ( $sjPos.z ) - ( $ejPos.z ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.z ) ) -n ( "spine_" + ( $x + 2 ) + "_jnt" ) -rad $radius`; | |
if ( $x==0 ) | |
{ | |
parent $crJnt[ $x ] $selJnt[ 0 ]; | |
} | |
if ( ( $x + 1 ) == ( $seg - 1 ) ) | |
{ | |
parent $selJnt[ 1 ] $crJnt[ $x ]; | |
} | |
} | |
// Adds created joints to the selection set. | |
sets -e -add $bindSet $crJnt; | |
joint -e -oj xyz -sao zdown -zso -ch $selJnt[ 0 ]; | |
// Gets the positions of the 3rd and 5th spine joint. | |
vector $spine3 = `joint -q -p $crJnt[ 1 ]`; | |
vector $spine5 = `joint -q -p $crJnt[ 3 ]`; | |
// Calls circleOneArrow proc to makes the torso ctrl. | |
circleOneArrow ; | |
string $torso = "nurbsCircle1"; | |
$torso = `rename $torso "torso_ctrl"`; | |
setAttr ( $torso + ".rz" ) -90; | |
setAttr ( $torso + ".t" ) ( $ejPos.x ) ( $ejPos.y ) 0; | |
select $torso; | |
scale -xz 1.2 1.2; | |
move -a ( $ejPos.x ) ( $ejPos.y ) ( $ejPos.z ) $torso; | |
makeIdentity -a 1 -t 1 -r 1 -s 1 $torso; | |
delete -ch $torso; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( $i > 5 ) setAttr -l 1 -k 0 -cb 0 ( $torso + $attrs[ $i ] ); | |
} | |
// Creates the hip ctrl. | |
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n "hip_ctrl"; | |
select -r hip_ctrl.cv[ 2 ] hip_ctrl.cv[ 4 ] hip_ctrl.cv[ 0 ] hip_ctrl.cv[ 6 ] ; | |
move -r -os -wd 0 -0.614947 0 ; | |
select -cl ; | |
string $hip = "hip_ctrl"; | |
select $hip; | |
move -rpr ( $sjPos.x ) ( $sjPos.y ) 0; | |
scale -xyz 2.3 2.3 2.3 $hip; | |
move -a ( $sjPos.x ) ( $sjPos.y ) ( $sjPos.z ) $hip; | |
makeIdentity -a 1 -t 1 -s 1 $hip; | |
delete -ch $hip; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( ( $i < 3 ) || ( $i > 5 ) ) setAttr -l 1 -k 0 -cb 0 ( $hip+$attrs[ $i ] ); | |
} | |
// Creates the upperBody ctrl. | |
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n "upperBody_ctrl"; | |
move -rpr ( $sjPos.x ) ( $sjPos.y ) 0; | |
string $upperBody = "upperBody_ctrl"; | |
scale -xz 2.5 2.5; | |
move -a ( $sjPos.x ) ( $sjPos.y ) ( $sjPos.z ) $upperBody; | |
makeIdentity -a 1 -t 1 -s 1 $upperBody; | |
delete -ch $upperBody; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( $i > 5 ) setAttr -l 1 -k 0 -cb 0 ( $upperBody + $attrs[ $i ] ); | |
} | |
// Creates the lowerTorso ctrl. | |
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n "lowerTorso_ctrl"; | |
move -rpr ( $spine3.x ) ( $spine3.y ) 0; | |
string $lowerTorso = "lowerTorso_ctrl"; | |
scale -xz 2.8 2.8; | |
move -a ( $spine3.x ) ( $spine3.y ) ( $spine3.z ) $lowerTorso; | |
makeIdentity -a 1 -t 1 -s 1 $lowerTorso; | |
delete -ch $lowerTorso; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( ( $i < 3 ) || ( $i > 5 ) ) setAttr -l 1 -k 0 -cb 0 ( $lowerTorso + $attrs[ $i ] ); | |
} | |
// Creates the upperTorso ctrl. | |
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1 -n "upperTorso_ctrl"; | |
move -rpr ( $spine5.x ) ( $spine5.y ) 0; | |
string $upperTorso = "upperTorso_ctrl"; | |
scale -xz 2.3 2.3; | |
move -a ( $spine5.x ) ( $spine5.y ) ( $spine5.z ) $upperTorso; | |
makeIdentity -a 1 -t 1 -s 1 $upperTorso; | |
delete -ch $upperTorso; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
if ( ( $i < 3 ) || ( $i > 5 ) ) setAttr -l 1 -k 0 -cb 0 ( $upperTorso + $attrs[ $i ] ); | |
} | |
// Parents the ctrls. | |
parent $upperTorso $lowerTorso; | |
parent $lowerTorso $upperBody; | |
// For loop creates the global ctrl, using the | |
// circleOneArrow proc multiple times and adding | |
// the shapes to the first. | |
for ( $i = 1; $i < 5; $i++ ) | |
{ | |
circleOneArrow; | |
rename nurbsCircle1 ( "circle" + $i ); | |
delete -ch ( "circle" + $i ); | |
if ( $i > 1 ) | |
{ | |
setAttr ( "circle" + $i + ".ry" ) ( 90 * ( $i - 1 ) ); | |
makeIdentity -a 1 -r 1 ( "circle" + $i ); | |
parent -add -s ( "circleShape" + $i ) circle1; | |
delete ( "circle" + $i ); | |
} | |
} | |
// Positions the global ctrl. | |
string $globalCtrl = "circle1"; | |
$globalCtrl = `rename $globalCtrl ( $charName + "_global_ctrl" )`; | |
select $globalCtrl; | |
move -rpr ( $globalLoc.x ) ( $globalLoc.y ) ( $globalLoc.z ); | |
scale -xz 3 3; | |
makeIdentity -a 1 -t 1 -s 1 $globalCtrl; | |
// Adds the global scale attribute to the global ctrl. | |
addAttr -ln globalScale -dv 1 -k 1 $globalCtrl; | |
connectAttr ( $globalCtrl + ".globalScale" ) ( $globalCtrl + ".sx" ); | |
connectAttr ( $globalCtrl + ".globalScale" ) ( $globalCtrl + ".sy" ); | |
connectAttr ( $globalCtrl + ".globalScale" ) ( $globalCtrl + ".sz" ); | |
setAttr -l 1 -k 0 -cb 0 ( $globalCtrl + ".sx" ); | |
setAttr -l 1 -k 0 -cb 0 ( $globalCtrl + ".sy" ); | |
setAttr -l 1 -k 0 -cb 0 ( $globalCtrl + ".sz" ); | |
// Creates a spline ik for the spine and creates the curve info node | |
string $ikHandle[] = `ikHandle -sj $selJnt[ 0 ] -ee $selJnt[ 1 ] -sol ikSplineSolver -n spine_ikHandle`; | |
$ikHandle[ 1 ] = `rename $ikHandle[ 1 ] ( $ikHandle[ 0 ] + "_eff" )`; | |
$ikHandle[ 2 ] = `rename $ikHandle[ 2 ] spine_curve`; | |
string $spineInfo = `arclen -ch 1 $ikHandle[ 2 ]`; | |
$spineInfo = `rename $spineInfo spine_curveInfo`; | |
float $spineLengthNorm = `getAttr ( $spineInfo + ".arcLength" )`; | |
// Turns of inherits transform on the spine curve. | |
setAttr ( $ikHandle[ 2 ] + ".inheritsTransform" ) 0; | |
// Sets up the advanced twist controls for the spine ik. | |
setAttr ( $ikHandle[ 0 ] + ".dTwistControlEnable" ) 1; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpType" ) 4; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorY" ) 0; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorEndY" ) 0; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorZ" ) -1; | |
setAttr ( $ikHandle[ 0 ] + ".dWorldUpVectorEndZ" ) -1; | |
connectAttr ( $hip + ".worldMatrix" ) ( $ikHandle[ 0 ] + ".dWorldUpMatrix" ); | |
connectAttr ( $torso + ".worldMatrix" ) ( $ikHandle[ 0 ] + ".dWorldUpMatrixEnd" ); | |
// Constraining the hip and torso joints to their respective ctrls. | |
parentConstraint $hip $selJnt[ 2 ]; | |
parentConstraint $torso $selJnt[ 3 ]; | |
// Creates the groups. | |
string $group[]; | |
$group[ 0 ] = `group -em -n "body_ctrl_grp"`; | |
$group[ 1 ] = `group -n "body_fk_ctrl_grp" -p $group[ 0 ] $upperBody`; | |
xform -os -piv 0 0 0; | |
$group[ 2 ] = `group -n ( $hip + "_grp" ) -p $group[ 0 ] $hip`; | |
xform -os -piv ( $sjPos.x ) ( $sjPos.y ) ( $sjPos.z ); | |
$group[ 3 ] = `group -n ( $torso + "_grp" ) -p $group[ 0 ] $torso`; | |
xform -os -piv ( $ejPos.x ) ( $ejPos.y ) ( $ejPos.z); | |
$group[ 4 ] = `group -n "spine_grp" $selJnt[ 0 ] $selJnt[ 2 ] $selJnt[ 3 ]`; | |
xform -os -piv 0 0 0; | |
$group[ 5 ] = `group -n "spine_doNotTouch_grp" $ikHandle[ 0 ] $ikHandle[ 2 ]`; | |
xform -os -piv 0 0 0; | |
$group[ 6 ] = `group -n ( $charName + "_ctrl_grp" ) -p $globalCtrl $group[ 0 ] $group[ 4 ] $group[ 5 ]`; | |
// Constrains the hip and torso grps to the body and upper torso ctrls. | |
parentConstraint -mo $upperBody $group[ 2 ]; | |
parentConstraint -mo $upperTorso $group[ 3 ]; | |
// Skines the spine curve to the hip and torso joints. | |
skinCluster $selJnt[ 2 ] $selJnt[ 3 ] $ikHandle[ 2 ]; | |
// Creates the settings grp and adds the backStretch attribute. | |
$group[ 7 ] = `group -em -n ( $charName + "_settings_grp" ) -p $globalCtrl`; | |
for ( $i = 0; $i < 10; $i++ ) | |
{ | |
setAttr -l 1 -k 0 -cb 0 ( $group[ 7 ] + $attrs[ $i ] ); | |
} | |
addAttr -ln backStretch -dv 1 -k 1 $group[ 7 ]; | |
// Sets keys for the backStretch attribute. | |
setKeyframe -t 1 -v 1 ( $group[ 7 ] + ".backStretch" ); | |
setKeyframe -t 6 -v 1 ( $group[ 7 ]+".backStretch" ); | |
keyTangent -e -a -t 1 -oa 77 -ow 1 ( $group[ 7 ] + ".backStretch" ); | |
keyTangent -e -a -t 6 -ia -55 -ow 1 ( $group[ 7 ] + ".backStretch" ); | |
// Adds power attribute to the spine joints and | |
// creates the frame cache nodes for the spine joints and connects | |
// them to the spines joints pow attributes. | |
for ( $i = 1; $i < 7; $i++ ) | |
{ | |
addAttr -ln "pow" -k 1 ( "spine_" + $i + "_jnt" ); | |
shadingNode -au frameCache -n ( "spine_" + $i + "_frameCache" ); | |
setAttr ( "spine_" + $i + "_frameCache.varyTime" ) $i; | |
connectAttr ( $group[ 7 ]+".backStretch" ) ( "spine_" + $i + "_frameCache.stream" ); | |
connectAttr ( "spine_" + $i + "_frameCache.varying" ) ( "spine_" + $i + "_jnt.pow" ); | |
} | |
// Creates the expression for the spine joints. | |
string $expr = ( "$normal = " + $spineInfo + ".arcLength / " + $globalCtrl + ".globalScale ;\n" + | |
"$scale = $normal / " + $spineLengthNorm + ";\n" + | |
"$inv = 1 / sqrt( $scale ) ;\n" ); | |
for ( $i = 1; $i < 7; $i++ ) | |
{ | |
$expr += ( "spine_" + $i+ "_jnt.sx = $scale ;\n" + | |
"spine_" + $i + "_jnt.sy = pow( $inv,spine_"+$i+"_jnt.pow ) ;\n" + | |
"spine_" + $i + "_jnt.sz = pow( $inv,spine_" + $i + "_jnt.pow ) ;\n" ); | |
} | |
expression -n "back_stretch" -s $expr; | |
// Creates the character geo grp. | |
group -n ( $charName+"_geo_grp" ) -p $globalCtrl -em; | |
// Hides nodes that don't need to be seen by the animator. | |
hide $group[ 5 ]; | |
select -cl; | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////// Procedure: circleOneArrow //////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the curve that is used for // | |
// the global control and torso control. // | |
proc circleOneArrow () | |
{ | |
circle -c 0 0 0 -nr 0 1 0 -sw 360 -r 1 -d 3 -ut 0 -tol 0.01 -s 8 -ch 1; | |
insertKnotCurve -ch 1 -cos on -nk 1 -add 1 -ib 0 -rpo 1 nurbsCircle1.u[ 3.52925230366488 ] nurbsCircle1.u[ 4.49813938939366 ]; | |
select -cl ; | |
move -r -os -wd 0 0 0.974629 nurbsCircle1.cv[ 6 ]; | |
insertKnotCurve -ch 1 -cos on -nk 1 -add 1 -ib 0 -rpo 1 | |
nurbsCircle1.u[ 3.52598188091927 ] nurbsCircle1.u[ 4.46805625096428 ] nurbsCircle1.u[ 3.59280657983577 ] | |
nurbsCircle1.u[ 4.39392776408716 ] nurbsCircle1.u[ 4.06840938886799 ] nurbsCircle1.u[ 3.92979615398919 ] | |
nurbsCircle1.u[ 3.85844362514615 ] nurbsCircle1.u[ 4.15186051711318 ] nurbsCircle1.u[ 3.76581400743692 ] | |
nurbsCircle1.u[ 4.24250665744479 ] nurbsCircle1.u[ 3.71122961366576 ] nurbsCircle1.u[ 4.29777691966406 ]; | |
move -r -os -wd -0.19739 0 0 nurbsCircle1.cv[ 6:8 ]; | |
move -r -os -wd 0.0456708 0 -0.259252 nurbsCircle1.cv[ 6 ]; | |
move -r -os -wd -0.0596628 0 0 nurbsCircle1.cv[ 8 ]; | |
move -r -os -wd 0.147498 0 -0.272523 nurbsCircle1.cv[ 18 ]; | |
move -r -os -wd 0.197007 0 0 nurbsCircle1.cv[ 17 ]; | |
move -r -os -wd 0.253897 0 0 nurbsCircle1.cv[ 16 ]; | |
move -r -os -wd -0.325064 0 0 nurbsCircle1.cv[ 9 ]; | |
move -r -os -wd 0.315789 0 0 nurbsCircle1.cv[ 15 ]; | |
move -r -os -wd 0 0 0.336547 nurbsCircle1.cv[ 12 ]; | |
move -r -os -wd 0 0 0.236395 nurbsCircle1.cv[ 11 ] nurbsCircle1.cv[ 13 ]; | |
move -r -os -wd 0 0 0.299215 nurbsCircle1.cv[ 10 ] nurbsCircle1.cv[ 14 ]; | |
scale -r -p 0.00219073cm 0cm 1.875649cm 3.60206 1 1 nurbsCircle1.cv[ 10 ] nurbsCircle1.cv[ 14 ]; | |
scale -r -p 0.00219073cm 0cm 1.875649cm 2.246504 1 1 nurbsCircle1.cv[ 10 ] nurbsCircle1.cv[ 14 ]; | |
move -r -os -wd 0 0 -0.54371 nurbsCircle1.cv[ 10 ] nurbsCircle1.cv[ 14 ]; | |
move -r -os -wd 0 0 0.0472791 nurbsCircle1.cv[ 11 ] nurbsCircle1.cv[ 13 ]; | |
move -r -os -wd 0 0 -0.0709186 nurbsCircle1.cv[ 9 ] nurbsCircle1.cv[ 15 ]; | |
scale -r -p -0.00108229cm 0cm 1.145404cm 0.598983 1 1 nurbsCircle1.cv[ 5:9 ] nurbsCircle1.cv[ 15:19 ]; | |
move -r -os -wd 0 0 0.0472791 nurbsCircle1.cv[ 5:6 ] nurbsCircle1.cv[ 18:19 ]; | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////////// Procedure: locators /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the locators that are used // | |
// for placeing the rest of the rig. The locators can be // | |
// moved, after creation, to where they need to be for // | |
// rest of the rig. // | |
proc locators( string $locButton, string $spineButton ) | |
{ | |
// Disables the locators button and enables the spine button. | |
button -e -en 0 $locButton; | |
button -e -en 1 $spineButton; | |
// Sets up initial variables. | |
string $selJnt[]; | |
string $locators[] = { "hip", "torso", "global", "neck", "head" }; | |
vector $hipLoc = << 0, -2.203, -0.461 >>; | |
vector $torsoLoc = << 0, 0.659, -0.461 >>; | |
vector $globalLoc = << 0, -6.254, 0 >>; | |
vector $neckLoc = << 0, 1.39, -0.461 >>; | |
vector $headLoc = << 0, 2.141, -0.203 >>; | |
// Creates the locators. | |
for ( $i = 0; $i < ( size ( $locators ) ); $i++ ) | |
{ | |
spaceLocator -n ( $locators[ $i ]+"_loc" ); | |
} | |
// Positions the locators. | |
select -cl; | |
setAttr hip_loc.t ( $hipLoc.x ) ( $hipLoc.y ) ( $hipLoc.z ); | |
setAttr torso_loc.t ( $torsoLoc.x ) ( $torsoLoc.y ) ( $torsoLoc.z ); | |
setAttr global_loc.t ( $globalLoc.x ) ( $globalLoc.y ) ( $globalLoc.z ); | |
setAttr neck_loc.t ( $neckLoc.x ) ( $neckLoc.y ) ( $neckLoc.z ); | |
setAttr head_loc.t ( $headLoc.x ) ( $headLoc.y ) ( $headLoc.z ); | |
// Creaets the skinBind joints selection set. | |
string $bindSet = `sets -n skinBind_jnts -em`; | |
select -cl; | |
// Dialog box tells user to place locators where they need them. | |
confirmDialog -t "Place Locators" -m "The locators have been created.\nYou may now place them where\nyou need them." | |
-ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "information"; | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////////// Procedure: reset ///////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure resets the tool so it can be // | |
// reused without calling the window again. // | |
proc reset( string $charName, string $editName, string $locators, string $spine, string $neck ) | |
{ | |
textFieldButtonGrp -e -ed 1 -tx "" $charName; | |
button -e -en 0 $editName; | |
button -e -en 0 $locators; | |
button -e -en 0 $spine; | |
button -e -en 0 $neck; | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////////// Procedure: editName /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure allows the user to edit the name // | |
// and deactivates the buttons for creation so the user // | |
// doesn't accidentally press them while editing. // | |
proc editName( string $characterName, string $editName, string $locators ) | |
{ | |
textFieldButtonGrp -e -ed 1 $characterName; | |
button -e -en 0 $editName; | |
button -e -en 0 $locators; | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: validName /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure checks if the name is valid and // | |
// substrings the name to 16 characters. // | |
proc validName( string $characterName, string $editName, string $locators ) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $characterName`; | |
// If name is more than 16 characters then substring the first 16. | |
int $size = size( $testString ); | |
if ( $size > 16 ) | |
{ | |
$testString = `substring $testString 1 16`; | |
textFieldButtonGrp -e -tx $testString $characterName; | |
} | |
// Returns the valid characters in the name. | |
string $matchingPart = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $testString`; | |
// If matched name is the same as name goodmatch = 1 else 0. | |
int $goodMatch = ! `strcmp $matchingPart $testString`; | |
// If no name is given then goodmatch is 0. | |
if ( $testString == "" ) | |
{ | |
$goodMatch = 0; | |
} | |
// If goodmatch is 1 then disable textField and enable edit name and create buttons. | |
// Else give warning. | |
if ( $goodMatch ) | |
{ | |
textFieldButtonGrp -e -ed 0 $characterName; | |
button -e -en 1 $editName; | |
button -e -en 1 $locators; | |
} | |
else | |
{ | |
confirmDialog -t "Warning" -m "Invalid character name." -ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: validName /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure substrings the name to 16 // | |
// characters if name was greater than 16 characters. // | |
proc sizeName( string $characterName ) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $characterName`; | |
int $size = size( $testString ); | |
if ( $size > 16 ) | |
{ | |
$testString = `substring $testString 1 16`; | |
textFieldButtonGrp -e -tx $testString $characterName; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: autoSpineUI ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This is the main call procedure. It sets up and // | |
// creates the UI for rigging the spine and neck for a // | |
// biped character. // | |
global proc autoRigUI() | |
{ | |
// If the window exists it deletes it when this procedure | |
// is ran. | |
if ( `window -q -ex autoRig` ) deleteUI autoRig; | |
global string $characterName; | |
global string $editName; | |
global string $locators; | |
global string $spine; | |
global string $neck; | |
global string $reset; | |
string $dialogBoxWindow = `window -t "Auto Rigger" -rtf 1 autoRig`; | |
columnLayout -adj 1; | |
frameLayout -l "Name"; | |
columnLayout -adj 1; | |
// TextField is to name character, on change the text is dropped to 16 characters if it was more. | |
// Check name button checks if the name is valid. | |
// Edit name button allows user to edit the entered name. | |
$characterName = `textFieldButtonGrp -l "Character Name" -cc "sizeName( $characterName )" -bl "Check Name" -bc "validName( $characterName, $editName, $locators )"`; | |
$editName = `button -en 0 -l "Edit Name" -c "editName( $characterName, $editName, $locators )"`; | |
setParent ..; | |
setParent ..; | |
frameLayout -l "Rig"; | |
columnLayout -adj 1; | |
rowColumnLayout -nc 3; | |
$locators = `button -en 0 -l "Create Locators" -c "locators( $locators, $spine )"`; | |
$spine = `button -en 0 -l "Rig Spine" -c "spine( $characterName, $spine, $neck )"`; | |
$neck = `button -en 0 -l "Rig Neck" -c "neck( $characterName, $neck )"`; | |
setParent ..; | |
setParent ..; | |
setParent ..; | |
columnLayout -adj 1; | |
$reset = `button -l "Reset Tool" -c "reset( $characterName, $editName, $locators, $spine, $neck )"`; | |
showWindow $dialogBoxWindow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdBarycentricsV0.1.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: This is a prototype script. It allows the /// | |
/// user to create joints that follow vertices. /// | |
/// With a model that has a blend shape that is /// | |
/// completely changed, without adding or removing /// | |
/// vertices, this means joints created with this /// | |
/// script will move with the vertices. Giving the /// | |
/// to rig one character, blend it to the other and /// | |
/// the rig is maintained. /// | |
/// The joints are place at the center of the /// | |
/// triangle defined by the three vertices selected /// | |
/// for that joint. /// | |
/// /// | |
/// USAGE: Source script then run: baryRigUI(); /// | |
/// /// | |
/// EDITS TO DO: Simplify the expression for the joints. /// | |
/// There is too much math going on and it's hard /// | |
/// to make sense of. /// | |
/// Fix up the UI. /// | |
/// /// | |
/// THINGS TO ADD: A way to fully rig characters and allow for /// | |
/// the bary joints to still move. /// | |
/// /// | |
/// VERSIONS: 0.1 - May 30, 2012 - Initial Prototype /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: createJoint ///////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the joints. Using the // | |
// three selected vertices to place the joint and creates // | |
// an expression that keeps the joint in the center of // | |
// the triangle defined by the three vertices. // | |
proc createJoint( int $isParent, string $parent, string $joint ) | |
{ | |
// Put selected vertices into an array. | |
string $slVerts[ 3 ] = `ls -sl -fl`; | |
select -cl; | |
// Create joint. | |
$joint = `joint -n ( $joint + "_baryJnt" )`; | |
// The expression that moves each joint based on the positions of | |
// the three chosen vertices. Most people will not understand this | |
// math at all, just know that it works. | |
expression -n ( $joint + "_Expr" ) -s | |
( "string $verts[] = { \"" + $slVerts[ 0 ] + "\", \"" + $slVerts[ 1 ] + "\", \"" + $slVerts[ 2 ] + "\" };\n\n" + | |
"vector $aPos = `xform -q -t $verts[ 0 ]`;\n" + | |
"vector $bPos = `xform -q -t $verts[ 1 ]`;\n" + | |
"vector $cPos = `xform -q -t $verts[ 2 ]`;\n\n" + | |
"vector $abPos = { ( ( $aPos.x + $bPos.x ) / 2 ), ( ( $aPos.y + $bPos.y ) / 2 ), ( ( $aPos.z + $bPos.z ) / 2 ) };\n" + | |
"vector $bcPos = { ( ( $bPos.x + $cPos.x ) / 2 ), ( ( $bPos.y + $cPos.y ) / 2 ), ( ( $bPos.z + $cPos.z ) / 2 ) };\n" + | |
"vector $acPos = { ( ( $aPos.x + $cPos.x ) / 2 ), ( ( $aPos.y + $cPos.y ) / 2 ), ( ( $aPos.z + $cPos.z ) / 2 ) };\n\n" + | |
"float $centerPosX = 0;\n" + | |
"float $centerPosY = 0;\n" + | |
"float $centerPosZ = 0;\n\n" + | |
"if ( ( ( $cPos.y - $abPos.y ) != 0 ) && ( ( $aPos.y - $bcPos.y ) != 0 ) && ( ( $bPos.y - $acPos.y ) != 0 ) )\n" + | |
"{\n" + | |
" if ( ( ( $cPos.x - $abPos.x ) != 0 ) && ( ( $aPos.x - $bcPos.x ) != 0 ) && ( ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) * ( - $cPos.x ) + $cPos.y ) - ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y ) ) / ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y );\n" + | |
" $centerPosZ = ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $bPos.x - $acPos.x ) != 0 ) && ( ( $aPos.x - $bcPos.x ) != 0 ) && ( ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) - ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.y ) - ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y ) ) / ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) - ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y );\n" + | |
" $centerPosZ = ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.x - $abPos.x ) != 0 ) && ( ( $bPos.x - $acPos.x ) != 0 ) && ( ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) * ( - $cPos.x ) + $cPos.y ) - ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.y ) ) / ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.x - $abPos.x ) ) );\n" + | |
" $centerPosY = ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( $centerPosX ) + ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.y );\n" + | |
" $centerPosZ = ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( $centerPosX ) + ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.z - $abPos.z ) != 0 ) && ( ( $aPos.z - $bcPos.z ) != 0 ) && ( ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) * ( - $cPos.z ) + $cPos.y ) - ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y ) ) / ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y );\n" + | |
" $centerPosX = ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x );\n" + | |
" }\n" + | |
" else if ( ( ( $bPos.z - $acPos.z ) != 0 ) && ( ( $aPos.z - $bcPos.z ) != 0 ) && ( ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) - ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.y ) - ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y ) ) / ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) - ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y );\n" + | |
" $centerPosX = ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.z - $abPos.z ) != 0 ) && ( ( $bPos.z - $acPos.z ) != 0 ) && ( ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) * ( - $cPos.z ) + $cPos.y ) - ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.y ) ) / ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) - ( ( $cPos.y - $abPos.y ) / ( $cPos.z - $abPos.z ) ) );\n" + | |
" $centerPosY = ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( $centerPosZ ) + ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.y );\n" + | |
" $centerPosX = ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( $centerPosZ ) + ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.x );\n" + | |
" }\n" + | |
"}\n" + | |
"else\n" + | |
"{\n" + | |
" if ( ( ( $cPos.x - $abPos.x ) != 0 ) && ( ( $aPos.x - $bcPos.x ) != 0 ) && ( ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) - ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) * ( - $cPos.x ) + $cPos.z ) - ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z ) ) / ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) - ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y );\n" + | |
" $centerPosZ = ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $bPos.x - $acPos.x ) != 0 ) && ( ( $aPos.x - $bcPos.x ) != 0 ) && ( ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) - ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.z ) - ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z ) ) / ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) - ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.y );\n" + | |
" $centerPosZ = ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( $centerPosX ) + ( ( ( $aPos.z - $bcPos.z ) / ( $aPos.x - $bcPos.x ) ) * ( - $aPos.x ) + $aPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.x - $abPos.x ) != 0 ) && ( ( $bPos.x - $acPos.x ) != 0 ) && ( ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) - ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosX = ( ( ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) * ( - $cPos.x ) + $cPos.z ) - ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.z ) ) / ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) - ( ( $cPos.z - $abPos.z ) / ( $cPos.x - $abPos.x ) ) );\n" + | |
" $centerPosY = ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( $centerPosX ) + ( ( ( $bPos.y - $acPos.y ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.y );\n" + | |
" $centerPosZ = ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( $centerPosX ) + ( ( ( $bPos.z - $acPos.z ) / ( $bPos.x - $acPos.x ) ) * ( - $bPos.x ) + $bPos.z );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.z - $abPos.z ) != 0 ) && ( ( $aPos.z - $bcPos.z ) != 0 ) && ( ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) - ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) * ( - $cPos.z ) + $cPos.x ) - ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x ) ) / ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) - ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y );\n" + | |
" $centerPosX = ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x );\n" + | |
" }\n" + | |
" else if ( ( ( $bPos.z - $acPos.z ) != 0 ) && ( ( $aPos.z - $bcPos.z ) != 0 ) && ( ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) - ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.x ) - ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x ) ) / ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) - ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) );\n" + | |
" $centerPosY = ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.y - $bcPos.y ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.y );\n" + | |
" $centerPosX = ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( $centerPosZ ) + ( ( ( $aPos.x - $bcPos.x ) / ( $aPos.z - $bcPos.z ) ) * ( - $aPos.z ) + $aPos.x );\n" + | |
" }\n" + | |
" else if ( ( ( $cPos.z - $abPos.z ) != 0 ) && ( ( $bPos.z - $acPos.z ) != 0 ) && ( ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) - ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) ) != 0 ) )\n" + | |
" {\n" + | |
" $centerPosZ = ( ( ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) * ( - $cPos.z ) + $cPos.x ) - ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.x ) ) / ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) - ( ( $cPos.x - $abPos.x ) / ( $cPos.z - $abPos.z ) ) );\n" + | |
" $centerPosY = ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( $centerPosZ ) + ( ( ( $bPos.y - $acPos.y ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.y );\n" + | |
" $centerPosX = ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( $centerPosZ ) + ( ( ( $bPos.x - $acPos.x ) / ( $bPos.z - $acPos.z ) ) * ( - $bPos.z ) + $bPos.x );\n" + | |
" }\n" + | |
"}\n\n" + | |
"move -a $centerPosX $centerPosY $centerPosZ " + $joint + ";" ) -o $joint; | |
// If a parent joint was loaded then parent the new joint to it. | |
if ( $isParent ) | |
{ | |
parent $joint $parent; | |
} | |
} | |
// This procedure gets the values to be used in the creation procedure. | |
proc getInfo( string $parentJoint, string $jointName ) | |
{ | |
string $parent = `textFieldButtonGrp -q -tx $parentJoint`; | |
string $joint = `textFieldButtonGrp -q -tx $jointName`; | |
int $isParent = 0; | |
if ( $parent != "" ) | |
{ | |
$isParent = 1; | |
} | |
createJoint( $isParent, $parent, $joint ); | |
} | |
// This procedure disables the create and edit name button and | |
// enables the text field if user wants to edit name. | |
// This requires the user to recheck the name before creating the | |
// city. | |
proc editName( string $jointName, string $editName, string $create ) | |
{ | |
textFieldButtonGrp -e -ed 1 $jointName; | |
button -e -en 0 $editName; | |
button -e -en 0 $create; | |
} | |
// This procedure checks if the name is valid and substrings the name to 32 characters. | |
proc validName( string $jointName, string $editName, string $create ) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $jointName`; | |
// If name is more than 32 characters then substring the first 32. | |
int $size = size( $testString ); | |
if ( $size > 32 ) | |
{ | |
$testString = `substring $testString 1 16`; | |
textFieldButtonGrp -e -tx $testString $jointName; | |
} | |
// Returns the valid characters in the name. | |
string $matchingPart = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $testString`; | |
// If matched name is the same as name goodmatch = 1 else 0. | |
int $goodMatch = ! `strcmp $matchingPart $testString`; | |
// If no name is given then goodmatch is 0. | |
if ( $testString == "" ) | |
{ | |
$goodMatch = 0; | |
} | |
// If goodmatch is 1 then disable textField and enable edit name and create buttons. | |
// Else give warning. | |
if ( $goodMatch ) | |
{ | |
textFieldButtonGrp -e -ed 0 $jointName; | |
button -e -en 1 $editName; | |
button -e -en 1 $create; | |
} | |
else | |
{ | |
confirmDialog -t "Warning" -m "Invalid joint name." -ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
} | |
} | |
// Substrings the name to 32 characters if name was greater than 32 characters. | |
proc sizeName( string $jointName ) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $jointName`; | |
int $size = size( $testString ); | |
if ( $size > 32 ) | |
{ | |
$testString = `substring $testString 1 32`; | |
textFieldButtonGrp -e -tx $testString $jointName; | |
} | |
} | |
// Loads the name of the selected parent joint. | |
proc loadParent( string $parentJoint ) | |
{ | |
string $jnts[] = `ls -sl -type "joint"`; | |
textFieldButtonGrp -e -tx $jnts[0] $parentJoint; | |
} | |
// UI creator | |
global proc baryRigUI() | |
{ | |
// If window exists then delete it. Prevents multiple instances of the | |
// same window. | |
if (`window -q -ex bariRig`) deleteUI bariRig; | |
// Declares global strings. | |
global string $parentJoint, $jointName, $editName, $create; | |
// Makes window size to everything in it. | |
string $dialogBoxWindow = `window -t "Baricentric Rigger" -rtf 1 bariRig`; | |
columnLayout -adj 1; | |
frameLayout -l "Joints"; | |
columnLayout -adj 1; | |
$parentJoint = `textFieldButtonGrp -l "Parent Joint" -bl "Load Parent" -bc "loadParent( $parentJoint )"`; | |
$jointName = `textFieldButtonGrp -l "Joint Name" -cc "sizeName( $jointName )" -bl "Check Name" -bc "validName( $jointName, $editName, $create )"`; | |
$editName = `button -en 0 -l "Edit Name" -c "editName( $jointName, $editName, $create )"`; | |
setParent ..; | |
setParent ..; | |
$create = `button -l "Create Joint" -en 0 -c "getInfo( $parentJoint, $jointName )"`; | |
// Show the window. | |
showWindow $dialogBoxWindow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdCityGenV1.0.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: Generates a random city based on user /// | |
/// input. City can have aniamtion, controls are /// | |
/// in the "city" group node. /// | |
/// /// | |
/// USAGE: Source script then run: makeCityUI(); /// | |
/// /// | |
/// EDITS TO DO: Fix up the UI. /// | |
/// Edit white space. /// | |
/// /// | |
/// THINGS TO ADD: More variety of buildings and attach /// | |
/// shaders. /// | |
/// /// | |
/// VERSIONS: 1.0 - Nov 14, 2011 - Initial Release /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// NOTE: The Animation controls are in the top node for // | |
// each city you create. // | |
// // | |
//////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: buildCity /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the plots for the buildings // | |
// and does it in a way that prevents them from // | |
// intersecting. // | |
proc buildCity(int $citySize, int $buildSize, string $cityName, int $animate, int $refresh, int $buildMin, int $buildMax) | |
{ | |
// Setting up initial variables. This matrix had to have | |
// values assigned or maya would crash when adding it later on. | |
matrix $city[24][24] = << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>; | |
matrix $check[24][24]; | |
matrix $add[24][24]; | |
int $plotNum = 1; | |
int $area = pow($citySize, 2); | |
int $plotSize; | |
string $buildings[]; | |
string $plots[]; | |
// Creating groups for the parts. | |
// While plots_$count exists then $count++ and check again. | |
int $count = 1; | |
string $object = ("plots_"+$count); | |
while (`objExists $object`) | |
{ | |
$count ++; | |
$object = ("plots_"+$count); | |
} | |
string $plotGrp = `group -n $object -em`; | |
// While buildings_$count exists then $count++ and check again. | |
int $count = 1; | |
string $object = ("buildings_"+$count); | |
while (`objExists $object`) | |
{ | |
$count ++; | |
$object = ("buildings_"+$count); | |
} | |
string $bldngGrp = `group -n $object -em`; | |
group -n $cityName $plotGrp $bldngGrp; | |
// This while loops creats buildings while $ares is greater than 0. | |
while ($area > 0) | |
{ | |
// This loops shecks if plotsize is good. | |
int $good = 0; | |
while (! $good) | |
{ | |
// Generate a random plotsize based on total area | |
// and checks if it's less than or equal to the user input | |
// for building size squared . | |
$plotSize = rand(1, $area+1); | |
if ($plotSize <= (pow($buildSize, 2))) | |
{ | |
print ("PLOT: "+$plotSize+"\n"); | |
for ($d=1; $d<$buildSize+1; $d++) | |
{ | |
// Checks if $plotSize/$d is not a decimal and if it's <= $buildsize. | |
// If true break from loop and $good is 1. | |
if (((float($plotSize) / $d) == (int($plotSize) / $d)) && ((float($plotSize) / $d) <= $buildSize)) | |
{ | |
$good = 1; | |
break; | |
} | |
} | |
} | |
} | |
// Set values for $x and $z (length and width). | |
int $x = rand(1, ($buildSize+1)); | |
print ("X: "+$x+"\n"); | |
int $z = float($plotSize) / $x; | |
print ("Z: "+$z+"\n"); | |
// While $z is a decimal or greater than $buildSize set new values for $x and $z. | |
while (($z != (float($plotSize) / $x)) || ($z > $buildSize)) | |
{ | |
$x = rand(1, ($buildSize+1)); | |
print ("X: "+$x+"\n"); | |
$z = float($plotSize) / $x; | |
print ("Z: "+$z+"\n"); | |
} | |
int $countZ = 0; | |
int $countX = -1; | |
int $bad = 1; | |
// This loop checks for intersection in the plots. | |
while ($bad) | |
{ | |
// This checks the position of the leading $x and $z points, | |
// when they get to the end of the matrix they go back to the | |
// beginning drop down one row. | |
// If plot never fits, always intersects, then break from while loop | |
// this will cause it to get a new plotSize and try again. | |
if ($x+$countX == $citySize) | |
{ | |
$countX = 0; | |
if ($z+$countZ == $citySize) | |
{ | |
$bad = 1; | |
$countZ ++; | |
break; | |
}else{ | |
$countZ ++; | |
} | |
}else{ | |
$countX ++; | |
} | |
// Resets the check array. | |
$check = << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>; | |
// For the current plot, and positions put 1 in those spots in the matrix. | |
for ($za = 0+$countZ; $za<$z+$countZ; $za++) | |
{ | |
for ($xa = 0+$countX; $xa<$x+$countX; $xa++) | |
{ | |
$check[$za][$xa] = 1; | |
} | |
} | |
// Adds city matrix and check matrix | |
$add = $city + $check; | |
// Loop checks the add matrix, if any values are 2 then $bad is true | |
// and break from for loop to move plot. | |
for ($za = 0; $za<24; $za++) | |
{ | |
for ($xa = 0; $xa<24; $xa++) | |
{ | |
if ($add[$za][$xa] == 2) | |
{ | |
$bad = 1; | |
break; | |
}else{ | |
$bad = 0; | |
} | |
} | |
if ($bad) break; | |
} | |
} | |
// If not plot fit. | |
if (! $bad) | |
{ | |
// Add 1's to city matrix for new plot. | |
for ($za = 0+$countZ; $za<$z+$countZ; $za++) | |
{ | |
for ($xa = 0+$countX; $xa<$x+$countX; $xa++) | |
{ | |
$city[$za][$xa] = 1; | |
} | |
} | |
// Creates a poly plane for the plot, positions it, | |
// parents it to the plot group and refresh the viewpane. | |
string $block[] = `polyPlane -w $x -h $z -sx 1 -sy 1 -ch 0 -n ($cityName+"_plot_"+$plotNum)`; | |
$plots[($plotNum-1)] = $block[0]; | |
setAttr ($block[0]+".t") (((float($x)/2)+$countX)-($citySize/2)) 0 (((float($z)/2)+$countZ)-($citySize/2)); | |
parent $block[0] $plotGrp; | |
print $city; | |
if ($refresh) refresh -cv -f; | |
// Randomly choose a building type. | |
switch(int(rand(0,3))) | |
{ | |
case 0: | |
officeOne($x, $z, $countX, $countZ, $citySize, $cityName, $plotNum, $refresh, $buildMin, $buildMax); | |
break; | |
case 1: | |
officeTwo($x, $z, $countX, $countZ, $citySize, $cityName, $plotNum, $refresh, $buildMin, $buildMax); | |
break; | |
case 2: | |
officeThree($x, $z, $countX, $countZ, $citySize, $cityName, $plotNum, $refresh, $buildMin, $buildMax); | |
} | |
// Parent new building to the building group. | |
$buildings[($plotNum-1)] = ($cityName+"_building_"+$plotNum); | |
parent $buildings[$plotNum-1] $bldngGrp; | |
// Add 1 to plotNum and subtract plotSize from area. | |
$plotNum ++; | |
$area -= $plotSize; | |
} | |
} | |
// If animate was chosen in the UI then add expression to building. | |
if ($animate) | |
{ | |
animation($buildings, $plotNum, $cityName); | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: animation /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure adds the animation to the buildings // | |
// and adds the attributes to the top node. // | |
proc animation(string $buildings[], int $plotNum, string $cityName) | |
{ | |
// Adds attribute to control the frequency of the animation. | |
addAttr -at "float" -ln "frequency" -dv 2.00 -min 0.00 -max 5.00 -k 1 $cityName; | |
string $frequency = ($cityName+".frequency"); | |
// Adds attribute to control the number of waves in the city. | |
addAttr -at "float" -ln "wave" -dv 1 -min 0.1 -max 20.00 -k 1 $cityName; | |
string $wave = ($cityName+".wave"); | |
// Adds attribute to control the height of the buildings. | |
addAttr -at "float" -ln "height" -dv 10 -min 0.0 -max 15.0 -k 1 $cityName; | |
string $height = ($cityName+".height"); | |
// Adding an enum attribute to the city, this will be used to control which animation the user wants. | |
addAttr -at enum -en "None:Sine Wave:Radial Sine Wave" -ln "animationType" -r 1 $cityName; | |
string $animType = ($cityName+".animationType"); | |
setAttr $animType -cb 1 1; | |
// For each building created, give it an expression. | |
for ($i = 1; $i < $plotNum; $i++) | |
{ | |
expression -n ("building_"+$i+"_bounce") -s ( | |
"if ("+$animType+" == 0)\n"+ | |
"{\n"+ | |
" scaleY = 1;\n"+ | |
"}else if ("+$animType+" == 1){\n"+ | |
" scaleY = abs(sin("+$frequency+"*time-("+$i+"*3.1415926)/((2*"+($plotNum-1)+")/"+$wave+"))*"+$height+");\n"+ | |
"}else if ("+$animType+" == 2){\n"+ | |
" scaleY = abs(sin("+$frequency+"*time-((pow(abs(translateX), 2)+pow(abs(translateZ), 2))*3.1415926)/((2*"+($plotNum-1)+")/("+$wave+"*5)))*"+$height+");\n"+ | |
"}") -o ($buildings[$i-1]); | |
} | |
select $cityName; | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: officeOne /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure models a building based on given // | |
// values from the plot and chooses a random number of // | |
// floors. First floor has four doors and the other // | |
// floors are either extruded in or extruding every other // | |
// face for windows. // | |
proc officeOne(int $x, int $z, int $countX, int $countZ, int $citySize, string $cityName, int $num, int $refresh, int $buildMin, int $buildMax) | |
{ | |
// $y is number of floors. | |
int $y = rand($buildMin, $buildMax); | |
// Create a plane and positions it. | |
string $office[] = `polyPlane -ch 0 -w ($x-.25) -h ($z-.25) -sx ($x*9) -sy ($z*9) -n ($cityName+"_building_"+$num)`; | |
setAttr ($office[0]+".t") (((float($x)/2)+$countX)-($citySize/2)) 0 (((float($z)/2)+$countZ)-($citySize/2)); | |
// Gets the number of faces on the plane for top and bottom | |
// minus one. Then refresh the viewpane. | |
int $faces = ($x*9)*($z*9)-1; | |
int $topBottom = $faces*2+1; | |
if ($refresh) refresh -cv -f; | |
// For the number of floors extrude up and refresh the view. | |
for ($i = 0; $i < $y; $i++) | |
{ | |
polyExtrudeFacet -ch 0 -ltz 0.091 -sma 0 ($office[0]+".f[0:"+$faces+"]"); | |
if ($refresh) refresh -cv -f; | |
select -cl; | |
} | |
// Set variables. | |
int $done = $topBottom; | |
int $selectX; | |
int $selectZ; | |
// loops sets select X and Z this is for finding | |
// the middle face on the first floor. | |
for ($i = 1; $i < 3; $i++) | |
{ | |
switch ($i) | |
{ | |
case 1: | |
$selectX = (($x*9)+1)/2; | |
break; | |
case 2: | |
$selectZ = (($z*9)+1)/2; | |
break; | |
} | |
} | |
// Find the face for each door(middle face on first floor). | |
// And add to done. | |
int $door1 = ($done+$selectX+1); | |
$done += ($x*9)+1; | |
int $door2 = ($done+($selectZ*2-1)); | |
int $door3 = ($done+($selectZ*2-2)); | |
$done += ($z*9)*2-2; | |
int $door4 = ($done+$selectX); | |
$done += ($x*9)+1; | |
// Extrude doors and refresh. | |
polyExtrudeFacet -ch 0 -ltz -0.02 -ls 0.507678 0.769128 1 -sma 0 ($office[0]+".f["+$door1+"]") ($office[0]+".f["+$door2+"]") ($office[0]+".f["+$door3+"]") ($office[0]+".f["+$door4+"]"); | |
if ($refresh) refresh -cv -f; | |
// For loop operates on the rest of the floors | |
int $level = (($x*9)+($z*9))*2; | |
for ($i = 1; $i<$y; $i++) | |
{ | |
// If odd extrude in whole floor, if even | |
// extrude in every other window. | |
int $section[] = {$done+1, $done+$level}; | |
if ((float($i)/2) == (int($i)/2)) | |
{ | |
// Because of the way Maya generates faces from extruding | |
// the pattern for selecting faces can be confusing. | |
select -cl; | |
int $count2 = 2; | |
int $tgl = 0; | |
// Loop operates on all the faces on the floor and | |
// selects every other. | |
for ($s = 0; $s < $level-1; $s++) | |
{ | |
// If not first face, start to toggle. | |
// Toggle is used to select faces on the side | |
// of the building. | |
if ($s > 0) | |
{ | |
if ($count2 <2) | |
{ | |
$count2 ++; | |
}else{ | |
$count2 = 1; | |
if ($tgl) | |
{ | |
$tgl = 0; | |
}else{ | |
$tgl = 1; | |
} | |
} | |
} | |
// $count is current face. | |
int $count = ($s+1)+$done; | |
// if a front face and even then select. | |
if ($s < ($x*9)) | |
{ | |
if (($s > 1) && ((float($s)/2) == (int($s)/2))) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
// If a side face and toggle is on then select. | |
// Face creation alternates sides so toggle is true twice | |
// then false twice. | |
}else if ((($s > ($x*9)+1) && ($s < $level-($x*9+2))) && ($tgl)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
// If a back face and odd then select. | |
}else if ($s > $level-($x*9+1)) | |
{ | |
if ((float($s)/2) != (int($s)/2)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
} | |
} | |
// Get selection and extrude, then refresh view. | |
string $windows[] = `ls -sl`; | |
polyExtrudeFacet -ch 0 -ltz -0.048 -ls 0.755657 0.819903 0 -sma 0 $windows; | |
if ($refresh) refresh -cv -f; | |
}else{ | |
// Extrudes whole floor then refresh view. | |
polyExtrudeFacet -ch 0 -ltz -0.04 -ls 0.313056 0.313056 1 -sma 0 ($office[0]+".f["+$section[0]+":"+$section[1]+"]"); | |
if ($refresh) refresh -cv -f; | |
} | |
// Add level (number of faces on floor) to done. | |
$done += $level; | |
} | |
select -cl; | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: officeTwo /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure models a building based on given // | |
// values from the plot and chooses a random number of // | |
// floors. Similar to officeOne, but it's all everyother // | |
// face for windows and the windows stagger. // | |
proc officeTwo(int $x, int $z, int $countX, int $countZ, int $citySize, string $cityName, int $num, int $refresh, int $buildMin, int $buildMax) | |
{ | |
int $y = rand($buildMin, $buildMax); | |
string $office[] = `polyPlane -ch 0 -w ($x-.25) -h ($z-.25) -sx ($x*9) -sy ($z*9) -n ($cityName+"_building_"+$num)`; | |
setAttr ($office[0]+".t") (((float($x)/2)+$countX)-($citySize/2)) 0 (((float($z)/2)+$countZ)-($citySize/2)); | |
int $faces = ($x*9)*($z*9)-1; | |
int $topBottom = $faces*2+1; | |
if ($refresh) refresh -cv -f; | |
select -cl; | |
for ($i = 0; $i < $y; $i++) | |
{ | |
polyExtrudeFacet -ch 0 -ltz 0.091 -sma 0 ($office[0]+".f[0:"+$faces+"]"); | |
if ($refresh) refresh -cv -f; | |
select -cl; | |
} | |
int $done = $topBottom; | |
int $level = (($x*9)+($z*9))*2; | |
for ($i = 1; $i<$y+1; $i++) | |
{ | |
if ((float($i)/2) == (int($i)/2)) | |
{ | |
select -cl; | |
int $count2 = 2; | |
int $tgl = 0; | |
for ($s = 0; $s < $level-1; $s++) | |
{ | |
if ($s > 0) | |
{ | |
if ($count2 <2) | |
{ | |
$count2 ++; | |
}else{ | |
$count2 = 1; | |
if ($tgl) | |
{ | |
$tgl = 0; | |
}else{ | |
$tgl = 1; | |
} | |
} | |
} | |
int $count = ($s+1)+$done; | |
if ($s < ($x*9)) | |
{ | |
if (($s > 1) && ((float($s)/2) == (int($s)/2))) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
}else if ((($s > ($x*9)+1) && ($s < $level-($x*9+2))) && ($tgl)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
}else if ($s > $level-($x*9+1)) | |
{ | |
if ((float($s)/2) != (int($s)/2)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
} | |
} | |
string $windows[] = `ls -sl`; | |
polyExtrudeFacet -ch 0 -ltz -0.024 -ls 0.45 0.55 0 -sma 0 $windows; | |
if ($refresh) refresh -cv -f; | |
}else{ | |
select -cl; | |
int $count2 = 2; | |
int $tgl = 1; | |
for ($s = 0; $s < $level-1; $s++) | |
{ | |
if ($s > 0) | |
{ | |
if ($count2 <2) | |
{ | |
$count2 ++; | |
}else{ | |
$count2 = 1; | |
if ($tgl) | |
{ | |
$tgl = 0; | |
}else{ | |
$tgl = 1; | |
} | |
} | |
} | |
int $count = ($s+1)+$done; | |
if ($s < ($x*9)) | |
{ | |
if (($s > 1) && ((float($s)/2) != (int($s)/2))) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
}else if ((($s > ($x*9)+1) && ($s < $level-($x*9+2))) && ($tgl)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
}else if (($s > $level-($x*9)-1) && ($s < $level-2)) | |
{ | |
if ((float($s)/2) == (int($s)/2)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
} | |
} | |
string $windows[] = `ls -sl`; | |
polyExtrudeFacet -ch 0 -ltz -0.024 -ls 0.45 0.55 0 -sma 0 $windows; | |
if ($refresh) refresh -cv -f; | |
} | |
$done += $level; | |
} | |
select -cl; | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: officeThree ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure models a building based on given // | |
// values from the plot and chooses a random number of // | |
// floors. First floor has four doors and the other // | |
// floors are either extruded in and has windows or // | |
// extruding every other face for windows. // | |
proc officeThree(int $x, int $z, int $countX, int $countZ, int $citySize, string $cityName, int $num, int $refresh, int $buildMin, int $buildMax) | |
{ | |
// $y is number of floors. | |
int $y = rand($buildMin, $buildMax); | |
// Create a plane and positions it. | |
string $office[] = `polyPlane -ch 0 -w ($x-.25) -h ($z-.25) -sx ($x*9) -sy ($z*9) -n ($cityName+"_building_"+$num)`; | |
setAttr ($office[0]+".t") (((float($x)/2)+$countX)-($citySize/2)) 0 (((float($z)/2)+$countZ)-($citySize/2)); | |
// Gets the number of faces on the plane for top and bottom | |
// minus one. Then refresh the viewpane. | |
int $faces = ($x*9)*($z*9)-1; | |
int $topBottom = $faces*2+1; | |
if ($refresh) refresh -cv -f; | |
// For the number of floors extrude up and refresh the view. | |
for ($i = 0; $i < $y; $i++) | |
{ | |
polyExtrudeFacet -ch 0 -ltz 0.091 -sma 0 ($office[0]+".f[0:"+$faces+"]"); | |
if ($refresh) refresh -cv -f; | |
select -cl; | |
} | |
// Set variables. | |
int $done = $topBottom; | |
int $selectX; | |
int $selectZ; | |
// loops sets select X and Z this is for finding | |
// the middle face on the first floor. | |
for ($i = 1; $i < 3; $i++) | |
{ | |
switch ($i) | |
{ | |
case 1: | |
$selectX = (($x*9)+1)/2; | |
break; | |
case 2: | |
$selectZ = (($z*9)+1)/2; | |
break; | |
} | |
} | |
// Find the face for each door(middle face on first floor). | |
// And add to done. | |
int $door1 = ($done+$selectX+1); | |
$done += ($x*9)+1; | |
int $door2 = ($done+($selectZ*2-1)); | |
int $door3 = ($done+($selectZ*2-2)); | |
$done += ($z*9)*2-2; | |
int $door4 = ($done+$selectX); | |
$done += ($x*9)+1; | |
// Extrude doors and refresh. | |
polyExtrudeFacet -ch 0 -ltz -0.02 -ls 0.507678 0.769128 1 -sma 0 ($office[0]+".f["+$door1+"]") ($office[0]+".f["+$door2+"]") ($office[0]+".f["+$door3+"]") ($office[0]+".f["+$door4+"]"); | |
if ($refresh) refresh -cv -f; | |
// For loop operates on the rest of the floors | |
int $level = (($x*9)+($z*9))*2; | |
for ($i = 1; $i<$y; $i++) | |
{ | |
// If odd extrude in whole floor, if even | |
// extrude in every other window. | |
int $section[] = {$done+1, $done+$level}; | |
if ((float($i)/2) == (int($i)/2)) | |
{ | |
// Extrudes whole floor then refresh view. | |
polyExtrudeFacet -ch 0 -ltz -0.04 -ls 0.313056 0.9 1 -sma 0 ($office[0]+".f["+$section[0]+":"+$section[1]+"]"); | |
if ($refresh) refresh -cv -f; | |
// Because of the way Maya generates faces from extruding | |
// the pattern for selecting faces can be confusing. | |
select -cl; | |
int $count2 = 2; | |
int $tgl = 0; | |
// Loop operates on all the faces on the floor and | |
// selects every other. | |
for ($s = 0; $s < $level-1; $s++) | |
{ | |
// If not first face, start to toggle. | |
// Toggle is used to select faces on the side | |
// of the building. | |
if ($s > 0) | |
{ | |
if ($count2 <2) | |
{ | |
$count2 ++; | |
}else{ | |
$count2 = 1; | |
if ($tgl) | |
{ | |
$tgl = 0; | |
}else{ | |
$tgl = 1; | |
} | |
} | |
} | |
// $count is current face. | |
int $count = ($s+1)+$done; | |
// if a front face and even then select. | |
if ($s < ($x*9)) | |
{ | |
if (($s > 1) && ((float($s)/2) == (int($s)/2))) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
// If a side face and toggle is on then select. | |
// Face creation alternates sides so toggle is true twice | |
// then false twice. | |
}else if ((($s > ($x*9)+1) && ($s < $level-($x*9+2))) && ($tgl)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
// If a back face and odd then select. | |
}else if ($s > $level-($x*9+1)) | |
{ | |
if ((float($s)/2) != (int($s)/2)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
} | |
} | |
// Get selection and extrude, then refresh view. | |
string $windows[] = `ls -sl`; | |
polyExtrudeFacet -ch 0 -ltz -0.048 -ls 0.755657 0.819903 0 -sma 0 $windows; | |
if ($refresh) refresh -cv -f; | |
}else{ | |
select -cl; | |
int $count2 = 2; | |
int $tgl = 1; | |
for ($s = 0; $s < $level-1; $s++) | |
{ | |
if ($s > 0) | |
{ | |
if ($count2 <2) | |
{ | |
$count2 ++; | |
}else{ | |
$count2 = 1; | |
if ($tgl) | |
{ | |
$tgl = 0; | |
}else{ | |
$tgl = 1; | |
} | |
} | |
} | |
int $count = ($s+1)+$done; | |
if ($s < ($x*9)) | |
{ | |
if (($s > 1) && ((float($s)/2) != (int($s)/2))) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
}else if ((($s > ($x*9)+1) && ($s < $level-($x*9+2))) && ($tgl)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
}else if (($s > $level-($x*9)-1) && ($s < $level-2)) | |
{ | |
if ((float($s)/2) == (int($s)/2)) | |
{ | |
select -tgl ($office[0]+".f["+($count)+"]"); | |
} | |
} | |
} | |
string $windows[] = `ls -sl`; | |
polyExtrudeFacet -ch 0 -ltz -0.024 -ls 0.755657 0.819903 0 -sma 0 $windows; | |
if ($refresh) refresh -cv -f; | |
} | |
// Add level (number of faces on floor) to done. | |
$done += $level; | |
} | |
select -cl; | |
} | |
// This procedure gets the values to be used in the creation procedure. | |
proc buttonAction(string $city, string $exprChkBx, string $cityField, string $buildField, string $buildMin, string $buildMax) | |
{ | |
// Gets values. | |
string $cityName = `textFieldButtonGrp -q -tx $city`; | |
int $citySize = `intSliderGrp -q -v $cityField`; | |
int $buildSize = `intSliderGrp -q -v $buildField`; | |
int $animate = `checkBoxGrp -q -v1 $exprChkBx`; | |
int $refresh = `checkBoxGrp -q -v2 $exprChkBx`; | |
int $min = `intSliderGrp -q -v $buildMin`; | |
int $max = `intSliderGrp -q -v $buildMax`; | |
// While $cityName_$count exists then $count++ and check again. | |
int $count = 1; | |
string $object = ($cityName+"_"+$count); | |
while (`objExists $object`) | |
{ | |
$count ++; | |
$object = ($cityName+"_"+$count); | |
} | |
$cityName = $object; | |
// If statements check the values for user input error. | |
if ($citySize > 24) | |
{ | |
$citySize = 24; | |
}else if ($citySize < 1){ | |
$citySize = 1; | |
} | |
if ($buildSize > $citySize) | |
{ | |
$buildSize = $citySize; | |
}else if ($buildSize < 1){ | |
$buildSize = 1; | |
} | |
if ($max > 40) | |
{ | |
$max = 40; | |
}else if ($max < 1){ | |
$max = 1; | |
} | |
if ($min > 40) | |
{ | |
$min = 40; | |
}else if ($min < 1){ | |
$min = 1; | |
} | |
if($max < $min) $min = $max; | |
if($min > $max) $max = $min; | |
// Run whichButton procedure. | |
buildCity($citySize, $buildSize, $cityName, $animate, $refresh, $min, $max); | |
} | |
// Proc checks if max slider goes below min and adjusts min with it. | |
proc changeMin(string $buildMin, string $buildMax) | |
{ | |
int $min = `intSliderGrp -q -v $buildMin`; | |
int $max = `intSliderGrp -q -v $buildMax`; | |
if($max < $min) intSliderGrp -e -v $max $buildMin; | |
} | |
// Proc checks if min slider goes above miax and adjusts max with it. | |
proc changeMax(string $buildMin, string $buildMax) | |
{ | |
int $min = `intSliderGrp -q -v $buildMin`; | |
int $max = `intSliderGrp -q -v $buildMax`; | |
if($min > $max) intSliderGrp -e -v $min $buildMax; | |
} | |
// Proc adjusts building size slider's -max to be the value of | |
// citySize slider. | |
proc changeBuild(string $cityField, string $buildField) | |
{ | |
int $max = `intSliderGrp -q -v $cityField`; | |
intSliderGrp -e -max $max -fmx $max -v $max $buildField; | |
} | |
// This procedure disables the create and edit name button and | |
// enables the text field if user wants to edit name. | |
// This requires the user to recheck the name before creating the | |
// city. | |
proc editName(string $cityName, string $editName, string $create) | |
{ | |
textFieldButtonGrp -e -ed 1 $cityName; | |
button -e -en 0 $editName; | |
button -e -en 0 $create; | |
} | |
// This procedure checks if the name is valid and substrings the name to 16 characters. | |
proc validName(string $cityName, string $editName, string $create) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $cityName`; | |
// If name is more than 16 characters then substring the first 16. | |
int $size = size($testString); | |
if ($size>16) | |
{ | |
$testString = `substring $testString 1 16`; | |
textFieldButtonGrp -e -tx $testString $cityName; | |
} | |
// Returns the valid characters in the name. | |
string $matchingPart = `match "^[a-zA-Z][0-9a-zA-Z_]*$" $testString`; | |
// If matched name is the same as name goodmatch = 1 else 0. | |
int $goodMatch = ! `strcmp $matchingPart $testString`; | |
// If no name is given then goodmatch is 0. | |
if ($testString == "") | |
{ | |
$goodMatch = 0; | |
} | |
// If goodmatch is 1 then disable textField and enable edit name and create buttons. | |
// Else give warning. | |
if ($goodMatch) | |
{ | |
textFieldButtonGrp -e -ed 0 $cityName; | |
button -e -en 1 $editName; | |
button -e -en 1 $create; | |
}else{ | |
confirmDialog -t "Warning" -m "Invalid city name." -ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
} | |
} | |
// Substrings the name to 16 characters if name was greater than 16 characters. | |
proc sizeName(string $cityName) | |
{ | |
string $testString = `textFieldButtonGrp -q -tx $cityName`; | |
int $size = size($testString); | |
if ($size>16) | |
{ | |
$testString = `substring $testString 1 16`; | |
textFieldButtonGrp -e -tx $testString $cityName; | |
} | |
} | |
//UI Creator | |
global proc makeCityUI() | |
{ | |
if (`window -q -ex makeCityUI`) | |
{ | |
deleteUI makeCityUI; | |
} | |
//Declare Global Strings | |
global string $cityField; | |
global string $buildField; | |
global string $exprChkBx; | |
global string $create; | |
global string $destroy; | |
global string $cityName; | |
global string $editName; | |
global string $buildMin; | |
global string $buildMax; | |
//Makes window fit around content | |
string $dialogBoxWindow = `window -t "City Generator" -rtf 1 makeCityUI`; | |
columnLayout -adj 1; | |
frameLayout -l "Name"; | |
columnLayout -adj 1; | |
// TextField is to name the city, on change the text is dropped to 16 characters if it was more. | |
// Check name button checks if the name is valid. | |
// Edit name button allows user to edit the entered name. | |
$cityName = `textFieldButtonGrp -l "City Name" -cc "sizeName($cityName)" -bl "Check Name" -bc "validName($cityName, $editName, $create)"`; | |
$editName = `button -en 0 -l "Edit Name" -c "editName($cityName, $editName, $create)"`; | |
setParent ..; | |
setParent ..; | |
frameLayout -l "Size"; | |
columnLayout -adj 1; | |
//This creates the int sliders for the building and city size, it creates the UI | |
$cityField = `intSliderGrp -f 1 -l "City Size" -min 1 -max 24 -fmn 1 -fmx 24 -v 24 -dc "changeBuild($cityField, $buildField)"`; | |
$buildField = `intSliderGrp -f 1 -l "Building Size" -min 1 -max 24 -fmn 1 -fmx 24 -v 4`; | |
$buildMin = `intSliderGrp -f 1 -l "Minimum Building Floors" -min 1 -max 30 -fmn 1 -fmx 30 -v 1 -dc "changeMax($buildMin, $buildMax)"`; | |
$buildMax = `intSliderGrp -f 1 -l "Maximum Building Floors" -min 1 -max 30 -fmn 1 -fmx 30 -v 20 -dc "changeMin($buildMin, $buildMax)"`; | |
setParent ..; | |
setParent ..; | |
frameLayout -l "Options"; | |
columnLayout -adj 1; | |
// Check box is to animate the city and refresh the viewpane. | |
$exprChkBx = `checkBoxGrp -ncb 2 -la2 "Animate" "Refresh" -va2 0 1`; | |
setParent ..; | |
setParent ..; | |
frameLayout -l "Generate"; | |
columnLayout -adj 1; | |
// Create a "creation" button | |
$create = `button -en 0 -l "Create" -c "buttonAction($cityName, $exprChkBx, $cityField, $buildField, $buildMin, $buildMax)"`; | |
// Create a "destruction" button | |
$destroy = `button -label "Destroy / Clear Scene" -align "center" -command "file -f -new;"`; | |
//Show window | |
showWindow $dialogBoxWindow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdGrassV0.1.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: Populates a mesh named ground with grass. /// | |
/// Each grass mesh is attached to a vertex and has /// | |
/// has a joint chain and an expression. When the /// | |
/// When the vertices on the mesh are changed the /// | |
/// grass adjusts which way it faces and adjusts its /// | |
/// bend/curl. /// | |
/// /// | |
/// USAGE: Source script then run: grass( 1, 1 ); /// | |
/// /// | |
/// EDITS TO DO: Add a conditional to limit the bends, even /// | |
/// more, when the y normal is close to 1 or -1. /// | |
/// Fix a few of the loops to make them more /// | |
/// intuitive. /// | |
/// Edit White space. /// | |
/// /// | |
/// THINGS TO ADD: Menu, option for using NURBS, option for /// | |
/// only using selected vertices, option to use a /// | |
/// selected mesh as the grass, option to not use /// | |
/// joints and only populate. /// | |
/// A system for using curves and not joints. /// | |
/// /// | |
/// VERSIONS: 0.1 - Oct 12, 2011 - Initial Prototype /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
////////////////// Global Procedure: grass ///////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// Main call procedure, source the script then run this. // | |
// Include two float values for the maximum bend in the // | |
// grass and the minimum, this acts as a range for the // | |
// bend. // | |
// // | |
// Default: grass( 1, 1 ); // | |
// Zero ( 0 ), cannot be used for the bend minimum. // | |
// // | |
// NOTE: The UVs of the ground mesh need to be layed // | |
// out, before running the script, this doesn't // | |
// need to be done for the primitive meshes. // | |
// Transforms need to be frozen to update the // | |
// positions of the vertices, do this before // | |
// applying any animation to the mesh. // | |
// Animation, lighting and anything else should be // | |
// before running this script, as it can be // | |
// PROCESSOR HEAVY. Depending on the number of // | |
// vertices in the mesh. // | |
global proc grass(float $bendMax, float $bendMin) | |
{ | |
// Sets some initial strings to be used in the | |
// procedures. | |
string $ground = "ground"; | |
string $grass = "grass"; | |
string $grassTexture; | |
string $grassS = "grassShader"; | |
string $grassSG = ($grassS+"SG"); | |
string $joints[]; | |
string $grassGrps = "grass_grps"; | |
// Checks if bendMin is 0. | |
if ($bendMin == 0) | |
{ | |
error "Minimum bend cannot equal zero, cannot divide by zero.\n"; | |
} | |
// Runs procedures, some return values to be used later. | |
groundCheck($ground); | |
$grassTexture = grassTexturePath(); | |
createGrass($grass, $grassS, $grassSG, $grassTexture); | |
$joints = createJoints($grass); | |
populateGrass($ground, $grass, $joints, $grassGrps, $bendMax, $bendMin); | |
// After everything else is done, groups the grass and | |
// ground under world and turns off inherits transform | |
// on the grass grp. | |
group -n "world" $ground $grassGrps; | |
setAttr ($grassGrps+".inheritsTransform") 0; | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: groundCheck ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure checks to see if a mesh named // | |
// ground exists. If it does it freezes the // | |
// transformations, this is to update the uv. If not // | |
// then the script errors out and asks for a mesh named // | |
// ground. // | |
proc groundCheck(string $ground) | |
{ | |
if (`objExists $ground`) | |
{ | |
print "Ground exists.\n"; | |
}else{ | |
error "No ground exists. Create a mesh named ground and try again.\n"; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////// Procedure: grassTexturePath /////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedures allows the user to set a texture // | |
// to be applied to the grass. // | |
proc string grassTexturePath() | |
{ | |
print "Select a texture for the grass.\n"; | |
// This string is for the file filters. | |
string $filters = "All Files (*.*);;JPEG (*.jpg);;Targa (*.tga);;Tiff (*.tiff);;IFF (*.iff);;GIF (*.gif);;Bitmap (*.bmp)"; | |
// Queries the current set workspace/project directory path. | |
string $dir = `workspace -q -dir`; | |
// Opens the file dialog box, if nothing is selected or | |
// the selection is canceled then the user is asked if | |
// he/she wants to continue without a texture, if not | |
// then the script errors out to be reran. | |
string $grassTexture[] = `fileDialog2 -ds 2 -cap "Open Texture" -dir $dir -ff $filters -sff "All Files" -fm 1`; | |
string $confirm; | |
if ($grassTexture[0] == "") | |
{ | |
$confirm = `confirmDialog -t "No Texture" -m "No texture was selected. Are you sure you want to\n continue without a texture?" -ma "center" -b "Yes" -b "No" -db "Yes" -cb "No" -ds "No" -icn "question"`; | |
} | |
if ($confirm == "No") | |
{ | |
error "Restart the script and choose a texture.\n"; | |
} | |
// Returns the file path for the texture. | |
return $grassTexture[0]; | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: createGrass ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the master grass geometry // | |
// that the attached grass are copied from. The UVs are // | |
// adjusted, a new blinn shading network is created and // | |
// it attaches the chosen texture to the grass. // | |
proc createGrass(string $grass, string $grassS, string $grassSG, string $grassTexture) | |
{ | |
// Creates the master grass mesh. | |
polyPlane -w 1 -h 8 -sx 1 -sy 8 -ax 0 0 1 -cuv 2 -ch 1 -n $grass; | |
xform -pivots 0 -4 0; | |
move -rpr 0 0 0; | |
select -r grass.e[3] grass.e[6] grass.e[9] grass.e[12] grass.e[15] grass.e[18] grass.e[21] grass.e[24] ; | |
scale -x 0.95404; | |
select -d grass.e[3] ; | |
scale -x 0.935408; | |
select -d grass.e[6] ; | |
scale -x 0.95808; | |
select -d grass.e[9] ; | |
scale -x 0.891177; | |
select -d grass.e[12] ; | |
scale -x 0.902911; | |
select -d grass.e[15] ; | |
scale -x 0.824543; | |
select -d grass.e[18] ; | |
scale -x 0.780672; | |
scale -x 0.949012; | |
select -d grass.e[21] ; | |
scale -x 0.456029; | |
polyCollapseEdge -ch 1 grass.e[24]; | |
select -r grass.e[21] ; | |
scale -x 0.778965; | |
select -r grass.e[18] ; | |
scale -x 0.908768; | |
select -r grass.e[15] ; | |
scale -x 0.926951; | |
select -r grass.e[12] ; | |
scale -x 0.944705; | |
select -r grass.e[9] ; | |
scale -x 0.94611; | |
select -r grass.e[6] ; | |
scale -x 0.9656; | |
select -r grass.e[6] ; | |
scale -x 1.033333; | |
select -r grass.e[12] ; | |
scale -x 1; | |
select -cl; | |
// Projects the UVs and adjusts them. | |
polyAutoProjection -lm 0 -pb 0 -ibd 1 -cm 0 -l 2 -sc 1 -o 1 -p 6 -ps 0.2 -ws 0 grass.f[0:7]; | |
select -r grass.map[0:16] ; | |
setAttr "grassShape.uvPivot" -type double2 .5 0.5 ; | |
select -r grass.map[0:16] ; | |
setAttr "grassShape.uvPivot" -type double2 0.498274 0.5 ; | |
polyEditUV -u 0.435774 -v 0 ; | |
polyEditUV -pu 0.498274 -pv 0.5 -su 0.551282 -sv 1 ; | |
select -r grass.map[16] ; | |
setAttr "grassShape.uvPivot" -type double2 0.498274 0.922395 ; | |
polyEditUV -u 0 -v -0.075613 ; | |
select -r grassShape.map[14:15] ; | |
polyEditUV -pu 0.498274 -pv 0.873506 -su 0.75641 -sv 1 ; | |
// Deletes 4 edges to drop the poly count to 4. | |
polyDelEdge -cv true -ch 1 grass.e[3] grass.e[9] grass.e[15] grass.e[21]; | |
// Creates a new blinn shader and network. | |
shadingNode -asShader blinn -n $grassS; | |
sets -renderable true -noSurfaceShader true -empty -name $grassSG; | |
connectAttr -f grassShader.outColor grassShaderSG.surfaceShader; | |
select -r $grass; | |
hyperShade -a grassShader; | |
// Sets attributes for the new shader. | |
setAttr "grassShader.diffuse" 0.642; | |
setAttr "grassShader.eccentricity" 0.163; | |
setAttr "grassShader.specularRollOff" 0.276; | |
setAttr "grassShader.specularColor" -type double3 1 0.997 0.863 ; | |
// Creates a file node and place2dTexture node and | |
// connects their attributes. | |
shadingNode -asTexture file -n grassFile; | |
shadingNode -asUtility place2dTexture -n grassPlace2dTexture; | |
connectAttr -f ("grassPlace2dTexture.coverage") ("grassFile.coverage"); | |
connectAttr -f ("grassPlace2dTexture.translateFrame") ("grassFile.translateFrame"); | |
connectAttr -f ("grassPlace2dTexture.rotateFrame") ("grassFile.rotateFrame"); | |
connectAttr -f ("grassPlace2dTexture.mirrorU") ("grassFile.mirrorU"); | |
connectAttr -f ("grassPlace2dTexture.mirrorV") ("grassFile.mirrorV"); | |
connectAttr -f ("grassPlace2dTexture.stagger") ("grassFile.stagger"); | |
connectAttr -f ("grassPlace2dTexture.wrapU") ("grassFile.wrapU"); | |
connectAttr -f ("grassPlace2dTexture.wrapV") ("grassFile.wrapV"); | |
connectAttr -f ("grassPlace2dTexture.repeatUV") ("grassFile.repeatUV"); | |
connectAttr -f ("grassPlace2dTexture.offset") ("grassFile.offset"); | |
connectAttr -f ("grassPlace2dTexture.rotateUV") ("grassFile.rotateUV"); | |
connectAttr -f ("grassPlace2dTexture.noiseUV") ("grassFile.noiseUV"); | |
connectAttr -f ("grassPlace2dTexture.vertexUvOne") ("grassFile.vertexUvOne"); | |
connectAttr -f ("grassPlace2dTexture.vertexUvTwo") ("grassFile.vertexUvTwo"); | |
connectAttr -f ("grassPlace2dTexture.vertexUvThree") ("grassFile.vertexUvThree"); | |
connectAttr -f ("grassPlace2dTexture.vertexCameraOne") ("grassFile.vertexCameraOne"); | |
connectAttr ("grassPlace2dTexture.outUV") ("grassFile.uv"); | |
connectAttr ("grassPlace2dTexture.outUvFilterSize") ("grassFile.uvFilterSize"); | |
defaultNavigation -force true -connectToExisting -source ("grassFile") -destination grassShader.color; | |
// Sets the file texture to the selected image/texture. | |
setAttr grassFile.fileTextureName -typ "string" $grassTexture; | |
// Freezes the transforms and deletes the history on | |
// the master grass. | |
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $grass; | |
delete -ch grass; | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: createJoints ///////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure creates the master joints that the // | |
// master grass is then bound to. // | |
proc string[] createJoints(string $grass) | |
{ | |
// Gets the bounding box of the master grass and | |
// positions the first joint to the minimumY and the | |
// end joint to the maximumY. | |
float $grassBox[] = `exactWorldBoundingBox $grass`; | |
string $selJnt[]; | |
$selJnt[0] = `joint -p 0 $grassBox[1] 0 -n grass_1_jnt -rad 0.5`; | |
$selJnt[1] = `joint -p 0 $grassBox[4] 0 -n grass_end_jnt -rad 0.5`; | |
// Gets the absolute positions of the new joints. | |
vector $sjPos = (`joint -q -p $selJnt[0]`); | |
vector $ejPos = (`joint -q -p $selJnt[1]`); | |
string $crJnt[]; | |
// Clears the selection and sets $seg to 4. | |
select -cl; | |
int $seg=4; | |
// For loop creates joints in the proper position | |
// and assigns them to an array and parents the first | |
// created joint to the start joint and parents the | |
// end joint to the last created joint. | |
for ($i=$seg; $i>1; $i--) | |
{ | |
// This gets the value to use in the $crJnt array. | |
// Then creates a new joint based on the positions | |
// of the start and end joint and which segment joint | |
// is being created. | |
int $x = abs ($i-$seg); | |
$crJnt[$x] = `joint -p ((((($sjPos.x)-($ejPos.x))/$seg)*($i-1))+($ejPos.x)) ((((($sjPos.y)-($ejPos.y))/$seg)*($i-1))+($ejPos.y)) ((((($sjPos.z)-($ejPos.z))/$seg)*($i-1))+($ejPos.z)) -n ("grass_"+($x+2)+"_jnt") -rad 0.5`; | |
// Conditional checks if first segment joint is | |
// being created and if true it is parented to | |
// the start joint. Then checks if the last | |
// segment joint is being created and if true | |
// the end joint gets parented to the last segment | |
// joint. | |
if ($x==0) | |
{ | |
parent $crJnt[$x] $selJnt[0]; | |
}else if (($x+1)==($seg-1)) { | |
parent $selJnt[1] $crJnt[$x]; | |
} | |
} | |
// Orients the joints to XYZ with the secondary axis | |
// pointing in -z. | |
joint -e -oj xyz -secondaryAxisOrient zdown -ch -zso $selJnt[0]; | |
// Binds the master grass mesh to the master joints. | |
bindSkin -tsb $selJnt[0] $crJnt[0] $crJnt[1] $crJnt[2] $grass; | |
// Puts the master start joint and the first 3 segment | |
// joints into an array then returns the array. | |
string $joints[] = {$selJnt[0], $crJnt[0], $crJnt[1], $crJnt[2]}; | |
return $joints; | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////// Procedure: populateGrass ///////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure moves the master grass to a vertex // | |
// on the ground mesh and bends it based on the inputed // | |
// bendMax, bendMin and the y normal of the vertex. // | |
// the master grass, mesh and joints, are duplicated // | |
// and the duplicated mesh is bound to the duplicated // | |
// joints. The new start joint is then normalConstrained // | |
// to the ground mesh. A transform node is created and // | |
// pointOnPolyConstrained to the ground mesh, the new // | |
// joint chain is then parented to the transform node. // | |
// The transform node and the grass mesh are then grouped // | |
// together and that group is parented to a main group // | |
// for all grass groups. An expression is then created // | |
// for the grass joints so that their bend is updated // | |
// when the normal of the ground vertex is changed. // | |
// This is done for all vertices on the ground mesh. // | |
proc populateGrass(string $ground, string $grass, string $joints[], string $grassGrps, float $bendMax, float $bendMin) | |
{ | |
// Bend min is inversed so that a smaller given number | |
// brings the minimum bend closer to zero. | |
$bendMin = 1/$bendMin; | |
// Creates a closestPointOnMesh node and the outMesh | |
// attr from the ground is connected to the inMesh | |
// and the translate of the master start joint is | |
// connected to the inPosition. | |
string $cpom = `createNode closestPointOnMesh -ss`; | |
connectAttr ($ground+"Shape.outMesh") ($cpom+".inMesh"); | |
connectAttr ($joints[0]+".translate") ($cpom+".inPosition"); | |
// Selects all vertices of the ground mesh and puts | |
// them into an array, then gets teh size of that array. | |
// The selection is cleared. | |
select -r "ground.vtx[*]"; | |
string $groundVtx[] = `ls -sl -fl`; | |
float $groundSize = size($groundVtx); | |
select -cl; | |
// A group is created, this is for all the grass groups. | |
group -n $grassGrps -em; | |
string $grassJnt[]; | |
// This Loops does what is specified in the procedure | |
// description. It loops for all vertices in the | |
// ground mesh. | |
for ($s=0; $s<$groundSize; $s++) | |
{ | |
// Queries the normals of the current vertex. | |
float $vtxNorm[] = `polyNormalPerVertex -q -xyz $groundVtx[$s]`; | |
// If the vertex is between -0.5 and 0.5 it sets | |
// is to -.5 or 0.5 respectively. This prevents | |
// the grass from bending in on itself, but that | |
// can be changed if the bendMax is changed. | |
if (($vtxNorm[1]<0.5)&&($vtxNorm[1]>(-0.5))) | |
{ | |
if ($vtxNorm[1]<0) | |
{ | |
$vtxNorm[1] = -0.5; | |
}else{ | |
$vtxNorm[1] = 0.5; | |
} | |
} | |
// This sets the randMin and randMax that the | |
// master joints use to randomize their rotations. | |
float $randMin = (-10*$bendMax)*(pow((1/$vtxNorm[1]),2)); | |
float $randMax = $randMin/(3*$bendMin); | |
// This randomly rotates the three master segment | |
// joints. To also rotate the start joint change | |
// $i=1 to $i=0. | |
for ($i=1; $i<4; $i++) | |
{ | |
setAttr ($joints[$i]+".rz") (rand($randMin,$randMax)); | |
} | |
// This queries the absolute translation of the | |
// current vertex and moves the master grass to | |
// that point. | |
float $posVtx[] = `xform -q -t $groundVtx[$s]`; | |
setAttr ($joints[0]+".translate") $posVtx[0] $posVtx[1] $posVtx[2]; | |
// The master grass mesh and joints are duplicated | |
// and the dupicate segment joints are put into an | |
// array. This array is used in the creation of | |
// the expression. | |
string $newGrass[] = `duplicate -rc $grass $joints[0]`; | |
for ($i=0; $i<3; $i++) | |
{ | |
$grassJnt[(($s*3)+$i)] = $newGrass[(2+$i)]; | |
} | |
// The new mesh is bound to the new joints, the new | |
// start joint is normalConstrained to the ground | |
// mesh and its pivot is set. | |
bindSkin -tsb $newGrass[1] $newGrass[2] $newGrass[3] $newGrass[4] $newGrass[0]; | |
string $normConst[] = `normalConstraint $ground $newGrass[1]`; | |
xform -piv $posVtx[0] $posVtx[1] $posVtx[2] $newGrass[1]; | |
// An empty node is created and moved to the current | |
// vertex, its transforms are then frozen. | |
string $null = `group -em -n ($newGrass[1]+"_grp")`; | |
setAttr ($null+".translate") $posVtx[0] $posVtx[1] $posVtx[2]; | |
makeIdentity -a 1 -t 1 -r 1 -s 1 $null; | |
// The empty node is pointOnPolyConstrained to the ground | |
// mesh and the constraint's U and V parameter are set | |
// to the current vertex, this information is received from | |
// the closestPointOnMesh node. The new grass start joint | |
// is parented to the empty node. | |
string $popc[] = `pointOnPolyConstraint $ground $null`; | |
float $pU = `getAttr ($cpom+".parameterU")`; | |
float $pV = `getAttr ($cpom+".parameterV")`; | |
setAttr ($popc[0]+".groundU0") $pU; | |
setAttr ($popc[0]+".groundV0") $pV; | |
parent $newGrass[1] $null; | |
// Groups the new grass mesh and transform node, with | |
// the joints, together, then parents this group node | |
// to the grass groups node. This it to organize the | |
// outliner. | |
string $grassGroup = `group -n ($newGrass[0]+"_grp") $newGrass[0] $null`; | |
parent $grassGroup $grassGrps; | |
// Expression is created to control the bend in the grass | |
// when the y normal of the vertex, the new grass is on, | |
// is changed. This expression is almost the same that | |
// was used earlier in the script to set the initial | |
// bends. | |
expression -n ("grass"+($s+1)+"_expr") -s | |
( | |
"float $vtxNorm[] = `polyNormalPerVertex -q -xyz "+$groundVtx[$s]+"`;\n"+ | |
"float $vtxNormPast;\n"+ | |
"float $yNorm;\n\n"+ | |
"if ($vtxNorm[1] != $vtxNormPast)\n"+ | |
"{\n"+ | |
"$yNorm = $vtxNorm[1];\n"+ | |
" if (($yNorm<0.5)&&($yNorm>(-0.5)))\n"+ | |
" {\n"+ | |
" if ($yNorm<0)\n"+ | |
" {\n"+ | |
" $yNorm = -0.5;\n"+ | |
" }else{\n"+ | |
" $yNorm = 0.5;\n"+ | |
" }\n"+ | |
" }\n"+ | |
" float $randMin = (-10*"+$bendMax+")*(pow((1/$yNorm),2));\n"+ | |
" float $randMax = $randMin/(3*"+$bendMin+");\n\n"+ | |
" "+$grassJnt[($s*3)]+".rz = (rand($randMin,$randMax));\n"+ | |
" "+$grassJnt[(($s*3)+1)]+".rz = (rand($randMin,$randMax));\n"+ | |
" "+$grassJnt[(($s*3)+2)]+".rz = (rand($randMin,$randMax));\n"+ | |
"}\n\n"+ | |
"$vtxNormPast = $vtxNorm[1];"); | |
} | |
// After all new grass is created the master grass, joints and | |
// closestPointOnMesh node are deleted. | |
delete $grass $joints[0] $cpom; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdScriptToolV0.1.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: This is a prototype script. A UI for /// | |
/// scripting. You press buttons to write your /// | |
/// script. though this system intends to be /// | |
/// intuitive. You can save and load scripts. /// | |
/// /// | |
/// USAGE: Source script then run: scriptUI(); /// | |
/// /// | |
/// EDITS TO DO: Edit white space. /// | |
/// /// | |
/// THINGS TO ADD: Well the script isn't finished yet, but I /// | |
/// plan on adding stuff so that you can search for /// | |
/// commands and their flags and insert them, with /// | |
/// a prompt for each selected flag. /// | |
/// Sections to add and insert variables and /// | |
/// procs it will keep track of them in your script /// | |
/// so you can be a bit more organized. This will /// | |
/// also work for loading scripts. /// | |
/// All buttons will have annotations so the /// | |
/// user understands how to use them. /// | |
/// Undo and Redo need to be added, along with /// | |
/// executing, sourcing, and making shelf buttons /// | |
/// from scripts. /// | |
/// Possible a system of error checking AND /// | |
/// fixing. /// | |
/// /// | |
/// VERSIONS: 0.1 - Nov 17, 2011 - Initial Prototype /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
//////////////////////////////////////////////////////////// | |
///////////////// Procedure: searchCommands //////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Search Commands is // | |
// pressed. It takes the search term in the search // | |
// commands text field and finds all matching strings in // | |
// the commands scroll list. // | |
proc searchCommands(string $mayaCommands[], string $searchCommand, string $commandListField) | |
{ | |
// Set nitial variables. | |
string $lowerCommand; | |
string $matchCommands[]; | |
int $matchNumber[]; | |
int $size = size($mayaCommands); | |
int $s = 0; | |
// Query the textField and tolower the term. | |
string $term = `textField -q -tx $searchCommand`; | |
$term = `tolower $term`; | |
// If term is not empty search for matching strings | |
// else show all commands. | |
if ($term != "") | |
{ | |
// For $i 0 to less than size of mayaCommands | |
// tolower the current command into a new | |
// variable, then match $term to lowerCommand | |
// if $match is not "" then set current matchNumber | |
// to current command. | |
for ($i = 0; $i<$size; $i++) | |
{ | |
// Sets command to lowercase. | |
$lowerCommand = `tolower $mayaCommands[$i]`; | |
// Matches command. | |
string $match = `match $term $lowerCommand`; | |
// If not empty. | |
if ($match != "") | |
{ | |
// $s is a seperate count from $i | |
// so $s only increases when a match is found. | |
$matchNumber[$s] = $i; | |
$s ++; | |
} | |
} | |
// Set $s back to 0. | |
$s = 0; | |
int $num; | |
// For num in matchNumber set matchCommand to | |
// mayaCommand of $num. | |
for ($num in $matchNumber) | |
{ | |
// This is a new array of only the matching strings. | |
$matchCommands[$s] = $mayaCommands[$num]; | |
$s ++; | |
} | |
// Remove all strings from the command scrollList. | |
textScrollList -e -ra $commandListField; | |
string $cmd; | |
// For $cmd in matchCommands append $cmd to the | |
// command scrollList. | |
for ($cmd in $matchCommands) | |
{ | |
textScrollList -e -a $cmd $commandListField; | |
} | |
}else{ | |
// If the search term was empty then remove al strings from list | |
// and append all in mayaCommands (this prevents doubles from appearing). | |
string $cmd; | |
textScrollList -e -ra $commandListField; | |
for ($cmd in $mayaCommands) | |
{ | |
textScrollList -e -a $cmd $commandListField; | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////////// Procedure: comment //////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when the Comment button // | |
// is pressed. It prompts the user for a string that // | |
// will be put into the script as a comment, escape // | |
// characters don't work due to the nature of string // | |
// variables. // | |
proc comment(string $scriptField) | |
{ | |
// Set initial variables. | |
global string $script; | |
string $comment; | |
// Prompt user for a comment. | |
string $result = `promptDialog -title "Input Comment" | |
-message "Enter the comment you want to add" | |
-ma "center" | |
-sf 1 | |
-button "OK" -button "Cancel" | |
-defaultButton "Cancel" -cancelButton "Cancel" | |
-dismissString "Cancel"`; | |
// If user pressed ok then append text in prompt | |
// to the script. | |
if ($result == "OK") | |
{ | |
$insertString = `promptDialog -query -text`; | |
$script += ("/*"+$insertString+"*/ "); | |
scrollField -e -tx $script $scriptField; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
////////////////// Procedure: insertString ///////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when the String button is // | |
// pressed. It prompts the user for a string that // | |
// will be put into the script in quotes, escape // | |
// characters get put into the string, but the user must // | |
// use them wisely because they could end up with an // | |
// unterminated string. // | |
proc insertString(string $scriptField) | |
{ | |
// Sets initial variables. | |
global string $script; | |
string $insertString; | |
// Prompt user for a string. | |
string $result = `promptDialog -title "Input String" | |
-message "Make sure your string is valid with your script.\nUse back slashes wisely and properly." | |
-ma "center" | |
-sf 1 | |
-button "OK" -button "Cancel" | |
-defaultButton "Cancel" -cancelButton "Cancel" | |
-dismissString "Cancel"`; | |
// If user pressed ok then append text in promt | |
// to string. | |
if ($result == "OK") | |
{ | |
$insertString = `promptDialog -query -text`; | |
$script += ("\""+$insertString+"\" "); | |
scrollField -e -tx $script $scriptField; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
///////////////////// Procedure: number //////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when the Number button is // | |
// pressed. It prompts the user for a number that // | |
// will be put into the script. Only integer and float // | |
// nubmers, positive or negative, are valid. If not // | |
// valid it warns the user. // | |
proc number(string $scriptField) | |
{ | |
// Sets initial variables. | |
global string $script; | |
string $number; | |
// Prompt user for a number. | |
string $result = `promptDialog -title "Input Number" | |
-message "A float or integer number." | |
-button "OK" -button "Cancel" | |
-defaultButton "Cancel" -cancelButton "Cancel" | |
-dismissString "Cancel"`; | |
// If the user pressed OK. | |
if ($result == "OK") | |
{ | |
// Query number and match for a +/- floating or integer number. | |
$number = `promptDialog -query -text`; | |
string $matchingPart = `match "^[0-9.-][0-9.]*$" $number`; | |
// If matched number is the same as input number, goodmatch = 1 else 0. | |
int $goodMatch = ! `strcmp $matchingPart $number`; | |
// If no number is given then goodmatch is 0. | |
if ($number == "") | |
{ | |
$goodMatch = 0; | |
} | |
// If goodmatch is 1 then append number to script. | |
// Else give warning. | |
if ($goodMatch) | |
{ | |
$script += ($number+" "); | |
scrollField -e -tx $script $scriptField; | |
}else{ | |
confirmDialog -t "Warning" -m "Invalid number." | |
-ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: saveScript ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Save Script is // | |
// pressed. It saves the selected text in the script // | |
// field to a mel file of the users choice, if no text is // | |
// selected then it errors out. // | |
proc saveScript(string $scriptField) | |
{ | |
// Query the selected text. | |
string $selected = `scrollField -q -sl $scriptField`; | |
// If no text is selected then error, else prompt for a file. | |
if ($selected == "") | |
{ | |
error "Select the text you wish to save."; | |
}else{ | |
// Query the working directory and prompt for a file. | |
string $dir = `workspace -q -dir`; | |
string $filepath[] = `fileDialog2 -ds 2 -cap "Save Script..." -dir $dir -ff "Mel (*.mel)" -sff "Mel" -fm 0`; | |
// If no filepath is chosen then error out | |
// else save selected text to named mel file. | |
if ($filepath[0] == "") | |
{ | |
error "No filepath chosen."; | |
}else{ | |
// This opens a file of the named filepath | |
// and enables it to write only/ | |
$fileId=`fopen $filepath[0] "w"`; | |
// Writes the selected text to the file | |
// then closese the file. | |
fprint $fileId $selected; | |
fclose $fileId; | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: loadScript ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Load Script is // | |
// pressed. It loads the chosen mel file to the script // | |
// field, overwriting what was previously there. // | |
proc loadScript(string $scriptField) | |
{ | |
// Set initial variables and query if there is text in the | |
// script Field. | |
global string $script; | |
string $confirm; | |
string $line; | |
string $isText = `scrollField -q -tx $scriptField`; | |
// If there is text in the scriptField, prompt the user if | |
// they want to overwrite thair work. | |
if ($isText != "") | |
{ | |
$confirm = `confirmDialog -t "Load script?" -m "Are you sure you want to load a script?\nIt will overwrite your work." | |
-ma "center" -b "Yes" -b "No" -db "No" -cb "No" -ds "No" -icn "question"`; | |
} | |
// If the User confirmed to overwrite their script | |
// or there was to text in the script field then | |
// prompt the user for a mel script to load. | |
if (($confirm == "Yes") || ($isText == "")) | |
{ | |
// Query working directory and prompt user | |
// for an existing file. | |
string $dir = `workspace -q -dir`; | |
string $filepath[] = `fileDialog2 -ds 2 -cap "Load Script..." -dir $dir -ff "Mel (*.mel)" -sff "Mel" -fm 1`; | |
// If a file path was chosen. | |
if ($filepath[0] != "") | |
{ | |
// Open the chosen file and get the | |
// first line. | |
$fileId=`fopen $filepath[0] "r"`; | |
$newline = `fgetline $fileId`; | |
string $text[]; | |
// While newline has characters | |
// add to text array newline then get next line. | |
while (size($newline) > 0) | |
{ | |
$text[size($text)] = $newline; | |
$newline = `fgetline $fileId`; | |
} | |
// Set script to nothing. | |
$script = ""; | |
// For $line in $text append $line to $script | |
for ($line in $text) | |
{ | |
$script += $line; | |
} | |
// Close file and reload the scriptField with new script. | |
fclose $fileId; | |
scrollField -e -tx $script $scriptField; | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: newScript /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when New Script is // | |
// pressed. It prompts the user if they want to start a // | |
// script without saving, if so then set clear $script // | |
// and reload the scriptField. // | |
proc newScript(string $scriptField) | |
{ | |
global string $script; | |
string $isText = `scrollField -q -tx $scriptField`; | |
string $new; | |
// If there is text in the scriptField, prompt the user if | |
// they want to start a new script without saving. | |
if ($isText != "") | |
{ | |
$new = `confirmDialog -t "New Script?" | |
-m "Are you sure you want to start a\nnew script without saving?" | |
-ma "center" -b "Yes" -b "No" -db "No" -cb "No" -ds "No" -icn "question"`; | |
} | |
// If Yes then clear script. | |
if ($new == "Yes") | |
{ | |
$script = ""; | |
scrollField -e -tx $script $scriptField; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: editScript ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Edit Script is // | |
// pressed. It enables the scriptField for the user to // | |
// type into and disables most everything else so the // | |
// user doesn't mess up their work. When pressed again // | |
// disables the scriptField and re-enables everything // | |
// else. // | |
proc editScript(string $scriptField, string $fileMenu, string $undo, string $redo, string $toolTab) | |
{ | |
// Set $script and query the state of the scriptField. | |
global string $script; | |
int $state = `scrollField -q -ed $scriptField`; | |
// If scriptField is on then disable it and | |
// enables everything else. Else enable it | |
// and disable everything else. | |
if ($state) | |
{ | |
$script = `scrollField -q -tx $scriptField`; | |
scrollField -e -ed 0 $scriptField; | |
menu -e -en 1 $fileMenu; | |
menuItem -e -en 1 $undo; | |
menuItem -e -en 1 $redo; | |
tabLayout -e -en 1 $toolTab; | |
}else{ | |
scrollField -e -ed 1 $scriptField; | |
menu -e -en 0 $fileMenu; | |
menuItem -e -en 0 $undo; | |
menuItem -e -en 0 $redo; | |
tabLayout -e -en 0 $toolTab; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////////// Procedure: showTool /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Toggle Tool Window // | |
// is pressed. It toggles the visibility of the Tool // | |
// window, so if the user closed it, then it can be // | |
// reopened. // | |
proc showTool(string $showTool) | |
{ | |
if (`window -q -vis scriptToolUI`) | |
{ | |
window -e -vis 0 scriptToolUI; | |
}else{ | |
window -e -vis 1 scriptToolUI; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
/////////////////// Procedure: showScript ////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This procedure is called when Toggle Script Window // | |
// is pressed. It toggles the visibility of the Script // | |
// window, so if the user closed it, then it can be // | |
// reopened. // | |
proc showScript(string $showScript) | |
{ | |
if (`window -q -vis scriptUI`) | |
{ | |
window -e -vis 0 scriptUI; | |
}else{ | |
window -e -vis 1 scriptUI; | |
} | |
} | |
//////////////////////////////////////////////////////////// | |
//////////////////// Procedure: scriptUI /////////////////// | |
//////////////////////////////////////////////////////////// | |
// // | |
// This is the main procedure that creates the // | |
// user interface. Everything is made using form layouts // | |
// this allows the user to size the window to how they // | |
// want it. // | |
global proc scriptUI() | |
{ | |
// If windows exists then delete them. Prevents multiple instances of the | |
// same windows. | |
if (`window -q -ex scriptToolUI`) deleteUI scriptToolUI; | |
if (`window -q -ex scriptUI`) deleteUI scriptUI; | |
// Declares global strings. | |
global string $scriptWindow; | |
global string $scriptToolWindow; | |
global string $scriptField; | |
global string $scriptLayout; | |
global string $scriptMenu; | |
global string $script; | |
global string $fileMenu; | |
global string $undo; | |
global string $redo; | |
global string $showTool; | |
global string $showScript; | |
global string $toolTab; | |
global string $logicTab; | |
global string $mayaTab; | |
global string $variableTab; | |
global string $procedureTab; | |
global string $searchCommand; | |
global string $commandListField; | |
global string $searchFlag; | |
global string $flagListField; | |
global string $searchVariable; | |
global string $variableListField; | |
global string $searchProcedure; | |
global string $procedureListField; | |
// This string is used for the Maya Commands tab. | |
global string $mayaCommands[] = {"addAttr", "aimConstraint", "arcLen", "bevel", "bindSkin", "blendShape", "button", "camera", | |
"checkBox", "checkBoxGrp", "circle", "cluster", "collision", "columnLayout", "cone", "confirmDialog", "connectAttr", | |
"connectDynamic", "createNode", "curve", "cylinder", "delete", "deleteAttr", "deleteUI", "disconnectAttr", "duplicate", | |
"duplicateCurve", "duplicateSurface", "dynExpression", "emit", "emitter", "error", "eval", "exists", "expression", | |
"extendCurve", "extrude", "file", "fileDialog2", "filletCurve", "flexor", "floatField", "floatFieldGrp", | |
"floatScrollBar", "floatSlider", "floatSlider2", "floatSliderButtonGrp", "floatSliderGrp", "flow", "flowLayout", | |
"fluidEmitter", "formLayout", "frameLayout", "geometryConstraint", "getAttr", "getFluidAttr", "getParticleAttr", | |
"goal", "gravity", "grid", "gridLayout", "group", "hide", "hudButton", "hudSlider", "hudSliderButton", "iconTextButton", | |
"iconTextCheckBox", "iconTextRadioButton", "iconTextRadioCollection", "iconTextScrollList", "iconTextStaticLabel", | |
"ikHandle", "ikSolver", "insertJoint", "insertKnotCurve", "insertKnotSurface", "instance", "intersect", "intField", | |
"intFieldGrp", "intScrollBar", "intSlider", "intSliderGrp", "joint", "jointCluster", "jointLattice", "keyframe", | |
"lattice", "layerButton", "layout", "layoutDialog", "lightlink", "listAttr", "ls", "makeIdentity", "match", "menu", | |
"menuBarLayout", "menuEditor", "menuItem", "mirrorJoint", "move", "newton", "normalConstrint", "nurbsBoolean", | |
"nurbsCube", "nurbsPlane", "nurbsSquare", "nurbsToPoly", "objectCenter", "objExists", "offsetCurve", "optionMenu", | |
"optionMenuGrp", "orbit", "orientConstraint", "panelLayout", "paramLocator", "parent", "parentConstraint", | |
"particle", "particleExists", "plane", "play", "playBackOptions", "playblast", "pointConstraint", "pointLight", | |
"pointOnCurve", "pointOnPolyConstraint", "pointOnSurface", "poleVectorConstraint", "polyAppend", "polyBevel", | |
"polyBoolOp", "polyCone", "polyCube", "polyCylinder", "polyPlane", "polySphere", "polyTorus", "popupMenu", "print", | |
"progressBar", "radial", "radioButton", "radioButtonGrp", "radioCollection", "refresh", "revolve", "rotate", | |
"rowColumnLayout", "rowLayout", "scale", "scaleConstraint", "scriptNode", "scrollField", "scrollLayout", "select", | |
"setAttr", "setDrivenKeyframe", "setKeyframe", "sets", "shadingNode", "showWindow", "skinCluster", "spaceLocator", | |
"sphere", "spotLight", "surface", "tabLayout", "text", "textCurves", "textField", "textFieldButtonGrp", "textFieldGrp", | |
"textScrollList", "timer", "tokenisze", "tokenizeList", "torus", "turbulence", "vortex", "warning", "window", "xform"}; | |
// Query the users script color settings, this is used to color the buttons. | |
vector $syntaxText = `displayRGBColor -q syntaxText`; | |
vector $syntaxKey = `displayRGBColor -q syntaxKeywords`; | |
vector $syntaxString = `displayRGBColor -q syntaxStrings`; | |
vector $syntaxComment = `displayRGBColor -q syntaxComments`; | |
vector $syntaxCommand = `displayRGBColor -q syntaxCommands`; | |
// Creates the Script Tool Window... this section is long, I don't want to comment it. | |
$scriptToolWindow = `window -t "User Friendly Scripting Tool" -s 1 -mb 1 -tlc 5 825 -wh 550 800 -ret scriptToolUI`; | |
menu -l "Window" -hm 1 ; | |
$showScript = `menuItem -l "Toggle Script Window" -c "showScript($showScript)"`; | |
$form = `formLayout -nd 100 "form"`; | |
$toolTab = `tabLayout -imw 5 -imh 10 "toolTab"`; | |
$logicTab = `formLayout -nd 225 "Logic"`; | |
$maths = `frameLayout -l "Maths"`; | |
$mathsForm = `formLayout -nd 71`; | |
$blah = "blah"; | |
$a1 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "+" -rs 0 -c "$script += \"+ \"; scrollField -e -tx $script $scriptField;"`; | |
$a2 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "*" -rs 0 -c "$script += \"* \"; scrollField -e -tx $script $scriptField;"`; | |
$a3 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "=" -rs 0 -c "$script += \"= \"; scrollField -e -tx $script $scriptField;"`; | |
$a4 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "." -rs 0 -c "$script += \". \"; scrollField -e -tx $script $scriptField;"`; | |
$a5 = `button -w 10 -h 10 -bgc 1.0 0.7 0.0 -l "Number" -rs 0 -c "number($scriptField)"`; | |
$a7 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "-" -rs 0 -c "$script += \"- \"; scrollField -e -tx $script $scriptField;"`; | |
$a8 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "/" -rs 0 -c "$script += \"/ \"; scrollField -e -tx $script $scriptField;"`; | |
$a9 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "!" -rs 0 -c "$script += \"! \"; scrollField -e -tx $script $scriptField;"`; | |
$a10 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ":" -rs 0 -c "$script += \": \"; scrollField -e -tx $script $scriptField;"`; | |
$a13 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "<" -rs 0 -c "$script += \"< \"; scrollField -e -tx $script $scriptField;"`; | |
$a14 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ">" -rs 0 -c "$script += \"> \"; scrollField -e -tx $script $scriptField;"`; | |
$a15 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "&&&&" -rs 0 -c "$script += \"&& \"; scrollField -e -tx $script $scriptField;"`; | |
$a16 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ";" -rs 0 -c "$script += \"; \"; scrollField -e -tx $script $scriptField;"`; | |
$a19 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "(" -rs 0 -c "$script += \"( \"; scrollField -e -tx $script $scriptField;"`; | |
$a20 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ")" -rs 0 -c "$script += \") \"; scrollField -e -tx $script $scriptField;"`; | |
$a21 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "||" -rs 0 -c "$script += \"|| \"; scrollField -e -tx $script $scriptField;"`; | |
$a22 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "," -rs 0 -c "$script += \", \"; scrollField -e -tx $script $scriptField;"`; | |
$a25 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "[" -rs 0 -c "$script += \"[ \"; scrollField -e -tx $script $scriptField;"`; | |
$a26 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "]" -rs 0 -c "$script += \"] \"; scrollField -e -tx $script $scriptField;"`; | |
$a27 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "{" -rs 0 -c "$script += \"{ \"; scrollField -e -tx $script $scriptField;"`; | |
$a28 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "}" -rs 0 -c "$script += \"} \"; scrollField -e -tx $script $scriptField;"`; | |
$a29 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "<<" -rs 0 -c "$script += \"<< \"; scrollField -e -tx $script $scriptField;"`; | |
$a30 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ">>" -rs 0 -c "$script += \">> \"; scrollField -e -tx $script $scriptField;"`; | |
$a31 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "+=" -rs 0 -c "$script += \"+= \"; scrollField -e -tx $script $scriptField;"`; | |
$a32 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "-=" -rs 0 -c "$script += \"-= \"; scrollField -e -tx $script $scriptField;"`; | |
$a33 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "<=" -rs 0 -c "$script += \"<= \"; scrollField -e -tx $script $scriptField;"`; | |
$a34 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l ">=" -rs 0 -c "$script += \">= \"; scrollField -e -tx $script $scriptField;"`; | |
$a35 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "==" -rs 0 -c "$script += \"== \"; scrollField -e -tx $script $scriptField;"`; | |
$a36 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "!=" -rs 0 -c "$script += \"!= \"; scrollField -e -tx $script $scriptField;"`; | |
formLayout -e | |
-attachForm $a1 "top" 5 | |
-attachForm $a1 "left" 5 | |
-attachPosition $a1 "bottom" 0 11 | |
-attachPosition $a1 "right" 0 11 | |
-attachForm $a2 "top" 5 | |
-attachControl $a2 "left" 5 $a1 | |
-attachPosition $a2 "bottom" 0 11 | |
-attachPosition $a2 "right" 0 22 | |
-attachForm $a3 "top" 5 | |
-attachControl $a3 "left" 5 $a2 | |
-attachPosition $a3 "bottom" 0 11 | |
-attachPosition $a3 "right" 0 33 | |
-attachForm $a4 "top" 5 | |
-attachControl $a4 "left" 5 $a3 | |
-attachPosition $a4 "bottom" 0 11 | |
-attachPosition $a4 "right" 0 44 | |
-attachForm $a5 "top" 5 | |
-attachControl $a5 "left" 5 $a4 | |
-attachPosition $a5 "bottom" 0 44 | |
-attachForm $a5 "right" 5 | |
-attachControl $a7 "top" 5 $a1 | |
-attachForm $a7 "left" 5 | |
-attachPosition $a7 "bottom" 0 22 | |
-attachPosition $a7 "right" 0 11 | |
-attachControl $a8 "top" 5 $a2 | |
-attachControl $a8 "left" 5 $a7 | |
-attachPosition $a8 "bottom" 0 22 | |
-attachPosition $a8 "right" 0 22 | |
-attachControl $a9 "top" 5 $a3 | |
-attachControl $a9 "left" 5 $a8 | |
-attachPosition $a9 "bottom" 0 22 | |
-attachPosition $a9 "right" 0 33 | |
-attachControl $a10 "top" 5 $a4 | |
-attachControl $a10 "left" 5 $a9 | |
-attachPosition $a10 "bottom" 0 22 | |
-attachPosition $a10 "right" 0 44 | |
-attachControl $a13 "top" 5 $a7 | |
-attachForm $a13 "left" 5 | |
-attachPosition $a13 "bottom" 0 33 | |
-attachPosition $a13 "right" 0 11 | |
-attachControl $a14 "top" 5 $a8 | |
-attachControl $a14 "left" 5 $a13 | |
-attachPosition $a14 "bottom" 0 33 | |
-attachPosition $a14 "right" 0 22 | |
-attachControl $a15 "top" 5 $a9 | |
-attachControl $a15 "left" 5 $a14 | |
-attachPosition $a15 "bottom" 0 33 | |
-attachPosition $a15 "right" 0 33 | |
-attachControl $a16 "top" 5 $a10 | |
-attachControl $a16 "left" 5 $a15 | |
-attachPosition $a16 "bottom" 0 33 | |
-attachPosition $a16 "right" 0 44 | |
-attachControl $a19 "top" 5 $a13 | |
-attachForm $a19 "left" 5 | |
-attachPosition $a19 "bottom" 0 44 | |
-attachPosition $a19 "right" 0 11 | |
-attachControl $a20 "top" 5 $a14 | |
-attachControl $a20 "left" 5 $a19 | |
-attachPosition $a20 "bottom" 0 44 | |
-attachPosition $a20 "right" 0 22 | |
-attachControl $a21 "top" 5 $a15 | |
-attachControl $a21 "left" 5 $a20 | |
-attachPosition $a21 "bottom" 0 44 | |
-attachPosition $a21 "right" 0 33 | |
-attachControl $a22 "top" 5 $a16 | |
-attachControl $a22 "left" 5 $a21 | |
-attachPosition $a22 "bottom" 0 44 | |
-attachPosition $a22 "right" 0 44 | |
-attachControl $a25 "top" 5 $a19 | |
-attachForm $a25 "left" 5 | |
-attachPosition $a25 "bottom" 0 55 | |
-attachPosition $a25 "right" 0 11 | |
-attachControl $a26 "top" 5 $a20 | |
-attachControl $a26 "left" 5 $a25 | |
-attachPosition $a26 "bottom" 0 55 | |
-attachPosition $a26 "right" 0 22 | |
-attachControl $a27 "top" 5 $a21 | |
-attachControl $a27 "left" 5 $a26 | |
-attachPosition $a27 "bottom" 0 55 | |
-attachPosition $a27 "right" 0 33 | |
-attachControl $a28 "top" 5 $a22 | |
-attachControl $a28 "left" 5 $a27 | |
-attachPosition $a28 "bottom" 0 55 | |
-attachPosition $a28 "right" 0 44 | |
-attachControl $a29 "top" 5 $a5 | |
-attachControl $a29 "left" 5 $a28 | |
-attachPosition $a29 "bottom" 0 55 | |
-attachPosition $a29 "right" 0 55 | |
-attachControl $a30 "top" 5 $a5 | |
-attachControl $a30 "left" 5 $a29 | |
-attachPosition $a30 "bottom" 0 55 | |
-attachForm $a30 "right" 5 | |
-attachControl $a31 "top" 5 $a25 | |
-attachForm $a31 "left" 5 | |
-attachForm $a31 "bottom" 5 | |
-attachPosition $a31 "right" 0 11 | |
-attachControl $a32 "top" 5 $a26 | |
-attachControl $a32 "left" 5 $a31 | |
-attachForm $a32 "bottom" 5 | |
-attachPosition $a32 "right" 0 22 | |
-attachControl $a33 "top" 5 $a27 | |
-attachControl $a33 "left" 5 $a32 | |
-attachForm $a33 "bottom" 5 | |
-attachPosition $a33 "right" 0 33 | |
-attachControl $a34 "top" 5 $a28 | |
-attachControl $a34 "left" 5 $a33 | |
-attachForm $a34 "bottom" 5 | |
-attachPosition $a34 "right" 0 44 | |
-attachControl $a35 "top" 5 $a29 | |
-attachControl $a35 "left" 5 $a34 | |
-attachForm $a35 "bottom" 5 | |
-attachPosition $a35 "right" 0 55 | |
-attachControl $a36 "top" 5 $a30 | |
-attachControl $a36 "left" 5 $a35 | |
-attachForm $a36 "bottom" 5 | |
-attachForm $a36 "right" 5 | |
$mathsForm; | |
setParent ..; | |
setParent ..; | |
$condsLoops = `frameLayout -l "Conditionals & Loops"`; | |
$condsLoopsForm = `formLayout -nd 110`; | |
$b1 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "if" -rs 0 -c "$script += \"if \"; scrollField -e -tx $script $scriptField;"`; | |
$b2 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "else" -rs 0 -c "$script += \"else \"; scrollField -e -tx $script $scriptField;"`; | |
$b3 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "in" -rs 0 -c "$script += \"in \"; scrollField -e -tx $script $scriptField;"`; | |
$b4 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "switch" -rs 0 -c "$script += \"switch \"; scrollField -e -tx $script $scriptField;"`; | |
$b5 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "case" -rs 0 -c "$script += \"case \"; scrollField -e -tx $script $scriptField;"`; | |
$b6 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "break" -rs 0 -c "$script += \"break \"; scrollField -e -tx $script $scriptField;"`; | |
$b7 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "for" -rs 0 -c "$script += \"for \"; scrollField -e -tx $script $scriptField;"`; | |
$b8 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "do" -rs 0 -c "$script += \"do \"; scrollField -e -tx $script $scriptField;"`; | |
$b9 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "while" -rs 0 -c "$script += \"while \"; scrollField -e -tx $script $scriptField;"`; | |
formLayout -e | |
-attachForm $b1 "top" 5 | |
-attachForm $b1 "left" 5 | |
-attachPosition $b1 "bottom" 0 35 | |
-attachPosition $b1 "right" 0 35 | |
-attachForm $b2 "top" 5 | |
-attachControl $b2 "left" 5 $b1 | |
-attachPosition $b2 "bottom" 0 35 | |
-attachPosition $b2 "right" 0 70 | |
-attachForm $b3 "top" 5 | |
-attachControl $b3 "left" 5 $b2 | |
-attachPosition $b3 "bottom" 0 35 | |
-attachForm $b3 "right" 5 | |
-attachControl $b4 "top" 5 $b1 | |
-attachForm $b4 "left" 5 | |
-attachPosition $b4 "bottom" 0 70 | |
-attachPosition $b4 "right" 0 35 | |
-attachControl $b5 "top" 5 $b2 | |
-attachControl $b5 "left" 5 $b4 | |
-attachPosition $b5 "bottom" 0 70 | |
-attachPosition $b5 "right" 0 70 | |
-attachControl $b6 "top" 5 $b3 | |
-attachControl $b6 "left" 5 $b5 | |
-attachPosition $b6 "bottom" 0 70 | |
-attachForm $b6 "right" 5 | |
-attachControl $b7 "top" 5 $b4 | |
-attachForm $b7 "left" 5 | |
-attachForm $b7 "bottom" 5 | |
-attachPosition $b7 "right" 0 35 | |
-attachControl $b8 "top" 5 $b5 | |
-attachControl $b8 "left" 5 $b7 | |
-attachForm $b8 "bottom" 5 | |
-attachPosition $b8 "right" 0 70 | |
-attachControl $b9 "top" 5 $b6 | |
-attachControl $b9 "left" 5 $b8 | |
-attachForm $b9 "bottom" 5 | |
-attachForm $b9 "right" 5 | |
$condsLoopsForm; | |
setParent ..; | |
setParent ..; | |
$varProc = `frameLayout -l "Variables & Procedures"`; | |
$varProcForm = `formLayout -nd 105`; | |
$c1 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "int" -rs 0 -c "$script += \"int \"; scrollField -e -tx $script $scriptField;"`; | |
$c2 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "float" -rs 0 -c "$script += \"float \"; scrollField -e -tx $script $scriptField;"`; | |
$c3 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "string" -rs 0 -c "$script += \"string \"; scrollField -e -tx $script $scriptField;"`; | |
$c4 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "vector" -rs 0 -c "$script += \"vector \"; scrollField -e -tx $script $scriptField;"`; | |
$c5 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "matrix" -rs 0 -c "$script += \"matrix \"; scrollField -e -tx $script $scriptField;"`; | |
$c6 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "return" -rs 0 -c "$script += \"return \"; scrollField -e -tx $script $scriptField;"`; | |
$c7 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "global" -rs 0 -c "$script += \"global \"; scrollField -e -tx $script $scriptField;"`; | |
$c8 = `button -w 10 -h 10 -bgc ($syntaxKey.x) ($syntaxKey.y) ($syntaxKey.z) -l "proc" -rs 0 -c "$script += \"proc \"; scrollField -e -tx $script $scriptField;"`; | |
formLayout -e | |
-attachForm $c1 "top" 5 | |
-attachForm $c1 "left" 5 | |
-attachPosition $c1 "bottom" 0 25 | |
-attachPosition $c1 "right" 0 50 | |
-attachForm $c2 "top" 5 | |
-attachControl $c2 "left" 5 $c1 | |
-attachPosition $c2 "bottom" 0 25 | |
-attachForm $c2 "right" 5 | |
-attachControl $c3 "top" 5 $c1 | |
-attachForm $c3 "left" 5 | |
-attachPosition $c3 "bottom" 0 50 | |
-attachPosition $c3 "right" 0 50 | |
-attachControl $c4 "top" 5 $c2 | |
-attachControl $c4 "left" 5 $c3 | |
-attachPosition $c4 "bottom" 0 50 | |
-attachForm $c4 "right" 5 | |
-attachControl $c5 "top" 5 $c3 | |
-attachForm $c5 "left" 5 | |
-attachPosition $c5 "bottom" 0 75 | |
-attachPosition $c5 "right" 0 50 | |
-attachControl $c6 "top" 5 $c4 | |
-attachControl $c6 "left" 5 $c5 | |
-attachPosition $c6 "bottom" 0 75 | |
-attachForm $c6 "right" 5 | |
-attachControl $c7 "top" 5 $c5 | |
-attachForm $c7 "left" 5 | |
-attachForm $c7 "bottom" 5 | |
-attachPosition $c7 "right" 0 50 | |
-attachControl $c8 "top" 5 $c6 | |
-attachControl $c8 "left" 5 $c7 | |
-attachForm $c8 "bottom" 5 | |
-attachForm $c8 "right" 5 | |
$varProcForm; | |
setParent ..; | |
setParent ..; | |
$strings = `frameLayout -l "Strings and String Commands"`; | |
$stringsForm = `formLayout -nd 205`; | |
$d1 = `button -w 10 -h 10 -bgc ($syntaxString.x) ($syntaxString.y) ($syntaxString.z) -l "\" \" String" -rs 0 -c "insertString($scriptField)"`; | |
$d2 = `button -w 10 -h 10 -bgc ($syntaxComment.x) ($syntaxComment.y) ($syntaxComment.z) -l "/* */ Comment" -rs 0 -c "comment($scriptField)"`; | |
$d3 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "` Backtick" -rs 0 -c "$script += \"` \"; scrollField -e -tx $script $scriptField;"`; | |
$d4 = `button -w 10 -h 10 -bgc ($syntaxString.x) ($syntaxString.y) ($syntaxString.z) -l "\\ t Tab" -rs 0 -c "$script += \"\t\"; scrollField -e -tx $script $scriptField;"`; | |
$d5 = `button -w 10 -h 10 -bgc ($syntaxString.x) ($syntaxString.y) ($syntaxString.z) -l "\\ n Newline" -rs 0 -c "$script += \"\\n\"; scrollField -e -tx $script $scriptField;"`; | |
$d7 = `button -w 10 -h 10 -bgc ($syntaxString.x) ($syntaxString.y) ($syntaxString.z) -l "Space" -rs 0 -c "$script += \" \"; scrollField -e -tx $script $scriptField;"`; | |
$d8 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "endString" -rs 0 -c "$script += \"endString \"; scrollField -e -tx $script $scriptField;"`; | |
$d9 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "startString" -rs 0 -c "$script += \"startString \"; scrollField -e -tx $script $scriptField;"`; | |
$d10 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "substitute" -rs 0 -c "$script += \"substitute \"; scrollField -e -tx $script $scriptField;"`; | |
$d11 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "size" -rs 0 -c "$script += \"size \"; scrollField -e -tx $script $scriptField;"`; | |
$d12 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "sort" -rs 0 -c "$script += \"sort \"; scrollField -e -tx $script $scriptField;"`; | |
$d13 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "endsWith" -rs 0 -c "$script += \"endsWith \"; scrollField -e -tx $script $scriptField;"`; | |
$d14 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "startsWith" -rs 0 -c "$script += \"startsWith \"; scrollField -e -tx $script $scriptField;"`; | |
$d15 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "substituteAllString" -rs 0 -c "$script += \"substituteAllString \"; scrollField -e -tx $script $scriptField;"`; | |
$d16 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "strcmp" -rs 0 -c "$script += \"strcmp \"; scrollField -e -tx $script $scriptField;"`; | |
$d17 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "tokenize" -rs 0 -c "$script += \"tokenize \"; scrollField -e -tx $script $scriptField;"`; | |
$d18 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "match" -rs 0 -c "$script += \"match \"; scrollField -e -tx $script $scriptField;"`; | |
$d19 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "gmatch" -rs 0 -c "$script += \"gmatch \"; scrollField -e -tx $script $scriptField;"`; | |
$d20 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "substring" -rs 0 -c "$script += \"substring \"; scrollField -e -tx $script $scriptField;"`; | |
$d21 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "tolower" -rs 0 -c "$script += \"tolower \"; scrollField -e -tx $script $scriptField;"`; | |
$d22 = `button -w 10 -h 10 -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "toupper" -rs 0 -c "$script += \"toupper \"; scrollField -e -tx $script $scriptField;"`; | |
formLayout -e | |
-attachForm $d1 "top" 5 | |
-attachForm $d1 "left" 7 | |
-attachPosition $d1 "bottom" 0 40 | |
-attachPosition $d1 "right" 0 66 | |
-attachForm $d2 "top" 5 | |
-attachControl $d2 "left" 7 $d1 | |
-attachPosition $d2 "bottom" 0 40 | |
-attachPosition $d2 "right" 0 132 | |
-attachForm $d3 "top" 5 | |
-attachControl $d3 "left" 7 $d2 | |
-attachPosition $d3 "bottom" 0 40 | |
-attachForm $d3 "right" 7 | |
-attachControl $d4 "top" 5 $d1 | |
-attachForm $d4 "left" 7 | |
-attachPosition $d4 "bottom" 0 80 | |
-attachPosition $d4 "right" 0 66 | |
-attachControl $d5 "top" 5 $d1 | |
-attachControl $d5 "left" 7 $d4 | |
-attachPosition $d5 "bottom" 0 80 | |
-attachPosition $d5 "right" 0 132 | |
-attachControl $d7 "top" 5 $d3 | |
-attachControl $d7 "left" 7 $d5 | |
-attachPosition $d7 "bottom" 0 80 | |
-attachForm $d7 "right" 7 | |
-attachControl $d8 "top" 5 $d4 | |
-attachForm $d8 "left" 5 | |
-attachPosition $d8 "bottom" 0 120 | |
-attachPosition $d8 "right" 0 40 | |
-attachControl $d9 "top" 5 $d5 | |
-attachControl $d9 "left" 5 $d8 | |
-attachPosition $d9 "bottom" 0 120 | |
-attachPosition $d9 "right" 0 80 | |
-attachControl $d10 "top" 5 $d5 | |
-attachControl $d10 "left" 5 $d9 | |
-attachPosition $d10 "bottom" 0 120 | |
-attachPosition $d10 "right" 0 120 | |
-attachControl $d11 "top" 5 $d5 | |
-attachControl $d11 "left" 5 $d10 | |
-attachPosition $d11 "bottom" 0 120 | |
-attachPosition $d11 "right" 0 160 | |
-attachControl $d12 "top" 5 $d7 | |
-attachControl $d12 "left" 5 $d11 | |
-attachPosition $d12 "bottom" 0 120 | |
-attachForm $d12 "right" 5 | |
-attachControl $d13 "top" 5 $d8 | |
-attachForm $d13 "left" 5 | |
-attachPosition $d13 "bottom" 0 160 | |
-attachPosition $d13 "right" 0 40 | |
-attachControl $d14 "top" 5 $d9 | |
-attachControl $d14 "left" 5 $d13 | |
-attachPosition $d14 "bottom" 0 160 | |
-attachPosition $d14 "right" 0 80 | |
-attachControl $d15 "top" 5 $d10 | |
-attachControl $d15 "left" 5 $d14 | |
-attachPosition $d15 "bottom" 0 160 | |
-attachPosition $d15 "right" 0 120 | |
-attachControl $d16 "top" 5 $d11 | |
-attachControl $d16 "left" 5 $d15 | |
-attachPosition $d16 "bottom" 0 160 | |
-attachPosition $d16 "right" 0 160 | |
-attachControl $d17 "top" 5 $d12 | |
-attachControl $d17 "left" 5 $d16 | |
-attachPosition $d17 "bottom" 0 160 | |
-attachForm $d17 "right" 5 | |
-attachControl $d18 "top" 5 $d13 | |
-attachForm $d18 "left" 5 | |
-attachForm $d18 "bottom" 5 | |
-attachPosition $d18 "right" 0 40 | |
-attachControl $d19 "top" 5 $d14 | |
-attachControl $d19 "left" 5 $d18 | |
-attachForm $d19 "bottom" 5 | |
-attachPosition $d19 "right" 0 80 | |
-attachControl $d20 "top" 5 $d15 | |
-attachControl $d20 "left" 5 $d19 | |
-attachForm $d20 "bottom" 5 | |
-attachPosition $d20 "right" 0 120 | |
-attachControl $d21 "top" 5 $d16 | |
-attachControl $d21 "left" 5 $d20 | |
-attachForm $d21 "bottom" 5 | |
-attachPosition $d21 "right" 0 160 | |
-attachControl $d22 "top" 5 $d17 | |
-attachControl $d22 "left" 5 $d21 | |
-attachForm $d22 "bottom" 5 | |
-attachForm $d22 "right" 5 | |
$stringsForm; | |
setParent ..; | |
setParent ..; | |
$functions = `frameLayout -l "Math Functions"`; | |
$functionsForm = `formLayout -nd 205`; | |
$e1 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "abs" -rs 0 -c "$script += \"abs \"; scrollField -e -tx $script $scriptField;"`; | |
$e2 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "exp" -rs 0 -c "$script += \"exp\"; scrollField -e -tx $script $scriptField;"`; | |
$e3 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "sin" -rs 0 -c "$script += \"sin \"; scrollField -e -tx $script $scriptField;"`; | |
$e4 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "cos" -rs 0 -c "$script += \"cos \"; scrollField -e -tx $script $scriptField;"`; | |
$e5 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "tan" -rs 0 -c "$script += \"tan \"; scrollField -e -tx $script $scriptField;"`; | |
$e6 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "pow" -rs 0 -c "$script += \"pow \"; scrollField -e -tx $script $scriptField;"`; | |
$e7 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "sqrt" -rs 0 -c "$script += \"sqrt \"; scrollField -e -tx $script $scriptField;"`; | |
$e8 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "fmod" -rs 0 -c "$script += \"fmod \"; scrollField -e -tx $script $scriptField;"`; | |
$e9 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "log" -rs 0 -c "$script += \"log \"; scrollField -e -tx $script $scriptField;"`; | |
$e10 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "sign" -rs 0 -c "$script += \"sign \"; scrollField -e -tx $script $scriptField;"`; | |
$e11 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "angle" -rs 0 -c "$script += \"angle \"; scrollField -e -tx $script $scriptField;"`; | |
$e12 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "cross" -rs 0 -c "$script += \"cross \"; scrollField -e -tx $script $scriptField;"`; | |
$e13 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "min" -rs 0 -c "$script += \"min \"; scrollField -e -tx $script $scriptField;"`; | |
$e14 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "max" -rs 0 -c "$script += \"max \"; scrollField -e -tx $script $scriptField;"`; | |
$e15 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "dot" -rs 0 -c "$script += \"dot \"; scrollField -e -tx $script $scriptField;"`; | |
$e16 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "mag" -rs 0 -c "$script += \"mag \"; scrollField -e -tx $script $scriptField;"`; | |
$e17 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "linstep" -rs 0 -c "$script += \"linstep \"; scrollField -e -tx $script $scriptField;"`; | |
$e18 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "smoothstep" -rs 0 -c "$script += \"smoothstep \"; scrollField -e -tx $script $scriptField;"`; | |
$e19 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "rot" -rs 0 -c "$script += \"rot \"; scrollField -e -tx $script $scriptField;"`; | |
$e20 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "unit" -rs 0 -c "$script += \"unit \"; scrollField -e -tx $script $scriptField;"`; | |
$e21 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "rand" -rs 0 -c "$script += \"rand \"; scrollField -e -tx $script $scriptField;"`; | |
$e22 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "sphrand" -rs 0 -c "$script += \"sphrand \"; scrollField -e -tx $script $scriptField;"`; | |
$e23 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "deg_to_rad" -rs 0 -c "$script += \"deg_to_rad \"; scrollField -e -tx $script $scriptField;"`; | |
$e24 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "rad_to_deg" -rs 0 -c "$script += \"rad_to_deg \"; scrollField -e -tx $script $scriptField;"`; | |
$e25 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "noise" -rs 0 -c "$script += \"noise \"; scrollField -e -tx $script $scriptField;"`; | |
$e26 = `button -w 10 -h 10 -bgc ($syntaxText.x) ($syntaxText.y) ($syntaxText.z) -l "seed" -rs 0 -c "$script += \"seed \"; scrollField -e -tx $script $scriptField;"`; | |
formLayout -e | |
-attachForm $e1 "top" 7 | |
-attachForm $e1 "left" 5 | |
-attachPosition $e1 "bottom" 0 33 | |
-attachPosition $e1 "right" 0 40 | |
-attachForm $e2 "top" 7 | |
-attachControl $e2 "left" 5 $e1 | |
-attachPosition $e2 "bottom" 0 33 | |
-attachPosition $e2 "right" 0 80 | |
-attachForm $e3 "top" 7 | |
-attachControl $e3 "left" 5 $e2 | |
-attachPosition $e3 "bottom" 0 33 | |
-attachPosition $e3 "right" 0 120 | |
-attachForm $e4 "top" 7 | |
-attachControl $e4 "left" 5 $e3 | |
-attachPosition $e4 "bottom" 0 33 | |
-attachPosition $e4 "right" 0 160 | |
-attachForm $e5 "top" 7 | |
-attachControl $e5 "left" 5 $e4 | |
-attachPosition $e5 "bottom" 0 33 | |
-attachForm $e5 "right" 5 | |
-attachControl $e6 "top" 7 $e1 | |
-attachForm $e6 "left" 5 | |
-attachPosition $e6 "bottom" 0 66 | |
-attachPosition $e6 "right" 0 40 | |
-attachControl $e7 "top" 7 $e2 | |
-attachControl $e7 "left" 5 $e6 | |
-attachPosition $e7 "bottom" 0 66 | |
-attachPosition $e7 "right" 0 80 | |
-attachControl $e8 "top" 7 $e3 | |
-attachControl $e8 "left" 5 $e7 | |
-attachPosition $e8 "bottom" 0 66 | |
-attachPosition $e8 "right" 0 120 | |
-attachControl $e9 "top" 7 $e4 | |
-attachControl $e9 "left" 5 $e8 | |
-attachPosition $e9 "bottom" 0 66 | |
-attachPosition $e9 "right" 0 160 | |
-attachControl $e10 "top" 7 $e5 | |
-attachControl $e10 "left" 5 $e9 | |
-attachPosition $e10 "bottom" 0 66 | |
-attachForm $e10 "right" 5 | |
-attachControl $e11 "top" 7 $e6 | |
-attachForm $e11 "left" 5 | |
-attachPosition $e11 "bottom" 0 99 | |
-attachPosition $e11 "right" 0 50 | |
-attachControl $e12 "top" 7 $e7 | |
-attachControl $e12 "left" 5 $e11 | |
-attachPosition $e12 "bottom" 0 99 | |
-attachPosition $e12 "right" 0 100 | |
-attachControl $e13 "top" 7 $e8 | |
-attachControl $e13 "left" 5 $e12 | |
-attachPosition $e13 "bottom" 0 99 | |
-attachPosition $e13 "right" 0 150 | |
-attachControl $e14 "top" 7 $e9 | |
-attachControl $e14 "left" 5 $e13 | |
-attachPosition $e14 "bottom" 0 99 | |
-attachForm $e14 "right" 5 | |
-attachControl $e15 "top" 7 $e11 | |
-attachForm $e15 "left" 5 | |
-attachPosition $e15 "bottom" 0 132 | |
-attachPosition $e15 "right" 0 50 | |
-attachControl $e16 "top" 7 $e12 | |
-attachControl $e16 "left" 5 $e15 | |
-attachPosition $e16 "bottom" 0 132 | |
-attachPosition $e16 "right" 0 100 | |
-attachControl $e17 "top" 7 $e13 | |
-attachControl $e17 "left" 5 $e16 | |
-attachPosition $e17 "bottom" 0 132 | |
-attachPosition $e17 "right" 0 150 | |
-attachControl $e18 "top" 7 $e14 | |
-attachControl $e18 "left" 5 $e17 | |
-attachPosition $e18 "bottom" 0 132 | |
-attachForm $e18 "right" 5 | |
-attachControl $e19 "top" 7 $e15 | |
-attachForm $e19 "left" 5 | |
-attachPosition $e19 "bottom" 0 165 | |
-attachPosition $e19 "right" 0 50 | |
-attachControl $e20 "top" 7 $e16 | |
-attachControl $e20 "left" 5 $e19 | |
-attachPosition $e20 "bottom" 0 165 | |
-attachPosition $e20 "right" 0 100 | |
-attachControl $e21 "top" 7 $e17 | |
-attachControl $e21 "left" 5 $e20 | |
-attachPosition $e21 "bottom" 0 165 | |
-attachPosition $e21 "right" 0 150 | |
-attachControl $e22 "top" 7 $e18 | |
-attachControl $e22 "left" 5 $e21 | |
-attachPosition $e22 "bottom" 0 165 | |
-attachForm $e22 "right" 5 | |
-attachControl $e23 "top" 7 $e19 | |
-attachForm $e23 "left" 5 | |
-attachForm $e23 "bottom" 7 | |
-attachPosition $e23 "right" 0 50 | |
-attachControl $e24 "top" 7 $e20 | |
-attachControl $e24 "left" 5 $e19 | |
-attachForm $e24 "bottom" 7 | |
-attachPosition $e24 "right" 0 100 | |
-attachControl $e25 "top" 7 $e21 | |
-attachControl $e25 "left" 5 $e20 | |
-attachForm $e25 "bottom" 7 | |
-attachPosition $e25 "right" 0 150 | |
-attachControl $e26 "top" 7 $e22 | |
-attachControl $e26 "left" 5 $e21 | |
-attachForm $e26 "bottom" 7 | |
-attachForm $e26 "right" 5 | |
$functionsForm; | |
setParent ..; | |
setParent ..; | |
formLayout -e | |
-attachForm $maths "top" 5 | |
-attachForm $maths "left" 5 | |
-attachPosition $maths "bottom" 0 55 | |
-attachForm $maths "right" 5 | |
-attachControl $condsLoops "top" 5 $maths | |
-attachForm $condsLoops "left" 5 | |
-attachPosition $condsLoops "bottom" 0 110 | |
-attachPosition $condsLoops "right" 0 110 | |
-attachControl $varProc "top" 5 $maths | |
-attachControl $varProc "left" 5 $condsLoops | |
-attachPosition $varProc "bottom" 0 110 | |
-attachForm $varProc "right" 5 | |
-attachControl $strings "top" 5 $condsLoops | |
-attachForm $strings "left" 5 | |
-attachPosition $strings "bottom" 0 165 | |
-attachForm $strings "right" 5 | |
-attachControl $functions "top" 5 $strings | |
-attachForm $functions "left" 5 | |
-attachForm $functions "bottom" 5 | |
-attachForm $functions "right" 5 | |
$logicTab; | |
setParent ..; | |
$mayaTab = `formLayout -nd 100 "Maya Commands"`; | |
$searchCommand = `textField -h 25`; | |
$searchCommandButton = `button -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "Search Commands" -c "searchCommands($mayaCommands, $searchCommand, $commandListField)"`; | |
$commandListField = `textScrollList`; | |
$searchFlag = `textField -h 25`; | |
$searchFlagButton = `button -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "Search Flags"`; | |
$flagListField = `textScrollList`; | |
$insertCommandButton = `button -bgc ($syntaxCommand.x) ($syntaxCommand.y) ($syntaxCommand.z) -l "Insert Command"`; | |
formLayout -e | |
-attachForm $searchCommand "top" 5 | |
-attachForm $searchCommand "left" 5 | |
-attachNone $searchCommand "bottom" | |
-attachPosition $searchCommand "right" 0 48 | |
-attachForm $searchCommandButton "top" 5 | |
-attachControl $searchCommandButton "left" 5 $searchCommand | |
-attachNone $searchCommandButton "bottom" | |
-attachForm $searchCommandButton "right" 5 | |
-attachControl $commandListField "top" 5 $searchCommand | |
-attachForm $commandListField "left" 5 | |
-attachPosition $commandListField "bottom" 0 48 | |
-attachForm $commandListField "right" 5 | |
-attachControl $searchFlag "top" 5 $commandListField | |
-attachForm $searchFlag "left" 5 | |
-attachNone $searchFlag "bottom" | |
-attachPosition $searchFlag "right" 0 48 | |
-attachControl $searchFlagButton "top" 5 $commandListField | |
-attachControl $searchFlagButton "left" 5 $searchFlag | |
-attachNone $searchFlagButton "bottom" | |
-attachForm $searchFlagButton "right" 5 | |
-attachControl $flagListField "top" 5 $searchFlag | |
-attachForm $flagListField "left" 5 | |
-attachPosition $flagListField "bottom" 0 93 | |
-attachForm $flagListField "right" 5 | |
-attachControl $insertCommandButton "top" 5 $flagListField | |
-attachForm $insertCommandButton "left" 5 | |
-attachForm $insertCommandButton "bottom" 5 | |
-attachForm $insertCommandButton "right" 5 | |
$mayaTab; | |
// For mayaCmd in mayaCommands append each to the | |
// command scroll list. | |
string $mayaCmd; | |
for ($mayaCmd in $mayaCommands) | |
{ | |
textScrollList -e -a $mayaCmd $commandListField; | |
} | |
setParent ..; | |
$variablesTab = `formLayout -nd 100 "Variables"`; | |
$searchVariable = `textField -h 25`; | |
$searchVariableButton = `button -l "Search Variables"`; | |
$variableListField = `textScrollList`; | |
$insertVariableButton = `button -l "Insert Variable"`; | |
$newVariableButton = `button -l "New Variable"`; | |
formLayout -e | |
-attachForm $searchVariable "top" 5 | |
-attachForm $searchVariable "left" 5 | |
-attachNone $searchVariable "bottom" | |
-attachPosition $searchVariable "right" 0 48 | |
-attachForm $searchVariableButton "top" 5 | |
-attachControl $searchVariableButton "left" 5 $searchVariable | |
-attachNone $searchVariableButton "bottom" | |
-attachForm $searchVariableButton "right" 5 | |
-attachControl $variableListField "top" 5 $searchVariable | |
-attachForm $variableListField "left" 5 | |
-attachPosition $variableListField "bottom" 0 93 | |
-attachForm $variableListField "right" 5 | |
-attachControl $insertVariableButton "top" 5 $variableListField | |
-attachForm $insertVariableButton "left" 5 | |
-attachForm $insertVariableButton "bottom" 5 | |
-attachPosition $insertVariableButton "right" 0 48 | |
-attachControl $newVariableButton "top" 5 $variableListField | |
-attachControl $newVariableButton "left" 5 $insertVariableButton | |
-attachForm $newVariableButton "bottom" 5 | |
-attachForm $newVariableButton "right" 5 | |
$variablesTab; | |
setParent ..; | |
$proceduresTab = `formLayout -nd 100 "Procedures"`; | |
$searchProcedure = `textField -h 25`; | |
$searchProcedureButton = `button -l "Search Procedures"`; | |
$procedureListField = `textScrollList`; | |
$insertProcedureButton = `button -l "Insert Procedure"`; | |
$newProcedureButton = `button -l "New Procedure"`; | |
formLayout -e | |
-attachForm $searchProcedure "top" 5 | |
-attachForm $searchProcedure "left" 5 | |
-attachNone $searchProcedure "bottom" | |
-attachPosition $searchProcedure "right" 0 48 | |
-attachForm $searchProcedureButton "top" 5 | |
-attachControl $searchProcedureButton "left" 5 $searchProcedure | |
-attachNone $searchProcedureButton "bottom" | |
-attachForm $searchProcedureButton "right" 5 | |
-attachControl $procedureListField "top" 5 $searchProcedure | |
-attachForm $procedureListField "left" 5 | |
-attachPosition $procedureListField "bottom" 0 93 | |
-attachForm $procedureListField "right" 5 | |
-attachControl $insertProcedureButton "top" 5 $procedureListField | |
-attachForm $insertProcedureButton "left" 5 | |
-attachForm $insertProcedureButton "bottom" 5 | |
-attachPosition $insertProcedureButton "right" 0 48 | |
-attachControl $newProcedureButton "top" 5 $procedureListField | |
-attachControl $newProcedureButton "left" 5 $insertProcedureButton | |
-attachForm $newProcedureButton "bottom" 5 | |
-attachForm $newProcedureButton "right" 5 | |
$proceduresTab; | |
setParent ..; | |
formLayout -e | |
-attachForm $toolTab "top" 0 | |
-attachForm $toolTab "left" 0 | |
-attachForm $toolTab "right" 0 | |
-attachForm $toolTab "bottom" 0 | |
$form; | |
showWindow $scriptToolWindow; | |
// Script Field Window. | |
window -e -tlc 5 825 -wh 550 800 $scriptToolWindow; | |
$scriptWindow = `window -t "Script Editor" -mb 1 -tlc 5 5 -wh 800 800 -ret scriptUI`; | |
$fileMenu = `menu -l "File" -to 1`; | |
menuItem -l "New Script" -c "newScript($scriptField)"; | |
menuItem -l "Load Script..." -c "loadScript($scriptField)"; | |
menuItem -l "Save Script..." -c "saveScript($scriptField)"; | |
menu -l "Edit" -to 1; | |
$undo = `menuItem -l "Undo"`; | |
$redo = `menuItem -l "Redo"`; | |
menuItem -l "Edit Script" -c "editScript($scriptField, $fileMenu, $undo, $redo, $toolTab)"; | |
menu -l "Window" -hm 1 ; | |
$showTool = `menuItem -l "Toggle Tool Window" -c "showTool($showTool)"`; | |
$scriptLayout = `formLayout -nd 100`; | |
$scriptField = `scrollField -tx $script -ed 0 scriptField`; | |
formLayout -e | |
-attachForm $scriptField "top" 0 | |
-attachForm $scriptField "left" 10 | |
-attachForm $scriptField "bottom" 10 | |
-attachForm $scriptField "right" 10 | |
$scriptLayout; | |
showWindow $scriptWindow; | |
window -e -tlc 5 5 -wh 800 800 $scriptWindow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// | |
/// /// | |
/// SCRIPT: kdSegmentJointV1.0.mel - MEL Script /// | |
/// /// | |
/// AUTHOR: Kory Dondzila - kory@korydondzila.com /// | |
/// www.korydondzila.com /// | |
/// /// | |
/// DESCRIPTION: Divides the selected joint into equal /// | |
/// segments. /// | |
/// /// | |
/// USAGE: Source script then run: segmentJointUI(); /// | |
/// /// | |
/// EDITS TO DO: N/A /// | |
/// /// | |
/// THINGS TO ADD: N/A /// | |
/// /// | |
/// VERSIONS: 1.0 - Oct 26, 2011 - Initial Release /// | |
/// /// | |
////////////////////////////////////////////////////////////////////////// | |
// This is the procedure that segments the joint. | |
proc segment( string $segmentField, string $orient1, string $orient2, string $orient3, string $orient4 ) | |
{ | |
// Gets the selected joints, procedure returns if | |
// no joints are selected or there is no child joints. | |
string $selJnt[] = `ls -typ "joint" -sl -dag`; | |
if ( size( $selJnt ) == 0 ) | |
{ | |
confirmDialog -t "Warning" -m "No joint was selected." -ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
return; | |
} | |
else if ( size( $selJnt ) == 1 ) | |
{ | |
confirmDialog -t "Warning" -m "Only one joint was selected.\nSelect a joint with a child joint." -ma "center" -b "OK" -db "OK" -cb "OK" -ds "OK" -icn "warning"; | |
return; | |
} | |
// Gets the number of segments from the UI. | |
int $seg = `intSliderGrp -q -v $segmentField`; | |
// Gets the selected orientation. | |
int $whichOrient1 = `radioButtonGrp -q -sl $orient1`; | |
int $whichOrient2 = `radioButtonGrp -q -sl $orient2`; | |
string $jntOrient; | |
// If the first button grp has a button selected | |
// assign a string based on case. Else go to the second | |
// button grp. | |
if ( $whichOrient1 > 0 ) | |
{ | |
switch ( $whichOrient1 ) | |
{ | |
case 1: | |
$jntOrient = "xyz"; | |
break; | |
case 2: | |
$jntOrient = "yxz"; | |
break; | |
case 3: | |
$jntOrient = "zxy"; | |
break; | |
case 4: | |
$jntOrient = "none"; | |
break; | |
} | |
} | |
else | |
{ | |
switch ( $whichOrient2 ) | |
{ | |
case 1: | |
$jntOrient = "xzy"; | |
break; | |
case 2: | |
$jntOrient = "yzx"; | |
break; | |
case 3: | |
$jntOrient = "zyx"; | |
break; | |
} | |
} | |
// Gets the selected second axis orientation. | |
int $whichOrient3 = `radioButtonGrp -q -sl $orient3`; | |
int $whichOrient4 = `radioButtonGrp -q -sl $orient4`; | |
string $secOrient; | |
// If the third button grp has a button selected | |
// assign a string based on case. Else go to the fourth | |
// button grp. | |
if ( $whichOrient3 > 0 ) | |
{ | |
switch ( $whichOrient3 ) | |
{ | |
case 1: | |
$secOrient = "xup"; | |
break; | |
case 2: | |
$secOrient = "yup"; | |
break; | |
case 3: | |
$secOrient = "zup"; | |
break; | |
} | |
} | |
else | |
{ | |
switch ( $whichOrient4 ) | |
{ | |
case 1: | |
$secOrient = "xdown"; | |
break; | |
case 2: | |
$secOrient = "ydown"; | |
break; | |
case 3: | |
$secOrient = "zdown"; | |
break; | |
} | |
} | |
// Gets the positions of the selected joint and it's child joint. | |
vector $sjPos = ( `joint -q -p $selJnt[0]` ); | |
vector $ejPos = ( `joint -q -p $selJnt[1]` ); | |
string $crJnt[]; | |
float $radius = ( `getAttr ($selJnt[0]+".radius" ) `; | |
// Input an integer for the TOTAL number of segments you need, for $seg. | |
select -cl; | |
// For loop creates joints in the proper position | |
// and assigns them to an array and parents the first created joint | |
// to the start joint and parents the end joint to the last created joint. | |
for ( $i = $seg; $i > 1; $i-- ) | |
{ | |
int $x = abs ( $i - $seg ); | |
$crJnt[ $x ] = `joint -p ( ( ( ( ( $sjPos.x ) - ( $ejPos.x ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.x ) ) | |
( ( ( ( ( $sjPos.y ) - ( $ejPos.y ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.y ) ) | |
( ( ( ( ( $sjPos.z ) - ( $ejPos.z ) ) / $seg ) * ( $i - 1 ) ) + ( $ejPos.z ) ) -rad $radius`; | |
if ( $x == 0 ) | |
parent $crJnt[ $x ] $selJnt[ 0 ]; | |
if ( ( $x + 1 ) == ( $seg - 1 ) ) | |
parent $selJnt[ 1 ] $crJnt[ $x ]; | |
} | |
// Orients the joints. | |
joint -e -oj $jntOrient -sao $secOrient -zso -ch $selJnt[0]; | |
} | |
// Main call procedure, sets up and creates the window. | |
global proc segmentJointUI() | |
{ | |
// If window exists then delete it. Prevents multiple instances of the | |
// same window. | |
if ( `window -q -ex segJoint` ) deleteUI segJoint; | |
// Declares global strings. | |
global string $segmentField; | |
global string $orient1; | |
global string $orient2; | |
global string $orient3; | |
global string $orient4; | |
// Makes window size to everything in it. | |
string $dialogBoxWindow = `window -t "Segment Joint" -rtf 1 segJoint`; | |
columnLayout -adj 1; | |
frameLayout -l "Segments"; | |
$segmentField = `intSliderGrp -l "Segments" -f 1 -min 2 -max 10 -fmx 100 -v 3`; | |
setParent ..; | |
frameLayout -l "Orientation"; | |
$orient1 = `radioButtonGrp -nrb 4 -sl 1 -la4 "xyz" "yxz" "zxy" "None"`; | |
$orient2 = `radioButtonGrp -nrb 3 -scl $orient1 -la3 "xzy" "yzx" "zyx"`; | |
setParent ..; | |
frameLayout -l "Second Axis Orientation"; | |
$orient3 = `radioButtonGrp -nrb 3 -sl 1 -la3 "+ X" "+ Y" "+ Z"`; | |
$orient4 = `radioButtonGrp -nrb 3 -scl $orient3 -la3 "- X" "- Y" "- Z"`; | |
setParent ..; | |
button -l "Segment Joint" -c "segment( $segmentField, $orient1, $orient2, $orient3, $orient4 )"; | |
// Show the window. | |
showWindow $dialogBoxWindow; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment