SDK Particle Emitter Node:

- Changed properties layout
- Added a button in the properties panel to emitt all particles 
- The mesh type can now be changed in the properties panel

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7948 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent f5dceb6c4d
commit 3a6e089954
  1. 20
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/AbstractSceneExplorerNode.java
  2. 103
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java
  3. 79
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitterButtonProperty.java
  4. 103
      sdk/jme3-core/src/com/jme3/gde/core/util/ButtonInplaceEditor.java

@ -41,6 +41,8 @@ import org.openide.loaders.DataObject;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.NodeAdapter;
import org.openide.nodes.NodeListener;
import org.openide.nodes.Sheet;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
@ -166,6 +168,23 @@ public abstract class AbstractSceneExplorerNode extends AbstractNode implements
return prop;
}
protected Property makeEmbedProperty(Object obj,Class objectClass, Class returntype, String method, String setter, String name) {
Property prop = null;
try {
if (readOnly) {
prop = new SceneExplorerProperty(objectClass.cast(obj), returntype, method, null);
} else {
prop = new SceneExplorerProperty(objectClass.cast(obj), returntype, method, setter, this);
}
prop.setName(name);
} catch (NoSuchMethodException ex) {
Exceptions.printStackTrace(ex);
}
return prop;
}
protected void createFields(Class c, Sheet.Set set, Object obj) throws SecurityException {
for (Field field : c.getDeclaredFields()) {
PropertyDescriptor prop = PropertyUtils.getPropertyDescriptor(c, field);
@ -189,4 +208,5 @@ public abstract class AbstractSceneExplorerNode extends AbstractNode implements
public Node[] createNodes(Object key, DataObject dataObject, boolean readOnly) {
return new Node[]{Node.EMPTY};
}
}

@ -33,12 +33,16 @@ package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.effect.shapes.EmitterShape;
import com.jme3.effect.ParticleEmitter;
import com.jme3.gde.core.sceneexplorer.nodes.SceneExplorerNode;
import com.jme3.effect.ParticleMesh;
import com.jme3.effect.influencers.ParticleInfluencer;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import java.awt.Image;
import java.beans.PropertyEditor;
import java.lang.reflect.InvocationTargetException;
import org.openide.loaders.DataObject;
import org.openide.nodes.Node;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.ImageUtilities;
@ -46,12 +50,11 @@ import org.openide.util.ImageUtilities;
*
* @author normenhansen
*/
@org.openide.util.lookup.ServiceProvider(service=SceneExplorerNode.class)
public class JmeParticleEmitter extends JmeGeometry{
@org.openide.util.lookup.ServiceProvider(service = SceneExplorerNode.class)
public class JmeParticleEmitter extends JmeGeometry {
public JmeParticleEmitter() {
}
private static Image smallImage =
ImageUtilities.loadImage("com/jme3/gde/core/sceneexplorer/nodes/icons/particleemitter.gif");
private ParticleEmitter geom;
@ -84,51 +87,89 @@ public class JmeParticleEmitter extends JmeGeometry{
return sheet;
}
createFields(geom.getClass(), set, obj);
// set.put(makeProperty(obj, boolean.class, "isEnabled", "setEnabled", "Enabled"));
// set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "Emitter Shape"));
// set.put(makeProperty(obj, int.class, "getNumVisibleParticles", "setNumParticles", "Num Particles"));
// set.put(makeProperty(obj, float.class, "getParticlesPerSec", "setParticlesPerSec", "Particles Per Sec"));
// set.put(makeProperty(obj, ColorRGBA.class, "getStartColor", "setStartColor", "Start Color"));
// set.put(makeProperty(obj, ColorRGBA.class, "getEndColor", "setEndColor", "End Color"));
// set.put(makeProperty(obj, float.class, "getStartSize", "setStartSize", "Start Size"));
// set.put(makeProperty(obj, float.class, "getEndSize", "setEndSize", "End Size"));
// set.put(makeProperty(obj, float.class, "getHighLife", "setHighLife", "High Life"));
// set.put(makeProperty(obj, float.class, "getLowLife", "setLowLife", "Low Life"));
// set.put(makeProperty(obj, float.class, "getGravity", "setGravity", "Gravity"));
// set.put(makeProperty(obj, Vector3f.class, "getInitialVelocity", "setInitialVelocity", "Initial Velocity"));
// set.put(makeProperty(obj, Vector3f.class, "getFaceNormal", "setFaceNormal", "Face Normal"));
// set.put(makeProperty(obj, float.class, "getVelocityVariation", "setVelocityVariation", "Velocity Variation"));
// set.put(makeProperty(obj, boolean.class, "isFacingVelocity", "setFacingVelocity", "Facing Velocity"));
// set.put(makeProperty(obj, boolean.class, "isRandomAngle", "setRandomAngle", "Random Angle"));
// set.put(makeProperty(obj, boolean.class, "isInWorldSpace", "setInWorldSpace", "World Space"));
// set.put(makeProperty(obj, float.class, "getRotateSpeed", "setRotateSpeed", "Rotate Speed"));
// set.put(makeProperty(obj, boolean.class, "isSelectRandomImage", "setSelectRandomImage", "Select Random Image"));
// set.put(makeProperty(obj, int.class, "getImagesX", "setImagesX", "Images X"));
// set.put(makeProperty(obj, int.class, "getImagesY", "setImagesY", "Images Y"));
// set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "shape"));
set.put(createButtonProperty());
set.put(makeProperty(obj, boolean.class, "isEnabled", "setEnabled", "Enabled"));
set.put(makeProperty(obj, ParticleMesh.Type.class, "getMeshType", "setMeshType", "Mesh Type"));
set.put(makeProperty(obj, EmitterShape.class, "getShape", "setShape", "Emitter Shape"));
set.put(makeProperty(obj, int.class, "getMaxNumParticles", "setNumParticles", "Num Particles"));
set.put(makeProperty(obj, float.class, "getParticlesPerSec", "setParticlesPerSec", "Particles Per Sec"));
set.put(makeProperty(obj, ColorRGBA.class, "getStartColor", "setStartColor", "Start Color"));
set.put(makeProperty(obj, ColorRGBA.class, "getEndColor", "setEndColor", "End Color"));
set.put(makeProperty(obj, float.class, "getStartSize", "setStartSize", "Start Size"));
set.put(makeProperty(obj, float.class, "getEndSize", "setEndSize", "End Size"));
set.put(makeProperty(obj, float.class, "getHighLife", "setHighLife", "High Life"));
set.put(makeProperty(obj, float.class, "getLowLife", "setLowLife", "Low Life"));
set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity"));
set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, Vector3f.class, "getInitialVelocity", "setInitialVelocity", "Initial Velocity"));
set.put(makeEmbedProperty(obj.getParticleInfluencer(), ParticleInfluencer.class, float.class, "getVelocityVariation", "setVelocityVariation", "Velocity Variation"));
set.put(makeProperty(obj, Vector3f.class, "getFaceNormal", "setFaceNormal", "Face Normal"));
set.put(makeProperty(obj, boolean.class, "isFacingVelocity", "setFacingVelocity", "Facing Velocity"));
set.put(makeProperty(obj, boolean.class, "isRandomAngle", "setRandomAngle", "Random Angle"));
set.put(makeProperty(obj, boolean.class, "isInWorldSpace", "setInWorldSpace", "World Space"));
set.put(makeProperty(obj, float.class, "getRotateSpeed", "setRotateSpeed", "Rotate Speed"));
set.put(makeProperty(obj, boolean.class, "isSelectRandomImage", "setSelectRandomImage", "Select Random Image"));
set.put(makeProperty(obj, int.class, "getImagesX", "setImagesX", "Images X"));
set.put(makeProperty(obj, int.class, "getImagesY", "setImagesY", "Images Y"));
sheet.put(set);
return sheet;
}
@Override
public void propertyChange(String name, Object before, Object after) {
if (!name.equals("Emitt all particles")) {
fireSave(true);
firePropertyChange(name, before, after);
}
}
@Override
public Class getExplorerObjectClass() {
return ParticleEmitter.class;
}
@Override
public Class getExplorerNodeClass() {
return JmeParticleEmitter.class;
}
@Override
public Node[] createNodes(Object key, DataObject key2, boolean cookie) {
JmeSpatialChildren children=new JmeSpatialChildren((com.jme3.scene.Spatial)key);
JmeSpatialChildren children = new JmeSpatialChildren((com.jme3.scene.Spatial) key);
children.setReadOnly(cookie);
children.setDataObject(key2);
return new Node[]{new JmeParticleEmitter((ParticleEmitter) key, children).setReadOnly(cookie)};
}
public ParticleEmitter getEmitter() {
return geom;
}
private Property createButtonProperty() {
return new PropertySupport.ReadWrite("emitt", Object.class, "Emitt all particles", "Click here to emitt all particles of this emitter ") {
JmeParticleEmitterButtonProperty pe;
@Override
public Object getValue() throws IllegalAccessException, InvocationTargetException {
return "";
}
@Override
public PropertyEditor getPropertyEditor() {
if (pe == null) {
pe = new JmeParticleEmitterButtonProperty(JmeParticleEmitter.this);
pe.attachEnv(pe.env);
}
return pe;
}
@Override
public void setValue(Object t) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
}
};
}
}

