SDK : SceneComposer
- Added support for Axis X,Y,Z scaling into the ScaleTool, still need some enhancement
This commit is contained in:
parent
abb1a69d6f
commit
5ef1292484
@ -22,7 +22,8 @@ import org.openide.loaders.DataObject;
|
||||
*/
|
||||
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;
|
||||
@ -43,8 +44,9 @@ public class ScaleTool extends SceneEditTool {
|
||||
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;
|
||||
@ -59,7 +61,7 @@ public class ScaleTool extends SceneEditTool {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(Vector2f screenCoord, JmeNode rootNode, DataObject currentDataObject, JmeSpatial selectedSpatial) {
|
||||
if (pickedPlane == null) {
|
||||
if (pickedMarker == null) {
|
||||
highlightAxisMarker(camera, screenCoord, axisPickType, true);
|
||||
}
|
||||
/*else {
|
||||
@ -72,9 +74,9 @@ public class ScaleTool extends SceneEditTool {
|
||||
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;
|
||||
@ -82,22 +84,31 @@ public class ScaleTool extends SceneEditTool {
|
||||
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();
|
||||
@ -114,7 +125,7 @@ public class ScaleTool extends SceneEditTool {
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user