macroScript pb_AnimationBaker category:"Piranha-Bytes" buttonText:"AniBake" toolTip:"Animation Baker" ( struct BakeObj_DEF (Name, nPos, nRot, nTrans) rollout ro_BakePose "pb Animation Baker" ( groupBox grp_Objects "Bake Options: " pos:[5,5] width:310 height:100 checkbutton ui_AllObj "All Objects" pos:[10,25] width:100 height:20 checked:true checkbutton ui_SelObj "Selected Objects" pos:[110,25] width:100 height:20 checkbutton ui_ChildObj "Child Objects" pos:[210,25] width:100 height:20 button ui_AffObj "Affected Objects:" pos:[15,52] width:100 height:20 tooltip:"Print all affected objects to listener" label lbl_objCount "0" pos:[120,55] spinner ui_FrameRangeS "Range: " pos:[15,80] fieldwidth:40 range:[-99999,99999,0] type:#integer spinner ui_FrameRangeE "- " pos:[110,80] fieldwidth:40 range:[-99999,99999,0] type:#integer button ui_BakeChar "Bake Animation" pos:[5,110] width:100 height:20 tooltip:"Bake all animations" button ui_ReverseBaked "Reverse Baked Animation" pos:[110,110] width:150 height:20 enabled:false tooltip:"Reverse the previously baked animation" local bakeList = #() local theObjectList = #() function getChildNodes boneList childList = ( for c=1 to childList.count do ( append boneList childList[c] getChildNodes boneList childList[c].children ) ) function getObjectSelection = ( objs = #() if ui_AllObj.state == true then objs = objects as array if ui_SelObj.state == true then objs = getCurrentSelection() if ui_ChildObj.state == true then ( allChilds = #() objs = getCurrentSelection() for b=1 to objs.count do ( nodeList = #(objs[b]) getChildNodes nodeList objs[b].children join allChilds nodeList ) objs = #() for f=1 to allChilds.count do ( if (findItem objs allChilds[f]) == 0 then append objs allChilds[f] ) ) lbl_objCount.caption = objs.count as string lbl_objCount.pos = [120,55] return objs ) on ro_BakePose open do ( theObjectList = getObjectSelection() ui_FrameRangeS.value = animationRange.start ui_FrameRangeE.value = animationRange.end ) on ui_ChildObj changed state do ( ui_ChildObj.state = true ui_AllObj.state = false ui_SelObj.state = false theObjectList = getObjectSelection() ui_ReverseBaked.enabled = false ) on ui_AllObj changed state do ( ui_ChildObj.state = false ui_AllObj.state = true ui_SelObj.state = false theObjectList = getObjectSelection() ui_ReverseBaked.enabled = false ) on ui_SelObj changed state do ( ui_ChildObj.state = false ui_AllObj.state = false ui_SelObj.state = true theObjectList = getObjectSelection() ui_ReverseBaked.enabled = false ) on ui_AffObj pressed do print theObjectList function getChildBones boneList childList = ( for c=1 to childList.count do ( if ((classOf childList[c]) == BoneGeometry) then append boneList childList[c] getChildBones boneList childList[c].children ) ) on ui_ReverseBaked pressed do ( boneList = theObjectList aRange = interval ui_FrameRangeS.value ui_FrameRangeE.value progressStart "Reversing animation..." fCount = (((aRange.end - aRange.Start) as integer) / ticksperFrame) fAdv = (100.0 / fcount) / 2 prog = 0 cancelBake = false bakeTransList = #() for a=aRange.start to aRange.end do ( tList = #() progressUpdate prog cancelBake = getProgressCancel() if cancelBake == true then ( cancelBake = false messageBox "Sorry, canceling not possible!" ) for n=1 to boneList.count do ( at time a (append tList boneList[n].transform) ) append bakeTransList tList prog = prog + fAdv ) with animate on ( theKey = aRange.start for a=aRange.end to aRange.start by -1 do ( progressUpdate prog cancelBake = getProgressCancel() if cancelBake == true then ( cancelBake = false messageBox "Sorry, canceling not posiible!" ) prog = prog + fAdv for n=1 to boneList.count do ( ca = ((a as integer) / TicksPerFrame) + 1 at time theKey boneList[n].transform = bakeTransList[ca][n] ) theKey = theKey + 1 ) ) progressEnd() ) on ui_BakeChar pressed do ( theObjectList = getObjectSelection() boneList = theObjectList aRange = interval ui_FrameRangeS.value ui_FrameRangeE.value bakeTransList = #() progressStart "Baking animation..." fCount = (((aRange.end - aRange.Start) as integer) / ticksperFrame) print fCount fAdv = (100.0 / fcount) / 2 prog = 0 cancelBake = false for a=aRange.start to aRange.end do ( tList = #() progressUpdate prog cancelBake = getProgressCancel() if cancelBake == true then ( cancelBake = false messageBox "Sorry, canceling not possible!" ) for n=1 to boneList.count do ( at time a (append tList boneList[n].transform) ) append bakeTransList tList prog = prog + fAdv ) for n=1 to boneList.count do ( setInheritanceFlags boneList[n] #all keepPos:true boneList[n].position.controller = position_xyz() boneList[n].rotation.controller = euler_xyz() boneList[n].scale.controller = scalexyz() ) with animate on ( for a=aRange.start to aRange.end do ( progressUpdate prog prog = prog + fAdv cancelBake = getProgressCancel() if cancelBake == true then ( cancelBake = false messageBox "Sorry, canceling not possible!" ) for n=1 to boneList.count do ( ca = ((a as integer) / TicksPerFrame) + 1 at time a boneList[n].transform = bakeTransList[ca][n] ) ) ) ui_ReverseBaked.enabled = true progressEnd() ) ) createDialog ro_BakePose width:320 height:140 )