diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java index 2ad04aa8d..50b6d5cfe 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java @@ -357,7 +357,7 @@ public class SceneComposerToolController extends SceneToolController { public void setTransformationType(String type) { if(type != null){ if(type.equals("Local")){ - setTransformationType(transformationType.local); + setTransformationType(TransformationType.local); } else if(type.equals("Global")){ setTransformationType(TransformationType.global); } else if(type.equals("Camera")){ @@ -365,15 +365,9 @@ public class SceneComposerToolController extends SceneToolController { } } } - /** - * @return the transformationType - */ - public TransformationType getTransformationType() { - return transformationType; - } /** - * @param transformationType the transformationType to set + * @param type the transformationType to set */ public void setTransformationType(TransformationType type) { if(type != this.transformationType){ @@ -385,6 +379,13 @@ public class SceneComposerToolController extends SceneToolController { } } + /** + * @return the transformationType + */ + public TransformationType getTransformationType() { + return transformationType; + } + /** * A marker on the screen that shows where a point light or * a spot light is. This marker is not part of the scene, diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java index a553f35f2..b3a48a6f6 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java @@ -60,11 +60,44 @@ public class MoveTool extends SceneEditTool { wasDragging = false; } pickManager.reset(); + } else { + if (toolController.getSelectedSpatial() == null) { + return; + } + + if (pickedMarker == null) { + pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedMarker == null) { + return; + } + + if (pickedMarker.equals(QUAD_XY)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); + } else if (pickedMarker.equals(QUAD_XZ)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); + } else if (pickedMarker.equals(QUAD_YZ)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); + } else if (pickedMarker.equals(ARROW_X)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_X; // move only X + } else if (pickedMarker.equals(ARROW_Y)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_Y; // move only Y + } else if (pickedMarker.equals(ARROW_Z)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_Z; // move only Z + } + startPosition = toolController.getSelectedSpatial().getLocalTranslation().clone(); + wasDragging = true; + } } } @Override public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { + if (pressed) { + cancel(); + } } @Override @@ -89,58 +122,40 @@ public class MoveTool extends SceneEditTool { wasDragging = false; } pickManager.reset(); - return; - } - - if (toolController.getSelectedSpatial() == null) { - return; - } - - if (pickedMarker == null) { - pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); - if (pickedMarker == null) { + } else if (wasDragging == true) { + 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(); - if (pickedMarker.equals(QUAD_XY)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); - } else if (pickedMarker.equals(QUAD_XZ)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); - } else if (pickedMarker.equals(QUAD_YZ)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); - } else if (pickedMarker.equals(ARROW_X)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_X; // move only X - } else if (pickedMarker.equals(ARROW_Y)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_Y; // move only Y - } else if (pickedMarker.equals(ARROW_Z)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_Z; // move only Z + } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) { + diff = pickManager.getTranslation(constraintAxis); } - startPosition = toolController.getSelectedSpatial().getLocalTranslation().clone(); - - } - 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(); } - Vector3f position = startPosition.add(diff); - lastPosition = position; - toolController.getSelectedSpatial().setLocalTranslation(position); - updateToolsTransformation(); - - wasDragging = true; } @Override public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + if (pressed) { + cancel(); + } + } + + private void cancel() { + if (wasDragging) { + wasDragging = false; + toolController.getSelectedSpatial().setLocalTranslation(startPosition); + setDefaultAxisMarkerColors(); + pickedMarker = null; // mouse released, reset selection + constraintAxis = Vector3f.UNIT_XYZ; // no constraint + pickManager.reset(); + } } protected class MoveUndo extends AbstractUndoableSceneEdit { diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java index c43ae52d0..58c69f516 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java @@ -53,12 +53,36 @@ public class RotateTool extends SceneEditTool { actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate)); wasDragging = false; } + pickManager.reset(); + } else { + if (toolController.getSelectedSpatial() == null) { + return; + } + + if (pickedMarker == null) { + pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedMarker == null) { + return; + } + + if (pickedMarker.equals(QUAD_XY)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); + } else if (pickedMarker.equals(QUAD_XZ)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); + } else if (pickedMarker.equals(QUAD_YZ)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); + } + startRotate = toolController.getSelectedSpatial().getLocalRotation().clone(); + wasDragging = true; + } } } @Override public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { - + if (pressed) { + cancel(); + } } @Override @@ -67,12 +91,12 @@ public class RotateTool extends SceneEditTool { highlightAxisMarker(camera, screenCoord, axisPickType); } else { pickedMarker = null; + pickManager.reset(); } } @Override public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { - if (!pressed) { setDefaultAxisMarkerColors(); pickedMarker = null; // mouse released, reset selection @@ -82,45 +106,36 @@ public class RotateTool extends SceneEditTool { actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate)); wasDragging = false; } - return; - } - - if (toolController.getSelectedSpatial() == null) { - return; - } - - if (pickedMarker == null) { - pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); - if (pickedMarker == null) { + pickManager.reset(); + } else if (wasDragging) { + if (!pickManager.updatePick(camera, screenCoord)) { return; } - if (pickedMarker.equals(QUAD_XY)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); - } else if (pickedMarker.equals(QUAD_XZ)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); - } else if (pickedMarker.equals(QUAD_YZ)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); + if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { + Quaternion rotation = startRotate.mult(pickManager.getLocalRotation()); + toolController.getSelectedSpatial().setLocalRotation(rotation); + lastRotate = rotation; } - startRotate = toolController.getSelectedSpatial().getLocalRotation().clone(); - } - if (!pickManager.updatePick(camera, screenCoord)) { - return; - } - - if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { - Quaternion rotation = startRotate.mult(pickManager.getLocalRotation()); - toolController.getSelectedSpatial().setLocalRotation(rotation); - lastRotate = rotation; + updateToolsTransformation(); } - updateToolsTransformation(); - wasDragging = true; } @Override - public - void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + if (pressed) { + cancel(); + } + } + private void cancel() { + if (wasDragging) { + wasDragging = false; + toolController.getSelectedSpatial().setLocalRotation(startRotate); + setDefaultAxisMarkerColors(); + pickedMarker = null; // mouse released, reset selection + pickManager.reset(); + } } private class ScaleUndo extends AbstractUndoableSceneEdit { diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java index edde41a24..a34478372 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java @@ -39,7 +39,7 @@ public class ScaleTool extends SceneEditTool { @Override public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) { super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController); - pickManager = Lookup.getDefault().lookup(PickManager.class); + pickManager = Lookup.getDefault().lookup(PickManager.class); displayPlanes(); } @@ -54,12 +54,40 @@ public class ScaleTool extends SceneEditTool { wasDragging = false; } pickManager.reset(); + } else { + if (toolController.getSelectedSpatial() == null) { + return; + } + if (pickedMarker == null) { + pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedMarker == null) { + return; + } + + if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), + SceneComposerToolController.TransformationType.camera, camera, screenCoord); + } else if (pickedMarker.equals(ARROW_X)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_X; // scale only X + } else if (pickedMarker.equals(ARROW_Y)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_Y; // scale only Y + } else if (pickedMarker.equals(ARROW_Z)) { + pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); + constraintAxis = Vector3f.UNIT_Z; // scale only Z + } + startScale = toolController.getSelectedSpatial().getLocalScale().clone(); + wasDragging = true; + } } } @Override public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { - + if (pressed) { + cancel(); + } } @Override @@ -83,61 +111,45 @@ public class ScaleTool extends SceneEditTool { wasDragging = false; } pickManager.reset(); - return; - } - - if (toolController.getSelectedSpatial() == null) { - return; - } - if (pickedMarker == null) { - pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); - if (pickedMarker == null) { + } else if (wasDragging) { + if (!pickManager.updatePick(camera, screenCoord)) { return; } - if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), - SceneComposerToolController.TransformationType.camera, camera, screenCoord); - } else if (pickedMarker.equals(ARROW_X)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_X; // scale only X - } else if (pickedMarker.equals(ARROW_Y)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_Y; // scale only Y - } else if (pickedMarker.equals(ARROW_Z)) { - pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); - constraintAxis = Vector3f.UNIT_Z; // scale only Z + constraintAxis = pickManager.getStartOffset().normalize(); + float diff = pickManager.getTranslation(constraintAxis).dot(constraintAxis); + diff *= 0.5f; + Vector3f scale = startScale.add(new Vector3f(diff, diff, diff)); + lastScale = scale; + toolController.getSelectedSpatial().setLocalScale(scale); + } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) { + // Get the translation in the spatial Space + Quaternion worldToSpatial = toolController.getSelectedSpatial().getWorldRotation().inverse(); + Vector3f diff = pickManager.getTranslation(worldToSpatial.mult(constraintAxis)); + diff.multLocal(0.5f); + Vector3f scale = startScale.add(diff); + lastScale = scale; + toolController.getSelectedSpatial().setLocalScale(scale); } - startScale = toolController.getSelectedSpatial().getLocalScale().clone(); - } - - if (!pickManager.updatePick(camera, screenCoord)) { - return; + updateToolsTransformation(); } - if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { - constraintAxis = pickManager.getStartOffset().normalize(); - float diff = pickManager.getTranslation(constraintAxis).dot(constraintAxis); - diff *= 0.5f; - Vector3f scale = startScale.add(new Vector3f(diff, diff, diff)); - lastScale = scale; - toolController.getSelectedSpatial().setLocalScale(scale); - } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) { - // Get the translation in the spatial Space - Quaternion worldToSpatial = toolController.getSelectedSpatial().getWorldRotation().inverse(); - Vector3f diff = pickManager.getTranslation(worldToSpatial.mult(constraintAxis)); - diff.multLocal(0.5f); - Vector3f scale = startScale.add(diff); - lastScale = scale; - toolController.getSelectedSpatial().setLocalScale(scale); - } - updateToolsTransformation(); - - wasDragging = true; } @Override public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + if (pressed) { + cancel(); + } + } + private void cancel() { + if (wasDragging) { + wasDragging = false; + toolController.getSelectedSpatial().setLocalScale(startScale); + setDefaultAxisMarkerColors(); + pickedMarker = null; // mouse released, reset selection + pickManager.reset(); + } } private class ScaleUndo extends AbstractUndoableSceneEdit {