PDA

View Full Version : Evaluate script every frame


mef
12-17-2008, 01:03 AM
I have a situation where I need my script to be evaluated every frame to compare the position of two objects. Can someone clue me in?

-Marc

RobGalanakis
12-17-2008, 01:13 AM
You can use a 'timeChangeCallback' or alternatively a 'redrawViewsCallback' and checking whether the time changed.

ZeBoxx2
12-17-2008, 02:55 AM
redrawviews callback will fail in a render, of course - do you need to be able to run that script for each frame in a render as well ?

RobGalanakis
12-17-2008, 03:51 AM
Haha, I have a games-centric view. Never think about rendering >_<

mef
12-17-2008, 10:57 PM
Yes. The script has to be able to run while rendering.
Basically the script hides objects that are beyond the far environment setting of the camera and unhides it once it gets close enough.
I'm doing this to help reduce the memory overhead when rendering complex scenes in MR.
BTW. Thanks for the quick response.

Marc

ghostSource
12-18-2008, 09:02 AM
a little workaround that might help, if the script is not too complex, would be to create for example a helper and assign a scriptcontroller as positioncontroller. place your script in this controller - it will be evaluated every frame.



Martin

mef
01-02-2009, 09:40 PM
Thanks everybody.
I used 'registerTimeCallback <fn>' . That seemed to do the trick.
I haven't tested everything out yet with rendering, but at least I know I'm in the ballpark.


Marc

Bobo
01-02-2009, 09:55 PM
Thanks everybody.
I used 'registerTimeCallback <fn>' . That seemed to do the trick.
I haven't tested everything out yet with rendering, but at least I know I'm in the ballpark.


Marc

A word of warning - hiding objects IS NOT SUPPORTED by the renderer. The hidden state of objects is evaluated ONCE when the rendering starts and any object that was hidden or unhidden on the first frame will remain in that state for the whole sequence unless you call render() once per frame to update the scene for the renderer to see the changes.

A possible solution is to write a script which processes the visibility once and stored the data in the Visibility track of the objects. Then when you render, objects that should not be seen will be skipped by the renderer due to their visibility track, and when they come into view will appear again. If you change the animation, just rerun the script to update the visibility keys.

mef
01-02-2009, 11:35 PM
It seems that I get the same result regardless of which option I try. I've tried Hide/Unhide and I've tried using visibility tracks. It works fine in the viewport but does not update on a per-frame basis when rendering. I'm looking to see if there is another callback that I should be using.

--------------------------------------------------------------------------

Bobo.
I just reread what you wrote above and if I'm reading it correctly, what you're saying is that I should have the script create the keys for the visibility track of the objects instead of trying to have Max do it dynamically while rendering. And then if there's a change, just overwrite those keys.
I'll give it a try.

Marc

Bobo
01-03-2009, 02:50 AM
Bobo.
I just reread what you wrote above and if I'm reading it correctly, what you're saying is that I should have the script create the keys for the visibility track of the objects instead of trying to have Max do it dynamically while rendering. And then if there's a change, just overwrite those keys.
I'll give it a try.

Marc

You are reading that correctly. In theory (I haven't tried it, but it sounds plausible), you could place a Script Controller in the Visibility track of each object and update its content dynamically which should work in viewport and at render time. The value in the Visibility Track is being read by the renderer on each frame and if the controller says the object is invisible, the renderer wouldn't care whether the value came from a keyframed controller or a procedural one...

mef
01-04-2009, 07:03 PM
Thanks guys. Thanks for all of your help. I got the script working and now I just have to put on a few finishing touches and it will be all good. Just in time too because I had to have it ready for Monday.

Marc

CGTalk Moderation
01-04-2009, 07:03 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.