SDK SceneComposer : Added the new Move Shortcut, you can use this shortcut with all others tools
This commit is contained in:
parent
e27b8a5739
commit
fb44f5fb7b
@ -189,6 +189,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
|
scm.getActiveShortcut().setCamera(camera);
|
||||||
scm.getActiveShortcut().actionPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
scm.getActiveShortcut().actionPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
||||||
} else if (editTool != null) {
|
} else if (editTool != null) {
|
||||||
editTool.setCamera(camera);
|
editTool.setCamera(camera);
|
||||||
@ -207,6 +208,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
|
scm.getActiveShortcut().setCamera(camera);
|
||||||
scm.getActiveShortcut().actionSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
scm.getActiveShortcut().actionSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
||||||
} else if (editTool != null) {
|
} else if (editTool != null) {
|
||||||
editTool.setCamera(camera);
|
editTool.setCamera(camera);
|
||||||
@ -218,6 +220,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
|
scm.getActiveShortcut().setCamera(camera);
|
||||||
scm.getActiveShortcut().mouseMoved(mouseLoc, rootNode, editorController.getCurrentDataObject(), selectedSpatial);
|
scm.getActiveShortcut().mouseMoved(mouseLoc, rootNode, editorController.getCurrentDataObject(), selectedSpatial);
|
||||||
} else if (editTool != null) {
|
} else if (editTool != null) {
|
||||||
editTool.setCamera(camera);
|
editTool.setCamera(camera);
|
||||||
@ -229,6 +232,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
|
scm.getActiveShortcut().setCamera(camera);
|
||||||
scm.getActiveShortcut().draggedPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
scm.getActiveShortcut().draggedPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
||||||
} else if (editTool != null) {
|
} else if (editTool != null) {
|
||||||
editTool.setCamera(camera);
|
editTool.setCamera(camera);
|
||||||
@ -240,6 +244,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
|
scm.getActiveShortcut().setCamera(null);
|
||||||
scm.getActiveShortcut().draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
scm.getActiveShortcut().draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
|
||||||
} else if (editTool != null) {
|
} else if (editTool != null) {
|
||||||
editTool.setCamera(camera);
|
editTool.setCamera(camera);
|
||||||
@ -249,7 +254,7 @@ public class SceneComposerToolController extends SceneToolController {
|
|||||||
|
|
||||||
public void doKeyPressed(KeyInputEvent kie) {
|
public void doKeyPressed(KeyInputEvent kie) {
|
||||||
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
ShortcutManager scm = Lookup.getDefault().lookup(ShortcutManager.class);
|
||||||
|
|
||||||
if (scm.isActive()) {
|
if (scm.isActive()) {
|
||||||
scm.doKeyPressed(kie);
|
scm.doKeyPressed(kie);
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,6 +12,7 @@ import com.jme3.gde.scenecomposer.SceneComposerToolController;
|
|||||||
import com.jme3.gde.scenecomposer.tools.PickManager;
|
import com.jme3.gde.scenecomposer.tools.PickManager;
|
||||||
import com.jme3.input.KeyInput;
|
import com.jme3.input.KeyInput;
|
||||||
import com.jme3.input.event.KeyInputEvent;
|
import com.jme3.input.event.KeyInputEvent;
|
||||||
|
import com.jme3.math.Quaternion;
|
||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
@ -28,18 +29,21 @@ public class MoveShortcut extends ShortcutTool {
|
|||||||
private Vector3f currentAxis;
|
private Vector3f currentAxis;
|
||||||
private StringBuilder numberBuilder;
|
private StringBuilder numberBuilder;
|
||||||
private Spatial spatial;
|
private Spatial spatial;
|
||||||
private Vector3f initalLocation;
|
|
||||||
private Vector3f finalLocation;
|
private Vector3f finalLocation;
|
||||||
private PickManager pickManager;
|
private PickManager pickManager;
|
||||||
|
private boolean pickEnabled;
|
||||||
|
private Vector3f startPosition;
|
||||||
|
private Vector3f finalPosition;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
||||||
public boolean isActivableBy(KeyInputEvent kie) {
|
public boolean isActivableBy(KeyInputEvent kie) {
|
||||||
return kie.getKeyCode() == KeyInput.KEY_G;
|
return kie.getKeyCode() == KeyInput.KEY_G;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
spatial.setLocalTranslation(initalLocation);
|
spatial.setLocalTranslation(startPosition);
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +52,14 @@ public class MoveShortcut extends ShortcutTool {
|
|||||||
terminate();
|
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
|
@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); //To change body of generated methods, choose Tools | Templates.
|
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) {
|
if (selectedSpatial == null) {
|
||||||
terminate();
|
terminate();
|
||||||
} else {
|
} else {
|
||||||
spatial = selectedSpatial;
|
init(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyInputEvent kie) {
|
public void keyPressed(KeyInputEvent kie) {
|
||||||
if (kie.isPressed()) {
|
if (kie.isPressed()) {
|
||||||
|
System.out.println(kie);
|
||||||
/*
|
|
||||||
ShortcutTool otherShortcut = Lookup.getDefault().lookup(ShortcutManager.class).getActivableShortcut(kie);
|
|
||||||
if(otherShortcut != null){
|
|
||||||
Lookup.getDefault().lookup(ShortcutManager.class).setShortCut(otherShortcut);
|
|
||||||
}*/
|
|
||||||
Lookup.getDefault().lookup(ShortcutManager.class).activateShortcut(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 numberChanged = ShortcutManager.checkNumberKey(kie, numberBuilder);
|
||||||
boolean enterHit = ShortcutManager.checkEnterHit(kie);
|
boolean enterHit = ShortcutManager.checkEnterHit(kie);
|
||||||
boolean escHit = ShortcutManager.checkEscHit(kie);
|
boolean escHit = ShortcutManager.checkEscHit(kie);
|
||||||
@ -85,11 +93,24 @@ public class MoveShortcut extends ShortcutTool {
|
|||||||
cancel();
|
cancel();
|
||||||
} else if (enterHit) {
|
} else if (enterHit) {
|
||||||
apply();
|
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) {
|
} else if (axisChanged || numberChanged) {
|
||||||
//update transformation
|
//update transformation
|
||||||
float number = ShortcutManager.getNumberkey(numberBuilder);
|
float number = ShortcutManager.getNumberkey(numberBuilder);
|
||||||
Vector3f translation = currentAxis.mult(number);
|
Vector3f translation = currentAxis.mult(number);
|
||||||
finalLocation = initalLocation.add(translation);
|
finalLocation = startPosition.add(translation);
|
||||||
spatial.setLocalTranslation(finalLocation);
|
spatial.setLocalTranslation(finalLocation);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -99,7 +120,7 @@ public class MoveShortcut extends ShortcutTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) {
|
||||||
if (!pressed) {
|
if (pressed) {
|
||||||
apply();
|
apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,13 +134,39 @@ public class MoveShortcut extends ShortcutTool {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject dataObject, JmeSpatial selectedSpatial) {
|
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject dataObject, JmeSpatial selectedSpatial) {
|
||||||
pickManager.updatePick(camera, screenCoord);
|
|
||||||
/* PickManager pickManager = Lookup.getDefault().lookup(PickManager.class);
|
if (!pickEnabled) {
|
||||||
if (toolController.isSnapToScene()) {
|
if (currentAxis.equals(Vector3f.UNIT_XYZ)) {
|
||||||
moveManager.setAlternativePickTarget(rootNode.getLookup().lookup(Node.class));
|
pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), SceneComposerToolController.TransformationType.camera, camera, screenCoord);
|
||||||
}
|
pickEnabled = true;
|
||||||
// free form translation
|
} else if (currentAxis.equals(Vector3f.UNIT_X)) {
|
||||||
moveManager.move(camera, screenCoord, axis, toolController.isSnapToGrid());*/
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user