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. 9
      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. 3
      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. 29
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java
  8. 37
      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>() {
public Object call() throws Exception {
doSetCamFocus(focus);
doSetCamFocus(focus, moveCamera);
return null;
}
});
@ -161,6 +161,11 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
}
public void doSetCamFocus(Vector3f 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);
}

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

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

@ -571,7 +571,7 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce
}//GEN-LAST:event_resetCursorButtonActionPerformed
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
private void cursorToSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cursorToSelectionButtonActionPerformed
@ -1017,6 +1017,7 @@ private void jToggleSelectGeomActionPerformed(java.awt.event.ActionEvent evt) {/
editorController.setToolController(toolController);
toolController.refreshNonSpatialMarkers();
toolController.setCamController(camController);
editorController.setTerrainLodCamera();
final SpatialAssetDataObject dobj = ((SpatialAssetDataObject) currentRequest.getDataObject());

@ -421,7 +421,7 @@ public class SelectTool extends SceneEditTool {
if (toolController.isSnapToGrid()) {
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.renderer.Camera;
/**
* Runs in the JME thread, not awt thread.
* Listens to mouse/camera input and relays the movements
@ -124,14 +125,19 @@ public class TerrainCameraController extends AbstractCameraController {
if (button == 0) {
if (isTerrainEditButtonEnabled() && !forceCameraControls) {
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 (isTerrainEditButtonEnabled() && !forceCameraControls) {
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.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.lookup.InstanceContent;
/**
* 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_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 {
JmeSpatial rootNode;
public void save() throws IOException {
if (alphaLayersChanged) {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
currentFileObject.saveAsset();
//currentFileObject.saveAsset();
//TerrainSaveCookie sc = currentFileObject.getCookie(TerrainSaveCookie.class);
//if (sc != null) {
//Node root = rootNode.getLookup().lookup(Node.class);
doSaveAlphaImages();
//content.remove(TerrainSaveCookie.this);
//}
return null;
}
});
alphaLayersChanged = false;
}
}
}
private TerrainSaveCookie terrainSaveCookie = new TerrainSaveCookie();
public TerrainEditorController(JmeSpatial jmeRootNode, AssetDataObject currentFileObject, TerrainEditorTopComponent topComponent) {
public TerrainEditorController(JmeSpatial jmeRootNode,
AssetDataObject currentFileObject,
TerrainEditorTopComponent topComponent)
{
this.jmeRootNode = jmeRootNode;
rootNode = this.jmeRootNode.getLookup().lookup(Node.class);
this.currentFileObject = currentFileObject;
//this.content = content;
terrainSaveCookie.rootNode = jmeRootNode;
this.currentFileObject.setSaveCookie(terrainSaveCookie);
this.topComponent = topComponent;
this.jmeRootNode.addNodeListener(this);
}
public void setToolController(TerrainToolController toolController) {
}
public FileObject getCurrentFileObject() {
return currentFileObject.getPrimaryFile();
}
@ -219,6 +226,15 @@ public class TerrainEditorController implements NodeListener {
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.
* @param worldLoc the location in the world where the tool was activated
@ -583,6 +599,7 @@ public class TerrainEditorController implements NodeListener {
image.getData(0).rewind();
tex.getImage().setUpdateNeeded();
setNeedsSave(true);
alphaLayersChanged();
}
/**

@ -66,6 +66,7 @@ import java.text.NumberFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
@ -91,6 +92,8 @@ import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent;
import org.openide.util.Lookup.Result;
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.WindowManager;
@ -122,11 +125,22 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
private Map<String, JButton> buttons = new HashMap<String, JButton>();
private JPanel insideToolSettings;
//private InstanceContent content;
public TerrainEditorTopComponent() {
initComponents();
setName(NbBundle.getMessage(TerrainEditorTopComponent.class, "CTL_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));
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
if (paintButton.isSelected()) {
PaintTerrainTool tool = new PaintTerrainTool();
PaintTerrainTool tool = new PaintTerrainTool(editorController);
toolController.setTerrainEditButtonState(tool);
setHintText(tool);
} else {
@ -802,7 +816,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
Float f = new Float(shininessField.getText());
editorController.setShininess(Math.max(0, f));
} catch (Exception e) {
return;
Logger.getLogger(TerrainEditorTopComponent.class.getName()).log(Level.WARNING,
"Error accessing shininess field in terrain material.", e);
}
}//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
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) {
editorController.cleanup();
}
//this.associateLookup( new AbstractLookup(content) ); // for saving alpha images
editorController = new TerrainEditorController(jmeNode, file, this);
this.sentRequest = request;
request.setWindowTitle("TerrainEditor - " + manager.getRelativeAssetPath(file.getPrimaryFile().getPath()));
request.setToolNode(new Node("TerrainEditorToolNode"));
@ -1339,7 +1359,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
toolController.setEditorController(editorController);
toolController.setCameraController(camController);
toolController.setTopComponent(this);
editorController.setToolController(toolController);
toolController.setHeightToolRadius((float) radiusSlider.getValue() / (float) radiusSlider.getMaximum());
toolController.setHeightToolHeight((float) heightSlider.getValue() / (float) heightSlider.getMaximum());
@ -1449,10 +1468,6 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
while (textureTable.getModel().getRowCount() > 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);
if (scale == null) {
scale = editorController.DEFAULT_TEXTURE_SCALE;
scale = TerrainEditorController.DEFAULT_TEXTURE_SCALE;
}
addRow(new Object[]{"", i, i, scale});
}
@ -1540,7 +1555,7 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
}
protected void addNewTexture(int newIndex) {
float scale = editorController.DEFAULT_TEXTURE_SCALE;
float scale = TerrainEditorController.DEFAULT_TEXTURE_SCALE;
// add it 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) {
this.cameraController = cameraController;
super.setCamController(cameraController);
}
public void setTopComponent(TerrainEditorTopComponent topComponent) {

@ -32,9 +32,9 @@
package com.jme3.gde.terraineditor.tools;
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.SceneUndoRedoManager;
import com.jme3.gde.terraineditor.TerrainEditorController;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
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
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
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.doActionPerformed(rootNode, dataObject, false);
actions.add(action);
setModified(rootNode, dataObject);
}
@Override
@ -149,6 +154,7 @@ public class PaintTerrainTool extends TerrainTool {
}
protected void setModified(final AbstractSceneExplorerNode rootNode, final DataObject dataObject) {
controller.alphaLayersChanged();
if (dataObject.isModified())
return;
java.awt.EventQueue.invokeLater(new Runnable() {

Loading…
Cancel
Save