Rhinocommon Particle System Class


(Luis Fraguada) #1

Sorry, I could not resist…

Was this added recently? Any examples floating around?


(Dale Fugier) #2

@stevebaer, do you know anything about this?


(Steve Baer) #3

Yes, I wrote it :smile:

This class has been in RhinoCommon for a while now. It is primarily set up for drawing a number of similar “particles” and does not have any other particle system functionality that you may be expecting to see (i.e. physics simulations). That being said, physics simulations can use this class to draw the simulation.


(Luis Fraguada) #4

I guess I would like to know the benefit of using this over say, a point cloud, or even a collection of points. I see the particle can take a size and bitmap id. Does it have specific display attributes?


(Steve Baer) #5

Particles can be drawn as screen oriented sprites. This is what differentiates these from point clouds or a collection of points. There is logic built into the particle system to draw from back to front based on the view orientation. This is because sprites may have alpha and we need to use a painters algorithm technique for drawing when things like alpha are involved.


(Luis Fraguada) #6

Cool. Good stuff to know. Thanks!


(Luis Fraguada) #7


That will come in handy! Thx.

Luis

p.s. some quick and dirty code:

 readonly PSDisplay psDisplay = new PSDisplay();
 psDisplay.file = img; //img is some .png file path

 //pts is a List of Point3d coming from somewhere else
 foreach(Point3d pt in pts)
 {
   Rhino.Geometry.Particle p = new Rhino.Geometry.Particle();
   p.Location = pt;
   p.Size = 10;
   p.Color = Color.FromArgb(10, 255, 0, 255);
   psDisplay.ps.Add(p);
 }

 public class PSDisplay : Rhino.Display.DisplayConduit
  {
    public Rhino.Geometry.ParticleSystem ps = new Rhino.Geometry.ParticleSystem();
    public string file;

    protected override void DrawForeground(Rhino.Display.DrawEventArgs e)
    {
      Bitmap bm = new Bitmap(file);
      Rhino.Display.DisplayBitmap dbm = new Rhino.Display.DisplayBitmap(bm);
      e.Display.DrawParticles(ps, dbm);
    }
  }

at some other point, one should enable or disable the display:

if(display)
    {
      psDisplay.Enabled = true;
      Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
    } else {
      psDisplay.Enabled = false;
      Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
    }