|
@@ -5,8 +5,11 @@
|
|
|
package com.jme3.gde.scenecomposer.tools;
|
|
|
|
|
|
import com.jme3.asset.AssetManager;
|
|
|
+import com.jme3.bullet.control.CharacterControl;
|
|
|
+import com.jme3.bullet.control.RigidBodyControl;
|
|
|
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
|
|
|
import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
|
|
|
+import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
|
|
|
import com.jme3.gde.scenecomposer.SceneComposerToolController;
|
|
|
import com.jme3.gde.scenecomposer.SceneEditTool;
|
|
|
import com.jme3.math.Vector2f;
|
|
@@ -17,12 +20,11 @@ import org.openide.loaders.DataObject;
|
|
|
import org.openide.util.Lookup;
|
|
|
|
|
|
/**
|
|
|
- * Move an object.
|
|
|
- * When created, it generates a quad that will lie along a plane
|
|
|
- * that the user selects for moving on. When the mouse is over
|
|
|
- * the axisMarker, it will highlight the plane that it is over: XY,XZ,YZ.
|
|
|
- * When clicked and then dragged, the selected object will move along that
|
|
|
- * plane.
|
|
|
+ * Move an object. When created, it generates a quad that will lie along a plane
|
|
|
+ * that the user selects for moving on. When the mouse is over the axisMarker,
|
|
|
+ * it will highlight the plane that it is over: XY,XZ,YZ. When clicked and then
|
|
|
+ * dragged, the selected object will move along that plane.
|
|
|
+ *
|
|
|
* @author Brent Owens
|
|
|
*/
|
|
|
public class MoveTool extends SceneEditTool {
|
|
@@ -30,7 +32,9 @@ public class MoveTool extends SceneEditTool {
|
|
|
private Vector3f pickedMarker;
|
|
|
private Vector3f constraintAxis; //used for one axis move
|
|
|
private boolean wasDragging = false;
|
|
|
- private MoveManager moveManager;
|
|
|
+ private Vector3f startPosition;
|
|
|
+ private Vector3f lastPosition;
|
|
|
+ private PickManager pickManager;
|
|
|
|
|
|
public MoveTool() {
|
|
|
axisPickType = AxisMarkerPickType.axisAndPlane;
|
|
@@ -41,7 +45,7 @@ public class MoveTool extends SceneEditTool {
|
|
|
@Override
|
|
|
public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) {
|
|
|
super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController);
|
|
|
- moveManager = Lookup.getDefault().lookup(MoveManager.class);
|
|
|
+ pickManager = Lookup.getDefault().lookup(PickManager.class);
|
|
|
displayPlanes();
|
|
|
}
|
|
|
|
|
@@ -52,10 +56,10 @@ public class MoveTool extends SceneEditTool {
|
|
|
pickedMarker = null; // mouse released, reset selection
|
|
|
constraintAxis = Vector3f.UNIT_XYZ; // no constraint
|
|
|
if (wasDragging) {
|
|
|
- actionPerformed(moveManager.makeUndo());
|
|
|
+ actionPerformed(new MoveUndo(toolController.getSelectedSpatial(), startPosition, lastPosition));
|
|
|
wasDragging = false;
|
|
|
- }
|
|
|
- moveManager.reset();
|
|
|
+ }
|
|
|
+ pickManager.reset();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -70,21 +74,21 @@ public class MoveTool extends SceneEditTool {
|
|
|
highlightAxisMarker(camera, screenCoord, axisPickType);
|
|
|
} else {
|
|
|
pickedMarker = null;
|
|
|
- moveManager.reset();
|
|
|
+ pickManager.reset();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
|
|
|
- if (!pressed) {
|
|
|
+ if (!pressed) {
|
|
|
setDefaultAxisMarkerColors();
|
|
|
pickedMarker = null; // mouse released, reset selection
|
|
|
constraintAxis = Vector3f.UNIT_XYZ; // no constraint
|
|
|
if (wasDragging) {
|
|
|
- actionPerformed(moveManager.makeUndo());
|
|
|
+ actionPerformed(new MoveUndo(toolController.getSelectedSpatial(), startPosition, lastPosition));
|
|
|
wasDragging = false;
|
|
|
}
|
|
|
- moveManager.reset();
|
|
|
+ pickManager.reset();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -99,25 +103,43 @@ public class MoveTool extends SceneEditTool {
|
|
|
}
|
|
|
|
|
|
if (pickedMarker.equals(QUAD_XY)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XY, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
} else if (pickedMarker.equals(QUAD_XZ)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XZ, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
} else if (pickedMarker.equals(QUAD_YZ)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.YZ, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
} else if (pickedMarker.equals(ARROW_X)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XY, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
constraintAxis = Vector3f.UNIT_X; // move only X
|
|
|
} else if (pickedMarker.equals(ARROW_Y)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.YZ, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
constraintAxis = Vector3f.UNIT_Y; // move only Y
|
|
|
} else if (pickedMarker.equals(ARROW_Z)) {
|
|
|
- moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XZ, true);
|
|
|
+ pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ,
|
|
|
+ PickManager.TransformationType.local, camera, screenCoord);
|
|
|
constraintAxis = Vector3f.UNIT_Z; // move only Z
|
|
|
}
|
|
|
+ startPosition = toolController.getSelectedSpatial().getLocalTranslation().clone();
|
|
|
+
|
|
|
}
|
|
|
- if (!moveManager.move(camera, screenCoord, constraintAxis, false)) {
|
|
|
+ if (!pickManager.updatePick(camera, screenCoord)) {
|
|
|
return;
|
|
|
}
|
|
|
+ Vector3f diff = Vector3f.ZERO;
|
|
|
+ if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) {
|
|
|
+ diff = pickManager.getTranslation();
|
|
|
+
|
|
|
+ } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) {
|
|
|
+ diff = pickManager.getTranslation(constraintAxis);
|
|
|
+ }
|
|
|
+ Vector3f position = startPosition.add(diff);
|
|
|
+ lastPosition = position;
|
|
|
+ toolController.getSelectedSpatial().setLocalTranslation(position);
|
|
|
updateToolsTransformation();
|
|
|
|
|
|
wasDragging = true;
|
|
@@ -126,4 +148,50 @@ public class MoveTool extends SceneEditTool {
|
|
|
@Override
|
|
|
public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
|
|
|
}
|
|
|
+
|
|
|
+ protected class MoveUndo extends AbstractUndoableSceneEdit {
|
|
|
+
|
|
|
+ private Spatial spatial;
|
|
|
+ private Vector3f before = new Vector3f(), after = new Vector3f();
|
|
|
+
|
|
|
+ MoveUndo(Spatial spatial, Vector3f before, Vector3f after) {
|
|
|
+ this.spatial = spatial;
|
|
|
+ this.before.set(before);
|
|
|
+ if (after != null) {
|
|
|
+ this.after.set(after);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sceneUndo() {
|
|
|
+ spatial.setLocalTranslation(before);
|
|
|
+ RigidBodyControl control = spatial.getControl(RigidBodyControl.class);
|
|
|
+ if (control != null) {
|
|
|
+ control.setPhysicsLocation(spatial.getWorldTranslation());
|
|
|
+ }
|
|
|
+ CharacterControl character = spatial.getControl(CharacterControl.class);
|
|
|
+ if (character != null) {
|
|
|
+ character.setPhysicsLocation(spatial.getWorldTranslation());
|
|
|
+ }
|
|
|
+ // toolController.selectedSpatialTransformed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sceneRedo() {
|
|
|
+ spatial.setLocalTranslation(after);
|
|
|
+ RigidBodyControl control = spatial.getControl(RigidBodyControl.class);
|
|
|
+ if (control != null) {
|
|
|
+ control.setPhysicsLocation(spatial.getWorldTranslation());
|
|
|
+ }
|
|
|
+ CharacterControl character = spatial.getControl(CharacterControl.class);
|
|
|
+ if (character != null) {
|
|
|
+ character.setPhysicsLocation(spatial.getWorldTranslation());
|
|
|
+ }
|
|
|
+ //toolController.selectedSpatialTransformed();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAfter(Vector3f after) {
|
|
|
+ this.after.set(after);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|