@ -0,0 +1,79 @@
package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.effect.ParticleEmitter;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.util.ButtonInplaceEditor;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditorSupport;
import java.util.concurrent.Callable;
import org.openide.explorer.propertysheet.ExPropertyEditor;
import org.openide.explorer.propertysheet.InplaceEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
/**
*
* @author Nehon
*/
public class JmeParticleEmitterButtonProperty extends PropertyEditorSupport implements ExPropertyEditor, InplaceEditor.Factory {
JmeParticleEmitter pe;
public JmeParticleEmitterButtonProperty(JmeParticleEmitter pe) {
super();
this.pe = pe;
}
PropertyEnv env;
public void attachEnv(PropertyEnv env) {
this.env = env;
env.registerInplaceEditorFactory(this);
}
private ButtonInplaceEditor ed = null;
public InplaceEditor getInplaceEditor() {
if (ed == null) {
ed = new ButtonInplaceEditor("Emitt!");
ed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
pe.getEmitter().killAllParticles();
pe.getEmitter().emitAllParticles();
return null;
}
});
}
});
}
return ed;
}
@Override
public boolean isPaintable() {
return true;
}
@Override
public void paintValue(Graphics gfx, Rectangle box) {
if (ed == null) {
getInplaceEditor();
}
ed.setSize(box.width, box.height);
ed.doLayout();
Graphics g = gfx.create(box.x, box.y, box.width, box.height);
ed.setOpaque(false);
ed.paint(g);
g.dispose();
pe.refresh(false);
}
}

