* fixed a material bug in editor initialization

* changed terrain saving to use the cookie instead of the node, saving works well now
* updated to use new API changes

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7627 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 14 years ago
parent 3b8e37a51e
commit be8929da87
  1. 11
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainCameraController.java
  2. 152
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java
  3. 38
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java
  4. 10
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java

@ -46,6 +46,7 @@ import com.jme3.math.Ray;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import java.util.logging.Logger;
/**
@ -63,8 +64,8 @@ public class TerrainCameraController extends AbstractCameraController {
private boolean terrainEditToolActivated = false;
protected Application app;
private float toolModifyRate = 0.01f; // how frequently (in seconds) it should update
private long lastModifyTime;
private float toolModifyRate = 0.05f; // how frequently (in seconds) it should update to throttle down the tool effect
private float lastModifyTime; // last time the tool executed
public TerrainCameraController(Camera cam) {
super(cam, SceneApplication.getApplication().getInputManager());
@ -193,7 +194,11 @@ public class TerrainCameraController extends AbstractCameraController {
private void doTerrainUpdates(float dt) {
if (terrainEditToolActivated) {
if (app.getContext().getTimer().getTime() >= lastModifyTime + (toolModifyRate*1000)) {
lastModifyTime += dt;
if (lastModifyTime >= toolModifyRate) {
lastModifyTime = 0;
toolController.doTerrainEditToolActivated();
terrainEditToolActivated = false;
lastModifyTime = app.getContext().getTimer().getTime();

@ -35,10 +35,10 @@ package com.jme3.gde.terraineditor;
import com.jme3.asset.AssetManager;
import com.jme3.asset.TextureKey;
import com.jme3.bounding.BoundingBox;
import com.jme3.gde.core.assets.AssetDataObject;
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
import com.jme3.gde.core.util.DataObjectSaveNode;
import com.jme3.material.MatParam;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
@ -67,9 +67,7 @@ import javax.imageio.ImageIO;
import jme3tools.converters.ImageToAwt;
import org.openide.cookies.SaveCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.util.Exceptions;
/**
@ -81,8 +79,7 @@ public class TerrainEditorController {
private JmeSpatial jmeRootNode;
private Node terrainNode;
private Node rootNode;
private DataObject currentFileObject;
private DataObjectSaveNode alphaDataObject;
private AssetDataObject currentFileObject;
// texture settings
protected final String DEFAULT_TERRAIN_TEXTURE = "com/jme3/gde/terraineditor/dirt.jpg";
@ -91,90 +88,33 @@ public class TerrainEditorController {
private final int BASE_TEXTURE_COUNT = NUM_ALPHA_TEXTURES; // add any others here, like a global specular map
protected final int MAX_TEXTURE_LAYERS = 7-BASE_TEXTURE_COUNT; // 16 max, minus the ones we are reserving
public TerrainEditorController(JmeSpatial jmeRootNode, DataObject currentFileObject, TerrainEditorTopComponent topComponent) {
this.jmeRootNode = jmeRootNode;
rootNode = this.jmeRootNode.getLookup().lookup(Node.class);
this.currentFileObject = currentFileObject;
alphaDataObject = null;
}
public void setToolController(TerrainToolController toolController) {
}
//private DataObjectSaveNode alphaDataObject;
protected SaveCookie terrainSaveCookie = new SaveCookie() {
public void save() throws IOException {
//TODO: On OpenGL thread? -- safest way.. with get()?
SceneApplication.getApplication().enqueue(new Callable() {
/**
* Saves the data object into the topComponent via
* TerrainEditorTopComponent.addDataObject()
*/
public void getAlphaSaveDataObject(final TerrainEditorTopComponent topComponent) {
if (alphaDataObject != null)
topComponent.addDataObject(alphaDataObject);
else {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
doCreateAlphaSaveDataObject();
topComponent.addDataObject(alphaDataObject);
currentFileObject.saveAsset();
doSaveAlphaImages((Terrain)getTerrain(null));
return null;
}
});
}
};
public TerrainEditorController(JmeSpatial jmeRootNode, AssetDataObject currentFileObject, TerrainEditorTopComponent topComponent) {
this.jmeRootNode = jmeRootNode;
rootNode = this.jmeRootNode.getLookup().lookup(Node.class);
this.currentFileObject = currentFileObject;
this.currentFileObject.setSaveCookie(terrainSaveCookie);
}
public void doGetAlphaSaveDataObject(final TerrainEditorTopComponent topComponent) {
if (alphaDataObject != null)
topComponent.addDataObject(alphaDataObject);
else {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
doCreateAlphaSaveDataObject();
topComponent.addDataObject(alphaDataObject);
}
}
/*public void createAlphaSaveDataObject() throws DataObjectNotFoundException {
if (alphaDataObject != null)
return;
try {
SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception {
doCreateAlphaSaveDataObject();
return null;
}
}).get();
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}*/
private void doCreateAlphaSaveDataObject() {
if (alphaDataObject != null)
return;
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
String assetFolder = "";
AssetManager manager = SceneApplication.getApplication().getAssetManager();
if (manager != null && manager instanceof ProjectAssetManager)
assetFolder = ((ProjectAssetManager)manager).getAssetFolderName();
Texture alpha0 = doGetAlphaTexture(terrain, 0);
String path = alpha0.getKey().getName();
Logger.getLogger(TerrainEditorController.class.getName()).info("Creating AlphaSaveDataObject, path: "+assetFolder+path);
FileObject fb = FileUtil.toFileObject(new File(assetFolder+path));
try {
alphaDataObject = new DataObjectSaveNode(DataObject.find(fb));
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
public void setToolController(TerrainToolController toolController) {
}
public FileObject getCurrentFileObject() {
@ -187,49 +127,6 @@ public class TerrainEditorController {
public void setNeedsSave(boolean state) {
currentFileObject.setModified(state);
setNeedsSaveAlpha(state);
}
private void setNeedsSaveAlpha(boolean state) {
if (alphaDataObject == null)
doCreateAlphaSaveDataObject();
Terrain terrain = (Terrain)getTerrain(null);
AlphaTextureSaveCookie cookie = new AlphaTextureSaveCookie(terrain);
if(!alphaDataObject.getDataObject().isModified()){
alphaDataObject.setSaveCookie(cookie);
}
}
class AlphaTextureSaveCookie implements SaveCookie {
private Terrain terrain;
AlphaTextureSaveCookie(Terrain terrain) {
this.terrain = terrain;
}
public String getId() {
return terrain.getSpatial().getName();
}
public void save() throws IOException {
saveAlphaImages(terrain);
alphaDataObject.removeSaveCookie();
}
}
public boolean isNeedSave() {
return currentFileObject.isModified();
}
public void saveScene() {
try {
currentFileObject.getLookup().lookup(SaveCookie.class).save();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
protected Node getTerrain(Spatial root) {
@ -336,7 +233,7 @@ public class TerrainEditorController {
final Node node = jmeRootNode.getLookup().lookup(Node.class);
terrainNode = null;
rootNode = null;
alphaDataObject = null;
// alphaDataObject = null;
}
/**
@ -559,6 +456,8 @@ public class TerrainEditorController {
else
terrain.getMaterial().setTexture("DiffuseMap_"+layer, tex);
doSetTextureScale(layer, DEFAULT_TEXTURE_SCALE);
setNeedsSave(true);
}
@ -861,7 +760,7 @@ public class TerrainEditorController {
parent.attachChild(terrain);
doCreateAlphaSaveDataObject();
// doCreateAlphaSaveDataObject();
setNeedsSave(true);
@ -1025,7 +924,7 @@ public class TerrainEditorController {
return;
setNeedsSaveAlpha(true);
setNeedsSave(true);
Texture tex = doGetAlphaTextureFromDiffuse(terrain, selectedTextureIndex);
Image image = tex.getImage();
@ -1063,7 +962,7 @@ public class TerrainEditorController {
* @param erase true if the tool should remove the paint instead of add it
* @param fadeFalloff the percentage of the radius when the paint begins to start fading
*/
protected void doPaintAction(int texIndex, Image image, Vector2f uv, boolean dragged, float radius, boolean erase, float fadeFalloff){
protected void doPaintAction(int texIndex, Image image, Vector2f uv, boolean dragged, float radius, boolean erase, float fadeFalloff){
Vector2f texuv = new Vector2f();
ColorRGBA color = ColorRGBA.Black;
@ -1075,6 +974,7 @@ public class TerrainEditorController {
int miny = (int) (uv.y*height - radius*height);
int maxy = (int) (uv.y*height + radius*height);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("Paint "+uv );
float radiusSquared = radius*radius;
float radiusFalloff = radius*fadeFalloff;
// go through each pixel, in the radius of the tool, in the image

@ -55,13 +55,9 @@ import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Vector;
import java.util.logging.Logger;
import javax.swing.AbstractCellEditor;
import javax.swing.DefaultListSelectionModel;
@ -70,7 +66,6 @@ import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileFilter;
@ -81,7 +76,6 @@ import javax.swing.table.TableCellRenderer;
import jme3tools.converters.ImageToAwt;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.progress.ProgressHandleFactory;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.nodes.NodeEvent;
import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent;
@ -94,8 +88,6 @@ import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.NotifyDescriptor.Confirmation;
import org.openide.WizardDescriptor;
import org.openide.cookies.SaveCookie;
import org.openide.loaders.DataObject;
import org.openide.nodes.NodeListener;
import org.openide.util.Exceptions;
import org.openide.util.HelpCtx;
@ -126,6 +118,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private SkyboxWizardAction skyboxWizard;
private JmeSpatial selectedSpat;
private TerrainNodeListener terrainDeletedNodeListener;
public enum TerrainEditButton {none, raiseTerrain, lowerTerrain, smoothTerrain, levelTerrain, paintTerrain, eraseTerrain};
@ -760,7 +753,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
addSaveNode(selectedSpat);
editorController.getAlphaSaveDataObject(this);
// editorController.getAlphaSaveDataObject(this);
editorController.setNeedsSave(true);
@ -971,7 +964,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
setSceneInfo(currentRequest.getJmeNode(), true);
editorController.doGetAlphaSaveDataObject(this);
//editorController.doGetAlphaSaveDataObject(this);
// if the opened scene has terrain, add it to a save node
Terrain terrain = (Terrain)editorController.getTerrain(null);
@ -1029,11 +1022,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
}
protected void addSaveNode(org.openide.nodes.Node node) {
org.openide.nodes.Node[] nodes = getActivatedNodes();
org.openide.nodes.Node[] newNodes = new org.openide.nodes.Node[nodes.length+1];
System.arraycopy(nodes, 0, newNodes, 0, nodes.length);
newNodes[newNodes.length-1] = node;
setActivatedNodes(newNodes);
setActivatedNodes(new org.openide.nodes.Node[]{node});
}
private void setSceneInfo(final JmeNode jmeNode, final boolean active) {
@ -1058,25 +1047,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
});
}
/*private boolean checkSaved() {
if (editorController != null && editorController.isNeedSave()) {
Confirmation msg = new NotifyDescriptor.Confirmation("Your Scene is not saved, do you want to save?",
NotifyDescriptor.YES_NO_CANCEL_OPTION,
NotifyDescriptor.WARNING_MESSAGE);
Object res = DialogDisplayer.getDefault().notify(msg);
if (NotifyDescriptor.CANCEL_OPTION.equals(res)) {
return false;
} else if (NotifyDescriptor.YES_OPTION.equals(res)) {
editorController.saveScene();
return true;
} else if (NotifyDescriptor.NO_OPTION.equals(res)) {
return true;
}
return true;
}
return true;
}*/
public boolean sceneClose(SceneRequest request) {
if (request.equals(currentRequest)) {
// if (checkSaved()) {

@ -48,6 +48,7 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.shape.Sphere;
import com.jme3.util.IntMap.Entry;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
/**
* The controller for the terrain modification tools. It will in turn interact
@ -104,7 +105,8 @@ public class TerrainToolController extends SceneToolController {
marker = new Geometry("edit marker");
Mesh m = new Sphere(8, 8, 3);
marker.setMesh(m);
Material mat = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
Material mat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", ColorRGBA.Green);
marker.setMaterial(mat);
marker.setLocalTranslation(0,0,0);
@ -125,8 +127,10 @@ public class TerrainToolController extends SceneToolController {
hideEditTool();
} else if (state == TerrainEditButton.raiseTerrain || state == TerrainEditButton.lowerTerrain) {
showEditTool(state);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("TERRAIN HEIGHT state");
} else if (state == TerrainEditButton.paintTerrain || state == TerrainEditButton.eraseTerrain) {
showEditTool(state);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("PAINT TERRAIN state");
}
}
@ -205,15 +209,19 @@ public class TerrainToolController extends SceneToolController {
if (TerrainEditButton.raiseTerrain == getCurrentEditButtonState() ) {
editorController.doModifyTerrainHeight(getMarkerLocation(), heightToolRadius, heightAmount);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("terrain raise height");
}
else if (TerrainEditButton.lowerTerrain == getCurrentEditButtonState() ) {
editorController.doModifyTerrainHeight(getMarkerLocation(), heightToolRadius, -heightAmount);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("terrain lower height");
}
else if(TerrainEditButton.paintTerrain == getCurrentEditButtonState()) {
editorController.doPaintTexture(selectedTextureIndex, getMarkerLocation(), heightToolRadius, paintAmount);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("terrain paint");
}
else if (TerrainEditButton.eraseTerrain == getCurrentEditButtonState() ) {
editorController.doPaintTexture(selectedTextureIndex, getMarkerLocation(), heightToolRadius, -paintAmount);
Logger.getLogger(TerrainEditorTopComponent.class.getName()).info("terrain erase");
}
}
}

Loading…
Cancel
Save