PDA

View Full Version : How to set a key at every frame while playback only without timer.


CerberusC
04-12-2009, 01:06 PM
That's my today's question. hehe

How can i do that?

Think about that.

You have an object and you want to set a key in position (it's just an example) at every frame, but you want to do taht only when you hit play.

So i tried using a timer, but it's not exact, and i know that i can do something like that with "slidertime", just right now i don't remember where i saw it and i dont find any help inside the maxscript help file.

I think it was a for loop, but i cannot imagine how.

Help please.

Cheers.

SyncViewS
04-12-2009, 02:24 PM
Hi Juan,
this is a super basic error-prone script, just to show elements you need for your work. It places a key on every frame only while showing playback, in the position tracks of the currently selected object.
Unfortunately results aren't that good, because every time a key is inserted, the animation curve is slightly changed because of key tangency handles, bringing to a quite different curve. I would avoid this by making a two pass algorithm: on the first pass gather controller values in an array, while on the second add the keys.

(
rollout rolTest "Set Keys"
(
checkButton cbtActive "Activate!" width:80 align:#center

function setKeyProc =
(
testNode = selection[1]

if ( (isValidNode testNode) and (isAnimPlaying() == true) ) then
(
-- Warning: very bad track selection mode!
addNewKey testNode.controller[1][1] currentTime
addNewKey testNode.controller[1][2] currentTime
addNewKey testNode.controller[1][3] currentTime
)
)

on cbtActive changed bState do
(
if (bState == true) then
(
registerTimeCallback setKeyProc
)
else
(
unRegisterTimeCallback setKeyProc
)
)

on rolTest close do
(
unRegisterTimeCallback setKeyProc
)
)

createDialog rolTest 90 30 style:#(#style_toolwindow, #style_border, #style_sysmenu)
)

- Enrico

CerberusC
04-12-2009, 02:33 PM
Thanks, going to test, i think for my script the curve problem is not a problem.

Cheers!

CerberusC
04-12-2009, 03:53 PM
Thanks Enrico, it works flawlessly for my purposes. :D

Now i have another question in the forum.

Cheers.

CGTalk Moderation
04-12-2009, 03:53 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.