PDA

View Full Version : How to execute MAX Script on every frame at render time ? - please advise


vicar
14-08-2006, 10:57 PM
Hello All !

I wonder if somebody would be so kind as to point me closer to the solution of the particular MAX Script issue I have.

Using Max 6, I need a precise control over a video file bitmap starttime property (found in "Time" rollout of the Material editor).
That property is not animatable directly in Max 6 :(, so I wrote a tiny script that manages what I want to achieve, but only at viewport level.

Here's a script :

*************************************
unRegisterTimeCallback startFrame_add

fn startFrame_add = (
if mod sliderTime 100 == 0 then (
meditMaterials[1].material1.diffuseMap.starttime += 25
)
)

registerTimeCallback startFrame_add

*************************************
I know it's very crude, but as said - it works as a "proof of concept".

What it does is : Every 100 frames the start time (offset) of a video file placed in difussion channel of my object material is set back by 25 frames.

I won't bore anybody explaining just why do I need such effect, suffice to say the script above works, but just in the viewports.

It does not execute at render time, however :(

I know I am missing something vital to do with a different type of callback mechanism, but after trying out several routes I am none the wiser still ...

Can anybody think of how to implement a script that will have the same result, but at reder time ?

(And before anybody suggests to edit my source Video file in the first place prior to using it in Diffuse channel - Thank you, but it would be very unpractical in my case as I need to use several varying segments of it with different delays)

Your help will be much appreciated !

Thank you.

Nykster
17-08-2006, 05:31 AM
Hi
I hope I understand the problem correctly, here's a solution that could work... if you haven't already tried it :)

You could use the "general event callback" from Max; #postRenderFrame:

callbacks.addScript #postRenderFrame "startFrame_add()" id:#MyCallBack

According to MaxScript reference, this callback will is sent after each frame is rendered. So the function "startFrame_add" will be called after each frame is done rendering. I haven't tried that particular callback, so I dont know if it's gonna work... Good luck :)

Oh and, you might wanna kill the callback when you close your script or something... (callbacks.removeScripts id:#MyCallBack)

Hope this helps...

eeek
07-04-2007, 10:47 AM
why dont you call the fn on each frame, then render each frame sequencially using a for loop? then load the frames into the video post and render out as a movie etc?

MaggieQue
20-04-2007, 05:24 AM
I used for loop generate keys.
http://i82.photobucket.com/albums/j243/maggieque/threedy/051.gif



deleteKeys meditMaterials[1].diffuse.controller /*Delete diffuse color keyframes at Slot1 material if applicable*/
delete $* /*Delete everything on scene*/
b = box() /*Create box*/
b.material = meditMaterials[1] /*Assign Slot1 material to box*/

animate on
(
for i=0 to 100 by 10 do /*Create key at every 10th frame within 100 frames*/
(
at time i
(
--Generate random color
meditMaterials[1].diffuse.r = (random 0 255)
meditMaterials[1].diffuse.g = (random 0 255)
meditMaterials[1].diffuse.b = (random 0 255)
)
)
)

MaggieQue
20-04-2007, 05:43 AM
I need a precise control over a video file bitmap starttime property (found in "Time" rollout of the Material editor).
That property is not animatable directly in Max 6 :(, so I wrote a tiny script that manages what I want to achieve, but only at viewport level.


meditMaterials[1].diffuseMap.starttime = 9f
meditMaterials[1].diffuseMap.playBackRate = 2
meditMaterials[1].diffuseMap.endCondition = 0 --0:Loop, 2:Ping Pong, 3:Hold

MaggieQue
08-05-2007, 11:29 PM
u could try this little funny script:


s = sphere()
for i = 0 to 100 do
(
sliderTime = i
s.radius = currentTime
)


The slide bar will move by itself. But after execute, when u scroll the timeline the radius remain unchange.


And I learnt this from maxscript reference file:

s = Sphere()
s.radius.controller = Float_Script()
s.radius.controller.script = "currentTime"
Assign controller to the sphere radius, when u scroll the timeline, radius change interactively.


Correct me if I'm wrong.