SDK's camera now focuses on the cursor, no more unresponsive zooming. Also fixed an issue with terrain editor's save cookies not resetting. Happy Halloween

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10860 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
bre..om 11 years ago
parent b14f33936f
commit d723af5009
  1. 11
      sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java
  2. 8
      sdk/jme3-core/src/com/jme3/gde/core/scene/controller/SceneToolController.java
  3. 3
      sdk/jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/JmeTerrainQuad.java
  4. 5
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java
  5. 2
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/SelectTool.java
  6. 10
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainCameraController.java
  7. 49
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java
  8. 39
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java
  9. 1
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java
  10. 8
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/PaintTerrainTool.java

@ -149,11 +149,11 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
}); });
} }
public void setCamFocus(final Vector3f focus) { public void setCamFocus(final Vector3f focus, final boolean moveCamera) {
SceneApplication.getApplication().enqueue(new Callable<Object>() { SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception { public Object call() throws Exception {
doSetCamFocus(focus); doSetCamFocus(focus, moveCamera);
return null; return null;
} }
}); });
@ -161,7 +161,12 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
} }
public void doSetCamFocus(Vector3f focus) { public void doSetCamFocus(Vector3f focus) {
cam.setLocation(cam.getLocation().add(focus.subtract(this.focus))); doSetCamFocus(focus, false);
}
public void doSetCamFocus(Vector3f focus, boolean moveCamera) {
if (moveCamera)
cam.setLocation(cam.getLocation().add(focus.subtract(this.focus)));
this.focus.set(focus); this.focus.set(focus);
} }

