Merge pull request #2 from Dokthar/scenecomposer/master

Scenecomposer/master
experimental
Dokthar 10 years ago
commit ece7104d7e
  1. 5
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java
  2. 36
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java
  3. 31
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java

@ -336,7 +336,7 @@ public abstract class SceneEditTool {
CollisionResults results = new CollisionResults(); CollisionResults results = new CollisionResults();
Ray ray = new Ray(); Ray ray = new Ray();
Vector3f pos = cam.getWorldCoordinates(mouseLoc, 0).clone(); 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(); dir.subtractLocal(pos).normalizeLocal();
ray.setOrigin(pos); ray.setOrigin(pos);
ray.setDirection(dir); ray.setDirection(dir);
@ -360,7 +360,7 @@ public abstract class SceneEditTool {
*/ */
protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType, boolean colorAll) { protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType, boolean colorAll) {
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
Vector3f picked = pickAxisMarker(camera, screenCoord, axisPickType); Vector3f picked = pickAxisMarker(camera, screenCoord, axisMarkerPickType);
if (picked == null) { if (picked == null) {
return; return;
} }
@ -453,6 +453,7 @@ public abstract class SceneEditTool {
// axis.attachChild(quadYZ); // axis.attachChild(quadYZ);
axis.setModelBound(new BoundingBox()); axis.setModelBound(new BoundingBox());
axis.updateModelBound();
return axis; return axis;
} }

@ -27,7 +27,8 @@ import org.openide.util.Lookup;
*/ */
public class MoveTool extends SceneEditTool { public class MoveTool extends SceneEditTool {
private Vector3f pickedPlane; private Vector3f pickedMarker;
private Vector3f constraintAxis; //used for one axis move
private boolean wasDragging = false; private boolean wasDragging = false;
private MoveManager moveManager; private MoveManager moveManager;
@ -48,7 +49,8 @@ public class MoveTool extends SceneEditTool {
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) {
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
pickedPlane = null; // mouse released, reset selection pickedMarker = null; // mouse released, reset selection
constraintAxis = Vector3f.UNIT_XYZ; // no constraint
if (wasDragging) { if (wasDragging) {
actionPerformed(moveManager.makeUndo()); actionPerformed(moveManager.makeUndo());
wasDragging = false; wasDragging = false;
@ -64,10 +66,10 @@ public class MoveTool extends SceneEditTool {
@Override @Override
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) { public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) {
if (pickedPlane == null) { if (pickedMarker == null) {
highlightAxisMarker(camera, screenCoord, axisPickType); highlightAxisMarker(camera, screenCoord, axisPickType);
} else { } else {
pickedPlane = null; pickedMarker = null;
moveManager.reset(); moveManager.reset();
} }
} }
@ -76,7 +78,8 @@ public class MoveTool extends SceneEditTool {
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();
pickedPlane = null; // mouse released, reset selection pickedMarker = null; // mouse released, reset selection
constraintAxis = Vector3f.UNIT_XYZ; // no constraint
if (wasDragging) { if (wasDragging) {
actionPerformed(moveManager.makeUndo()); actionPerformed(moveManager.makeUndo());
wasDragging = false; wasDragging = false;
@ -89,21 +92,30 @@ public class MoveTool extends SceneEditTool {
return; return;
} }
if (pickedPlane == null) { if (pickedMarker == null) {
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType);
if (pickedPlane == null) { if (pickedMarker == null) {
return; return;
} }
if (pickedPlane.equals(new Vector3f(1, 1, 0))) { if (pickedMarker.equals(QUAD_XY)) {
moveManager.initiateMove(toolController.getSelectedSpatial(), MoveManager.XY, true); 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); 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); 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; return;
} }
updateToolsTransformation(); updateToolsTransformation();

@ -22,7 +22,8 @@ import org.openide.loaders.DataObject;
*/ */
public class ScaleTool extends SceneEditTool { public class ScaleTool extends SceneEditTool {
private Vector3f pickedPlane; private Vector3f pickedMarker;
private Vector3f constraintAxis; //used for one axis scale
private Vector2f lastScreenCoord; private Vector2f lastScreenCoord;
private Vector3f startScale; private Vector3f startScale;
private Vector3f lastScale; private Vector3f lastScale;
@ -43,8 +44,9 @@ public class ScaleTool extends SceneEditTool {
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) {
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
pickedPlane = null; // mouse released, reset selection pickedMarker = null; // mouse released, reset selection
lastScreenCoord = null; lastScreenCoord = null;
constraintAxis = Vector3f.UNIT_XYZ; // no axis constraint
if (wasDragging) { if (wasDragging) {
actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale));
wasDragging = false; wasDragging = false;
@ -59,7 +61,7 @@ public class ScaleTool extends SceneEditTool {
@Override @Override
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) { public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) {
if (pickedPlane == null) { if (pickedMarker == null) {
highlightAxisMarker(camera, screenCoord, axisPickType, true); highlightAxisMarker(camera, screenCoord, axisPickType, true);
} }
/*else { /*else {
@ -72,9 +74,9 @@ public class ScaleTool extends SceneEditTool {
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();
pickedPlane = null; // mouse released, reset selection pickedMarker = null; // mouse released, reset selection
lastScreenCoord = null; lastScreenCoord = null;
constraintAxis = Vector3f.UNIT_XYZ; // no axis constraint
if (wasDragging) { if (wasDragging) {
actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale));
wasDragging = false; wasDragging = false;
@ -82,12 +84,21 @@ public class ScaleTool extends SceneEditTool {
return; return;
} }
if (toolController.getSelectedSpatial() == null) if (toolController.getSelectedSpatial() == null) {
return; return;
if (pickedPlane == null) { }
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); if (pickedMarker == null) {
if (pickedPlane == null) pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType);
if (pickedMarker == null) {
return; 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(); startScale = toolController.getSelectedSpatial().getLocalScale().clone();
} }
@ -97,7 +108,7 @@ public class ScaleTool extends SceneEditTool {
float diff = screenCoord.y - lastScreenCoord.y; float diff = screenCoord.y - lastScreenCoord.y;
diff *= 0.1f; diff *= 0.1f;
lastScreenCoord = screenCoord; 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; lastScale = scale;
toolController.getSelectedSpatial().setLocalScale(scale); toolController.getSelectedSpatial().setLocalScale(scale);
updateToolsTransformation(); updateToolsTransformation();

Loading…
Cancel
Save