|
|
@ -21,107 +21,118 @@ import org.openide.loaders.DataObject; |
|
|
|
* @author sploreg |
|
|
|
* @author sploreg |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
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; |
|
|
|
private boolean wasDragging = false; |
|
|
|
private boolean wasDragging = false; |
|
|
|
|
|
|
|
|
|
|
|
public ScaleTool() { |
|
|
|
public ScaleTool() { |
|
|
|
axisPickType = AxisMarkerPickType.axisAndPlane; |
|
|
|
axisPickType = AxisMarkerPickType.axisAndPlane; |
|
|
|
setOverrideCameraControl(true); |
|
|
|
setOverrideCameraControl(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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); |
|
|
|
displayPlanes(); |
|
|
|
displayPlanes(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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) { |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { |
|
|
|
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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 { |
|
|
|
pickedPlane = null; |
|
|
|
pickedPlane = null; |
|
|
|
lastScreenCoord = null; |
|
|
|
lastScreenCoord = null; |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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(); |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (lastScreenCoord == null) { |
|
|
|
if (lastScreenCoord == null) { |
|
|
|
lastScreenCoord = screenCoord; |
|
|
|
lastScreenCoord = screenCoord; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wasDragging = true; |
|
|
|
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) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class ScaleUndo extends AbstractUndoableSceneEdit { |
|
|
|
private class ScaleUndo extends AbstractUndoableSceneEdit { |
|
|
|
|
|
|
|
|
|
|
|
private Spatial spatial; |
|
|
|
private Spatial spatial; |
|
|
|
private Vector3f before,after; |
|
|
|
private Vector3f before, after; |
|
|
|
|
|
|
|
|
|
|
|
ScaleUndo(Spatial spatial, Vector3f before, Vector3f after) { |
|
|
|
ScaleUndo(Spatial spatial, Vector3f before, Vector3f after) { |
|
|
|
this.spatial = spatial; |
|
|
|
this.spatial = spatial; |
|
|
|
this.before = before; |
|
|
|
this.before = before; |
|
|
|
this.after = after; |
|
|
|
this.after = after; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void sceneUndo() { |
|
|
|
public void sceneUndo() { |
|
|
|
spatial.setLocalScale(before); |
|
|
|
spatial.setLocalScale(before); |
|
|
@ -133,6 +144,6 @@ public class ScaleTool extends SceneEditTool { |
|
|
|
spatial.setLocalScale(after); |
|
|
|
spatial.setLocalScale(after); |
|
|
|
toolController.selectedSpatialTransformed(); |
|
|
|
toolController.selectedSpatialTransformed(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|