@ -27,6 +27,7 @@ import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.control.CameraControl;
import com.jme3.scene.debug.Arrow; import com.jme3.scene.debug.Arrow;
import com.jme3.scene.debug.Grid; import com.jme3.scene.debug.Grid;
import com.jme3.scene.debug.WireBox; import com.jme3.scene.debug.WireBox;
@ -48,6 +49,7 @@ public class SceneToolController implements AppState {
protected Spatial selectionShape; protected Spatial selectionShape;
protected AssetManager manager; protected AssetManager manager;
protected Material blueMat; protected Material blueMat;
protected AbstractCameraController camController;
public SceneToolController(AssetManager manager) { public SceneToolController(AssetManager manager) {
this.toolsNode = new Node("ToolsNode"); this.toolsNode = new Node("ToolsNode");
@ -62,6 +64,10 @@ public class SceneToolController implements AppState {
SceneApplication.getApplication().getStateManager().attach(this); SceneApplication.getApplication().getStateManager().attach(this);
} }
public void setCamController(AbstractCameraController camController) {
this.camController = camController;
}
protected void initTools() { protected void initTools() {
blueMat = createBlueMat(); blueMat = createBlueMat();
@ -167,6 +173,8 @@ public class SceneToolController implements AppState {
public void doSetCursorLocation(Vector3f location) { public void doSetCursorLocation(Vector3f location) {
cursor.setLocalTranslation(location); cursor.setLocalTranslation(location);
if (camController != null)
camController.doSetCamFocus(location);
} }
public void snapCursorToSelection() { public void snapCursorToSelection() {

@ -34,7 +34,10 @@ package com.jme3.gde.core.sceneexplorer.nodes;
import com.jme3.gde.core.icons.IconList; import com.jme3.gde.core.icons.IconList;
import com.jme3.terrain.geomipmap.TerrainQuad; import com.jme3.terrain.geomipmap.TerrainQuad;
import java.awt.Image; import java.awt.Image;
import java.io.IOException;
import org.openide.cookies.SaveCookie;
import org.openide.loaders.DataObject; import org.openide.loaders.DataObject;
import org.openide.nodes.Node;
import org.openide.nodes.Sheet; import org.openide.nodes.Sheet;
/** /**

@ -571,7 +571,7 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce
}//GEN-LAST:event_resetCursorButtonActionPerformed }//GEN-LAST:event_resetCursorButtonActionPerformed
private void camToCursorSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camToCursorSelectionButtonActionPerformed private void camToCursorSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_camToCursorSelectionButtonActionPerformed
camController.setCamFocus(toolController.getCursorLocation()); camController.setCamFocus(toolController.getCursorLocation(), true);
}//GEN-LAST:event_camToCursorSelectionButtonActionPerformed }//GEN-LAST:event_camToCursorSelectionButtonActionPerformed
private void cursorToSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cursorToSelectionButtonActionPerformed private void cursorToSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cursorToSelectionButtonActionPerformed
@ -1017,7 +1017,8 @@ private void jToggleSelectGeomActionPerformed(java.awt.event.ActionEvent evt) {/
editorController.setToolController(toolController); editorController.setToolController(toolController);
toolController.refreshNonSpatialMarkers(); toolController.refreshNonSpatialMarkers();
toolController.setCamController(camController);
editorController.setTerrainLodCamera(); editorController.setTerrainLodCamera();
final SpatialAssetDataObject dobj = ((SpatialAssetDataObject) currentRequest.getDataObject()); final SpatialAssetDataObject dobj = ((SpatialAssetDataObject) currentRequest.getDataObject());
listener = new ProjectAssetManager.ClassPathChangeListener() { listener = new ProjectAssetManager.ClassPathChangeListener() {

@ -421,7 +421,7 @@ public class SelectTool extends SceneEditTool {
if (toolController.isSnapToGrid()) { if (toolController.isSnapToGrid()) {
result.set(Math.round(result.x), result.y, Math.round(result.z)); result.set(Math.round(result.x), result.y, Math.round(result.z));
} }
toolController.doSetCursorLocation(result); toolController.setCursorLocation(result);
} }
} }
} }

@ -44,6 +44,7 @@ import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
/** /**
* Runs in the JME thread, not awt thread. * Runs in the JME thread, not awt thread.
* Listens to mouse/camera input and relays the movements * Listens to mouse/camera input and relays the movements
@ -124,14 +125,19 @@ public class TerrainCameraController extends AbstractCameraController {
if (button == 0) { if (button == 0) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) { if (isTerrainEditButtonEnabled() && !forceCameraControls) {
toolController.setPrimary(pressed); toolController.setPrimary(pressed);
System.out.println("primary "+pressed); //System.out.println("primary "+pressed);
} else if (!isTerrainEditButtonEnabled() && !forceCameraControls) {
if (!pressed) {
Vector3f pick = getTerrainCollisionPoint();
toolController.setCursorLocation(pick);
}
} }
} }
if (button == 1) { if (button == 1) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) { if (isTerrainEditButtonEnabled() && !forceCameraControls) {
toolController.setAlternate(pressed); toolController.setAlternate(pressed);
System.out.println("alternate "+pressed); //System.out.println("alternate "+pressed);
} }
} }
} }

@ -79,6 +79,7 @@ import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent; import org.openide.nodes.NodeReorderEvent;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.util.lookup.InstanceContent;
/** /**
* Modifies the actual terrain in the scene. * Modifies the actual terrain in the scene.
@ -101,42 +102,48 @@ public class TerrainEditorController implements NodeListener {
protected final int MAX_DIFFUSE = 12; protected final int MAX_DIFFUSE = 12;
protected final int MAX_TEXTURES = 16-NUM_ALPHA_TEXTURES; // 16 max (diffuse and normal), minus the ones we are reserving protected final int MAX_TEXTURES = 16-NUM_ALPHA_TEXTURES; // 16 max (diffuse and normal), minus the ones we are reserving
private boolean alphaLayersChanged = false;
//private InstanceContent content;
class TerrainSaveCookie implements SaveCookie { class TerrainSaveCookie implements SaveCookie {
JmeSpatial rootNode; JmeSpatial rootNode;
public void save() throws IOException { public void save() throws IOException {
SceneApplication.getApplication().enqueue(new Callable() { if (alphaLayersChanged) {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
currentFileObject.saveAsset(); //currentFileObject.saveAsset();
//TerrainSaveCookie sc = currentFileObject.getCookie(TerrainSaveCookie.class); //TerrainSaveCookie sc = currentFileObject.getCookie(TerrainSaveCookie.class);
//if (sc != null) { //if (sc != null) {
//Node root = rootNode.getLookup().lookup(Node.class); //Node root = rootNode.getLookup().lookup(Node.class);
doSaveAlphaImages(); doSaveAlphaImages();
//} //content.remove(TerrainSaveCookie.this);
return null; //}
} return null;
}); }
});
alphaLayersChanged = false;
}
} }
} }
private TerrainSaveCookie terrainSaveCookie = new TerrainSaveCookie(); private TerrainSaveCookie terrainSaveCookie = new TerrainSaveCookie();
public TerrainEditorController(JmeSpatial jmeRootNode, AssetDataObject currentFileObject, TerrainEditorTopComponent topComponent) { public TerrainEditorController(JmeSpatial jmeRootNode,
AssetDataObject currentFileObject,
TerrainEditorTopComponent topComponent)
{
this.jmeRootNode = jmeRootNode; this.jmeRootNode = jmeRootNode;
rootNode = this.jmeRootNode.getLookup().lookup(Node.class); rootNode = this.jmeRootNode.getLookup().lookup(Node.class);
this.currentFileObject = currentFileObject; this.currentFileObject = currentFileObject;
//this.content = content;
terrainSaveCookie.rootNode = jmeRootNode; terrainSaveCookie.rootNode = jmeRootNode;
this.currentFileObject.setSaveCookie(terrainSaveCookie); this.currentFileObject.setSaveCookie(terrainSaveCookie);
this.topComponent = topComponent; this.topComponent = topComponent;
this.jmeRootNode.addNodeListener(this); this.jmeRootNode.addNodeListener(this);
} }
public void setToolController(TerrainToolController toolController) {
}
public FileObject getCurrentFileObject() { public FileObject getCurrentFileObject() {
return currentFileObject.getPrimaryFile(); return currentFileObject.getPrimaryFile();
} }
@ -218,6 +225,15 @@ public class TerrainEditorController implements NodeListener {
return null; return null;
} }
/**
* Painting happened and the alpha maps need saving.
*/
public void alphaLayersChanged() {
//if (!alphaLayersChanged)
// content.add(terrainSaveCookie);
alphaLayersChanged = true;
}
/** /**
* Perform the actual height modification on the terrain. * Perform the actual height modification on the terrain.
@ -583,6 +599,7 @@ public class TerrainEditorController implements NodeListener {
image.getData(0).rewind(); image.getData(0).rewind();
tex.getImage().setUpdateNeeded(); tex.getImage().setUpdateNeeded();
setNeedsSave(true); setNeedsSave(true);
alphaLayersChanged();
} }
/** /**

@ -66,6 +66,7 @@ import java.text.NumberFormat;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
@ -91,6 +92,8 @@ import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent; import org.openide.nodes.NodeReorderEvent;
import org.openide.util.Lookup.Result; import org.openide.util.Lookup.Result;
import org.openide.util.*; import org.openide.util.*;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.windows.TopComponent; import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager; import org.openide.windows.WindowManager;
@ -121,12 +124,23 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private DDSPreview ddsPreview; private DDSPreview ddsPreview;
private Map<String, JButton> buttons = new HashMap<String, JButton>(); private Map<String, JButton> buttons = new HashMap<String, JButton>();
private JPanel insideToolSettings; private JPanel insideToolSettings;
//private InstanceContent content;
public TerrainEditorTopComponent() { public TerrainEditorTopComponent() {
initComponents(); initComponents();
setName(NbBundle.getMessage(TerrainEditorTopComponent.class, "CTL_TerrainEditorTopComponent")); setName(NbBundle.getMessage(TerrainEditorTopComponent.class, "CTL_TerrainEditorTopComponent"));
setToolTipText(NbBundle.getMessage(TerrainEditorTopComponent.class, "HINT_TerrainEditorTopComponent")); setToolTipText(NbBundle.getMessage(TerrainEditorTopComponent.class, "HINT_TerrainEditorTopComponent"));
associateLookup(ExplorerUtils.createLookup(new ExplorerManager(), getActionMap())); //content = new InstanceContent();
/*ActionMap actionMap = getActionMap();
for (Object key : actionMap.allKeys() ) {
System.out.println("key: "+key+ actionMap.get(key));
Action value = actionMap.get(key);
}*/
//actionMap.put(, terrainWizard);
Lookup lookup = ExplorerUtils.createLookup(new ExplorerManager(), getActionMap());
associateLookup(lookup);
setIcon(ImageUtilities.loadImage(ICON_PATH, true)); setIcon(ImageUtilities.loadImage(ICON_PATH, true));
result = Utilities.actionsGlobalContext().lookupResult(JmeSpatial.class); result = Utilities.actionsGlobalContext().lookupResult(JmeSpatial.class);
} }
@ -745,7 +759,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private void paintButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paintButtonActionPerformed private void paintButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_paintButtonActionPerformed
if (paintButton.isSelected()) { if (paintButton.isSelected()) {
PaintTerrainTool tool = new PaintTerrainTool(); PaintTerrainTool tool = new PaintTerrainTool(editorController);
toolController.setTerrainEditButtonState(tool); toolController.setTerrainEditButtonState(tool);
setHintText(tool); setHintText(tool);
} else { } else {
@ -802,7 +816,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
Float f = new Float(shininessField.getText()); Float f = new Float(shininessField.getText());
editorController.setShininess(Math.max(0, f)); editorController.setShininess(Math.max(0, f));
} catch (Exception e) { } catch (Exception e) {
return; Logger.getLogger(TerrainEditorTopComponent.class.getName()).log(Level.WARNING,
"Error accessing shininess field in terrain material.", e);
} }
}//GEN-LAST:event_shininessFieldActionPerformed }//GEN-LAST:event_shininessFieldActionPerformed
@ -1283,12 +1298,17 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
//SceneUndoRedoManager m = Lookup.getDefault().lookup(SceneUndoRedoManager.class);//TODO remove this line //SceneUndoRedoManager m = Lookup.getDefault().lookup(SceneUndoRedoManager.class);//TODO remove this line
Logger.getLogger(TerrainEditorTopComponent.class.getName()).finer("Terrain openScene " + file.getName()); Logger.getLogger(TerrainEditorTopComponent.class.getName()).log(Level.FINER, "Terrain openScene {0}", file.getName());
if (editorController != null) { if (editorController != null) {
editorController.cleanup(); editorController.cleanup();
} }
//this.associateLookup( new AbstractLookup(content) ); // for saving alpha images
editorController = new TerrainEditorController(jmeNode, file, this); editorController = new TerrainEditorController(jmeNode, file, this);
this.sentRequest = request; this.sentRequest = request;
request.setWindowTitle("TerrainEditor - " + manager.getRelativeAssetPath(file.getPrimaryFile().getPath())); request.setWindowTitle("TerrainEditor - " + manager.getRelativeAssetPath(file.getPrimaryFile().getPath()));
request.setToolNode(new Node("TerrainEditorToolNode")); request.setToolNode(new Node("TerrainEditorToolNode"));
@ -1339,14 +1359,13 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
toolController.setEditorController(editorController); toolController.setEditorController(editorController);
toolController.setCameraController(camController); toolController.setCameraController(camController);
toolController.setTopComponent(this); toolController.setTopComponent(this);
editorController.setToolController(toolController);
toolController.setHeightToolRadius((float) radiusSlider.getValue() / (float) radiusSlider.getMaximum()); toolController.setHeightToolRadius((float) radiusSlider.getValue() / (float) radiusSlider.getMaximum());
toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum()); toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum());
//toolController.setToolMesh(meshForm.isSelected()); // future for adding brush shape //toolController.setToolMesh(meshForm.isSelected()); // future for adding brush shape
editorController.setTerrainLodCamera(); editorController.setTerrainLodCamera();
reinitTextureTable(); // update the UI reinitTextureTable(); // update the UI
if (editorController.getTerrain(null) != null) { if (editorController.getTerrain(null) != null) {
//createTerrainButton.setEnabled(false); // only let the user add one terrain //createTerrainButton.setEnabled(false); // only let the user add one terrain
@ -1449,10 +1468,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
while (textureTable.getModel().getRowCount() > 0) { while (textureTable.getModel().getRowCount() > 0) {
((TextureTableModel) textureTable.getModel()).removeRow(0); ((TextureTableModel) textureTable.getModel()).removeRow(0);
} }
if (editorController.getTerrain(null) == null) {
return;
}
} }
/** /**
@ -1513,7 +1528,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
Float scale = editorController.getTextureScale(i); Float scale = editorController.getTextureScale(i);
if (scale == null) { if (scale == null) {
scale = editorController.DEFAULT_TEXTURE_SCALE; scale = TerrainEditorController.DEFAULT_TEXTURE_SCALE;
} }
addRow(new Object[]{"", i, i, scale}); addRow(new Object[]{"", i, i, scale});
} }
@ -1540,7 +1555,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
} }
protected void addNewTexture(int newIndex) { protected void addNewTexture(int newIndex) {
float scale = editorController.DEFAULT_TEXTURE_SCALE; float scale = TerrainEditorController.DEFAULT_TEXTURE_SCALE;
// add it to the table model // add it to the table model
addRow(new Object[]{"", newIndex, null, scale}); // add to the table model addRow(new Object[]{"", newIndex, null, scale}); // add to the table model

@ -80,6 +80,7 @@ public class TerrainToolController extends SceneToolController {
public void setCameraController(TerrainCameraController cameraController) { public void setCameraController(TerrainCameraController cameraController) {
this.cameraController = cameraController; this.cameraController = cameraController;
super.setCamController(cameraController);
} }
public void setTopComponent(TerrainEditorTopComponent topComponent) { public void setTopComponent(TerrainEditorTopComponent topComponent) {

@ -32,9 +32,9 @@
package com.jme3.gde.terraineditor.tools; package com.jme3.gde.terraineditor.tools;
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode; import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
import com.jme3.gde.core.sceneexplorer.nodes.actions.AbstractStatefulGLToolAction;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.core.undoredo.SceneUndoRedoManager; import com.jme3.gde.core.undoredo.SceneUndoRedoManager;
import com.jme3.gde.terraineditor.TerrainEditorController;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -55,7 +55,11 @@ public class PaintTerrainTool extends TerrainTool {
private boolean painting = false; // to check when undo actions need to be set private boolean painting = false; // to check when undo actions need to be set
List<PaintTerrainToolAction> actions = new ArrayList<PaintTerrainToolAction>(); List<PaintTerrainToolAction> actions = new ArrayList<PaintTerrainToolAction>();
TerrainEditorController controller; // used to we can flag when alpha maps changed
public PaintTerrainTool(TerrainEditorController controller) {
this.controller = controller;
}
@Override @Override
public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) { public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
@ -83,6 +87,7 @@ public class PaintTerrainTool extends TerrainTool {
action = new PaintTerrainToolAction(point, radius, -weight, textureIndex); action = new PaintTerrainToolAction(point, radius, -weight, textureIndex);
action.doActionPerformed(rootNode, dataObject, false); action.doActionPerformed(rootNode, dataObject, false);
actions.add(action); actions.add(action);
setModified(rootNode, dataObject);
} }
@Override @Override
@ -149,6 +154,7 @@ public class PaintTerrainTool extends TerrainTool {
} }
protected void setModified(final AbstractSceneExplorerNode rootNode, final DataObject dataObject) { protected void setModified(final AbstractSceneExplorerNode rootNode, final DataObject dataObject) {
controller.alphaLayersChanged();
if (dataObject.isModified()) if (dataObject.isModified())
return; return;
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {

Loading…
Cancel
Save