Notifications
Clear all

[Closed] Script controllers and viewport redraw

Hi, folks! Those days I’m playing with math formulas at home, for trying to improve my math skills as well as understanding how to implement them in MAXScript. I was trying to make a ‘sphere constraint’ for a point, so it’s always moving on a surface of a sphere.

In my way on doing that, and checking some other things, I came across a little problem that I’m going to reproduce here. You need one sphere and one point on your scene. I want the radius of the sphere to be measured by the distance between the center of that sphere and the point. There it comes the script controller you should use in the Radius track:

sqrt (($Point02.pos.x - $Sphere01.pos.x)^2 + ($Point02.pos.y - $Sphere01.pos.y)^2 + ($Point02.pos.z - $Sphere01.pos.z)^2)

It works fine, but the scene only is redrawn when I play the scene or I move the timeline slider forward and backwards. I’d like to have it ‘in real time’, so as I move the point in the 3D space, the radius on the sphere changes.

Could you help me out on this? Thanks!

5 Replies
 JHN

Real time… you will be looking at custom attributes and some way to check the last value… I have had a fight with a realtime script controller but never finished it. But it definitly can be done, over at scriptspot there’s some script that uses it : http://www.scriptspot.com/3ds-max/realtime-spring

You should tear that apart, and please post your findings here, i’d be interrested!

My 2 eurocents,
-Johan

you need to add the Point as a ‘Node’ in the Expression script. That way it will update in realtime whenever you move the Point.

When you add the script controller to the radius of the sphere, use the Create Variables in the script controller and add the Point as a Node.
then in your script use this variable you have created to get the .pos of the Point as it updates in real time.
This also will mean that your script in not reliant upon the name of the Point and make the script much more robust.

Or run this as a script…perhaps from a new scene…

 
clearlistener()
delete $p*
delete $s*
p=point()
s=sphere()
p.pos = [25,0,0]
ThisRadius = float_script()
s.radius.controller = ThisRadius
ThisRadius.AddNode "MyObj" p
ThisRadius.AddNode "Me" s
Script = "MyRAdius = distance MyObj.pos Me.pos"
ThisRadius.script = Script

doing it this way will allow you to move the sphere and the point and rename both.

 JHN

yes go with hotknife I was getting ahead of myself, I was thinking about more complicated realtime issue (with lag)…

-Johan

Thanks, fellows! Usually when testing and trying things I don’t create variables in the Script Controller window, I just define them within the script, and that was the issue.

Thanks!!!