Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class SceneEditTool {
protected Node axisMarker;
protected Material redMat, blueMat, greenMat, yellowMat, cyanMat, magentaMat, orangeMat;
protected Geometry quadXY, quadXZ, quadYZ;

protected enum AxisMarkerPickType {

axisOnly, planeOnly, axisAndPlane
Expand Down Expand Up @@ -371,16 +371,17 @@ protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMark
axisMarker.getChild("arrowY").setMaterial(orangeMat);
} else if (picked == ARROW_Z) {
axisMarker.getChild("arrowZ").setMaterial(orangeMat);
}
} else {

if (picked == QUAD_XY || colorAll) {
axisMarker.getChild("quadXY").setMaterial(orangeMat);
}
if (picked == QUAD_XZ || colorAll) {
axisMarker.getChild("quadXZ").setMaterial(orangeMat);
}
if (picked == QUAD_YZ || colorAll) {
axisMarker.getChild("quadYZ").setMaterial(orangeMat);
if (picked == QUAD_XY || colorAll) {
axisMarker.getChild("quadXY").setMaterial(orangeMat);
}
if (picked == QUAD_XZ || colorAll) {
axisMarker.getChild("quadXZ").setMaterial(orangeMat);
}
if (picked == QUAD_YZ || colorAll) {
axisMarker.getChild("quadYZ").setMaterial(orangeMat);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,20 +20,21 @@
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 {

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;
Expand All @@ -41,7 +45,7 @@ public MoveTool() {
@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();
}

Expand All @@ -52,10 +56,10 @@ public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNod
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();
}
}

Expand All @@ -70,21 +74,21 @@ public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject curren
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;
}

Expand All @@ -99,25 +103,43 @@ public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNo
}

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;
Expand All @@ -126,4 +148,50 @@ public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNo
@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);
}
}
}
Loading