[Closed] Script Controller Not Evaluating on Render
Hi
I hae a strange problem with a script controller. It is not evaluating enough, when I render a frame or sequence or single frames. I have put a line in the script to print “Hello” each time it evaluates. Out of 100 frames it only prints it 32 times? If I preview it in the viewport it works fine. If I look in the Debug window and step through frame by frame it is ok. Just not in the renders!!?
Any help woulf be appreciated.
Using MAX 8
Harry
It would be best if we can see the expression and know what track it is on.
Hi Paul
The expression is on a Script Controller and goes as follows
RayDirection = $Middle_WheelLR_DUM.pos – $TOP_WheelLR_DUM.pos
RayDirection = normalize raydirection
Wheel = $TOP_WheelLR_DUM
Ground = $Ground
r = ray (Wheel.pos) raydirection
WhereonGround = intersectrayex Ground r
– Offset Original Dummy by Space Between them –
$Stp_SBuggy_WheelHeight_B_L.pos = WhereonGround[1].pos
$Stp_SBuggy_WheelHeight_B_L.pos.z -= 40
– print “hello”
WhereonGround[1].pos
I have done a little searching and the problem aonly appaers to occur with this scene. I have applied the script to a simple object and it works fine. Now I have to find out why this is happening on this scene.
Harry
have you declared variables?
you need to tell the script controller when to update – previous to max 8 you did this with the dependson command – in max 8 you need to assign variables so that when the (node, controller, maxobject ect…) that is assigned to the variable changes the script controller evaluates
mark
I think you are right.
So instead of using
RayDirection = normalize ($Middle_WheelLR_DUM.pos – $TOP_WheelLR_DUM.pos)
Wheel = $TOP_WheelLR_DUM
Ground = $Ground
one would have to define variables for Middle_WheelLR_DUM, TOP_WheelLR_DUM, Wheel and Ground and then assign the corresponding nodes to these variables just like it has always been the case in Expression controllers.
After that, inside the script the variables will contain references to the corresponding objects and can be used instead of $ pathnames, and the script will update whenever one of these objects updates…
Hi Guys
Thanks for getting back so quick. I understand what you are saying about the variables howeveer why would it work ok in the viewport and in a render of a simpler test scene?
I will go and try the variable approach straight away as this is pretty urgent
Bobo : I have to say that all of this is your fault I bought yours a Laszlos DVD on scripting at Christmas and this is what has happend! I am now writing scripts for everything LOL. Excellent DVD’s by the way.
Harry
Max nodes and their controllers are evaluated as needed, especially when rendering. Max tries to evaluate anything that requires evaluation and (since Max 6) tries to avoid doing this multiple times because of cascading event messages.
For example, a Dummy does not render, thus only its PRS controllers might require an evaluation on each frame during rendering as it can be used as part of hierarchy. A Spline primitive like a renderable Text evaluates its stack just on the first frame of rendering unless there is an animation in its Kerning. This is why getting animated text with MAXScript is tricky – if an external object would try to change the text on each frame, it would work in viewport but not in renderer, so you have to place the scipted controller in the Kerning track.
Max reevaluates all controllers on time change (when you play back or drag the time slider), so some evaluations could differ from what the renderer does.
In your example, your scripted controller is not explicitly dependent on any of the nodes it references by $path name. But if you change the time slider, the controller will still be reevaluated in the viewport because of this “brute force” approach. But if you would move one of the objects referenced in the controller without changing the time, no reevaluation will occur. Similarly, during rendering some of the evaluation could not match the results in the viewports, unless you make the controller dependent on the nodes it references.
In Max 3 to 7, you would do this by specifying dependsOn. In 8, you create variables which are stored in a Parameter Block and can contain pointers to the referenced nodes. Thus the controller behaves just like a real plugin dependent on another scene object and can resolve these dependencies even when the referenced nodes come from nested XRefs etc. MAXScript does not have to run around the scene collecting objects by $path name, Max already knows at a lower level when to send a notification to the controller to force an update because some referenced object has changed…
As for the DVD, I am sorry to hear I’ve made you addicted.
Be prepared for a new one next month which should blow your mind
Hi Bobo
Thanks for the explanation. I got called into work so couldnt try the variables yet
Will try them this weekend. Thanks for the explanation.
Have you got a new DVD coming out then?
Harry
Hi Again
I went through the script controller as advised and declared the varibles releating to objects. However the same problem remains. If I render out a sequence I do not get any animation. If I render out a sinlge frame it looks OK? If I preview it is also fine.
New Script as follows
RayDirection = WDM.pos – WDT.pos
RayDirection = normalize raydirection
Wheel = WDT
Ground = Ground_obj
r = ray (Wheel.pos) raydirection
WhereonGround = intersectrayex Ground r
what_i_move.pos = WhereonGround[1].pos
WhereonGround[1].pos
– WDT = Wheel Dummy top
– WDM = Wheel Dummy Middle
– WDG = Wheel Dummy Ground
– Ground_Obj = Ground Plane
– What_I_Move = Stp_SBuggy_WheelHeight_F_L
I appreciate any help you can give me.
Thanks
Harry
hi,
post a simple example scene displaying the problem and i will have a look at it and see if i can find the problem
mark
Hi Mark
Sorry for taking so long to get back. I havent been too well for the last couple of Days.
I cannot send the actual scene for NDA reasons. However i will try and create another simpler scene and send that in the next day or so.
Thanks
Harry