MAX高级应用.docx
《MAX高级应用.docx》由会员分享,可在线阅读,更多相关《MAX高级应用.docx(17页珍藏版)》请在冰点文库上搜索。
![MAX高级应用.docx](https://file1.bingdoc.com/fileroot1/2023-6/5/c6587ebc-90a7-4322-8f2a-77b3b3fc0734/c6587ebc-90a7-4322-8f2a-77b3b3fc07341.gif)
MAX高级应用
么什么高级意思,只是用来刷分,谨慎进入
ifPw_tools!
=undefinedthencloseRolloutFloaterPw_tools
Pw_tools=newrolloutfloater"完美工具"16023592075
rolloutSpring_tools"裙摆工具"width:
165height:
298
(
localFirstBoneArray=#()
localLastBoneArray=#()
localLastPointArray=#()
localChildArray=#()--子物体的数组
localPosArray=#()--用来创建线的坐标数组
localAddSpringPoints=#()--加弹簧的点
localLyLine--创建线性骨骼用的线
localMySpline
localAllObj
localPtTension=1--越小越有弹性
localPtInd=1.8
localPtMass=300.0--越重越有弹性越大越有弹性
localMassInd=1.3
localMyIks=#()
localfilename=""
GlobalEC_OBJ,EC_TargetObj,EC_SplineOBJ,EC_HelperOBJ
fnGetChildrenObj=
(
ifObj.children.count!
=0then
(
EC_TargetObj=Obj.children[1]
ifEC_TargetObj.children.count!
=0then(GetChildrenEC_TargetObj)
)
)
fnSplinIk=
(
IFgetCommandPanelTaskMode()!
=#motionthenSetCommandPanelTaskModeMode:
#Motion
-------------------------------------------------------------------------------------------
--CheckforGroupsandactaccordingly
-------------------------------------------------------------------------------------------
EC_OBJ=selection[1]
ifselection.count>1do
(
localh=EC_OBJ.parent
if(h!
=undefinedandh.isSelectedandisGroupHeadh)doEC_OBJ=h
)
Animateoff
(
-------------------------------------------------------------------------------------------
--DefineFilterFunctionsforPickObjectSelection
-------------------------------------------------------------------------------------------
fnChildFilto=Filters.Is_ChildEC_OBJoorFilters.Is_ParentEC_OBJo
fnShapeFilto=superClassOfo==Shapeando!
=EC_OBJ
-------------------------------------------------------------------------------------------
GetChildrenEC_OBJ
--EC_TargetOBJ=PickObjectcount:
1select:
truefilter:
ChildFiltcount:
#MultipleMessage:
"PickJointtocompleteIKChain"Rubberband:
EC_OBJ.posForceListenerFocus:
False
IfEC_TargetOBJ!
=#escapeorEC_TargetOBJ!
=undefinedthen
(
ifFilters.Is_ChildEC_OBJEC_TargetOBJthen
(
NIK=iksys.IKChainEC_OBJEC_TargetOBJ"SplineIKSolver"
appendMyIksNIK
)
Else
(
NIK=iksys.IKChainEC_TargetOBJEC_OBJ"SplineIKSolver"
appendMyIksNIK
)
)
EC_SplineOBJ=MySpline
--EC_SplineOBJ=PickObjectcount:
1select:
truefilter:
ShapeFiltcount:
#MultipleMessage:
"PickSplinetoassignSplineIK"Rubberband:
EC_TargetOBJ.posForceListenerFo
IfEC_SplineOBJ!
=undefinedandEC_SplineOBJ!
="None"then
(
-------------------------------------------------------------------------------------------
--MaketheSplinethegoalshapeoftheSplineIK
-------------------------------------------------------------------------------------------
NIK.transform.controller.pickShape=EC_SplineOBJ
-------------------------------------------------------------------------------------------
--AddSplinIKControlModifierandCreateHelpers
-------------------------------------------------------------------------------------------
mod=Spline_IK_Control()
AddModifierEC_SplineOBJ(mod)
mod.createHelper(0)
EC_HelperOBJ=mod.helper_list[1]
--Settheupnodetothefirsthelper
NIK.controller.upnode=EC_HelperObj
-------------------------------------------------------------------------------------------
--AddListControllerandPathConstraint
-------------------------------------------------------------------------------------------
localcont
ifFilters.Is_ChildEC_OBJEC_TargetOBJthen
(
cont=AddListControllerEC_OBJ"Pos"Position_List
Ifclassofcont[listCtrl.GetActivecont].object!
=Path_Constraintthenconstraint=AddConstraintEC_OBJ"Pos"Path_Constrainttrue
elseconstraint=cont[listCtrl.GetActivecont].object
)
else
(
cont=AddListControllerEC_TargetOBJ"Pos"Position_List
Ifclassofcont[listCtrl.GetActivecont].object!
=Path_Constraintthenconstraint=AddConstraintEC_TargetOBJ"Pos"Path_Constrainttrue
elseconstraint=cont[listCtrl.GetActivecont].object
)
-------------------------------------------------------------------------------------------
--AddPathConstraintObjectTargetasthespline
-------------------------------------------------------------------------------------------
constraint.AppendTargetEC_SplineObj50
DeleteKeysconstraint.percent.controller
constraint.percent=0.0
-------------------------------------------------------------------------------------------
--SetActiveController
-------------------------------------------------------------------------------------------
SetActiveControllercontconstraint
--Format"%\n"(EC_OBJ.name+"isPositionConstrainedto"+EC_HelperOBJ.name)to:
Listener
SelectEC_OBJ
)
MaxMotionMode
)
)
fnSaveONameObj=
(
f=createFilefilename
foroinObjdo
(
format"$%\n"o.nameto:
f--outputnameinapathnameform
)
closef
)
fndeleteObj=
(
f=openFilefilename
whilenoteoffdo
(
o=readValuef--readobject
try(deleteo)catch()
)
closef
)
fnSelChildrenselSelChilds=--把子物体加进选择集函数
(
fori=1tosel.children.countdo
(
tempsel=sel.children[i]
appendSelChildstempsel
iftempsel!
=undefineddoSelChildrentempselSelChilds
)
returnSelChilds
)
fnSelArrayToPosArraySelArray=--选择集转换成坐标pos集函数
(
foriinSelArraydo
(
appendPosArrayi.pos
)
returnPosArray
)
fndrawLineptArray=----画线函数
(
LyLine=SplineShapepos:
ptArray[1]
addNewSplineLyLine
foriin1toptArray.countdo
(
addKnotLyLine1#corner#lineptArray[i]
)
updateShapeLyLine
returnLyLine
)
fncopybonessel=--拷贝骨骼并隐藏
(
FirstBoneArray=#()--子物体数组
appendFirstBoneArraysel--把自己加进选择集
SelChildrenselFirstBoneArray--把子骨骼加入数组
LastBoneArray=#()
foriinFirstBoneArraydo
(
appendLastBoneArray(copyi)
)
foriin2toLastBoneArray.countdo
(
LastBoneArray[i].parent=LastBoneArray[i-1]
)
hideFirstBoneArray
SelectLastBoneArray[1]--选择新复制骨骼的跟骨骼
)
fnSetTensionobjsTensionInd=--设置弹簧拉力
(
foriinobjsdo
(
i.pos.controller.Spring.setTension1Tension
Tension=Tension/Ind
)
)
fnsetMassobjsMassInd=--设置弹簧重力
(
foriinobjsdo
(
i.pos.controller.Spring.setMassMass
Mass=Mass*Ind
)
)
fnbakeAnimsel=--烘焙关键帧
(
FirstBoneArray=#()--子物体数组
appendFirstBoneArraysel--把自己加进选择集
SelChildrenselFirstBoneArray--把子骨骼加入数组
bakepoints=#()
starttime=animationrange.start
endtime=animationrange.end
foriin1to(FirstBoneArray.count-1)do
(
bakepoint=Pointtransform:
FirstBoneArray[i].transformisSelected:
on
appendbakepointsbakepoint
)
try(
AllObj=AllObj+bakepoints
SaveONameAllObj--保存所有物体名称到文本文件
)catch()
fortinstarttimetoendtimeby1do
(
sliderTime=t
withanimateon
(
foriin1tobakepoints.countdo----点跟着骨骼打关键帧
(
bakepoints[i].transform=FirstBoneArray[i].transform
)
)
)
ifMyIks.count!
=0then(deleteMyIks)else(delete$'IKChain*')
fortinstarttimetoendtimeby1do
(
sliderTime=t
withanimateon
(
foriin1tobakepoints.countdo----真正烘焙骨骼关键帧
(
FirstBoneArray[i].transform=bakepoints[i].transform
)
)
)
)
buttonbtn_CreatIk"创建软物体"pos:
[5,10]width:
136height:
20
buttonbtn_verysoft"软"pos:
[5,35]width:
20height:
20
buttonbtn_veryhard"硬"pos:
[120,35]width:
20height:
20
buttonbtn5"savedate"pos:
[5,60]width:
136height:
20
buttonbtn_soft"软"pos:
[29,35]width:
20height:
20
buttonbtn_yiban"一般"pos:
[53,35]width:
38height:
20
buttonbtn_hard"硬"pos:
[96,35]width:
20height:
20
buttonbtn_bakeAnim"烘焙关键帧"pos:
[5,85]width:
136height:
20
buttonbtn_clearscene"清理场景"pos:
[5,110]width:
136height:
20
onSpring_toolsopendo
(
animButtonState=off
)
onbtn_CreatIkpresseddo
(
ifselection.count==1then
(
FirstBoneArray=#()--清空变量
LastBoneArray=#()--清空变量
MyIks=#()--清空变量
filename=maxFilePath+(getFilenameFilemaxFileName)+"_"+$.name+".dat"
copybones$--拷贝骨骼并隐藏原来的骨骼
PosArray=#()--画线用的坐标
AddSpringPoints=#()--清空变量加弹簧控制的点
SelArrayToPosArrayLastBoneArray
MySpline=drawLinePosArray
SplinIk()--我的创建splineik的函数,创建线性ik,替代了下面这行的命令,哈哈!
--macros.run"InverseKinematics""SPLINE_IK"
LyLine.modifiers[#Spline_IK_Control].linkTypes=1
--下面是给每个控制点加上弹簧
foriin2toLyLine.modifiers[#Spline_IK_Control].helper_list.countdo
(
TempPoint=LyLine.modifiers[#Spline_IK_Control].helper_list[i]
appendAddSpringPointsTempPoint
TempPoint.pos.controller=SpringPositionController()
)
AddSpringPoints[1].parent.parent=LastBoneArray[1].parent
completeRedraw()--刷新一下场景,不然弹簧拉力设置不上。
SetTensionAddSpringPointsPtTensionPtInd--设置弹性
setMassAddSpringPointsPtMassMassInd--设置点重量
foriin1to(FirstBoneArray.count-1)do
(
myik=IKSys.ikChainFirstBoneArray[i]FirstBoneArray[i+1]"IKHiSolver"
appendMyIksmyik
myik.parent=LastBoneArray[i]
hidemyik
)
selectFirstBoneArray[1]
Allpoints=#()--创建线性ik时候产生的point点集合
foriin1toLyLine.modifiers[#Spline_IK_Control].helper_list.countdo
(
TempPoint=LyLine.modifiers[#Spline_IK_Control].helper_list[i]
appendAllpointsTempPoint
)
------------------------下面保存数据----