-  Material live update in material support : now changing parameters in Material editor affect the scene in real time

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7985 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 3bb3277f3a
commit b035d52fa2
  1. 34
      sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java
  2. 61
      sdk/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java

@ -31,7 +31,6 @@
*/
package com.jme3.gde.materials;
import com.jme3.asset.AssetKey;
import com.jme3.asset.DesktopAssetManager;
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
@ -48,7 +47,6 @@ import java.awt.Rectangle;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.Callable;
@ -99,29 +97,33 @@ public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerProp
}
public void setAsText(final String text) throws IllegalArgumentException {
if ("create j3m file".equals(text)) {
AbstractSceneExplorerNode geom = SceneExplorerTopComponent.findInstance().getLastSelected();
assert (geom != null);
ProjectAssetManager pm = geom.getLookup().lookup(ProjectAssetManager.class);
assert (pm != null);
DataObject obj = geom.getLookup().lookup(DataObject.class);
assert (obj != null);
FileObject currentFile = obj.getPrimaryFile();
FileObject currentFolder = currentFile.getParent();
if ("create j3m file".equals(text)) {
try {
AbstractSceneExplorerNode geom = SceneExplorerTopComponent.findInstance().getLastSelected();
assert (geom != null);
ProjectAssetManager pm = geom.getLookup().lookup(ProjectAssetManager.class);
assert (pm != null);
DataObject obj = geom.getLookup().lookup(DataObject.class);
assert (obj != null);
FileObject currentFile = obj.getPrimaryFile();
FileObject currentFolder = currentFile.getParent();
int i = 0;
FileObject newFile = currentFolder.getFileObject(currentFile.getName(), "j3m");
String newFileName = currentFile.getName() + "-" + geom.getName();
FileObject newFile = currentFolder.getFileObject(newFileName, "j3m");
while (newFile != null) {
i++;
newFile = currentFolder.getFileObject(currentFile.getName() + "-" + i, "j3m");
newFileName = currentFile.getName() + "-" + geom.getName() + "-" + i;
newFile = currentFolder.getFileObject(newFileName, "j3m");
}
newFile = currentFolder.createData(currentFile.getName() + "-" + i, "j3m");
newFile = currentFolder.createData(newFileName, "j3m");
EditableMaterialFile properties = new EditableMaterialFile(newFile, pm);
material.setKey(new MaterialKey(pm.getRelativeAssetPath(newFile.getPath())));
properties.setAsMaterial(material);
currentFolder.refresh();
applyMaterial(material.getAssetName());
} catch (IOException ex) {
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
return;
}
@ -200,7 +202,7 @@ public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerProp
for (Iterator<PropertyChangeListener> it = listeners.iterator(); it.hasNext();) {
PropertyChangeListener propertyChangeListener = it.next();
//TODO: check what the "programmatic name" is supposed to be here.. for now its Quaternion
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, null, before, after));
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, "Material", before, after));
}
}

@ -4,20 +4,28 @@
*/
package com.jme3.gde.materials.multiview;
import com.jme3.asset.MaterialKey;
import com.jme3.gde.core.assets.AssetDataObject;
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent;
import com.jme3.gde.materials.EditableMaterialFile;
import com.jme3.gde.materials.MaterialProperty;
import com.jme3.gde.core.sceneexplorer.MaterialChangeListener;
import com.jme3.gde.core.sceneexplorer.MaterialChangeProvider;
import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent;
import com.jme3.gde.materials.multiview.widgets.MaterialPropertyWidget;
import com.jme3.gde.materials.multiview.widgets.MaterialWidgetListener;
import com.jme3.gde.materials.multiview.widgets.WidgetFactory;
import com.jme3.material.Material;
import java.awt.Component;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@ -36,13 +44,14 @@ import org.openide.util.HelpCtx;
import org.openide.util.Lookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.windows.CloneableTopComponent;
import org.openide.windows.Mode;
/**
* Top component which displays something.
*/
@ConvertAsProperties(dtd = "-//com.jme3.gde.materials.multiview//MaterialEditor//EN",
autostore = false)
public final class MaterialEditorTopComponent extends CloneableTopComponent implements MaterialWidgetListener {
public final class MaterialEditorTopComponent extends CloneableTopComponent implements MaterialWidgetListener, MaterialChangeProvider {
private static MaterialEditorTopComponent instance;
/** path to the icon used by the component and its open action */
@ -54,10 +63,12 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
private DataObject dataObject;
private EditableMaterialFile materialFile;
private String materialFileName;
private String relativeMaterialFileName;
private ProjectAssetManager manager;
private SaveCookie saveCookie = new SaveCookieImpl();
private boolean saveImmediate = true;
private boolean updateProperties = false;
private List<MaterialChangeListener> materialListeners = new ArrayList<MaterialChangeListener>();
public MaterialEditorTopComponent() {
}
@ -66,6 +77,7 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
this.dataObject = dataObject;
materialFileName = dataObject.getPrimaryFile().getPath();
initWindow();
}
private void initWindow() {
@ -87,8 +99,17 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
updateProperties();
materialPreviewWidget1.showMaterial(manager, materialFileName);
relativeMaterialFileName = manager.getRelativeAssetPath(materialFileName);
for (Iterator it = WindowManager.getDefault().getModes().iterator(); it.hasNext();) {
Mode mode = (Mode) it.next();
System.out.println(mode.getName());
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
@ -316,6 +337,7 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
saveImmediate = jCheckBox1.isSelected();
}//GEN-LAST:event_jCheckBox1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JComboBox jComboBox1;
@ -388,12 +410,14 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
@Override
public void componentOpened() {
// TODO add custom code on component opening
SceneExplorerTopComponent.getDefault().addMaterialChangeProvider(this);
}
@Override
public void componentClosed() {
materialPreviewWidget1.cleanUp();
clearMaterialChangeListeners();
SceneExplorerTopComponent.getDefault().removeMaterialChangeProvider(this);
}
void writeProperties(java.util.Properties p) {
@ -429,6 +453,27 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
return PREFERRED_ID;
}
public String getKey() {
return relativeMaterialFileName;
}
public void addMaterialChangeListener(MaterialChangeListener listener) {
materialListeners.add(listener);
}
public void removeMaterialChangeListener(MaterialChangeListener listener) {
materialListeners.remove(listener);
}
public void clearMaterialChangeListeners() {
materialListeners.clear();
}
public void addAllMaterialChangeListener(List<MaterialChangeListener> listeners) {
materialListeners.addAll(listeners);
}
private class DocumentChangeListener implements DocumentListener {
String newline = "\n";
@ -584,5 +629,17 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
public void propertyChanged(MaterialProperty property) {
String string = materialFile.getUpdatedContent();
jTextArea1.setText(string);
try {
MaterialKey key = new MaterialKey(manager.getRelativeAssetPath(materialFileName));
manager.deleteFromCache(key);
Material material = (Material) manager.loadAsset(key);
if (material != null) {
for (MaterialChangeListener listener : materialListeners) {
listener.setMaterial(material);
}
}
} catch (Exception e) {
}
}
}

Loading…
Cancel
Save