//
//
//Script Name:多米诺骨牌v.1
//Author:疯狂小猪
//Last Updated: 2011.10.5
//Email:[email protected]
//
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
global proc createDmn()
{
if (`window -ex dmn`)
deleteUI dmn;
window
-t "多米诺骨牌v.1"
-w 400 -h 300
-menuBar true
-menuBarVisible true
dmn;
menu
-label "edit"
-tearOff 0;
menuItem
-label "默认设置" -c "err";
menuItem
-label "退出"
-c "deleteUI dmn";
menu
-label "help"
-tearOff 0;
columnLayout
-cw 300
-adj true
-rowSpacing 5 ;
button
-h 30
-l "拾取曲线"
-al "center"
-c "loadCurve"
selectLabel;
textFieldGrp
-l "曲线选择"
loadCurve;
columnLayout
-adj true
-cal "left"
-rowSpacing 5 ;
separator
-style "in";
text
-fn boldLabelFont
-al "left"
-l "创建设置:";
intSliderGrp
-field true
-l"骨牌间隔"
-minValue 1 -maxValue 100.0
-fieldMinValue 1 -fieldMaxValue 100
-value 10 jiange;
intSliderGrp
-field true
-l"距离长度"
-minValue 400 -maxValue 1000
-fieldMinValue 400 -fieldMaxValue 1000
-value 400 changdu;
floatSliderGrp
-field true
-l"骨牌宽度"
-minValue 0 -maxValue 10
-fieldMinValue 0 -fieldMaxValue 10
-value 1.25 x;
floatSliderGrp
-field true
-l"骨牌高度"
-minValue 0 -maxValue 10
-fieldMinValue 0 -fieldMaxValue 10
-value 3 y;
floatSliderGrp
-field true
-l"骨牌厚度"
-minValue 0 -maxValue 10
-fieldMinValue 0 -fieldMaxValue 10
-value 0.3 z;
separator
-height 5
-style "in";
text
-fn boldLabelFont
-al "left"
-l "速度设置:";
intSliderGrp
-field true
-l"单体倒塌速度"
-minValue 1 -maxValue 100.0
-fieldMinValue 1 -fieldMaxValue 100
-value 20 dtsudu;
intSliderGrp
-field true
-l"全局倒塌速度"
-minValue 1 -maxValue 50
-fieldMinValue 1 -fieldMaxValue 50
-value 15 qjsudu;
intSliderGrp
-field true
-l"倒塌角度极限"
-minValue 50 -maxValue 90
-fieldMinValue 50 -fieldMaxValue 90
-value 84 singleRot;
columnLayout
-adj 1
-cal "left"
-cat "both" 5
-columnWidth 68
-rowSpacing 5;
button
-h 30
-l"创建骨牌"
-al "center"
-c "createDmn";
button
-h 30
-l"删除骨牌"
-al "center"
-c "deleteGp ";
button
-h 30
-l"删除曲线"
-al "center"
-c "deleteCurve";
button
-h 30
-l"创建动画"
-c "addMotion"
-al "center";
button
-h 30
-l"删除动画"
-c "deleteMotion"
-al "center";
setParent..;
showWindow dmn;
}
global proc dmn()
{
$curveName = `textFieldGrp -q -tx loadCurve`;
$mp = `intSliderGrp
-q -v changdu`;
$jiange = `intSliderGrp
-q -v jiange`;
$x = `floatSliderGrp
-q -v x`;
$y = `floatSliderGrp
-q -v y`;
$z = `floatSliderGrp
-q -v z`;
polyCube
-ch on
-o on
-w $x
-h $y
-d $z
-cuv 4
-n gp1;
move
-r 0 ($y/2*-1) 0 gp1.scalePivot gp1.rotatePivot ;
setAttr "gp1.translateY" ($y/2*-1);
group
-name "gp";
xform
-os
-piv 0 0 0;
select
-cl ;
select
-r gp1 $curveName ;
pathAnimation
-fractionMode true
-follow true
-followAxis z
-upAxis y
-worldUpType "vector"
-worldUpVector 0 1 0
-inverseUp false
-inverseFront false
-bank false
-startTimeU 1
-endTimeU
$mp;
for($ee=$jiange;$ee<=$mp;$ee+=$jiange)
{
currentTime $ee;
select
-r gp1 ;
duplicate
-rr;
}
currentTime 1;
cycleCheck -e 0;
delete motionPath1;
}
global proc createDmn()
{
if(`objExists curve1`)
{
if(`objExists gp`)
{
delete gp;
dmn;
}
else
{
dmn;
}
}
else
{
confirmDialog
-message "你必须创建一条曲线!"
-button "确定";
}
}
global proc deleteCurve()
{
select -cl;
SelectAllNURBSCurves;
$selection = `ls -sl`;
if(`size($selection)` == 0)
confirmDialog
-message "场景中没有可删除曲线"
-button "确定";
else
delete;
}
global proc deleteGp()
{
if(`objExists gp`)
delete gp;
else
confirmDialog
-message "场景中没有可删除的骨牌模型!"
-button "确定";
}
global proc loadCurve()
{
$select = `ls -sl`;
if(`size($select)` == 0)
{
confirmDialog
-message "你什么都没有选择"
-button "确定";
}
else
{
$selectShap = `listRelatives -f $select[0]` ;
if(`nodeType $selectShap` != "nurbsCurve")
{
confirmDialog
-button "确定"
-message "你选择的不是曲线物体";
}
else
{
textFieldGrp -e -tx $selectShap loadCurve;
}
}
}
global proc addMotion()
{
if(`objExists dmnMotion`)
{
delete dmnMotion;
}
expression -s "select -cl;\r\nselect \"gp*\";\r\n$select = `ls -sl`;\r\n$num = (`size($select)` -1 )/2;\r\nint $singleSpeed = `intSliderGrp -q -v dtsudu`;\r\nint $globalSpeed = `intSliderGrp -q -v qjsudu`;\r\nint $finalRot = `intSliderGrp -q -v singleRot`;\r\n\r\n\r\n\r\nfor($i=1;$i<=$num;$i++)\r\n{\r\n string $attr=\"gp\"+$i+\".rx\";\r\n $rot=linstep(0+$i*$globalSpeed,$singleSpeed+$i*$globalSpeed,frame)*$finalRot;\r\n setAttr $attr $rot;\r\n}" -o "" -n "dmnMotion" -ae 1 -uc all ;
}
global proc deleteMotion()
{
if(`objExists dmnMotion`)
{
currentTime 1;
delete dmnMotion;
}
}