axis-aligned terrain tool snapping support, thanks @shirkit
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9683 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
2cf1455867
commit
cf103e191d
@ -119,7 +119,7 @@ CreateTerrainVisualPanel2.smoothIterationsLabel.text=Rough
|
|||||||
CreateTerrainVisualPanel2.jLabel6.text=Smooth
|
CreateTerrainVisualPanel2.jLabel6.text=Smooth
|
||||||
CreateTerrainVisualPanel2.jLabel7.text=Height Scale:
|
CreateTerrainVisualPanel2.jLabel7.text=Height Scale:
|
||||||
CreateTerrainVisualPanel2.heightScale.text=1
|
CreateTerrainVisualPanel2.heightScale.text=1
|
||||||
TerrainEditorTopComponent.toolHint.slope=Right click to set the markers position. A simple right click set the first marker, holding ctrl sets the second marker. Hold the Left button to apply the slope in the area you are hovering.
|
TerrainEditorTopComponent.toolHint.slope=Right click to set the markers position. A simple right click set the first marker, holding CTRL and left-clicking sets the second marker. Holding CTRL will also snap the tool to axis-aligned angles. To build the slope, press the left mouse button after you have set the points.
|
||||||
TerrainEditorTopComponent.jLabel6.text=
|
TerrainEditorTopComponent.jLabel6.text=
|
||||||
TerrainEditorTopComponent.levelAbsoluteHeightField.text=0
|
TerrainEditorTopComponent.levelAbsoluteHeightField.text=0
|
||||||
TerrainEditorTopComponent.slopeTerrainButton.toolTipText=Slope terrain
|
TerrainEditorTopComponent.slopeTerrainButton.toolTipText=Slope terrain
|
||||||
|
@ -47,6 +47,7 @@ import com.jme3.scene.Node;
|
|||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.control.BillboardControl;
|
import com.jme3.scene.control.BillboardControl;
|
||||||
import com.jme3.scene.shape.Line;
|
import com.jme3.scene.shape.Line;
|
||||||
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.scene.shape.Sphere;
|
import com.jme3.scene.shape.Sphere;
|
||||||
import org.openide.loaders.DataObject;
|
import org.openide.loaders.DataObject;
|
||||||
|
|
||||||
@ -67,6 +68,11 @@ public class SlopeTerrainTool extends TerrainTool {
|
|||||||
toolHintTextKey = "TerrainEditorTopComponent.toolHint.slope";
|
toolHintTextKey = "TerrainEditorTopComponent.toolHint.slope";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean useStraightLine() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate(AssetManager manager, Node parent) {
|
public void activate(AssetManager manager, Node parent) {
|
||||||
super.activate(manager, parent);
|
super.activate(manager, parent);
|
||||||
@ -123,6 +129,7 @@ public class SlopeTerrainTool extends TerrainTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyInputEvent kie) {
|
public void keyPressed(KeyInputEvent kie) {
|
||||||
|
super.keyPressed(kie);
|
||||||
switch (kie.getKeyCode()) {
|
switch (kie.getKeyCode()) {
|
||||||
case KeyInput.KEY_LCONTROL:
|
case KeyInput.KEY_LCONTROL:
|
||||||
leftCtrl = kie.isPressed();
|
leftCtrl = kie.isPressed();
|
||||||
|
@ -34,6 +34,7 @@ package com.jme3.gde.terraineditor.tools;
|
|||||||
import com.jme3.asset.AssetManager;
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
||||||
import com.jme3.gde.terraineditor.ExtraToolParams;
|
import com.jme3.gde.terraineditor.ExtraToolParams;
|
||||||
|
import com.jme3.input.KeyInput;
|
||||||
import com.jme3.input.event.KeyInputEvent;
|
import com.jme3.input.event.KeyInputEvent;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
@ -62,6 +63,9 @@ public abstract class TerrainTool {
|
|||||||
protected float radius;
|
protected float radius;
|
||||||
protected float weight;
|
protected float weight;
|
||||||
protected float maxToolSize = 20; // override in sub classes
|
protected float maxToolSize = 20; // override in sub classes
|
||||||
|
private boolean doStraightline = false;
|
||||||
|
private Vector3f startPress;
|
||||||
|
private Vector3f axis;
|
||||||
private Meshes mesh;
|
private Meshes mesh;
|
||||||
|
|
||||||
public static enum Meshes {
|
public static enum Meshes {
|
||||||
@ -91,10 +95,25 @@ public abstract class TerrainTool {
|
|||||||
*/
|
*/
|
||||||
public abstract void actionSecondary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject);
|
public abstract void actionSecondary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signals that this tool will or will not snap to fixed axis angles
|
||||||
|
*/
|
||||||
|
protected boolean useStraightLine() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key was pressed.
|
* Key was pressed.
|
||||||
*/
|
*/
|
||||||
public void keyPressed(KeyInputEvent kie) {}
|
public void keyPressed(KeyInputEvent kie) {
|
||||||
|
if (useStraightLine() && (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL)) {
|
||||||
|
doStraightline = kie.isPressed();
|
||||||
|
if (!doStraightline) { // Clean the values
|
||||||
|
startPress = null;
|
||||||
|
axis = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location of the primary editor marker
|
* Location of the primary editor marker
|
||||||
@ -111,8 +130,36 @@ public abstract class TerrainTool {
|
|||||||
* @param newLoc
|
* @param newLoc
|
||||||
*/
|
*/
|
||||||
public void markerMoved(Vector3f newLoc) {
|
public void markerMoved(Vector3f newLoc) {
|
||||||
if (markerPrimary != null)
|
if (markerPrimary != null) {
|
||||||
markerPrimary.setLocalTranslation(newLoc);
|
if (!useStraightLine() || (!doStraightline && useStraightLine()))
|
||||||
|
markerPrimary.setLocalTranslation(newLoc); // if we're not using the straight line feature or the key isn't pressed
|
||||||
|
else {
|
||||||
|
if (startPress == null)
|
||||||
|
startPress = newLoc.clone(); // the user just started presseing
|
||||||
|
else {
|
||||||
|
Vector3f sub = newLoc.subtract(startPress);
|
||||||
|
if (axis == null) {
|
||||||
|
// grab the axis that the user is moving
|
||||||
|
Vector3f closest = Vector3f.UNIT_X;
|
||||||
|
float dist = sub.distance(closest);
|
||||||
|
float ddist;
|
||||||
|
if ((ddist = sub.distance(Vector3f.UNIT_Z)) < dist) {
|
||||||
|
closest = Vector3f.UNIT_Z;
|
||||||
|
dist = ddist;
|
||||||
|
}
|
||||||
|
if ((ddist = sub.distance(Vector3f.UNIT_Z.negate())) < dist) {
|
||||||
|
closest = Vector3f.UNIT_Z;
|
||||||
|
dist = ddist;
|
||||||
|
}
|
||||||
|
if (sub.distance(Vector3f.UNIT_X.negate()) < dist) {
|
||||||
|
closest = Vector3f.UNIT_X;
|
||||||
|
}
|
||||||
|
axis = closest;
|
||||||
|
}
|
||||||
|
markerPrimary.setLocalTranslation(sub.mult(axis).add(startPress)); // move the marker in straight line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user