-  Material live update in platform core


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7984 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 59b00bbae9
commit 3bb3277f3a
  1. 18
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/MaterialChangeListener.java
  2. 25
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/MaterialChangeProvider.java
  3. 90
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/SceneExplorerTopComponent.java
  4. 84
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeGeometry.java
  5. 1
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeParticleEmitter.java
  6. 5
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java

@ -0,0 +1,18 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.gde.core.sceneexplorer;
import com.jme3.material.Material;
/**
*
* @author Nehon
*/
public interface MaterialChangeListener {
public String getKey();
public void setMaterial(Material material);
}

@ -0,0 +1,25 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.jme3.gde.core.sceneexplorer;
import com.jme3.gde.core.sceneexplorer.MaterialChangeListener;
import java.util.List;
/**
*
* @author Nehon
*/
public interface MaterialChangeProvider {
public String getKey();
public void addMaterialChangeListener(MaterialChangeListener listener);
public void removeMaterialChangeListener(MaterialChangeListener listener);
public void addAllMaterialChangeListener(List<MaterialChangeListener> listeners);
public void clearMaterialChangeListeners();
}

@ -37,8 +37,13 @@ import com.jme3.gde.core.scene.SceneListener;
import com.jme3.gde.core.scene.SceneRequest;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openide.util.Lookup.Result;
import org.openide.util.NbBundle;
@ -77,6 +82,8 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
private final Result<AbstractSceneExplorerNode> nodeSelectionResult;
private AbstractSceneExplorerNode selectedSpatial;
private AbstractSceneExplorerNode lastSelected;
private Map<String, MaterialChangeProvider> materialChangeProviders = new HashMap<String, MaterialChangeProvider>();
private Map<String, List<MaterialChangeListener>> materialChangeListeners = new HashMap<String, List<MaterialChangeListener>>();
public SceneExplorerTopComponent() {
initComponents();
@ -238,7 +245,6 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
public UndoRedo getUndoRedo() {
return Lookup.getDefault().lookup(UndoRedo.class);
}
private transient ExplorerManager explorerManager = new ExplorerManager();
public ExplorerManager getExplorerManager() {
@ -261,6 +267,10 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
public void sceneRequested(SceneRequest request) {
this.request = request;
JmeNode node = request.getJmeNode();
for (Iterator it = materialChangeProviders.values().iterator(); it.hasNext();) {
MaterialChangeProvider provider = (MaterialChangeProvider) it.next();
provider.clearMaterialChangeListeners();
}
if (node != null) {
explorerManager.setRootContext(node);
explorerManager.getRootContext().setDisplayName(node.getName());
@ -282,4 +292,82 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
public AbstractSceneExplorerNode getLastSelected() {
return lastSelected;
}
public void addMaterialChangeProvider(MaterialChangeProvider provider) {
Logger.getLogger(SceneExplorerTopComponent.class.getName()).log(Level.INFO, "New materail provider registered for: {0}", provider.getKey());
materialChangeProviders.put(provider.getKey(), provider);
List<MaterialChangeListener> listeners = materialChangeListeners.get(provider.getKey());
if (listeners == null) {
return;
}
provider.addAllMaterialChangeListener(listeners);
}
public void removeMaterialChangeProvider(MaterialChangeProvider provider) {
Logger.getLogger(SceneExplorerTopComponent.class.getName()).log(Level.INFO, "Removing material provider for : {0}", provider.getKey());
System.out.println("Removing provider : " + provider.getKey());
materialChangeProviders.remove(provider.getKey());
}
public void addMaterialChangeListener(MaterialChangeListener listener) {
if (listener.getKey() != null) {
Logger.getLogger(SceneExplorerTopComponent.class.getName()).log(Level.INFO, "New material listener for : {0}", listener.getKey());
List<MaterialChangeListener> listeners = materialChangeListeners.get(listener.getKey());
if (listeners == null) {
listeners = new ArrayList<MaterialChangeListener>();
materialChangeListeners.put(listener.getKey(), listeners);
}
listeners.add(listener);
MaterialChangeProvider provider = materialChangeProviders.get(listener.getKey());
if (provider != null) {
provider.addMaterialChangeListener(listener);
}
}
}
public void removeMaterialChangeListener(MaterialChangeListener listener) {
Logger.getLogger(SceneExplorerTopComponent.class.getName()).log(Level.INFO, "Removing material listener for: {0}", listener.getKey());
List<MaterialChangeListener> listeners = materialChangeListeners.get(listener.getKey());
if (listeners == null) {
return;
}
listeners.remove(listener);
MaterialChangeProvider provider = materialChangeProviders.get(listener.getKey());
if (provider != null) {
provider.removeMaterialChangeListener(listener);
}
}
public void swapMaterialChangeListener(MaterialChangeListener listener, String oldKey, String newKey) {
Logger.getLogger(SceneExplorerTopComponent.class.getName()).log(Level.INFO, "Swaping material listeners : {0} -> {1}", new Object[]{oldKey, newKey});
if (oldKey != null) {
List<MaterialChangeListener> listeners = materialChangeListeners.get(oldKey);
if (listeners != null) {
listeners.remove(listener);
}
MaterialChangeProvider provider = materialChangeProviders.get(oldKey);
if (provider != null) {
provider.removeMaterialChangeListener(listener);
}
}
if (newKey != null) {
// assert newKey.equals(listener.getKey());
List<MaterialChangeListener> listeners = materialChangeListeners.get(newKey);
if (listeners == null) {
listeners = new ArrayList<MaterialChangeListener>();
materialChangeListeners.put(newKey, listeners);
}
listeners.add(listener);
MaterialChangeProvider provider = materialChangeProviders.get(newKey);
if (provider != null) {
provider.addMaterialChangeListener(listener);
}
}
}
}

@ -31,11 +31,16 @@
*/
package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent;
import com.jme3.gde.core.sceneexplorer.nodes.SceneExplorerNode;
import com.jme3.gde.core.sceneexplorer.MaterialChangeListener;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import java.awt.Image;
import java.io.IOException;
import java.util.concurrent.Callable;
import org.openide.loaders.DataObject;
import org.openide.nodes.Sheet;
import org.openide.util.ImageUtilities;
@ -44,8 +49,8 @@ import org.openide.util.ImageUtilities;
*
* @author normenhansen
*/
@org.openide.util.lookup.ServiceProvider(service=SceneExplorerNode.class)
public class JmeGeometry extends JmeSpatial {
@org.openide.util.lookup.ServiceProvider(service = SceneExplorerNode.class)
public class JmeGeometry extends JmeSpatial implements MaterialChangeListener {
private static Image smallImage =
ImageUtilities.loadImage("com/jme3/gde/core/sceneexplorer/nodes/icons/geometry.gif");
@ -58,6 +63,18 @@ public class JmeGeometry extends JmeSpatial {
super(spatial, children);
getLookupContents().add(spatial);
this.geom = spatial;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SceneExplorerTopComponent.findInstance().addMaterialChangeListener(JmeGeometry.this);
} catch (Exception e) {
e.printStackTrace();
}
}
});
setName(spatial.getName());
}
@ -71,6 +88,23 @@ public class JmeGeometry extends JmeSpatial {
return smallImage;
}
@Override
public void destroy() throws IOException {
super.destroy();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SceneExplorerTopComponent.findInstance().removeMaterialChangeListener(JmeGeometry.this);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@Override
protected Sheet createSheet() {
//TODO: multithreading..
@ -92,18 +126,62 @@ public class JmeGeometry extends JmeSpatial {
}
@Override
public Class getExplorerObjectClass() {
return Geometry.class;
}
@Override
public Class getExplorerNodeClass() {
return JmeGeometry.class;
}
@Override
public org.openide.nodes.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 org.openide.nodes.Node[]{new JmeGeometry((Geometry) key, children).setReadOnly(cookie)};
}
@Override
public void propertyChange(String name, final Object before, final Object after) {
super.propertyChange(name, before, after);
System.out.println(name);
if (name.equals("Material")) {
System.out.println(before.toString()+" "+after.toString());
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SceneExplorerTopComponent.findInstance().swapMaterialChangeListener(JmeGeometry.this, ((Material) before).getAssetName(), ((Material) after).getAssetName());
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
public void setMaterial(final Material material) {
if (material.getAssetName().equals(getKey())) {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
geom.setMaterial(material);
return null;
}
});
}
}
public Geometry getGeometry() {
return geom;
}
public String getKey() {
return geom.getMaterial().getAssetName();
}
}

@ -119,6 +119,7 @@ public class JmeParticleEmitter extends JmeGeometry {
@Override
public void propertyChange(String name, Object before, Object after) {
super.propertyChange(name, before, after);
if (!name.equals("Emit all particles")) {
fireSave(true);
firePropertyChange(name, before, after);

@ -109,16 +109,19 @@ public final class SceneViewerTopComponent extends TopComponent {
int code = AwtKeyInput.convertAwtKey(evt.getKeyCode());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
keyEvent.setTime(evt.getWhen());
if (app.getActiveCameraController() != null) {
app.getActiveCameraController().onKeyEvent(keyEvent);
}
}
public void keyReleased(KeyEvent evt) {
int code = AwtKeyInput.convertAwtKey(evt.getKeyCode());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
keyEvent.setTime(evt.getWhen());
if (app.getActiveCameraController() != null) {
app.getActiveCameraController().onKeyEvent(keyEvent);
}
}
});
}

Loading…
Cancel
Save