|
|
@ -21,7 +21,6 @@ import com.jme3.scene.Geometry; |
|
|
|
import com.jme3.scene.Node; |
|
|
|
import com.jme3.scene.Node; |
|
|
|
import com.jme3.scene.Spatial; |
|
|
|
import com.jme3.scene.Spatial; |
|
|
|
import com.jme3.scene.shape.Quad; |
|
|
|
import com.jme3.scene.shape.Quad; |
|
|
|
import com.jme3.util.TempVars; |
|
|
|
|
|
|
|
import org.openide.loaders.DataObject; |
|
|
|
import org.openide.loaders.DataObject; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -42,25 +41,24 @@ public class MoveTool extends SceneEditTool { |
|
|
|
private Vector3f offset; |
|
|
|
private Vector3f offset; |
|
|
|
private Node plane; |
|
|
|
private Node plane; |
|
|
|
Material pinkMat; |
|
|
|
Material pinkMat; |
|
|
|
private final Quaternion XY = new Quaternion().fromAngleAxis(0, new Vector3f(1,0,0)); |
|
|
|
private final Quaternion XY = new Quaternion().fromAngleAxis(0, new Vector3f(1, 0, 0)); |
|
|
|
private final Quaternion YZ = new Quaternion().fromAngleAxis(-FastMath.PI/2, new Vector3f(0,1,0)); |
|
|
|
private final Quaternion YZ = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0)); |
|
|
|
private final Quaternion XZ = new Quaternion().fromAngleAxis(FastMath.PI/2, new Vector3f(1,0,0)); |
|
|
|
private final Quaternion XZ = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0)); |
|
|
|
|
|
|
|
|
|
|
|
//temp vars
|
|
|
|
//temp vars
|
|
|
|
private Quaternion rot = new Quaternion(); |
|
|
|
private Quaternion rot = new Quaternion(); |
|
|
|
private Vector3f newPos = new Vector3f(); |
|
|
|
private Vector3f newPos = new Vector3f(); |
|
|
|
|
|
|
|
|
|
|
|
public MoveTool() { |
|
|
|
public MoveTool() { |
|
|
|
axisPickType = AxisMarkerPickType.axisAndPlane; |
|
|
|
axisPickType = AxisMarkerPickType.axisAndPlane; |
|
|
|
setOverrideCameraControl(true); |
|
|
|
setOverrideCameraControl(true); |
|
|
|
|
|
|
|
|
|
|
|
float size = 1000; |
|
|
|
float size = 1000; |
|
|
|
Geometry g = new Geometry("plane", new Quad(size, size)); |
|
|
|
Geometry g = new Geometry("plane", new Quad(size, size)); |
|
|
|
g.setLocalTranslation(-size/2, -size/2, 0); |
|
|
|
g.setLocalTranslation(-size / 2, -size / 2, 0); |
|
|
|
plane = new Node(); |
|
|
|
plane = new Node(); |
|
|
|
plane.attachChild(g); |
|
|
|
plane.attachChild(g); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -69,10 +67,6 @@ public class MoveTool extends SceneEditTool { |
|
|
|
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) { |
|
|
@ -88,15 +82,13 @@ public class MoveTool extends SceneEditTool { |
|
|
|
|
|
|
|
|
|
|
|
@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 (pickedPlane == null) { |
|
|
|
highlightAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
highlightAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
} |
|
|
|
} else { |
|
|
|
else { |
|
|
|
|
|
|
|
pickedPlane = null; |
|
|
|
pickedPlane = null; |
|
|
|
offset = null; |
|
|
|
offset = null; |
|
|
|
} |
|
|
|
} |
|
|
@ -114,60 +106,63 @@ public class MoveTool extends SceneEditTool { |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (toolController.getSelectedSpatial() == null) |
|
|
|
if (toolController.getSelectedSpatial() == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pickedPlane == null) { |
|
|
|
if (pickedPlane == null) { |
|
|
|
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); |
|
|
|
if (pickedPlane == null) |
|
|
|
if (pickedPlane == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
startLoc = toolController.getSelectedSpatial().getLocalTranslation().clone(); |
|
|
|
startLoc = toolController.getSelectedSpatial().getLocalTranslation().clone(); |
|
|
|
rot = rot.set(toolController.getSelectedSpatial().getWorldRotation()); |
|
|
|
rot = rot.set(toolController.getSelectedSpatial().getWorldRotation()); |
|
|
|
if (pickedPlane.equals(new Vector3f(1,1,0))) |
|
|
|
if (pickedPlane.equals(new Vector3f(1, 1, 0))) { |
|
|
|
plane.setLocalRotation(rot.multLocal(XY)); |
|
|
|
plane.setLocalRotation(rot.multLocal(XY)); |
|
|
|
else if (pickedPlane.equals(new Vector3f(1,0,1))) |
|
|
|
} else if (pickedPlane.equals(new Vector3f(1, 0, 1))) { |
|
|
|
plane.setLocalRotation(rot.multLocal(XZ)); |
|
|
|
plane.setLocalRotation(rot.multLocal(XZ)); |
|
|
|
else if (pickedPlane.equals(new Vector3f(0,1,1))) |
|
|
|
} else if (pickedPlane.equals(new Vector3f(0, 1, 1))) { |
|
|
|
plane.setLocalRotation(rot.multLocal(YZ)); |
|
|
|
plane.setLocalRotation(rot.multLocal(YZ)); |
|
|
|
|
|
|
|
} |
|
|
|
plane.setLocalTranslation(startLoc); |
|
|
|
plane.setLocalTranslation(startLoc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Vector3f planeHit = pickWorldLocation(camera, screenCoord, plane, null); |
|
|
|
Vector3f planeHit = pickWorldLocation(camera, screenCoord, plane, null); |
|
|
|
if (planeHit == null){ |
|
|
|
if (planeHit == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Spatial selected = toolController.getSelectedSpatial(); |
|
|
|
Spatial selected = toolController.getSelectedSpatial(); |
|
|
|
Spatial parent = selected.getParent(); |
|
|
|
Spatial parent = selected.getParent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( parent == null ){ |
|
|
|
if (parent == null) { |
|
|
|
//we are moving the root node, move is computed in local translation
|
|
|
|
//we are moving the root node, move is computed in local translation
|
|
|
|
if (offset == null){ |
|
|
|
if (offset == null) { |
|
|
|
offset = planeHit.subtract(startLoc); // get the offset when we start so it doesn't jump
|
|
|
|
offset = planeHit.subtract(startLoc); // get the offset when we start so it doesn't jump
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
newPos.set(planeHit).subtractLocal(offset); |
|
|
|
newPos.set(planeHit).subtractLocal(offset); |
|
|
|
lastLoc.set(newPos); |
|
|
|
lastLoc.set(newPos); |
|
|
|
selected.setLocalTranslation(newPos); |
|
|
|
selected.setLocalTranslation(newPos); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
//offset in world space
|
|
|
|
//offset in world space
|
|
|
|
if (offset == null){ |
|
|
|
if (offset == null) { |
|
|
|
offset = planeHit.subtract(selected.getWorldTranslation()); // get the offset when we start so it doesn't jump
|
|
|
|
offset = planeHit.subtract(selected.getWorldTranslation()); // get the offset when we start so it doesn't jump
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
newPos = planeHit.subtract(offset); |
|
|
|
newPos = planeHit.subtract(offset); |
|
|
|
|
|
|
|
|
|
|
|
//computing the inverse world transform to get the new localtranslation
|
|
|
|
//computing the inverse world transform to get the new localtranslation
|
|
|
|
newPos.subtractLocal(selected.getParent().getWorldTranslation()); |
|
|
|
newPos.subtractLocal(selected.getParent().getWorldTranslation()); |
|
|
|
newPos = selected.getParent().getWorldRotation().inverse().normalizeLocal().multLocal(newPos); |
|
|
|
newPos = selected.getParent().getWorldRotation().inverse().normalizeLocal().multLocal(newPos); |
|
|
|
newPos.divideLocal(selected.getWorldScale()); |
|
|
|
newPos.divideLocal(selected.getWorldScale()); |
|
|
|
selected.setLocalTranslation(newPos); |
|
|
|
selected.setLocalTranslation(newPos); |
|
|
|
lastLoc.set(newPos); |
|
|
|
lastLoc.set(newPos); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RigidBodyControl control = toolController.getSelectedSpatial().getControl(RigidBodyControl.class); |
|
|
|
RigidBodyControl control = toolController.getSelectedSpatial().getControl(RigidBodyControl.class); |
|
|
|
if (control != null) { |
|
|
|
if (control != null) { |
|
|
|
control.setPhysicsLocation(toolController.getSelectedSpatial().getWorldTranslation()); |
|
|
|
control.setPhysicsLocation(toolController.getSelectedSpatial().getWorldTranslation()); |
|
|
@ -177,26 +172,25 @@ public class MoveTool extends SceneEditTool { |
|
|
|
character.setPhysicsLocation(toolController.getSelectedSpatial().getWorldTranslation()); |
|
|
|
character.setPhysicsLocation(toolController.getSelectedSpatial().getWorldTranslation()); |
|
|
|
} |
|
|
|
} |
|
|
|
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 MoveUndo extends AbstractUndoableSceneEdit { |
|
|
|
private class MoveUndo extends AbstractUndoableSceneEdit { |
|
|
|
|
|
|
|
|
|
|
|
private Spatial spatial; |
|
|
|
private Spatial spatial; |
|
|
|
private Vector3f before,after; |
|
|
|
private Vector3f before, after; |
|
|
|
|
|
|
|
|
|
|
|
MoveUndo(Spatial spatial, Vector3f before, Vector3f after) { |
|
|
|
MoveUndo(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.setLocalTranslation(before); |
|
|
|
spatial.setLocalTranslation(before); |
|
|
|