From b27f86a3aec20e12b40f1336bc5dd09b54a0b270 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Wed, 15 Apr 2015 00:34:59 +0200 Subject: [PATCH 1/4] fix SceneEditTool : - axis pick is now available --- .../src/com/jme3/gde/scenecomposer/SceneEditTool.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java index d2767781c..461f76c0c 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java @@ -285,7 +285,7 @@ public abstract class SceneEditTool { * what part of the axis was selected. * For example if (1,0,0) is returned, then the X-axis pole was selected. * If (0,1,1) is returned, then the Y-Z plane was selected. - * + * * @return null if it did not intersect the marker */ protected Vector3f pickAxisMarker(Camera cam, Vector2f mouseLoc, AxisMarkerPickType pickType) { @@ -336,7 +336,7 @@ public abstract class SceneEditTool { CollisionResults results = new CollisionResults(); Ray ray = new Ray(); Vector3f pos = cam.getWorldCoordinates(mouseLoc, 0).clone(); - Vector3f dir = cam.getWorldCoordinates(mouseLoc, 0.1f).clone(); + Vector3f dir = cam.getWorldCoordinates(mouseLoc, 0.125f).clone(); dir.subtractLocal(pos).normalizeLocal(); ray.setOrigin(pos); ray.setDirection(dir); @@ -347,7 +347,7 @@ public abstract class SceneEditTool { /** * Show what axis or plane the mouse is currently over and will affect. - * @param axisMarkerPickType + * @param axisMarkerPickType */ protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType) { highlightAxisMarker(camera, screenCoord, axisMarkerPickType, false); @@ -355,12 +355,12 @@ public abstract class SceneEditTool { /** * Show what axis or plane the mouse is currently over and will affect. - * @param axisMarkerPickType + * @param axisMarkerPickType * @param colorAll highlight all parts of the marker when only one is selected */ protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType, boolean colorAll) { setDefaultAxisMarkerColors(); - Vector3f picked = pickAxisMarker(camera, screenCoord, axisPickType); + Vector3f picked = pickAxisMarker(camera, screenCoord, axisMarkerPickType); if (picked == null) { return; } @@ -453,6 +453,7 @@ public abstract class SceneEditTool { // axis.attachChild(quadYZ); axis.setModelBound(new BoundingBox()); + axis.updateModelBound(); return axis; } From abb1a69d6f050f811c8b78312fd2d735420b617e Mon Sep 17 00:00:00 2001 From: Maselbas Date: Wed, 15 Apr 2015 20:34:57 +0200 Subject: [PATCH 2/4] SDK : SceneComposer - Added support for Axis X,Y,Z movement into the MoveManager --- .../gde/scenecomposer/tools/MoveTool.java | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 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 97f48cc9f..c76258313 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 @@ -27,7 +27,8 @@ import org.openide.util.Lookup; */ public class MoveTool extends SceneEditTool { - private Vector3f pickedPlane; + private Vector3f pickedMarker; + private Vector3f constraintAxis; //used for one axis move private boolean wasDragging = false; private MoveManager moveManager; @@ -46,15 +47,7 @@ public class MoveTool extends SceneEditTool { @Override public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { - if (!pressed) { - setDefaultAxisMarkerColors(); - pickedPlane = null; // mouse released, reset selection - if (wasDragging) { - actionPerformed(moveManager.makeUndo()); - wasDragging = false; - } - moveManager.reset(); - } + onPrimary(screenCoord, pressed); } @Override @@ -63,20 +56,35 @@ public class MoveTool extends SceneEditTool { @Override public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) { - - if (pickedPlane == null) { + + if (pickedMarker == null) { highlightAxisMarker(camera, screenCoord, axisPickType); } else { - pickedPlane = null; + pickedMarker = null; moveManager.reset(); } } @Override public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + onPrimary(screenCoord, pressed); + } + + @Override + public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + } + + /** + * Called by ActionPrimary and draggedPrimay, improve user feedback + * + * @param screenCoord + * @param pressed + */ + private void onPrimary(Vector2f screenCoord, boolean pressed) { if (!pressed) { setDefaultAxisMarkerColors(); - pickedPlane = null; // mouse released, reset selection + pickedMarker = null; // mouse released, reset selection + constraintAxis = Vector3f.UNIT_XYZ; // no constraint if (wasDragging) { actionPerformed(moveManager.makeUndo()); wasDragging = false; @@ -89,29 +97,34 @@ public class MoveTool extends SceneEditTool { return; } - if (pickedPlane == null) { - pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); - if (pickedPlane == null) { + if (pickedMarker == null) { + pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedMarker == null) { return; } - if (pickedPlane.equals(new Vector3f(1, 1, 0))) { + if (pickedMarker.equals(QUAD_XY)) { moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XY, true); - } else if (pickedPlane.equals(new Vector3f(1, 0, 1))) { + } else if (pickedMarker.equals(QUAD_XZ)) { moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XZ, true); - } else if (pickedPlane.equals(new Vector3f(0, 1, 1))) { + } else if (pickedMarker.equals(QUAD_YZ)) { + moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.YZ, true); + } else if (pickedMarker.equals(ARROW_X)) { + moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XY, true); + constraintAxis = Vector3f.UNIT_X; // move only X + } else if (pickedMarker.equals(ARROW_Y)) { moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.YZ, true); + constraintAxis = Vector3f.UNIT_Y; // move only Y + } else if (pickedMarker.equals(ARROW_Z)) { + moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XZ, true); + constraintAxis = Vector3f.UNIT_Z; // move only Z } } - if (!moveManager.move(camera, screenCoord)) { + if (!moveManager.move(camera, screenCoord, constraintAxis, false)) { return; } updateToolsTransformation(); wasDragging = true; } - - @Override - public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { - } } From 5ef129248459969de8563731560e32e1a6617d99 Mon Sep 17 00:00:00 2001 From: Maselbas Date: Wed, 15 Apr 2015 23:31:13 +0200 Subject: [PATCH 3/4] SDK : SceneComposer - Added support for Axis X,Y,Z scaling into the ScaleTool, still need some enhancement --- .../gde/scenecomposer/tools/ScaleTool.java | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) 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 862ef2be2..cfac57ae1 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 @@ -21,107 +21,118 @@ import org.openide.loaders.DataObject; * @author sploreg */ public class ScaleTool extends SceneEditTool { - - private Vector3f pickedPlane; + + private Vector3f pickedMarker; + private Vector3f constraintAxis; //used for one axis scale private Vector2f lastScreenCoord; private Vector3f startScale; private Vector3f lastScale; private boolean wasDragging = false; - + public ScaleTool() { axisPickType = AxisMarkerPickType.axisAndPlane; setOverrideCameraControl(true); } - + @Override public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) { super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController); displayPlanes(); } - + @Override public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { if (!pressed) { setDefaultAxisMarkerColors(); - pickedPlane = null; // mouse released, reset selection + pickedMarker = null; // mouse released, reset selection lastScreenCoord = null; + constraintAxis = Vector3f.UNIT_XYZ; // no axis constraint if (wasDragging) { actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); wasDragging = false; } } } - + @Override public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { - + } @Override public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) { - if (pickedPlane == null) { + if (pickedMarker == null) { highlightAxisMarker(camera, screenCoord, axisPickType, true); } /*else { - pickedPlane = null; - lastScreenCoord = null; - }*/ + pickedPlane = null; + lastScreenCoord = null; + }*/ } @Override public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { if (!pressed) { setDefaultAxisMarkerColors(); - pickedPlane = null; // mouse released, reset selection + pickedMarker = null; // mouse released, reset selection lastScreenCoord = null; - + constraintAxis = Vector3f.UNIT_XYZ; // no axis constraint if (wasDragging) { actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); wasDragging = false; } return; } - - if (toolController.getSelectedSpatial() == null) + + if (toolController.getSelectedSpatial() == null) { return; - if (pickedPlane == null) { - pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); - if (pickedPlane == null) + } + if (pickedMarker == null) { + pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedMarker == null) { return; + } + if (pickedMarker.equals(ARROW_X)) { + constraintAxis = Vector3f.UNIT_X; // scale only X + } else if (pickedMarker.equals(ARROW_Y)) { + constraintAxis = Vector3f.UNIT_Y; // scale only Y + } else if (pickedMarker.equals(ARROW_Z)) { + constraintAxis = Vector3f.UNIT_Z; // scale only Z + } startScale = toolController.getSelectedSpatial().getLocalScale().clone(); } - + if (lastScreenCoord == null) { lastScreenCoord = screenCoord; } else { - float diff = screenCoord.y-lastScreenCoord.y; + float diff = screenCoord.y - lastScreenCoord.y; diff *= 0.1f; lastScreenCoord = screenCoord; - Vector3f scale = toolController.getSelectedSpatial().getLocalScale().add(diff, diff, diff); + Vector3f scale = toolController.getSelectedSpatial().getLocalScale().add(new Vector3f(diff, diff, diff).multLocal(constraintAxis)); lastScale = scale; toolController.getSelectedSpatial().setLocalScale(scale); updateToolsTransformation(); } - + wasDragging = true; } @Override public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { - + } 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; this.before = before; this.after = after; } - + @Override public void sceneUndo() { spatial.setLocalScale(before); @@ -133,6 +144,6 @@ public class ScaleTool extends SceneEditTool { spatial.setLocalScale(after); toolController.selectedSpatialTransformed(); } - + } } From 0d95422d53635fab63c0da93c941bfdc647b9bcc Mon Sep 17 00:00:00 2001 From: Maselbas Date: Thu, 16 Apr 2015 18:22:50 +0200 Subject: [PATCH 4/4] revert some changes in MoveTool --- .../gde/scenecomposer/tools/MoveTool.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 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 c76258313..478a0f7c6 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 @@ -47,7 +47,16 @@ public class MoveTool extends SceneEditTool { @Override public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { - onPrimary(screenCoord, pressed); + if (!pressed) { + setDefaultAxisMarkerColors(); + pickedMarker = null; // mouse released, reset selection + constraintAxis = Vector3f.UNIT_XYZ; // no constraint + if (wasDragging) { + actionPerformed(moveManager.makeUndo()); + wasDragging = false; + } + moveManager.reset(); + } } @Override @@ -67,21 +76,7 @@ public class MoveTool extends SceneEditTool { @Override public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { - onPrimary(screenCoord, pressed); - } - - @Override - public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { - } - - /** - * Called by ActionPrimary and draggedPrimay, improve user feedback - * - * @param screenCoord - * @param pressed - */ - private void onPrimary(Vector2f screenCoord, boolean pressed) { - if (!pressed) { + if (!pressed) { setDefaultAxisMarkerColors(); pickedMarker = null; // mouse released, reset selection constraintAxis = Vector3f.UNIT_XYZ; // no constraint @@ -127,4 +122,8 @@ public class MoveTool extends SceneEditTool { wasDragging = true; } + + @Override + public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + } }