[Closed] Evaluate script every frame
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
You can use a ‘timeChangeCallback’ or alternatively a ‘redrawViewsCallback’ and checking whether the time changed.
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 ?
Haha, I have a games-centric view. Never think about rendering >_<
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
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
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.
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
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…
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