Merge pull request #268 from Dokthar/scenecomposer/master

SDK SceneComposer : right click to cancel current transformation
experimental
normen 10 years ago
commit d3c644123a
  1. 17
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java
  2. 101
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java
  3. 79
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/RotateTool.java
  4. 106
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java

@ -357,7 +357,7 @@ public class SceneComposerToolController extends SceneToolController {
public void setTransformationType(String type) { public void setTransformationType(String type) {
if(type != null){ if(type != null){
if(type.equals("Local")){ if(type.equals("Local")){
setTransformationType(transformationType.local); setTransformationType(TransformationType.local);
} else if(type.equals("Global")){ } else if(type.equals("Global")){
setTransformationType(TransformationType.global); setTransformationType(TransformationType.global);
} else if(type.equals("Camera")){ } 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) { public void setTransformationType(TransformationType type) {
if(type != this.transformationType){ 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 marker on the screen that shows where a point light or
* a spot light is. This marker is not part of the scene, * a spot light is. This marker is not part of the scene,

@ -60,11 +60,44 @@ public class MoveTool extends SceneEditTool {
wasDragging = false; wasDragging = false;
} }
pickManager.reset(); 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 @Override
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
if (pressed) {
cancel();
}
} }
@Override @Override
@ -89,58 +122,40 @@ public class MoveTool extends SceneEditTool {
wasDragging = false; wasDragging = false;
} }
pickManager.reset(); pickManager.reset();
return; } else if (wasDragging == true) {
} if (!pickManager.updatePick(camera, screenCoord)) {
if (toolController.getSelectedSpatial() == null) {
return;
}
if (pickedMarker == null) {
pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType);
if (pickedMarker == null) {
return; 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)) { } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); diff = pickManager.getTranslation(constraintAxis);
} 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(); Vector3f position = startPosition.add(diff);
lastPosition = position;
} toolController.getSelectedSpatial().setLocalTranslation(position);
if (!pickManager.updatePick(camera, screenCoord)) { updateToolsTransformation();
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;
} }
@Override @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().setLocalTranslation(startPosition);
setDefaultAxisMarkerColors();
pickedMarker = null; // mouse released, reset selection
constraintAxis = Vector3f.UNIT_XYZ; // no constraint
pickManager.reset();
}
} }
protected class MoveUndo extends AbstractUndoableSceneEdit { protected class MoveUndo extends AbstractUndoableSceneEdit {

@ -53,12 +53,36 @@ public class RotateTool extends SceneEditTool {
actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate)); actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate));
wasDragging = false; 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 @Override
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
if (pressed) {
cancel();
}
} }
@Override @Override
@ -67,12 +91,12 @@ public class RotateTool extends SceneEditTool {
highlightAxisMarker(camera, screenCoord, axisPickType); highlightAxisMarker(camera, screenCoord, axisPickType);
} else { } else {
pickedMarker = null; pickedMarker = null;
pickManager.reset();
} }
} }
@Override @Override
public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
if (!pressed) { if (!pressed) {
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
pickedMarker = null; // mouse released, reset selection pickedMarker = null; // mouse released, reset selection
@ -82,45 +106,36 @@ public class RotateTool extends SceneEditTool {
actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate)); actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startRotate, lastRotate));
wasDragging = false; wasDragging = false;
} }
return; pickManager.reset();
} } else if (wasDragging) {
if (!pickManager.updatePick(camera, screenCoord)) {
if (toolController.getSelectedSpatial() == null) {
return;
}
if (pickedMarker == null) {
pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType);
if (pickedMarker == null) {
return; return;
} }
if (pickedMarker.equals(QUAD_XY)) { if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); Quaternion rotation = startRotate.mult(pickManager.getLocalRotation());
} else if (pickedMarker.equals(QUAD_XZ)) { toolController.getSelectedSpatial().setLocalRotation(rotation);
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); lastRotate = rotation;
} else if (pickedMarker.equals(QUAD_YZ)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord);
} }
startRotate = toolController.getSelectedSpatial().getLocalRotation().clone(); updateToolsTransformation();
}
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();
wasDragging = true;
} }
@Override @Override
public public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) {
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 { private class ScaleUndo extends AbstractUndoableSceneEdit {

@ -39,7 +39,7 @@ public class ScaleTool extends SceneEditTool {
@Override @Override
public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) { public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) {
super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController); super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController);
pickManager = Lookup.getDefault().lookup(PickManager.class); pickManager = Lookup.getDefault().lookup(PickManager.class);
displayPlanes(); displayPlanes();
} }
@ -54,12 +54,40 @@ public class ScaleTool extends SceneEditTool {
wasDragging = false; wasDragging = false;
} }
pickManager.reset(); 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 @Override
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
if (pressed) {
cancel();
}
} }
@Override @Override
@ -83,61 +111,45 @@ public class ScaleTool extends SceneEditTool {
wasDragging = false; wasDragging = false;
} }
pickManager.reset(); pickManager.reset();
return; } else if (wasDragging) {
} if (!pickManager.updatePick(camera, screenCoord)) {
if (toolController.getSelectedSpatial() == null) {
return;
}
if (pickedMarker == null) {
pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType);
if (pickedMarker == null) {
return; return;
} }
if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), constraintAxis = pickManager.getStartOffset().normalize();
SceneComposerToolController.TransformationType.camera, camera, screenCoord); float diff = pickManager.getTranslation(constraintAxis).dot(constraintAxis);
} else if (pickedMarker.equals(ARROW_X)) { diff *= 0.5f;
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); Vector3f scale = startScale.add(new Vector3f(diff, diff, diff));
constraintAxis = Vector3f.UNIT_X; // scale only X lastScale = scale;
} else if (pickedMarker.equals(ARROW_Y)) { toolController.getSelectedSpatial().setLocalScale(scale);
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); } else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) {
constraintAxis = Vector3f.UNIT_Y; // scale only Y // Get the translation in the spatial Space
} else if (pickedMarker.equals(ARROW_Z)) { Quaternion worldToSpatial = toolController.getSelectedSpatial().getWorldRotation().inverse();
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); Vector3f diff = pickManager.getTranslation(worldToSpatial.mult(constraintAxis));
constraintAxis = Vector3f.UNIT_Z; // scale only Z diff.multLocal(0.5f);
Vector3f scale = startScale.add(diff);
lastScale = scale;
toolController.getSelectedSpatial().setLocalScale(scale);
} }
startScale = toolController.getSelectedSpatial().getLocalScale().clone(); updateToolsTransformation();
}
if (!pickManager.updatePick(camera, screenCoord)) {
return;
} }
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 @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().setLocalScale(startScale);
setDefaultAxisMarkerColors();
pickedMarker = null; // mouse released, reset selection
pickManager.reset();
}
} }
private class ScaleUndo extends AbstractUndoableSceneEdit { private class ScaleUndo extends AbstractUndoableSceneEdit {

Loading…
Cancel
Save