home *** CD-ROM | disk | FTP | other *** search
/ Maximum 3D 3 / m3d-p3.iso / 3DS_MAX / 3DSMAX.2_0 / SCRIPTS / BANK.MS < prev    next >
Text File  |  1997-10-19  |  2KB  |  61 lines

  1. -- A bank-and-turn function that takes any animated object (not
  2. -- just one that is animated along a path) and will generate 
  3. -- bank and turn keyframes, with controls similar to those 
  4. -- in the path controller.
  5. --                                John Wainwright
  6.  
  7. bx     = box length:200 width:200 height:10 mapcoords:true \
  8.             lengthsegs:16 widthsegs:16
  9.             
  10. function fly obj bank:on bankAmount:40 smoothness:5.0 dt:2f bankSteps:5 =
  11. (
  12.     local tm = scaleMatrix obj.scale, local_r,
  13.           pt0 = at time (currentTime - dt) obj.pos,
  14.           pt1 = at time (currentTime + dt) obj.pos
  15.           
  16.     tm.translation = obj.pos
  17.     tm.row1 = normalize (pt1 - pt0)
  18.     tm.row2 = cross [0,0,1] tm.row1
  19.     tm.row3 = cross tm.row1 tm.row2
  20.  
  21.     if bank then 
  22.     (
  23.         local pt2, v0, v1,
  24.               cv = 0.0,
  25.               t = currentTime - (bankSteps/2.0) * smoothness,
  26.               terms = 0, 
  27.               end_t = (getTimeRange obj.pos.controller).end
  28.  
  29.         pt1 = at time t obj.pos
  30.         t += smoothness
  31.         pt2 = at time t obj.pos
  32.         t += smoothness
  33.         for i in 1 to bankSteps do
  34.         (
  35.             if t > end_t then exit
  36.             pt0 = pt1; pt1 = pt2
  37.             pt2 = at time t obj.pos
  38.             v0 = normalize (pt2 - pt1)
  39.             v1 = normalize (pt1 - pt0)
  40.             v0.z = v1.z = 0
  41.             if pt0 == pt1 then exit
  42.             cv += (cross v0 v1).z * bankAmount / length (pt1 - pt0)
  43.             terms += 1
  44.             t += smoothness
  45.         )
  46.         if terms > 0 then preRotateX tm ((cv/terms) * (180/pi))
  47.     )
  48.     obj.transform = tm
  49. )
  50.  
  51. -- this will place keyframes every 5 frames
  52. animate on for t in 0 to 100 by 5 do at time t fly $box01
  53.  
  54. -- this will place key frames at existing position keyframes,
  55. -- probably not enough
  56. animate on for k in $box01.pos.keys do at time k.time fly $box01
  57.  
  58. -- if you want to delete all the scale keys, use:
  59. deleteKeys $box01.scale.controller
  60.  
  61.