|
|
@ -39,7 +39,7 @@ public class ScaleTool extends SceneEditTool { |
|
|
|
@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); |
|
|
|
pickManager = Lookup.getDefault().lookup(PickManager.class); |
|
|
|
pickManager = Lookup.getDefault().lookup(PickManager.class); |
|
|
|
displayPlanes(); |
|
|
|
displayPlanes(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -54,12 +54,40 @@ public class ScaleTool extends SceneEditTool { |
|
|
|
wasDragging = false; |
|
|
|
wasDragging = false; |
|
|
|
} |
|
|
|
} |
|
|
|
pickManager.reset(); |
|
|
|
pickManager.reset(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (toolController.getSelectedSpatial() == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pickedMarker == null) { |
|
|
|
|
|
|
|
pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
|
|
|
|
if (pickedMarker == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { |
|
|
|
|
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), |
|
|
|
|
|
|
|
SceneComposerToolController.TransformationType.camera, camera, screenCoord); |
|
|
|
|
|
|
|
} else if (pickedMarker.equals(ARROW_X)) { |
|
|
|
|
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); |
|
|
|
|
|
|
|
constraintAxis = Vector3f.UNIT_X; // scale only X
|
|
|
|
|
|
|
|
} else if (pickedMarker.equals(ARROW_Y)) { |
|
|
|
|
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); |
|
|
|
|
|
|
|
constraintAxis = Vector3f.UNIT_Y; // scale only Y
|
|
|
|
|
|
|
|
} else if (pickedMarker.equals(ARROW_Z)) { |
|
|
|
|
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); |
|
|
|
|
|
|
|
constraintAxis = Vector3f.UNIT_Z; // scale only Z
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
startScale = toolController.getSelectedSpatial().getLocalScale().clone(); |
|
|
|
|
|
|
|
wasDragging = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { |
|
|
|
public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { |
|
|
|
|
|
|
|
if (pressed) { |
|
|
|
|
|
|
|
cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -83,61 +111,45 @@ public class ScaleTool extends SceneEditTool { |
|
|
|
wasDragging = false; |
|
|
|
wasDragging = false; |
|
|
|
} |
|
|
|
} |
|
|
|
pickManager.reset(); |
|
|
|
pickManager.reset(); |
|
|
|
return; |
|
|
|
} else if (wasDragging) { |
|
|
|
} |
|
|
|
if (!pickManager.updatePick(camera, screenCoord)) { |
|
|
|
|
|
|
|
|
|
|
|
if (toolController.getSelectedSpatial() == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pickedMarker == null) { |
|
|
|
|
|
|
|
pickedMarker = pickAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
|
|
|
|
if (pickedMarker == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { |
|
|
|
if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { |
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), camera.getRotation(), |
|
|
|
constraintAxis = pickManager.getStartOffset().normalize(); |
|
|
|
SceneComposerToolController.TransformationType.camera, camera, screenCoord); |
|
|
|
float diff = pickManager.getTranslation(constraintAxis).dot(constraintAxis); |
|
|
|
} else if (pickedMarker.equals(ARROW_X)) { |
|
|
|
diff *= 0.5f; |
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XY, getTransformType(), camera, screenCoord); |
|
|
|
Vector3f scale = startScale.add(new Vector3f(diff, diff, diff)); |
|
|
|
constraintAxis = Vector3f.UNIT_X; // scale only X
|
|
|
|
lastScale = scale; |
|
|
|
} else if (pickedMarker.equals(ARROW_Y)) { |
|
|
|
toolController.getSelectedSpatial().setLocalScale(scale); |
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_YZ, getTransformType(), camera, screenCoord); |
|
|
|
} else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) { |
|
|
|
constraintAxis = Vector3f.UNIT_Y; // scale only Y
|
|
|
|
// Get the translation in the spatial Space
|
|
|
|
} else if (pickedMarker.equals(ARROW_Z)) { |
|
|
|
Quaternion worldToSpatial = toolController.getSelectedSpatial().getWorldRotation().inverse(); |
|
|
|
pickManager.initiatePick(toolController.getSelectedSpatial(), PickManager.PLANE_XZ, getTransformType(), camera, screenCoord); |
|
|
|
Vector3f diff = pickManager.getTranslation(worldToSpatial.mult(constraintAxis)); |
|
|
|
constraintAxis = Vector3f.UNIT_Z; // scale only Z
|
|
|
|
diff.multLocal(0.5f); |
|
|
|
|
|
|
|
Vector3f scale = startScale.add(diff); |
|
|
|
|
|
|
|
lastScale = scale; |
|
|
|
|
|
|
|
toolController.getSelectedSpatial().setLocalScale(scale); |
|
|
|
} |
|
|
|
} |
|
|
|
startScale = toolController.getSelectedSpatial().getLocalScale().clone(); |
|
|
|
updateToolsTransformation(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!pickManager.updatePick(camera, screenCoord)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (pickedMarker.equals(QUAD_XY) || pickedMarker.equals(QUAD_XZ) || pickedMarker.equals(QUAD_YZ)) { |
|
|
|
|
|
|
|
constraintAxis = pickManager.getStartOffset().normalize(); |
|
|
|
|
|
|
|
float diff = pickManager.getTranslation(constraintAxis).dot(constraintAxis); |
|
|
|
|
|
|
|
diff *= 0.5f; |
|
|
|
|
|
|
|
Vector3f scale = startScale.add(new Vector3f(diff, diff, diff)); |
|
|
|
|
|
|
|
lastScale = scale; |
|
|
|
|
|
|
|
toolController.getSelectedSpatial().setLocalScale(scale); |
|
|
|
|
|
|
|
} else if (pickedMarker.equals(ARROW_X) || pickedMarker.equals(ARROW_Y) || pickedMarker.equals(ARROW_Z)) { |
|
|
|
|
|
|
|
// Get the translation in the spatial Space
|
|
|
|
|
|
|
|
Quaternion worldToSpatial = toolController.getSelectedSpatial().getWorldRotation().inverse(); |
|
|
|
|
|
|
|
Vector3f diff = pickManager.getTranslation(worldToSpatial.mult(constraintAxis)); |
|
|
|
|
|
|
|
diff.multLocal(0.5f); |
|
|
|
|
|
|
|
Vector3f scale = startScale.add(diff); |
|
|
|
|
|
|
|
lastScale = scale; |
|
|
|
|
|
|
|
toolController.getSelectedSpatial().setLocalScale(scale); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateToolsTransformation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
|
if (pressed) { |
|
|
|
|
|
|
|
cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void cancel() { |
|
|
|
|
|
|
|
if (wasDragging) { |
|
|
|
|
|
|
|
wasDragging = false; |
|
|
|
|
|
|
|
toolController.getSelectedSpatial().setLocalScale(startScale); |
|
|
|
|
|
|
|
setDefaultAxisMarkerColors(); |
|
|
|
|
|
|
|
pickedMarker = null; // mouse released, reset selection
|
|
|
|
|
|
|
|
pickManager.reset(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class ScaleUndo extends AbstractUndoableSceneEdit { |
|
|
|
private class ScaleUndo extends AbstractUndoableSceneEdit { |
|
|
|