Maxscript: Update script in realtime

Maxscript: Update script in realtime

Anonymous
Not applicable
3,299 Views
7 Replies
Message 1 of 8

Maxscript: Update script in realtime

Anonymous
Not applicable

I wan't to keep a script active so that it always updates or when relevant to do so.

See example below, how would i autoactivate this when changing geometry,camera or viewport?

 

for obj in geometry do
if distance obj $camera1 > 100 then obj.segs = 6
else obj.segs = 20

 

/Fred

0 Likes
Accepted solutions (1)
3,300 Views
7 Replies
Replies (7)
Message 2 of 8

leeminardi
Mentor
Mentor

The following will change the segs of a sphere based on the distance to a camera while the timeSlider is running and the positions of the sphere and/or camera are keyframed.

fn time_p = 
(clearSelection()
	select $Camera001
pcam = $Camera001.pos
select $Sphere001
psph = $Sphere001.pos
d = length (psph - pcam)
	format "\ndis: %" d
if d < 50 then $Sphere001.segs = 32 else $Sphere001.segs = 8
) -- end select	
registerTimeCallback time_p
lee.minardi
0 Likes
Message 3 of 8

Anonymous
Not applicable

Yes, thank you!. This solves this LOD-problem i had,when rendering. But in a more general way, how would one make 3ds max autoupdate after changes in max, and preferable not by time as it will always run then. For animatable objects i guess you could solve it with anim. controllers but how about  the rest?

0 Likes
Message 4 of 8

istan
Advisor
Advisor
Accepted solution

If you look for something lower level, there exists also a "registerRedrawViewsCallback"..

0 Likes
Message 5 of 8

Anonymous
Not applicable

Yes, this is very close to what i was looking for.

Maybe there is a callback-method for when mouse and keyboard-inputs in ui is given ?.

Otherwise i think i may be able to work with "registerRedrawViewsCallback".

Thanks.

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

After fiddling around with registerRedrawViewsCallback i realize its pretty much interact like i wan't.

The question i get though, is there already a registerRedrawViewsCallback active in the background where i can add my script?. If every registerRedrawViewsCallback is handled like a separate process i would presume it's less taxing on the system to put all code under one callback?. Or is it too little impact to affect performance?

 

/noob

0 Likes
Message 7 of 8

istan
Advisor
Advisor

I usually use this redraw callback in many of my C++ plugins for realtime drawing in the viewports. On node level I rather try to use the ReferenceMaker system - but this is very limitted for most of my applications.

0 Likes
Message 8 of 8

denisT.MaxDoctor
Advisor
Advisor

Just letting you guys know that any registering event using registerRedrawViewsCallback or registerTimeCallback is not animatable and renderable solution. You can't render it with animation sequence!

 

the only way to make it renderable is to involve anyhow a controller solution - Scripted controller, Expression, Constraint or Bind controllers.

 

here is a snippet how it can be done using a Script controller:

delete objects

s = geosphere()
c = freecamera pos:[200,0,0] dir:x_axis

ss = s.baseobject.segs.controller = float_script()

ss.addnode #cam c
ss.addnode #obj s

scr  = ""
scr += "if isvalidnode obj and iskindof cam Camera then\n"
scr += "(\n"
scr += "	int((200 - amin (distance obj cam) 200)/40) + 1\n"
scr += ") else 4\n"

ss.setexpression scr
0 Likes