@ -0,0 +1,103 @@
package com.jme3.gde.core.util;
import java.awt.Color;
import java.awt.Component;
import java.beans.PropertyEditor;
import javax.swing.DefaultButtonModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.openide.explorer.propertysheet.InplaceEditor;
import org.openide.explorer.propertysheet.PropertyEnv;
import org.openide.explorer.propertysheet.PropertyModel;
/**
*
* @author Nehon
*/
public class ButtonInplaceEditor extends JButton implements InplaceEditor {
private PropertyEditor editor = null;
private PropertyModel model;
private PropertyEnv env;
public ButtonInplaceEditor() {
this("Click");
setActionCommand(COMMAND_SUCCESS);
setForeground(Color.BLACK);
}
public ButtonInplaceEditor(String text) {
super(text);
setActionCommand(COMMAND_SUCCESS);
setForeground(Color.BLACK);
}
public ButtonInplaceEditor(Icon icon) {
super(icon);
setActionCommand(COMMAND_SUCCESS);
setForeground(Color.BLACK);
}
public ButtonInplaceEditor(String text, Icon icon) {
super(text, icon);
setActionCommand(COMMAND_SUCCESS);
setForeground(Color.BLACK);
}
public void connect(PropertyEditor pe, PropertyEnv pe1) {
editor = pe;
env = pe1;
reset();
}
public JComponent getComponent() {
return this;
}
public void clear() {
editor = null;
model = null;
}
public Object getValue() {
repaint();
updateUI();
return "";
}
public void setValue(Object o) {
repaint();
updateUI();
}
public boolean supportsTextEntry() {
return false;
}
public void reset() {
}
public KeyStroke[] getKeyStrokes() {
return new KeyStroke[0];
}
public PropertyEditor getPropertyEditor() {
return editor;
}
public PropertyModel getPropertyModel() {
return model;
}
public void setPropertyModel(PropertyModel pm) {
this.model = pm;
}
public boolean isKnownComponent(Component cmpnt) {
return false;
}
}
Loading…
Cancel
Save