Slight improvement to Renanse Particle Editor

Renanse's Particle Editor is an awesome tool. I have started using it to toy with particles and love it. (And my art team loves it even more than I do) But we were getting a little annoyed that everytime we wanted to change the color of the particle, a huge lag would occur. I looked through the code and quickly found out that it was caused by having to create a JColorChooser every click. Here is what I consider to be a slight improvement on the particle editor which creates one JColorChooser at the start of the program, which is then reused for the rest of the program. I hope i wasn't too messy with the implementation. I don't know if you like the change i made or if there was a reason for recreating the JColorChooser but I thought it would be best if i were to post the code that I wrote for it.



First off I added 3 new fields.

  JFrame colorchooserframe = new JFrame("Choose a color.");
  JColorChooser colorchooser = new JColorChooser();
  boolean colorstart = false;



I created a new method called colorchooserinit(). And called it during jbInit()

  private void jbInit() throws Exception {
        setTitle("Particle System Editor");
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        colorchooserinit();
        addWindowListener(new WindowAdapter() {
......



Here is colorchooserinit()

private void colorchooserinit() {
   colorchooser.setColor(endColorPanel.getBackground());
   colorchooserframe.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
     colorchooserframe.add(colorchooser);
     colorchooserframe.setSize(colorchooserframe.getPreferredSize());
   colorchooserframe.addWindowListener(new  WindowListener(){
      public void windowClosed(WindowEvent arg0) {}
      public void windowIconified(WindowEvent arg0) {}
      public void windowDeiconified(WindowEvent arg0) {}
      public void windowActivated(WindowEvent arg0) {}
      public void windowDeactivated(WindowEvent arg0) {}
      public void windowOpened(WindowEvent arg0){}
      public void windowClosing(WindowEvent arg0){
         Color color = colorchooser.getColor();
         if (color == null){
               return;
           }
           ColorRGBA rgba = makeColorRGBA(color);
           if (colorstart){
              rgba.a = (Integer.parseInt(startAlphaSpinner.getValue().toString()) / 255f);
              manager.setStartColor(rgba);
              startColorPanel.setBackground(color);
           }
           else{
               rgba.a = (Integer.parseInt(endAlphaSpinner.getValue().toString()) / 255f);
               manager.setEndColor(rgba);
               endColorPanel.setBackground(color);
           }
           regenCode();
           updateColorLabels();
      }
   
    });



and to finish it off i modified 2 more methods

    private void startColorPanel_mouseClicked(MouseEvent e) {
       if (!colorchooserframe.isVisible()){
          colorstart = true;
          colorchooserframe.setVisible(true);
       }
    }

    private void endColorPanel_mouseClicked(MouseEvent e) {
       if (!colorchooserframe.isVisible()){
          colorstart = false;
          colorchooserframe.setVisible(true);
       }
    }



and that did the trick for me.

Sounds good, I'll get that into cvs.  I'm also going to be working with particles here on the job in the next few weeks, so who knows…  we might be seeing more improvements to jME particles soon.  :slight_smile:

I went a different way on this, but it should achieve the same result.  Basically I used createDialog and reused the resulting JDialog instead of going with the JFrame in your code snip.  It's in CVS now.

okey dokey, what ever works.

and good to hear on particle news :slight_smile:



edit: i just tried the version you created, but for some reason that only works the first time that you open the color chooser, after that it goes back to regenerating the color chooser, not sure why, but it does for me.

renanse, can you devise a way to use the particle manager to change the perspective of the particles from the camera?  In Roll-A-Rama on the menu if you notice when you are in the menu the rain is falling down, but when you go on the menu around to the top the camera is facing down, but the rain is still "falling down" from the camera's perspective, which gives the effect of rain coming from the side. :-p  I understand why the particles need to be facing the camera, but was hoping your great 3d mind would be able to come with a better solution than what I'm doing to have to do. :wink:



darkfrog

DF, it sounds like you aren't using the particle manager properly?  Or have you consider rotating the menu box rather than the camera?

drfugly said:

edit: i just tried the version you created, but for some reason that only works the first time that you open the color chooser, after that it goes back to regenerating the color chooser, not sure why, but it does for me.


Hmm, the odd thing is, there is no create code left in there for the color chooser past the init stage.  What platform are you on?  I was using my powerbook last night to put this together.

im on windows xp,

java version 1.5.0_06

renanse, can you give me a brief explanation of how you would go about using the particle manager to give the appearance of rain falling down when the camera is looking down or up?



I originally had the cube move, but the camera moving around it shows some scenery and looks cooler in my opinion if I could just get the rain to look better. :o



darkfrog

This is going off the OP's topic.  DF, can you make another thread for this issue and we'll discuss there?

darkfrog always steals my threads >.<



yeah i looked at the the code, and what is weird is that dialog.setVisible(); is really quick, so so im thinking this might have something to do with the way that JColorChooser gets added to a dialog

Ok, well I took your sample and modified it for aesthetic purposes (added ok/cancel buttons, etc.)  It should be in CVS soon.  (Our commit process is fun here… :))

drfugly, you don’t spend enough time at the JGN forum so this is my way of punishing you. :-p



renanse: http://www.jmonkeyengine.com/jmeforum/index.php?topic=3158.0



darkfrog

@renanse ok that sounds great, i was thinking of adding buttons but got lazy and decided it was good enough :slight_smile:



@darkfrog maybe if JGN had some flaws i would have something to say, hmmm what do you think about that?



edit: just checkedout with CVS seems like there was an error with the code, all of the fields were duplicated, once i killed them the program worked and still does work fine. We're getting there 

drfugly, I'll get to work on that. :-p



darkfrog

drfugly…  I'm not seeing this at all.  What fields are you talking about?  Might you have had a cvs merge issue?  I checked that code in at work and updated and received the changes here at home and it looks fine…

ok w/e no worries everything is good now i guess.

Hehe time for some more questions!

I notice that you half implemented a Save .jme feature. I am wondering how you were thinking that this was going to work, since i would be very much interested in it. Also in your code generation i found 2 errors.

code.append("ParticleManager manager = new ParticleManager("
                + manager.getParticlesNumber()
                + ", display.getRenderer().getCamera());n");

there was no "g" in ".getCamera"

and

   code.append("manager.getParticles().addController(manager);n");

was missing a semicolon (Don't quote me that specific line, since i fixed it and forgot which line i fixed when i came back :( )

Thanks  again renanse!

The new jME exporter code Mojo and I have crafted over the last week also supports particles.  Once we are approved to get that into CVS, expect to see save/load work.  (And I hope that is soon, because our export/import system is fast, compact, extensible and really rocks!)

Hearing you guys talking about all the great stuff you're working on is bitter-sweet.  Bitter to not be able to jump into CVS and see it and use it NOW and sweet on the prospect that we might eventually get to use it. :-p



darkfrog