ScriptSpot

Forum topic · General Scripting

Turbosmooth iterations based on camera distance

By toondek · 2014-11-15

Description

Hi!

I am working on a personal short film project which requiers large and detailed scenes.
I am looking for a script to assign turbosmooth iterations based on camera distance to reduce details on far objects.
The script may have to control one turbosmooth modifier by objects or one instanced turbosmooth for all objects.

I searched the net and found nothing.

If someone could help me?

Thank you!

Comments (2)

Raffx · 2014-11-22

check on john Wainwright's maxscript 101 lessons, there are some stuff on LOD topic!

toondek · 2014-11-23

Thanks you Raffix, it's what i done.

And after many hours watching john Wainwright's maxscript 101 lessons, maxscript's help and other tutorials i have a base script to control turbosmooth's iterations based on camera distance and a little bit more.

But in building the script, i got lot of ideas for usefull addons but i have some difficulties to integret them into the script.

First, i was thinking it would be cool that the script's reference object could be any type of object than just cameras. So i add a button for picking object but i don't know how to tell to the script to use this object for the distance function...

In a second time, i wanted to had an helper like the gismo's rotation to see directly in the viewport the distance entered in the script. So i added creation of three circles into the script but i don't find the command lines to assign them a position constraint targeted to the picked object...

That's what the script looks like so far :


--Turbosmooth Object Distance IterationsTool by Toondek :

start = animationRange.start
end = animationRange.end

-- Turbosmooth Object Distance Tool Dialog :

rollout TS_Object_Distance_Tool "Turbosmooth Object Distance Iteration Tool"
(
--Dialog Parameters :

pickbutton pbtn "Pick Object"
spinner dist "Distance Reference : " range:[0,1000,1]
spinner it_true "Iterations if True :" type:#integer range:[0,5,1]
spinner it_false "Iterations if False :" type:#integer range:[0,5,1]
button create "OK"

--Display the name of the Object on the button:

function SetObjNameAsBtnText obj pbtn =
(
if obj != undefined do
(
pbtn.text = obj.name
)
)

on pbtn picked obj do SetObjNameAsBtnText obj pbtn

on create pressed do (

--Turbosmooth Object Distance Tool Parameters :

-- Set Turbosmooth's iterations keyframe creation range
with animate on
for t in start to end by 1 do

-- Select geometry type of object in the scene
at time t
for obj in geometry do

-- Set reference distance to object
if distance $Camera001 < dist.value then

-- Set Turbosmooth's iterations if distance test = true
obj.Turbosmooth.iterations = it_true.value
else

-- Set Turbosmooth's iterations if distance test = false
obj.Turbosmooth.iterations = it_false.value

-- Helpers creation :

-- XHelper Creation :
Circle radius:dist.value name:"XHelper"
rotate $XHelper 90 y_axis
$XHelper.wirecolor = red
$XHelper.showFrozenInGray = off
Freeze $XHelper

-- YHelper Creation :
Circle radius:dist.value name:"YHelper"
$YHelper.wirecolor = green
$YHelper.showFrozenInGray = off
Freeze $YHelper

-- ZHelper Creation :
Circle radius:dist.value name:"ZHelper"
rotate $ZHelper 90 z_axis
rotate $ZHelper 90 x_axis
$ZHelper.wirecolor = blue
$ZHelper.showFrozenInGray = off
Freeze $ZHelper
)
)
createDialog TS_Object_Distance_Tool width:400