SDK SceneComposer : Added the new Move Shortcut, you can use this shortcut with all others tools

experimental
Maselbas 10 years ago
parent e27b8a5739
commit fb44f5fb7b
  1. 5
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java
  2. 93
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/shortcuts/MoveShortcut.java

@ -189,6 +189,7 @@ public class SceneComposerToolController extends SceneToolController {
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (scm.isActive()) {
scm.getActiveShortcut().setCamera(camera);
scm.getActiveShortcut().actionPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} else if (editTool != null) {
editTool.setCamera(camera);
@ -207,6 +208,7 @@ public class SceneComposerToolController extends SceneToolController {
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (scm.isActive()) {
scm.getActiveShortcut().setCamera(camera);
scm.getActiveShortcut().actionSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} else if (editTool != null) {
editTool.setCamera(camera);
@ -218,6 +220,7 @@ public class SceneComposerToolController extends SceneToolController {
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (scm.isActive()) {
scm.getActiveShortcut().setCamera(camera);
scm.getActiveShortcut().mouseMoved(mouseLoc, rootNode, editorController.getCurrentDataObject(), selectedSpatial);
} else if (editTool != null) {
editTool.setCamera(camera);
@ -229,6 +232,7 @@ public class SceneComposerToolController extends SceneToolController {
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (scm.isActive()) {
scm.getActiveShortcut().setCamera(camera);
scm.getActiveShortcut().draggedPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} else if (editTool != null) {
editTool.setCamera(camera);
@ -240,6 +244,7 @@ public class SceneComposerToolController extends SceneToolController {
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
if (scm.isActive()) {
scm.getActiveShortcut().setCamera(null);
scm.getActiveShortcut().draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} else if (editTool != null) {
editTool.setCamera(camera);

@ -12,6 +12,7 @@ import com.jme3.gde.scenecomposer.SceneComposerToolController;
import com.jme3.gde.scenecomposer.tools.PickManager;
import com.jme3.input.KeyInput;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
@ -28,18 +29,21 @@ public class MoveShortcut extends ShortcutTool {
private Vector3f currentAxis;
private StringBuilder numberBuilder;
private Spatial spatial;
private Vector3f initalLocation;
private Vector3f finalLocation;
private PickManager pickManager;
private boolean pickEnabled;
private Vector3f startPosition;
private Vector3f finalPosition;
@Override
public boolean isActivableBy(KeyInputEvent kie) {
return kie.getKeyCode() == KeyInput.KEY_G;
}
@Override
public void cancel() {
spatial.setLocalTranslation(initalLocation);
spatial.setLocalTranslation(startPosition);
terminate();
}
@ -48,6 +52,14 @@ public class MoveShortcut extends ShortcutTool {
terminate();
}
private void init(Spatial selectedSpatial) {
spatial = selectedSpatial;
startPosition = spatial.getLocalTranslation().clone();
currentAxis = Vector3f.UNIT_XYZ;
pickManager = Lookup.getDefault().lookup(PickManager.class);
pickEnabled = false;
}
@Override
public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) {
super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController); //To change body of generated methods, choose Tools | Templates.
@ -56,27 +68,23 @@ public class MoveShortcut extends ShortcutTool {
if (selectedSpatial == null) {
terminate();
} else {
spatial = selectedSpatial;
initalLocation = spatial.getLocalTranslation();
currentAxis = new Vector3f().set(Vector3f.UNIT_XYZ);
pickManager = Lookup.getDefault().lookup(PickManager.class);
///pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord);
init(selectedSpatial);
}
}
@Override
public void keyPressed(KeyInputEvent kie) {
if (kie.isPressed()) {
/*
ShortcutTool otherShortcut = Lookup.getDefault().lookup(ShortcutManager.class).getActivableShortcut(kie);
if(otherShortcut != null){
Lookup.getDefault().lookup(ShortcutManager.class).setShortCut(otherShortcut);
}*/
System.out.println(kie);
Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(kie);
boolean axisChanged = ShortcutManager.checkAxisKey(kie, currentAxis);
Vector3f axis = new Vector3f();
boolean axisChanged = ShortcutManager.checkAxisKey(kie, axis);
if (axisChanged) {
currentAxis = axis;
System.out.println("AXIS : " + currentAxis);
}
boolean numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder);
boolean enterHit = ShortcutManager.checkEnterHit(kie);
boolean escHit = ShortcutManager.checkEscHit(kie);
@ -85,11 +93,24 @@ public class MoveShortcut extends ShortcutTool {
cancel();
} else if (enterHit) {
apply();
} else if (axisChanged && pickEnabled) {
//update pick manager
if (currentAxis.equals(Vector3f.UNIT_X)) {
System.out.println("setTransformation X");
pickManager.setTransformation(PickManager.PLANE_XY, getTransformType(), camera);
} else if (currentAxis.equals(Vector3f.UNIT_Y)) {
System.out.println("setTransformation Y");
pickManager.setTransformation(PickManager.PLANE_YZ, getTransformType(), camera);
} else if (currentAxis.equals(Vector3f.UNIT_Z)) {
System.out.println("setTransformation Z");
pickManager.setTransformation(PickManager.PLANE_XZ, getTransformType(), camera);
}
} else if (axisChanged || numberChanged) {
//update transformation
float number = ShortcutManager.getNumberkey(numberBuilder);
Vector3f translation = currentAxis.mult(number);
finalLocation = initalLocation.add(translation);
finalLocation = startPosition.add(translation);
spatial.setLocalTranslation(finalLocation);
}
@ -99,7 +120,7 @@ public class MoveShortcut extends ShortcutTool {
@Override
public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
if (!pressed) {
if (pressed) {
apply();
}
}
@ -113,13 +134,39 @@ public class MoveShortcut extends ShortcutTool {
@Override
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject dataObject, JmeSpatial selectedSpatial) {
pickManager.updatePick(camera, screenCoord);
/* PickManager pickManager = Lookup.getDefault().lookup(PickManager.class);
if (toolController.isSnapToScene()) {
moveManager.setAlternativePickTarget(rootNode.getLookup().lookup(Node.class));
if (!pickEnabled) {
if (currentAxis.equals(Vector3f.UNIT_XYZ)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), SceneComposerToolController.TransformationType.camera, camera, screenCoord);
pickEnabled = true;
} else if (currentAxis.equals(Vector3f.UNIT_X)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord);
pickEnabled = true;
} else if (currentAxis.equals(Vector3f.UNIT_Y)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord);
pickEnabled = true;
} else if (currentAxis.equals(Vector3f.UNIT_Z)) {
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord);
pickEnabled = true;
} else {
return;
}
}
if (pickManager.updatePick(camera, screenCoord)) {
//pick update success
Vector3f diff;
if (currentAxis.equals(Vector3f.UNIT_XYZ)) {
diff = pickManager.getTranslation();
} else {
diff = pickManager.getTranslation(currentAxis);
}
Vector3f position = startPosition.add(diff);
finalPosition = position;
toolController.getSelectedSpatial().setLocalTranslation(position);
updateToolsTransformation();
}
// free form translation
moveManager.move(camera, screenCoord, axis, toolController.isSnapToGrid());*/
}
@Override

Loading…
Cancel
Save