I'm working on something to improve working with lights in Max. The sample below is a simplified version of a small part of what I'm doing, but it illustrates the issue I'm having. Basically, this script should allow a light's shadow type to be animated. It works while scrubbing the slider, but not while rendering multiple frames at a time. What is it I'm doing wrong?
-- Function to set a light's shadow type
fn setShadowType lit t = (
local sg = &lit.shadowGenerator
case t of (
1: if classOf (*sg) != Adv__Ray_Traced do (*sg) = Adv__Ray_Traced()
2: if classOf (*sg) != mental_ray_Shadow_Map do (*sg) = mental_ray_Shadow_Map()
3: if classOf (*sg) != Area_Shadows do (*sg) = Area_Shadows()
4: if classOf (*sg) != ShadowMap do (*sg) = ShadowMap()
5: if classOf (*sg) != RayTraceShadow do (*sg) = RayTraceShadow()
default: ()
)
)
-- Function called by ddl_ShadowType handler
fn h_ddl_ShadowType ctrl = (
local h = ctrl.modifiers[#holder]
setShadowType h.lit h.shadowType
)
-- Custom attributes for control object
ca_ShadowControl = attributes "shadowControl" (
parameters params rollout:RO (
lit type:#maxObject
shadowType type:#integer ui:ddl_ShadowType animatable:true default:1
)
rollout RO "Shadow Control" (
local ctrl
dropDownList ddl_ShadowType "Shadow Type" \
items:#("Adv. Ray Traced", "mental ray Shadow Map", "Area Shadows", "Shadow Map", "Ray Traced Shadows")
on RO open do (
animButtonState = true
ctrl = (refs.dependentNodes (custAttributes.getOwner this))[1]
)
on ddl_ShadowType selected s do h_ddl_ShadowType ctrl
)
)
-- Set up callbacks
-------------------
unregisterTimeCallback updateShadows
callbacks.removeScripts id:#shadowControl
fn updateShadows = (
format "fn updateShadows\n"
format " currentTime: %\n" currentTime
local ctrl
for o in objects where (o.modifiers[#holder] != undefined) do ctrl = o
local h = ctrl.modifiers[#holder]
local lit = refs.dependentNodes h.lit firstOnly:true
local sg = &lit.shadowGenerator
case h.shadowType of (
1: if classOf (*sg) != Adv__Ray_Traced do (*sg) = Adv__Ray_Traced()
2: if classOf (*sg) != mental_ray_Shadow_Map do (*sg) = mental_ray_Shadow_Map()
3: if classOf (*sg) != Area_Shadows do (*sg) = Area_Shadows()
4: if classOf (*sg) != ShadowMap do (*sg) = ShadowMap()
5: if classOf (*sg) != RayTraceShadow do (*sg) = RayTraceShadow()
)
format " classOf lit.shadowGenerator: %\n" (classOf lit.shadowGenerator)
)
registerTimeCallback updateShadows
callbacks.addScript #preRenderEval "updateShadows()" id:#shadowControl
-- Set up test scene
(
delete objects
p = plane pos:[0,0,0] length:200 width:200
s = sphere pos:[37.5,25,50]
lit = freeSpot pos:[0,0,200] castShadows:on
ctrl = point pos:[0,0,0] size:100 box:on cross:off
holder = emptyModifier name:"holder"
custAttributes.add holder ca_ShadowControl #unique
addModifier ctrl holder
holder.lit = lit
with animate on for k = 0 to 4 do at time k ( -- General Parameters: (Shadow Types)
ctrl.modifiers[#holder].shadowType = k + 1
h_ddl_ShadowType ctrl
)
)