[Closed] bake Obj to Morpher
I’m looking to see if anyone has ideas on ways to enhance this code or even ways to make it run more efficiently.
The code essentially bakes all the selected objects into a morpher turning them on and then off at every frame to make it appear to be animating.
Right now it only works for up to a hundred frames that being because the morpher only allows for 100 of them.
(
try(destroyDialog ::rlBakeAnimation)catch()
ObjsArr = #()
fn fnAddItmsLst lst arr =
( -- add Objects to list
userSel = getCurrentSelection()
if userSel.count >= 1 do
(
for o in userSel do (appendIfUnique arr o)
lst.items = for i in arr collect i.name -- update list with array
)
)
fn fnRemoveItmsLst lst arr =
( -- remove objects from list
local currSel = lst.selection
for i = lst.items.count to 1 by -1 where currSel[i] do (deleteItem arr i)
lst.items = for i in arr collect i.name -- update list with array
lst.selection = #{}
)
fn fnClearLst lst arr =
( -- clears list
for i = lst.items.count to 1 by -1 do (deleteItem arr i)
lst.items = for i in arr collect i.name -- update list with array
lst.selection = #{}
)
--Rollout Ui
rollout rlBakeAnimation "Bake Animation"
(
groupbox gpbxGeneralParameters "Objects To Bake" width:160 height:220 pos:[10,6]
multiListBox mlbxBakeObjs "" pos:[19,28] width:140 height:12
button btnAddObjs "+" pos:[19,190] width:47 height:24
button btnRemoveObjs "-" pos:[66,190] width:46 height:24
button btnClearObjs "Clear" pos:[112,190] width:47 height:24
groupbox gpbxAnimRange "Animation Range" width:160 height:67 pos:[10,230]
label lbAnimStart "Start:" pos:[19,250]
label lbAnimEnd "End:" pos:[19,270]
spinner spnStartTime "" range:[-9999999,9999999,animationrange.start] fieldwidth:55 type:#integer pos:[92,250]
spinner spnEndTime "" range:[-9999999,9999999,animationrange.end] fieldwidth:55 type:#integer pos:[92,270]
button btnBakeAnimation "Run Bake Animation" pos:[10,300] width:160 height:28
on mlbxBakeObjs rightclick do (mlbxBakeObjs.selection = #{})
on btnAddObjs pressed do (fnAddItmsLst mlbxBakeObjs ObjsArr)
on btnRemoveObjs pressed do (fnRemoveItmsLst mlbxBakeObjs ObjsArr)
on btnClearObjs pressed do (fnClearLst mlbxBakeObjs ObjsArr)
fn animTime t =
(
return int(t + (0 - spnStartTime.value + 1))
)
on btnBakeAnimation pressed do
(
disableSceneRedraw()
startFrame = spnStartTime.value
endFrame = spnEndTime.value
if ObjsArr.count >= 1 do
(
undo off
(
blank = mesh numverts:0 numfaces:0
objs = #(blank)
for s in ObjsArr do
append objs s
snapshots = #()
for o = 1 to objs.count do
(
snapshots[o] = #()
for t = startFrame to endFrame do
(
snapshots[o][(animTime t)] = at time t snapshot objs[o]
)
)
for t = startFrame to endFrame do
(
--Try(ConvertTo snapshots[1][(animTime t)] Editable_Poly)Catch()
ConvertTo snapshots[1][(animTime t)] Editable_Poly
for s = 2 to snapshots.count do
(
snapshots[1][(animTime t)].EditablePoly.attach snapshots[s][(animTime t)] snapshots[1][(animTime t)]
)
)
base = snapshots[1][(animTime startFrame)]
AddModifier base (Morpher())
base.modifiers[1].Autoload_of_targets = 1
for t = (startFrame + 1) to endFrame do
(
WM3_MC_BuildFromNode base.modifiers[1] (animTime (t - 1)) snapshots[1][(animTime t)]
WM3_MC_Rebuild base.modifiers[1] (animTime (t-1))
)
with animate on
(
for t = startFrame to endFrame do
(
for s = 1 to (snapshots[1].count - 1) do
(
at time t WM3_MC_SetValue base.modifiers[1] s 0.0
)
)
for t = (startFrame + 1) to endFrame do
(
at time t WM3_MC_SetValue base.modifiers[1] (animTime (t - 1)) 100.0
)
)
for s = 2 to snapshots[1].count do
(
hide snapshots[1][s]
)
snapshots = undefined
base.wirecolor = blue
base.name = "BakedObjects"
select base
)
)
enableSceneRedraw()
completeRedraw()
)
)
createDialog rlBakeAnimation 180 338
)
John
I haven’t tried this so it’s only a suggestion. You could try using progressive morphs on each channel to multiply the number of targets you can use. I think you can have 26 progressive targets. Might be good to keep it to 25 so it’s a nice round number. But even that jumps the target count from 100 to 2500.
Or there’s always pointcache. You could script the recording of a single frame pointcache for all objects and have a massive stack that animates the strength value of each pointcache on for each successive frame and records a pointcache at the end. I’m actually revisiting an old script of mine right now that merges a list of pointcaches to a single pointcache file. I wrote this for combining a lot of separate animated sequences so they can be output for use in a realtime web engine.
Cheers,
Cg.
Hi @JokerMartini
I don’t fully understand what you want to do with that code. If what you want is to combine different meshes keeping each vertex animation maybe this script I’ve made, or some part of the code, will help you.
The script is called Rs PointCache Merger and does just what @3rd Dimentia said.
You can get it here: http://www.recubo.biz
And on Scriptspot you’ll find more info and tuts: http://www.scriptspot.com/3ds-max/scripts/rs-pointcache-merger