From a913d8e0c29b6c39a490ad88ac4c1036e9dfccad Mon Sep 17 00:00:00 2001 From: Maselbas Date: Thu, 30 Apr 2015 19:35:39 +0200 Subject: [PATCH] SDK Scenecomposer : now right clicking will cancel current transformation for the Scale, Rotate and Move Tool, looks like the selectTools shortcut - improved these tool feedback, its easier to begin the tranformation as its start on the first click instead of the first dragg --- .../gde/scenecomposer/tools/MoveTool.java | 101 ++++++++++------- .../gde/scenecomposer/tools/RotateTool.java | 79 +++++++------ .../gde/scenecomposer/tools/ScaleTool.java | 106 ++++++++++-------- 3 files changed, 164 insertions(+), 122 deletions(-) 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 {