Notifications
Clear all

[Closed] Switching lights on/off between frames

Hello !

I’m trying to create a script that runs before each frame is rendered in an animation that would be rendered on a farm.

Script checks through all lights and sets them on/off depending on a visibility of their parents. It does work when used manually (not as callback).

Here’s the code for manual usage:

for i = 1 to lights.count do (
  	lights[i].on = off
  		
  	if lights[i].parent.visibility == true then
  		(
  		lights[i].on = on
  		)
  )
  

Problem I’m facing is that it does not work when used as #preRenderFrame callback. The lights do set correctly before the first frame rendered, but not during the animation (thousands of frames) as multiple frames are rendered on a single machine.

This is what I have in prerender script:


  callbacks.removescripts id:#swl
  
  skripti = "print currentTime 
"
  skripti += "for i = 1 to lights.count do ( 
"
  skripti +="lights[i].on = off
"
  skripti +="	if lights[i].parent.visibility == true then (lights[i].on = on) ) 
"
  
  callbacks.addScript #preRenderFrame skripti id:#swl
  

Besides #preRenderFrame I’ve tried #preRenderEval. #preRender cannot be used as it is only executed in the beginning of the animation…

I use VRay 1.5 and Max 2009 64-bit.

Any help would be great to have

Jukka

3 Replies

It might be that it (light, renderer, etc.) simply doesn’t support animation of the on/off state of the light, much like 3ds Max doesn’t want you attempting to animate the hidden/unhidden state of a node. Just as the latter has a work-around in animating the visibility instead, you could animate the light’s multiplier to get an on/off switch; if you’re using any features that may appear independent of the multiplier, you’d have to adjust those as well.

Maybe it would be easier to create a script that keyframes the lights, you run it once, it turns on and off the lights as you desire and then render.

another option would be to put a script controller in the light multiplier and add the parent as a node, then you could use an if/then/else construct to set the appropriate light multiplier according to the visibility.