/* script by Yegor Tsyba */
/* http://www.shiva3d.net/ */
macroScript BakeSplineAnimation
enabledIn:#("max")
category:"Shiva Tools"
toolTip:"Bake Spline Animation"
buttonText:"Bake Spline Animation"
(
global BakeSplineAnimation_ui
try destroyDialog BakeSplineAnimation_ui catch()
rollout BakeSplineAnimation_ui "Bake Spline Animation"
(
spinner range_st "Frame range:" type:#integer range:[-10000,10000,0] pos:[5,0] fieldWidth:40
spinner range_end "to" type:#integer range:[-10000,10000,100] pos:[120,0] fieldWidth:40
edittext suffix_new_txt " New name suffix:" fieldWidth:100 pos:[5,20] text:"_Baked"
edittext suffix_old_txt "Origin name suffix:" fieldWidth:100 pos:[5,40] text:"_Original"
checkbox chk_del "Delete original" pos:[5,60] checked:false
checkbox chk_reduce "Reduce keys" pos:[100,60] checked:false
button btnBake "-=/ Bake! /=-" pos:[5,80] width:190 height:25 enabled:true
hyperLink homepage "www.shiva3d.net" address:"http://www.shiva3d.net/" pos:[55,105]
on BakeSplineAnimation_ui open do
(
range_st.value = animationRange.start
range_end.value = animationRange.end
)
on btnBake pressed do
(
objs = $selection
-- Shape filter --
local new_objs = #()
for o = 1 to objs.count do (
shp = copy objs[o]
if (convertToSplineShape shp) != undefined then append new_objs objs[o]
delete shp
)
objs = new_objs
new_objs = #()
-- Backe --
if objs.count > 0 then
(
ProgressStart ("Baking... " + objs.count as string + " Object(s)")
-- print "Start baking..."
for o = 1 to objs.count do (
print objs[o].name as string
source_obj = objs[o]
shp = copy source_obj
if (convertToSplineShape shp) != undefined then (
shp.name = source_obj.name + suffix_new_txt.text
append new_objs shp
source_obj.name += suffix_old_txt.text
animateVertex shp #all
--print objs[o].name
for t in (range_st.value as time ) to (range_end.value as time ) by 1 do (
--shp2 = copy source_obj
maxOps.cloneNodes source_obj cloneType:#copy newNodes:&nnl; shp2=nnl[1]
at time t convertToSplineShape shp2
animateVertex shp2 #all
-- print t
for i in 1 to shp[4][#Master].numsubs do (
local k = addNewKey shp[4][#Master][i].controller t
k.value = shp2[4][#Master][i].value
)
delete shp2
progressUpdate t
)
) else (
delete shp
print "...Its not shape. Skiped."
)
)
ProgressEnd()
-- Deleting originals --
if chk_del.checked == true then delete objs
-- Key Reducing --
if chk_reduce.checked == true do (
ProgressStart ("Redcing keys... " + new_objs.count as string + " Object(s)")
for o = 1 to new_objs.count do (
shp = new_objs[o]
for i in 1 to shp[4][#Master].numsubs do (
reduceKeys shp[4][#Master][i].controller 0.1 1f (interval range_st.value range_end.value)
)
)
ProgressEnd()
)
) else messagebox "No shapes selected!"
)
)
createDialog BakeSplineAnimation_ui 200 120 ( mouse.screenpos.x - 100 ) ( mouse.screenpos.y - 20 )
)