home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2002 April / GSSH42002.iso / EDITOREN / DS / gmax / gmaxinst_1-1.exe / gmaxsetup11.cab / radiusmanip.ms < prev    next >
Text File  |  2002-02-13  |  3KB  |  80 lines

  1. -- Generic radius manipulator
  2. -- Written by Scott Morrison
  3.  
  4. -- This manipulator sets the radius on any object or modifier with
  5. -- a parameter named "radius".  It creates a circle gizmo of the appropriate
  6. -- radius centered at the origin in the XY plane.
  7.  
  8. plugin simpleManipulator radiusManip
  9.     name:"RadiusManip"
  10.     invisible:true
  11. (
  12.     -- Create the green and red colors for the gizmo
  13.     local greenColor =  colorMan.getColor #manipulatorsActive
  14.     local redColor =    colorMan.getColor #manipulatorsSelected
  15.     local offsetLength = 0.0  -- AF (3/23/01) Used for mouse tracking
  16.  
  17.     -- This manipulator manipulates any node with a "radius" property
  18.     on canManipulate target return (findItem (getPropNames target) #radius) != 0
  19.  
  20.     -- Create the manipulator gizmo.
  21.     -- This is called initially and whenever the manipulator target changes
  22.     on updateGizmos do
  23.     (
  24.         -- Clear the current gizmo cache
  25.         this.clearGizmos()
  26.         
  27.         -- Set the radius of circle gizmo a little bigger than the target radius
  28.         giz = manip.makeCircle [0,0,0] (target.radius * 1.01) 28
  29.  
  30.         -- Add the circle to the manipulator
  31.         this.addGizmoShape giz 0 greenColor redColor  
  32.  
  33.         -- return the ToolTip string
  34.         return node.name + " radius = " + target.radius as string 
  35.     )
  36.  
  37.     -- mouseMove is called on every mouse move when dragging the manip
  38.     -- It needs to convert the mouse position 'm' into a new value for the radius
  39.     on mouseMove m which do
  40.     (
  41.         -- Create the XY plane.   
  42.         -- manip.makePlaneFromNormal takes a normal vector and a point
  43.         -- and creates a plane passing through the point with the given normal
  44.         local pl = manip.makePlaneFromNormal z_axis [0, 0, 0],
  45.         projectedPoint = [0,0,0]
  46.         
  47.         -- Compute the hit-ray in local coordinates
  48.         viewRay = this.getLocalViewRay m
  49.  
  50.         -- Intersect the plane with the view ray
  51.         res = pl.intersect viewRay &projectedPoint
  52.     
  53.         -- If the intersection worked, set the radius
  54.         if (res) then
  55.         (
  56.             target.radius = (length projectedPoint) / 1.01
  57.             offsetLength = 0.0
  58.             return true
  59.         )
  60.         -- AF (3/23/01) Plan B : the point wasn't on the plane because the plane 
  61.         -- was parallel to view or close to it.  Use the plane perpendicular to the view instead
  62.         pl = manip.makePlaneFromNormal viewRay.dir [0, 0, 0]
  63.         projectedPoint = [0,0,0]
  64.         res = pl.intersect viewRay &projectedPoint
  65.         if (res) then 
  66.         (  
  67.              -- (length projectedPoint) is equal to distance traveled
  68.              -- radius = distance traveled + the offset from the original mouse down point    
  69.             if offsetLength == 0.0 then 
  70.                 offsetLength = target.radius - (length projectedPoint)
  71.             target.radius = ((length projectedPoint) + offsetLength) / 1.01
  72.         )
  73.     )
  74.     
  75.     on MouseDown m which do
  76.     (
  77.         offsetLength = 0.0
  78.     )
  79. )
  80.