|
|
|
@ -45,25 +45,22 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
protected Spatial selected; |
|
|
|
|
|
|
|
|
|
private enum State {translate, rotate, scale}; |
|
|
|
|
private State currentState = null; |
|
|
|
|
|
|
|
|
|
private enum State { |
|
|
|
|
|
|
|
|
|
translate, rotate, scale |
|
|
|
|
}; |
|
|
|
|
private State currentState = null; |
|
|
|
|
private Vector3f currentAxis = Vector3f.UNIT_XYZ; |
|
|
|
|
|
|
|
|
|
private StringBuilder numberBuilder = new StringBuilder(); // gets appended with numbers
|
|
|
|
|
|
|
|
|
|
private Quaternion startRot; |
|
|
|
|
private Vector3f startTrans; |
|
|
|
|
private Vector3f startScale; |
|
|
|
|
|
|
|
|
|
private boolean wasDraggingL = false; |
|
|
|
|
private boolean wasDraggingR = false; |
|
|
|
|
private boolean wasDownR = false; |
|
|
|
|
private boolean ctrlDown = false; |
|
|
|
|
private boolean shiftDown = false; |
|
|
|
|
private boolean altDown = false; |
|
|
|
|
|
|
|
|
|
private MoveManager.MoveUndo moving; |
|
|
|
|
private ScaleUndo scaling; |
|
|
|
|
private RotateUndo rotating; |
|
|
|
@ -93,9 +90,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
checkModificatorKeys(kie); // alt,shift,ctrl
|
|
|
|
|
|
|
|
|
|
if (selected == null) |
|
|
|
|
if (selected == null) { |
|
|
|
|
return; // only do anything if a spatial is selected
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// key released
|
|
|
|
|
if (kie.isReleased()) { |
|
|
|
|
boolean commandUsed = checkCommandKey(kie); |
|
|
|
@ -105,17 +102,16 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
boolean enterHit = checkEnterHit(kie); |
|
|
|
|
boolean escHit = checkEscHit(kie); |
|
|
|
|
|
|
|
|
|
if (commandUsed) |
|
|
|
|
if (commandUsed) { |
|
|
|
|
return; // commands take priority
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (stateChange) { |
|
|
|
|
currentAxis = Vector3f.UNIT_XYZ; |
|
|
|
|
numberBuilder = new StringBuilder(); |
|
|
|
|
recordInitialState(selected); |
|
|
|
|
} |
|
|
|
|
else if (axisChange) {} |
|
|
|
|
else if (numberChange) {} |
|
|
|
|
else if (enterHit) { |
|
|
|
|
} else if (axisChange) { |
|
|
|
|
} else if (numberChange) { |
|
|
|
|
} else if (enterHit) { |
|
|
|
|
if (currentState != null && numberBuilder.length() > 0) { |
|
|
|
|
applyKeyedChangeState(selected); |
|
|
|
|
clearState(false); |
|
|
|
@ -127,8 +123,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
// reset conditions below:
|
|
|
|
|
|
|
|
|
|
if (escHit) { |
|
|
|
|
if (moving != null) |
|
|
|
|
if (moving != null) { |
|
|
|
|
moving.sceneUndo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
moving = null; |
|
|
|
|
clearState(); |
|
|
|
@ -151,13 +148,16 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
private void clearState(boolean resetSelected) { |
|
|
|
|
if (resetSelected && selected != null) { |
|
|
|
|
// reset the transforms
|
|
|
|
|
if (startRot != null) |
|
|
|
|
if (startRot != null) { |
|
|
|
|
selected.setLocalRotation(startRot); |
|
|
|
|
if (startTrans != null) |
|
|
|
|
} |
|
|
|
|
if (startTrans != null) { |
|
|
|
|
selected.setLocalTranslation(startTrans); |
|
|
|
|
if (startScale != null) |
|
|
|
|
} |
|
|
|
|
if (startScale != null) { |
|
|
|
|
selected.setLocalScale(startScale); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
currentState = null; |
|
|
|
|
currentAxis = Vector3f.UNIT_XYZ; |
|
|
|
|
numberBuilder = new StringBuilder(); |
|
|
|
@ -168,7 +168,6 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
startSelectedCoord = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void recordInitialState(Spatial selected) { |
|
|
|
|
startRot = selected.getLocalRotation().clone(); |
|
|
|
|
startTrans = selected.getLocalTranslation().clone(); |
|
|
|
@ -185,7 +184,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
Float value = null; |
|
|
|
|
try { |
|
|
|
|
value = new Float(numberBuilder.toString()); |
|
|
|
|
} catch (NumberFormatException e){ |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -196,14 +195,14 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
actionPerformed(moving); |
|
|
|
|
moving = null; |
|
|
|
|
} else if (currentState == State.scale) { |
|
|
|
|
float x = 1, y= 1, z = 1; |
|
|
|
|
if (currentAxis == Vector3f.UNIT_X) |
|
|
|
|
float x = 1, y = 1, z = 1; |
|
|
|
|
if (currentAxis == Vector3f.UNIT_X) { |
|
|
|
|
x = value; |
|
|
|
|
else if (currentAxis == Vector3f.UNIT_Y) |
|
|
|
|
} else if (currentAxis == Vector3f.UNIT_Y) { |
|
|
|
|
y = value; |
|
|
|
|
else if (currentAxis == Vector3f.UNIT_Z) |
|
|
|
|
} else if (currentAxis == Vector3f.UNIT_Z) { |
|
|
|
|
z = value; |
|
|
|
|
else if (currentAxis == Vector3f.UNIT_XYZ) { |
|
|
|
|
} else if (currentAxis == Vector3f.UNIT_XYZ) { |
|
|
|
|
x = value; |
|
|
|
|
y = value; |
|
|
|
|
z = value; |
|
|
|
@ -213,17 +212,18 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
selected.setLocalScale(after); |
|
|
|
|
actionPerformed(new ScaleUndo(selected, before, after)); |
|
|
|
|
} else if (currentState == State.rotate) { |
|
|
|
|
float x = 0, y= 0, z = 0; |
|
|
|
|
if (currentAxis == Vector3f.UNIT_X) |
|
|
|
|
float x = 0, y = 0, z = 0; |
|
|
|
|
if (currentAxis == Vector3f.UNIT_X) { |
|
|
|
|
x = 1; |
|
|
|
|
else if (currentAxis == Vector3f.UNIT_Y) |
|
|
|
|
} else if (currentAxis == Vector3f.UNIT_Y) { |
|
|
|
|
y = 1; |
|
|
|
|
else if (currentAxis == Vector3f.UNIT_Z) |
|
|
|
|
} else if (currentAxis == Vector3f.UNIT_Z) { |
|
|
|
|
z = 1; |
|
|
|
|
Vector3f axis = new Vector3f(x,y,z); |
|
|
|
|
} |
|
|
|
|
Vector3f axis = new Vector3f(x, y, z); |
|
|
|
|
Quaternion initialRot = selected.getLocalRotation().clone(); |
|
|
|
|
Quaternion rot = new Quaternion(); |
|
|
|
|
rot = rot.fromAngleAxis(value*FastMath.DEG_TO_RAD, axis); |
|
|
|
|
rot = rot.fromAngleAxis(value * FastMath.DEG_TO_RAD, axis); |
|
|
|
|
selected.setLocalRotation(selected.getLocalRotation().mult(rot)); |
|
|
|
|
RotateUndo undo = new RotateUndo(selected, initialRot, rot); |
|
|
|
|
actionPerformed(undo); |
|
|
|
@ -234,15 +234,18 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkModificatorKeys(KeyInputEvent kie) { |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL) |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LCONTROL || kie.getKeyCode() == KeyInput.KEY_RCONTROL) { |
|
|
|
|
ctrlDown = kie.isPressed(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT) |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LSHIFT || kie.getKeyCode() == KeyInput.KEY_RSHIFT) { |
|
|
|
|
shiftDown = kie.isPressed(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU) |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_LMENU || kie.getKeyCode() == KeyInput.KEY_RMENU) { |
|
|
|
|
altDown = kie.isPressed(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean checkCommandKey(KeyInputEvent kie) { |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_D) { |
|
|
|
@ -266,7 +269,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
currentState = State.translate; |
|
|
|
|
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); |
|
|
|
|
moveManager.reset(); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI,Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)); |
|
|
|
|
moveManager.initiateMove(selected, rot, false); |
|
|
|
|
moving = moveManager.makeUndo(); |
|
|
|
|
return true; |
|
|
|
@ -284,11 +287,11 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
if (kie.getKeyCode() == KeyInput.KEY_X) { |
|
|
|
|
currentAxis = Vector3f.UNIT_X; |
|
|
|
|
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI,Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion planRot = null; |
|
|
|
|
if(rot.dot(MoveManager.XY)<rot.dot(MoveManager.XZ)){ |
|
|
|
|
if (rot.dot(MoveManager.XY) < rot.dot(MoveManager.XZ)) { |
|
|
|
|
planRot = MoveManager.XY; |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
planRot = MoveManager.XZ; |
|
|
|
|
} |
|
|
|
|
moveManager.updatePlaneRotation(planRot); |
|
|
|
@ -296,11 +299,11 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} else if (kie.getKeyCode() == KeyInput.KEY_Y) { |
|
|
|
|
currentAxis = Vector3f.UNIT_Y; |
|
|
|
|
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI,Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion planRot = null; |
|
|
|
|
if(rot.dot(MoveManager.XY)<rot.dot(MoveManager.YZ)){ |
|
|
|
|
if (rot.dot(MoveManager.XY) < rot.dot(MoveManager.YZ)) { |
|
|
|
|
planRot = MoveManager.XY; |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
planRot = MoveManager.YZ; |
|
|
|
|
} |
|
|
|
|
moveManager.updatePlaneRotation(planRot); |
|
|
|
@ -308,11 +311,11 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} else if (kie.getKeyCode() == KeyInput.KEY_Z) { |
|
|
|
|
currentAxis = Vector3f.UNIT_Z; |
|
|
|
|
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI,Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion rot = camera.getRotation().mult(new Quaternion().fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y)); |
|
|
|
|
Quaternion planRot = null; |
|
|
|
|
if(rot.dot(MoveManager.XZ)<rot.dot(MoveManager.YZ)){ |
|
|
|
|
if (rot.dot(MoveManager.XZ) < rot.dot(MoveManager.YZ)) { |
|
|
|
|
planRot = MoveManager.XZ; |
|
|
|
|
}else{ |
|
|
|
|
} else { |
|
|
|
|
planRot = MoveManager.YZ; |
|
|
|
|
} |
|
|
|
|
moveManager.updatePlaneRotation(planRot); |
|
|
|
@ -329,8 +332,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} else { |
|
|
|
|
numberBuilder.insert(0, '-'); |
|
|
|
|
} |
|
|
|
|
} else |
|
|
|
|
} else { |
|
|
|
|
numberBuilder.append('-'); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} else if (kie.getKeyCode() == KeyInput.KEY_0 || kie.getKeyCode() == KeyInput.KEY_NUMPAD0) { |
|
|
|
|
numberBuilder.append('0'); |
|
|
|
@ -363,13 +367,14 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
numberBuilder.append('9'); |
|
|
|
|
return true; |
|
|
|
|
} else if (kie.getKeyCode() == KeyInput.KEY_PERIOD) { |
|
|
|
|
if (numberBuilder.indexOf(".") == -1){ // if it doesn't exist yet
|
|
|
|
|
if (numberBuilder.length() == 0 || |
|
|
|
|
(numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) |
|
|
|
|
if (numberBuilder.indexOf(".") == -1) { // if it doesn't exist yet
|
|
|
|
|
if (numberBuilder.length() == 0 |
|
|
|
|
|| (numberBuilder.length() == 1 && numberBuilder.charAt(0) == '-')) { |
|
|
|
|
numberBuilder.append("0."); |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
numberBuilder.append("."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -419,8 +424,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
// mouse released and wasn't dragging, place cursor
|
|
|
|
|
final Vector3f result = pickWorldLocation(getCamera(), screenCoord, rootNode); |
|
|
|
|
if (result != null) { |
|
|
|
|
if (toolController.isSnapToGrid()) |
|
|
|
|
if (toolController.isSnapToGrid()) { |
|
|
|
|
result.set(Math.round(result.x), result.y, Math.round(result.z)); |
|
|
|
|
} |
|
|
|
|
toolController.doSetCursorLocation(result); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -446,11 +452,10 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
rotating.sceneUndo(); |
|
|
|
|
rotating = null; |
|
|
|
|
clearState(); |
|
|
|
|
} |
|
|
|
|
else if (!wasDraggingR && !wasDownR) { // wasn't dragging and was not down already
|
|
|
|
|
} else if (!wasDraggingR && !wasDownR) { // wasn't dragging and was not down already
|
|
|
|
|
// pick on the spot
|
|
|
|
|
Spatial s = pickWorldSpatial(camera, screenCoord, rootNode); |
|
|
|
|
if (!toolController.selectTerrain() && isTerrain(s) ) { |
|
|
|
|
if (!toolController.selectTerrain() && isTerrain(s)) { |
|
|
|
|
// only select non-terrain
|
|
|
|
|
selected = null; |
|
|
|
|
return; |
|
|
|
@ -458,13 +463,15 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
// climb up and find the Model Node (parent) and select that, don't select the geom
|
|
|
|
|
Spatial linkNodeParent = findModelNodeParent(s); |
|
|
|
|
if (linkNodeParent != null) |
|
|
|
|
if (linkNodeParent != null) { |
|
|
|
|
s = linkNodeParent; |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
final Spatial selec = s; |
|
|
|
|
selected = selec; |
|
|
|
|
java.awt.EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
if (selec != null) { |
|
|
|
@ -493,14 +500,17 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
* TODO: use userData to determine the actual model's parent. |
|
|
|
|
*/ |
|
|
|
|
private Spatial findModelNodeParent(Spatial child) { |
|
|
|
|
if (child == null) |
|
|
|
|
if (child == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (child instanceof Node) |
|
|
|
|
if (child instanceof Node) { |
|
|
|
|
return child; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (child.getParent() != null) |
|
|
|
|
if (child.getParent() != null) { |
|
|
|
|
return findModelNodeParent(child.getParent()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
@ -525,20 +535,17 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
/** |
|
|
|
|
* Manipulate the spatial |
|
|
|
|
*/ |
|
|
|
|
private void handleMouseManipulate( Vector2f screenCoord, |
|
|
|
|
private void handleMouseManipulate(Vector2f screenCoord, |
|
|
|
|
State state, |
|
|
|
|
Vector3f axis, |
|
|
|
|
JmeNode rootNode, |
|
|
|
|
DataObject currentDataObject, |
|
|
|
|
JmeSpatial selectedSpatial) |
|
|
|
|
{ |
|
|
|
|
JmeSpatial selectedSpatial) { |
|
|
|
|
if (state == State.translate) { |
|
|
|
|
doMouseTranslate(axis, screenCoord, rootNode, selectedSpatial); |
|
|
|
|
} |
|
|
|
|
else if (state == State.scale) { |
|
|
|
|
} else if (state == State.scale) { |
|
|
|
|
doMouseScale(axis, screenCoord, rootNode, selectedSpatial); |
|
|
|
|
} |
|
|
|
|
else if (state == State.rotate) { |
|
|
|
|
} else if (state == State.rotate) { |
|
|
|
|
doMouseRotate(axis, screenCoord, rootNode, selectedSpatial); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -546,60 +553,67 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
private void doMouseTranslate(Vector3f axis, Vector2f screenCoord, JmeNode rootNode, JmeSpatial selectedSpatial) { |
|
|
|
|
MoveManager moveManager = Lookup.getDefault().lookup(MoveManager.class); |
|
|
|
|
if(toolController.isSnapToScene()){ |
|
|
|
|
if (toolController.isSnapToScene()) { |
|
|
|
|
moveManager.setAlternativePickTarget(rootNode.getLookup().lookup(Node.class)); |
|
|
|
|
} |
|
|
|
|
// free form translation
|
|
|
|
|
moveManager.move(camera, screenCoord, axis,toolController.isSnapToGrid()); |
|
|
|
|
moveManager.move(camera, screenCoord, axis, toolController.isSnapToGrid()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doMouseScale(Vector3f axis, Vector2f screenCoord, JmeNode rootNode, JmeSpatial selectedSpatial) { |
|
|
|
|
// scale based on the original mouse position and original model-to-screen position
|
|
|
|
|
// and compare that to the distance from the new mouse position and the original distance
|
|
|
|
|
if (startMouseCoord == null) |
|
|
|
|
if (startMouseCoord == null) { |
|
|
|
|
startMouseCoord = screenCoord.clone(); |
|
|
|
|
} |
|
|
|
|
if (startSelectedCoord == null) { |
|
|
|
|
Vector3f screen = getCamera().getScreenCoordinates(selected.getWorldTranslation()); |
|
|
|
|
startSelectedCoord = new Vector2f(screen.x, screen.y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (scaling == null) |
|
|
|
|
if (scaling == null) { |
|
|
|
|
scaling = new ScaleUndo(selected, selected.getLocalScale().clone(), null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float origDist = startMouseCoord.distanceSquared(startSelectedCoord); |
|
|
|
|
float newDist = screenCoord.distanceSquared(startSelectedCoord); |
|
|
|
|
if (origDist == 0) |
|
|
|
|
if (origDist == 0) { |
|
|
|
|
origDist = 1; |
|
|
|
|
float ratio = newDist/origDist; |
|
|
|
|
} |
|
|
|
|
float ratio = newDist / origDist; |
|
|
|
|
Vector3f prev = selected.getLocalScale(); |
|
|
|
|
if (axis == Vector3f.UNIT_X) |
|
|
|
|
if (axis == Vector3f.UNIT_X) { |
|
|
|
|
selected.setLocalScale(ratio, prev.y, prev.z); |
|
|
|
|
else if (axis == Vector3f.UNIT_Y) |
|
|
|
|
} else if (axis == Vector3f.UNIT_Y) { |
|
|
|
|
selected.setLocalScale(prev.x, ratio, prev.z); |
|
|
|
|
else if (axis == Vector3f.UNIT_Z) |
|
|
|
|
} else if (axis == Vector3f.UNIT_Z) { |
|
|
|
|
selected.setLocalScale(prev.x, prev.y, ratio); |
|
|
|
|
else |
|
|
|
|
} else { |
|
|
|
|
selected.setLocalScale(ratio, ratio, ratio); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doMouseRotate(Vector3f axis, Vector2f screenCoord, JmeNode rootNode, JmeSpatial selectedSpatial) { |
|
|
|
|
if (startMouseCoord == null) |
|
|
|
|
if (startMouseCoord == null) { |
|
|
|
|
startMouseCoord = screenCoord.clone(); |
|
|
|
|
} |
|
|
|
|
if (startSelectedCoord == null) { |
|
|
|
|
Vector3f screen = getCamera().getScreenCoordinates(selected.getWorldTranslation()); |
|
|
|
|
startSelectedCoord = new Vector2f(screen.x, screen.y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (rotating == null) |
|
|
|
|
if (rotating == null) { |
|
|
|
|
rotating = new RotateUndo(selected, selected.getLocalRotation().clone(), null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Vector2f origRot = startMouseCoord.subtract(startSelectedCoord); |
|
|
|
|
Vector2f newRot = screenCoord.subtract(startSelectedCoord); |
|
|
|
|
float newRotAngle = origRot.angleBetween(newRot); |
|
|
|
|
float temp = newRotAngle; |
|
|
|
|
|
|
|
|
|
if (lastRotAngle != 0) |
|
|
|
|
if (lastRotAngle != 0) { |
|
|
|
|
newRotAngle -= lastRotAngle; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lastRotAngle = temp; |
|
|
|
|
|
|
|
|
@ -616,8 +630,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void duplicateSelected() { |
|
|
|
|
if (selected == null) |
|
|
|
|
if (selected == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Spatial clone = selected.clone(); |
|
|
|
|
clone.move(1, 0, 1); |
|
|
|
|
|
|
|
|
@ -629,6 +644,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
refreshSelected(rootNode, selected.getParent()); |
|
|
|
|
|
|
|
|
|
java.awt.EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
if (cloned != null) { |
|
|
|
@ -648,8 +664,9 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void deleteSelected() { |
|
|
|
|
if (selected == null) |
|
|
|
|
if (selected == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Node parent = selected.getParent(); |
|
|
|
|
selected.removeFromParent(); |
|
|
|
|
actionPerformed(new DeleteUndo(selected, parent)); |
|
|
|
@ -663,6 +680,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
private void refreshSelected(final JmeNode jmeRootNode, final Node parent) { |
|
|
|
|
java.awt.EventQueue.invokeLater(new Runnable() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
jmeRootNode.getChild(parent).refresh(false); |
|
|
|
@ -673,7 +691,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
private class ScaleUndo extends AbstractUndoableSceneEdit { |
|
|
|
|
|
|
|
|
|
private Spatial spatial; |
|
|
|
|
private Vector3f before,after; |
|
|
|
|
private Vector3f before, after; |
|
|
|
|
|
|
|
|
|
ScaleUndo(Spatial spatial, Vector3f before, Vector3f after) { |
|
|
|
|
this.spatial = spatial; |
|
|
|
@ -695,7 +713,7 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
private class RotateUndo extends AbstractUndoableSceneEdit { |
|
|
|
|
|
|
|
|
|
private Spatial spatial; |
|
|
|
|
private Quaternion before,after; |
|
|
|
|
private Quaternion before, after; |
|
|
|
|
|
|
|
|
|
RotateUndo(Spatial spatial, Quaternion before, Quaternion after) { |
|
|
|
|
this.spatial = spatial; |
|
|
|
@ -763,15 +781,16 @@ public class SelectTool extends SceneEditTool { |
|
|
|
|
* Recursive call. |
|
|
|
|
*/ |
|
|
|
|
protected boolean isTerrain(Spatial s) { |
|
|
|
|
if (s == null) |
|
|
|
|
if (s == null) { |
|
|
|
|
return false; |
|
|
|
|
if (s instanceof Terrain) |
|
|
|
|
} |
|
|
|
|
if (s instanceof Terrain) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s.getParent() != null) { |
|
|
|
|
return isTerrain(s.getParent()); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|