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

  1. --  particle.ms
  2. --                        John Wainwright
  3. --
  4. -- this is a utility that demo's the new particle system
  5. -- access functions n Beta 2.1.  It lets you pick a particle system
  6. -- and a source of scene objects and will make copies of
  7. -- the source, 1 for each particle and then animate them to 
  8. -- follow particle movement - essentially turning any
  9. -- of the MAX particle systems into a geometry-based
  10. -- system.   
  11. --
  12. -- For the source you can pick a master object to clone
  13. -- or use the current selection, from which it will
  14. -- take a random set of clones for the particle objects.
  15. -- You can also make the objects z-axis follow the direction
  16. -- of particle flow by checking the follow checkbox.
  17. -- There's also visibility checkbox which controls whether the
  18. -- utility use a visibility track to hide particle objects
  19. -- corresponding to when their associated particles are
  20. -- born and die.  (note this doesn't hide them in the viewports
  21. -- so you might see odd movements there - render to see
  22. -- the visibility control working). 
  23. --
  24. -- If you've got a lot of particles, it can take a while to
  25. -- do the animation - see the "processing frame #" message
  26. -- under the create button in the rollout.
  27. --
  28. --  have fun!!
  29.  
  30. utility object_particle "Object Particles"
  31. (
  32.     local  system, master, particles,
  33.            start = animationRange.start.frame,
  34.            end = animationRange.end.frame
  35.  
  36.     group "Particle system"
  37.     (
  38.         pickbutton pick_system "Pick particle system"
  39.         label system_name
  40.    )
  41.  
  42.     group "Object source"
  43.     (
  44.         radiobuttons source_type
  45.             labels:#("Current selection", "Pick")
  46.         pickbutton pick_master "Pick master object" enabled:false
  47.         label master_name
  48.     )
  49.  
  50.     group "Animation"
  51.     (
  52.         checkbox follow "Follow velocity direction" checked:true
  53.         checkbox hide_em "Hide when outside range" checked:true
  54.         spinner start_frame "Start frame:" type:#integer range:[start, end, start]
  55.         spinner end_frame "End frame:" type:#integer range:[start, end, end]
  56.         button create_parts "Create object particles"
  57.         label status
  58.         button delete_parts "Delete object particles"
  59.     )
  60.     
  61.     on object_particle open do
  62.     (
  63.         master_name.text = system_name.text = ""
  64.         particles = #()
  65.     )
  66.     
  67.     on pick_system picked obj do
  68.         ( system = obj; system_name.text = system.name )
  69.     on pick_master picked obj do
  70.         ( master = obj; master_name.text = master.name )
  71.  
  72.     on source_type changed btn do
  73.     (
  74.         if btn == 1 then
  75.         (
  76.             master_name.text = ""
  77.             pick_master.enabled = false
  78.         )
  79.         else
  80.             pick_master.enabled = true
  81.     )
  82.         
  83.     on delete_parts pressed do
  84.         ( delete particles; particles = #() )
  85.  
  86.     on create_parts pressed do
  87.     (
  88.         if system == undefined or
  89.            (source_type.state == 1 and selection.count == 0) or
  90.            (source_type.state == 2 and master == undefined) then
  91.                 return undefined
  92.             
  93.         -- get the particles
  94.         status.text = "copying particle objects..."
  95.         particles = for i in 1 to particleCount system collect
  96.         (
  97.             if source_type.state == 1 then   -- current selection
  98.                 copy selection[random 1 (selection.count)]
  99.             else
  100.                 copy master             -- picked master
  101.         )
  102.         
  103.         -- animate particles        
  104.         animate on for t in start_frame.value to end_frame.value do at time t
  105.         (
  106.             status.text = "Processing frame " + (t as string)
  107.             for i in 1 to particleCount system do
  108.             (
  109.                 local pos = particlePos system i
  110.                 if pos != undefined then
  111.                 (
  112.                     particles[i].pos = pos
  113.                     if follow.checked then
  114.                         particles[i].dir = particleVelocity system i
  115.                     if hide_em.checked then
  116.                         particles[i].visibility = true
  117.                 )
  118.                 else
  119.                 (
  120.                     particles[i].pos = [0,0,0]
  121.                     if hide_em.checked then
  122.                         particles[i].visibility = false
  123.                 )
  124.             )
  125.         )
  126.         status.text = ""
  127.     )
  128. )
  129.