scale script

I am looking for a script that will scale an objects size based on its distance from a camera. One key thing it needs to do is only scale that said object after it enters a certain perimeter around the object being scaled. Also the camera must be able to control the spheres scale no matter what direction it is moving towards the sphere. For example:

sphere and camera are separated by 150 units.
sphere size is arbitrary but has a perimeter set at 100 units from pivot.
camera passes through 100 unit perimeter.
sphere will scale down relative to this distance that the camera moves. If the camera moves 50% into the perimeter the sphere will scale to 50%.
camera leaves the perimeter.
sphere will scale back up to its original size.

I am pretty lost on how to do this myself. I tried to use reaction manager but it did not work out. thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stenionet's picture

Insanto I can not make your

Insanto
I can not make your script work.
Can you give information how to use it?

Thanks.

Graph's picture

are you experienced with

are you experienced with maxscript? if so ..

have phun:

(
 
   if IN_DistDuff != undefined do unRegisterTimeCallback IN_DistDuff.zDepthPreview
 
 
         struct distStuff
         (
            var = 0
            ,
 
            fn getFurthestBBPoint o = --get furthest BBcorner-position of an obj in relation to viewport
            (
               local ma = o.max ; local mi = o.min
               local arr = #([ma.x,ma.y,ma.z],[ma.x,mi.y,ma.z],[mi.x,mi.y,ma.z],[mi.x,ma.y,ma.z],[ma.x,ma.y,mi.z],[ma.x,mi.y,mi.z],[mi.x,mi.y,mi.z],[mi.x,ma.y,mi.z])
               local maxDist = -99999999 ; local maxP = [0,0,0]
               for p in arr do(if(dist=distance(inverse(viewport.getTM())).pos p)>maxDist do(maxDist=dist;maxP=p))
               return maxP
            )--END getFurthestBBPoint FN
 
            ,
 
            fn getFurthestPos = --get furthest position of visible geometry in relation to viewwport
            (
               local objArr = for o in geometry where not (o.isHidden) collect o
               local arr = for o in objArr collect (getFurthestBBPoint o)
               local maxDist = -99999999 ; local maxP = [0,0,0]
               for p in arr do(if(dist=distance(inverse(viewport.getTM())).pos p)>maxDist do(maxDist=dist;maxP=p))
               return maxP
            )--END getFurthestPos FN
 
            ,
 
            fn zDepthPreview = --make zDepthPreview based on objDistance/MaxDist  --build in isInView check to objArr collection
            (
               local furthestPosFromView = getFurthestPos()
 
               if furthestPosFromView != [0,0,0] then
               (
                  local maxDist = distance(inverse(viewport.getTM())).pos furthestPosFromView
 
                  local objArr = for o in geometry where not (o.isHidden) collect o
 
                  for obj in objArr do
                  (
                     local centerDist = distance(inverse(viewport.getTM())).pos obj.center
 
                     local val = (abs(centerDist/maxDist-1)) * 255
                     obj.wireColor = color val val val
                  )
               )
               else --handling for non perp views
               (
 
               )
               return OK
            )--END zDepthPreview FN
 
            ,
 
            fn autoSmoothByDist = --set AutoSmooth Itterations based on objDistance/MaxDist
            (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
            )--END autoSmoothByDist FN
 
         )
         global IN_DistDuff = distStuff var:1
 
         registerTimeCallback IN_DistDuff.zDepthPreview
 
 
)--END local scope

Raphael Steves

stenionet's picture

I am looking for the same

I am looking for the same solution. For months I am searching and cannot find a way to do this.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.