- Removed grey selection. Select tool now use the blue selection managed by the toolController.
- Changed move plane gizmo to only appear when the move tool is activated
- Optimized moveTool to not instanciate new vectors on every frame.
- Changed particle emitter selection shape to bounding box

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7995 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent 02c7ab94a0
commit da55beac3d
  1. 65
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerToolController.java
  2. 1
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form
  3. 3
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java
  4. 367
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java
  5. 26
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/MoveTool.java
  6. 8
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/SelectTool.java

@ -9,7 +9,6 @@ import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.scene.controller.SceneToolController; import com.jme3.gde.core.scene.controller.SceneToolController;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
@ -27,10 +26,9 @@ public class SceneComposerToolController extends SceneToolController {
private SceneEditTool editTool; private SceneEditTool editTool;
private SceneEditorController editorController; private SceneEditorController editorController;
private ComposerCameraController cameraController; private ComposerCameraController cameraController;
private Camera overlayCam;
private ViewPort overlayView; private ViewPort overlayView;
private Node onTopToolsNode; private Node onTopToolsNode;
public SceneComposerToolController(Node toolsNode, AssetManager manager, JmeNode rootNode) { public SceneComposerToolController(Node toolsNode, AssetManager manager, JmeNode rootNode) {
super(toolsNode, manager); super(toolsNode, manager);
this.rootNode = rootNode; this.rootNode = rootNode;
@ -46,14 +44,14 @@ public class SceneComposerToolController extends SceneToolController {
public void setCameraController(ComposerCameraController cameraController) { public void setCameraController(ComposerCameraController cameraController) {
this.cameraController = cameraController; this.cameraController = cameraController;
// a node in a viewport that will always render on top // a node in a viewport that will always render on top
onTopToolsNode = new Node("OverlayNode"); onTopToolsNode = new Node("OverlayNode");
overlayView = SceneApplication.getApplication().getRenderManager().createMainView("Overlay", this.cameraController.getCamera()); overlayView = SceneApplication.getApplication().getRenderManager().createMainView("Overlay", this.cameraController.getCamera());
overlayView.setClearFlags(false, true, false); overlayView.setClearFlags(false, true, false);
overlayView.attachScene( onTopToolsNode ); overlayView.attachScene(onTopToolsNode);
} }
@Override @Override
public void cleanup() { public void cleanup() {
super.cleanup(); super.cleanup();
@ -62,7 +60,7 @@ public class SceneComposerToolController extends SceneToolController {
editorController = null; editorController = null;
onTopToolsNode.detachAllChildren(); onTopToolsNode.detachAllChildren();
} }
@Override @Override
public void update(float tpf) { public void update(float tpf) {
super.update(tpf); super.update(tpf);
@ -70,30 +68,32 @@ public class SceneComposerToolController extends SceneToolController {
onTopToolsNode.updateLogicalState(tpf); onTopToolsNode.updateLogicalState(tpf);
onTopToolsNode.updateGeometricState(); onTopToolsNode.updateGeometricState();
} }
if (editTool != null) if (editTool != null) {
editTool.updateToolsTransformation(selected); editTool.updateToolsTransformation();
}
} }
@Override @Override
public void render(RenderManager rm) { public void render(RenderManager rm) {
super.render(rm); super.render(rm);
} }
public boolean isEditToolEnabled() { public boolean isEditToolEnabled() {
return editTool != null; return editTool != null;
} }
/** /**
* If the current tool overrides camera zoom/pan controls * If the current tool overrides camera zoom/pan controls
*/ */
public boolean isOverrideCameraControl() { public boolean isOverrideCameraControl() {
if (editTool != null) if (editTool != null) {
return editTool.isOverrideCameraControl(); return editTool.isOverrideCameraControl();
else } else {
return false; return false;
}
} }
/** /**
* Scene composer edit tool activated. Pass in null to remove tools. * Scene composer edit tool activated. Pass in null to remove tools.
* *
@ -101,77 +101,80 @@ public class SceneComposerToolController extends SceneToolController {
*/ */
public void showEditTool(final SceneEditTool sceneEditTool) { public void showEditTool(final SceneEditTool sceneEditTool) {
SceneApplication.getApplication().enqueue(new Callable<Object>() { SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception { public Object call() throws Exception {
doEnableEditTool(sceneEditTool); doEnableEditTool(sceneEditTool);
return null; return null;
} }
}); });
} }
private void doEnableEditTool(SceneEditTool sceneEditTool) { private void doEnableEditTool(SceneEditTool sceneEditTool) {
if (editTool != null) if (editTool != null) {
editTool.hideMarker(); editTool.hideMarker();
}
editTool = sceneEditTool; editTool = sceneEditTool;
editTool.activate(manager, toolsNode, onTopToolsNode, selected, this); editTool.activate(manager, toolsNode, onTopToolsNode, selected, this);
} }
public void selectedSpatialTransformed() { public void selectedSpatialTransformed() {
if (editTool != null) { if (editTool != null) {
SceneApplication.getApplication().enqueue(new Callable<Object>() { SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception { public Object call() throws Exception {
editTool.updateToolsTransformation(selected); editTool.updateToolsTransformation();
return null; return null;
} }
}); });
} }
} }
public void setSelected(Spatial selected) { public void setSelected(Spatial selected) {
this.selected = selected; this.selected = selected;
} }
public void setNeedsSave(boolean needsSave) { public void setNeedsSave(boolean needsSave) {
editorController.setNeedsSave(needsSave); editorController.setNeedsSave(needsSave);
} }
/** /**
* Primary button activated, send command to the tool * Primary button activated, send command to the tool
* for appropriate action. * for appropriate action.
*/ */
public void doEditToolActivatedPrimary(Vector2f mouseLoc, boolean pressed, Camera camera) { public void doEditToolActivatedPrimary(Vector2f mouseLoc, boolean pressed, Camera camera) {
if (editTool != null){ if (editTool != null) {
editTool.setCamera(camera); editTool.setCamera(camera);
editTool.actionPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject()); editTool.actionPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} }
} }
/** /**
* Secondary button activated, send command to the tool * Secondary button activated, send command to the tool
* for appropriate action. * for appropriate action.
*/ */
public void doEditToolActivatedSecondary(Vector2f mouseLoc, boolean pressed, Camera camera) { public void doEditToolActivatedSecondary(Vector2f mouseLoc, boolean pressed, Camera camera) {
if (editTool != null){ if (editTool != null) {
editTool.setCamera(camera); editTool.setCamera(camera);
editTool.actionSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject()); editTool.actionSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} }
} }
public void doEditToolMoved(Vector2f mouseLoc, Camera camera) { public void doEditToolMoved(Vector2f mouseLoc, Camera camera) {
if (editTool != null){ if (editTool != null) {
editTool.setCamera(camera); editTool.setCamera(camera);
editTool.mouseMoved(mouseLoc); editTool.mouseMoved(mouseLoc);
} }
} }
public void doEditToolDraggedPrimary(Vector2f mouseLoc, boolean pressed, Camera camera) { public void doEditToolDraggedPrimary(Vector2f mouseLoc, boolean pressed, Camera camera) {
if (editTool != null) { if (editTool != null) {
editTool.setCamera(camera); editTool.setCamera(camera);
editTool.draggedPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject()); editTool.draggedPrimary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} }
} }
public void doEditToolDraggedSecondary(Vector2f mouseLoc, boolean pressed, Camera camera) { public void doEditToolDraggedSecondary(Vector2f mouseLoc, boolean pressed, Camera camera) {
if (editTool != null){ if (editTool != null) {
editTool.setCamera(camera); editTool.setCamera(camera);
editTool.draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject()); editTool.draggedSecondary(mouseLoc, pressed, rootNode, editorController.getCurrentDataObject());
} }

@ -321,6 +321,7 @@
</Component> </Component>
<Component class="javax.swing.JToggleButton" name="showSelectionToggleButton"> <Component class="javax.swing.JToggleButton" name="showSelectionToggleButton">
<Properties> <Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.showSelectionToggleButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.showSelectionToggleButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>

@ -263,6 +263,7 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.jLabel3.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.jLabel3.text")); // NOI18N
jToolBar1.add(jLabel3); jToolBar1.add(jLabel3);
showSelectionToggleButton.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(showSelectionToggleButton, org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.showSelectionToggleButton.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(showSelectionToggleButton, org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.showSelectionToggleButton.text")); // NOI18N
showSelectionToggleButton.setToolTipText(org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.showSelectionToggleButton.toolTipText")); // NOI18N showSelectionToggleButton.setToolTipText(org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.showSelectionToggleButton.toolTipText")); // NOI18N
showSelectionToggleButton.setFocusable(false); showSelectionToggleButton.setFocusable(false);
@ -956,6 +957,7 @@ private void emitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
toolController.cleanup(); toolController.cleanup();
} }
toolController = new SceneComposerToolController(currentRequest.getToolNode(), currentRequest.getManager(), request.getJmeNode()); toolController = new SceneComposerToolController(currentRequest.getToolNode(), currentRequest.getManager(), request.getJmeNode());
camController = new ComposerCameraController(SceneApplication.getApplication().getCamera(), request.getJmeNode()); camController = new ComposerCameraController(SceneApplication.getApplication().getCamera(), request.getJmeNode());
toolController.setEditorController(editorController); toolController.setEditorController(editorController);
camController.setToolController(toolController); camController.setToolController(toolController);
@ -965,6 +967,7 @@ private void emitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
toolController.setCameraController(camController); toolController.setCameraController(camController);
SelectTool tool = new SelectTool(); SelectTool tool = new SelectTool();
toolController.showEditTool(tool); toolController.showEditTool(tool);
toolController.setShowSelection(true);
}/* else { }/* else {
SceneApplication.getApplication().removeSceneListener(this); SceneApplication.getApplication().removeSceneListener(this);
currentRequest = null; currentRequest = null;

@ -4,7 +4,6 @@
*/ */
package com.jme3.gde.scenecomposer; package com.jme3.gde.scenecomposer;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingBox;
import com.jme3.bounding.BoundingVolume; import com.jme3.bounding.BoundingVolume;
@ -49,27 +48,31 @@ import org.openide.util.Lookup;
* @author Brent Owens * @author Brent Owens
*/ */
public abstract class SceneEditTool { public abstract class SceneEditTool {
protected static Vector3f ARROW_X = new Vector3f(1, 0, 0);
protected static Vector3f ARROW_Y = new Vector3f(0, 1, 0);
protected static Vector3f ARROW_Z = new Vector3f(0, 0, 1);
protected static Vector3f QUAD_XY = new Vector3f(1, 1, 0);
protected static Vector3f QUAD_XZ = new Vector3f(1, 0, 1);
protected static Vector3f QUAD_YZ = new Vector3f(0, 1, 1);
protected SceneComposerToolController toolController; protected SceneComposerToolController toolController;
protected AssetManager manager; protected AssetManager manager;
protected Camera camera; protected Camera camera;
private boolean overrideCameraControl = false; // if true, you cannot pan/zoom unless you hold SHIFT private boolean overrideCameraControl = false; // if true, you cannot pan/zoom unless you hold SHIFT
// the key to load the tool hint text from the resource bundle // the key to load the tool hint text from the resource bundle
protected String toolHintTextKey = "SceneComposerTopComponent.toolHint.default"; // not used yet protected String toolHintTextKey = "SceneComposerTopComponent.toolHint.default"; // not used yet
protected Spatial selectedSpatial;
protected Spatial selectionShape;
protected Node toolNode; protected Node toolNode;
protected Node onTopToolNode; protected Node onTopToolNode;
protected Node axisMarker; protected Node axisMarker;
protected Material redMat, blueMat, greenMat, yellowMat, cyanMat, magentaMat, orangeMat; protected Material redMat, blueMat, greenMat, yellowMat, cyanMat, magentaMat, orangeMat;
protected Geometry quadXY, quadXZ, quadYZ;
protected enum AxisMarkerPickType {axisOnly, planeOnly, axisAndPlane};
protected enum AxisMarkerPickType {
axisOnly, planeOnly, axisAndPlane
};
protected AxisMarkerPickType axisPickType; protected AxisMarkerPickType axisPickType;
/** /**
* The tool was selected, start showing the marker. * The tool was selected, start showing the marker.
* @param manager * @param manager
@ -78,61 +81,35 @@ public abstract class SceneEditTool {
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) {
this.manager = manager; this.manager = manager;
this.toolController = toolController; this.toolController = toolController;
this.selectedSpatial = selectedSpatial; //this.selectedSpatial = selectedSpatial;
addMarker(toolNode, onTopToolNode); addMarker(toolNode, onTopToolNode);
} }
protected void addMarker(Node toolNode, Node onTopToolNode) { protected void addMarker(Node toolNode, Node onTopToolNode) {
this.toolNode = toolNode; this.toolNode = toolNode;
this.onTopToolNode = onTopToolNode; this.onTopToolNode = onTopToolNode;
if (axisMarker == null) { if (axisMarker == null) {
axisMarker = createAxisMarker(); axisMarker = createAxisMarker();
} }
axisMarker.removeFromParent(); axisMarker.removeFromParent();
this.onTopToolNode.attachChild(axisMarker); this.onTopToolNode.attachChild(axisMarker);
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
// create and add the selection shape
if (selectionShape != null) if (toolController.getSelectionShape() != null) {
selectionShape.removeFromParent(); axisMarker.setLocalTranslation(toolController.getSelectedSpatial().getWorldTranslation());
selectionShape = createSelectionShape(toolNode, selectedSpatial);
if (selectionShape != null) {
setDefaultSelectionShapeColors();
this.toolNode.attachChild(selectionShape);
axisMarker.setLocalTranslation(selectedSpatial.getWorldTranslation());
selectionShape.setLocalTranslation(selectedSpatial.getWorldTranslation());
}
}
protected void replaceSelectionShape(Spatial spatial) {
if (spatial != null) {
if (selectionShape != null)
selectionShape.removeFromParent();
selectedSpatial = spatial;
toolController.setSelected(spatial);
selectionShape = createSelectionShape(toolNode, selectedSpatial);
setDefaultSelectionShapeColors();
toolNode.attachChild(selectionShape);
}
else {
if (selectionShape != null)
selectionShape.removeFromParent();
selectionShape = null;
} }
} }
/** /**
* Remove the marker from it's parent (the tools node) * Remove the marker from it's parent (the tools node)
*/ */
public void hideMarker() { public void hideMarker() {
if (axisMarker != null) if (axisMarker != null) {
axisMarker.removeFromParent(); axisMarker.removeFromParent();
if (selectionShape != null) }
selectionShape.removeFromParent();
} }
public boolean isOverrideCameraControl() { public boolean isOverrideCameraControl() {
@ -142,46 +119,38 @@ public abstract class SceneEditTool {
public void setOverrideCameraControl(boolean overrideCameraControl) { public void setOverrideCameraControl(boolean overrideCameraControl) {
this.overrideCameraControl = overrideCameraControl; this.overrideCameraControl = overrideCameraControl;
} }
/** /**
* Called when the selected spatial has been modified * Called when the selected spatial has been modified
* outside of the tool. * outside of the tool.
*/ */
public void updateToolsTransformation(final Spatial spatial) { public void updateToolsTransformation() {
if (selectionShape == null)
return;
// has anything changed?
if (!selectionShape.getLocalTranslation().equals(spatial.getWorldTranslation()) &&
!selectionShape.getLocalRotation().equals(spatial.getWorldRotation()) &&
!selectionShape.getLocalScale().equals(spatial.getWorldScale()))
return;
// something has updated, so update the tools
selectionShape.setLocalTranslation(spatial.getWorldTranslation());
selectionShape.setLocalRotation(spatial.getWorldRotation());
selectionShape.setLocalScale(selectedSpatial.getWorldScale());
SceneApplication.getApplication().enqueue(new Callable<Object>() { SceneApplication.getApplication().enqueue(new Callable<Object>() {
public Object call() throws Exception { public Object call() throws Exception {
axisMarker.setLocalTranslation(spatial.getWorldTranslation()); if (toolController.getSelectedSpatial() != null) {
axisMarker.setLocalRotation(selectedSpatial.getWorldRotation()); axisMarker.setLocalTranslation(toolController.getSelectedSpatial().getWorldTranslation());
axisMarker.setLocalRotation(toolController.getSelectedSpatial().getWorldRotation());
} else {
axisMarker.setLocalTranslation(Vector3f.ZERO);
axisMarker.setLocalRotation(Quaternion.IDENTITY);
}
return null; return null;
} }
}); });
} }
/** /**
* The primary action for the tool gets activated * The primary action for the tool gets activated
*/ */
public abstract void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject); public abstract void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject);
/** /**
* The secondary action for the tool gets activated * The secondary action for the tool gets activated
*/ */
public abstract void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject); public abstract void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject);
/** /**
* Called when the mouse is moved but not dragged (ie no buttons are pressed) * Called when the mouse is moved but not dragged (ie no buttons are pressed)
*/ */
@ -191,13 +160,13 @@ public abstract class SceneEditTool {
* Called when the mouse is moved while the primary button is down * Called when the mouse is moved while the primary button is down
*/ */
public abstract void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject); public abstract void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject);
/** /**
* Called when the mouse is moved while the secondary button is down * Called when the mouse is moved while the secondary button is down
*/ */
public abstract void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject); public abstract void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject);
/** /**
* Call when an action is performed that requires the scene to be saved * Call when an action is performed that requires the scene to be saved
* and an undo can be performed * and an undo can be performed
* @param undoer your implementation, probably with a begin and end state for undoing * @param undoer your implementation, probably with a begin and end state for undoing
@ -206,8 +175,7 @@ public abstract class SceneEditTool {
Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, undoer); Lookup.getDefault().lookup(SceneUndoRedoManager.class).addEdit(this, undoer);
toolController.setNeedsSave(true); toolController.setNeedsSave(true);
} }
/** /**
* Given the mouse coordinates, pick the geometry that is closest to the camera. * Given the mouse coordinates, pick the geometry that is closest to the camera.
* @param jmeRootNode to pick from * @param jmeRootNode to pick from
@ -215,13 +183,14 @@ public abstract class SceneEditTool {
*/ */
protected Spatial pickWorldSpatial(Camera cam, Vector2f mouseLoc, JmeNode jmeRootNode) { protected Spatial pickWorldSpatial(Camera cam, Vector2f mouseLoc, JmeNode jmeRootNode) {
Node rootNode = jmeRootNode.getLookup().lookup(Node.class); Node rootNode = jmeRootNode.getLookup().lookup(Node.class);
CollisionResult cr = pick(cam, mouseLoc, rootNode); CollisionResult cr = pick(cam, mouseLoc, rootNode);
if (cr != null) if (cr != null) {
return cr.getGeometry(); return cr.getGeometry();
else } else {
return null; return null;
}
} }
/** /**
* Given the mouse coordinate, pick the world location where the mouse intersects * Given the mouse coordinate, pick the world location where the mouse intersects
* a geometry. * a geometry.
@ -232,16 +201,16 @@ public abstract class SceneEditTool {
Node rootNode = jmeRootNode.getLookup().lookup(Node.class); Node rootNode = jmeRootNode.getLookup().lookup(Node.class);
return pickWorldLocation(cam, mouseLoc, rootNode); return pickWorldLocation(cam, mouseLoc, rootNode);
} }
protected Vector3f pickWorldLocation(Camera cam, Vector2f mouseLoc, Node rootNode) { protected Vector3f pickWorldLocation(Camera cam, Vector2f mouseLoc, Node rootNode) {
CollisionResult cr = pick(cam, mouseLoc, rootNode); CollisionResult cr = pick(cam, mouseLoc, rootNode);
if (cr != null) if (cr != null) {
return cr.getContactPoint(); return cr.getContactPoint();
else } else {
return null; return null;
}
} }
/** /**
* Pick a part of the axis marker. The result is a Vector3f that represents * Pick a part of the axis marker. The result is a Vector3f that represents
* what part of the axis was selected. * what part of the axis was selected.
@ -251,48 +220,49 @@ public abstract class SceneEditTool {
* @return null if it did not intersect the marker * @return null if it did not intersect the marker
*/ */
protected Vector3f pickAxisMarker(Camera cam, Vector2f mouseLoc, AxisMarkerPickType pickType) { protected Vector3f pickAxisMarker(Camera cam, Vector2f mouseLoc, AxisMarkerPickType pickType) {
if (axisMarker == null) if (axisMarker == null) {
return null; return null;
}
CollisionResult cr = pick(cam, mouseLoc, axisMarker); CollisionResult cr = pick(cam, mouseLoc, axisMarker);
if (cr == null || cr.getGeometry() == null) if (cr == null || cr.getGeometry() == null) {
return null; return null;
}
if (pickType == AxisMarkerPickType.planeOnly) { if (pickType == AxisMarkerPickType.planeOnly) {
if ("quadXY".equals(cr.getGeometry().getName()) ) { if ("quadXY".equals(cr.getGeometry().getName())) {
return new Vector3f(1,1,0); return QUAD_XY;
} else if ("quadXZ".equals(cr.getGeometry().getName()) ) { } else if ("quadXZ".equals(cr.getGeometry().getName())) {
return new Vector3f(1,0,1); return QUAD_XZ;
} else if ("quadYZ".equals(cr.getGeometry().getName()) ) { } else if ("quadYZ".equals(cr.getGeometry().getName())) {
return new Vector3f(0,1,1); return QUAD_YZ;
} }
} } else if (pickType == AxisMarkerPickType.axisOnly) {
else if (pickType == AxisMarkerPickType.axisOnly) { if ("arrowX".equals(cr.getGeometry().getName())) {
if ("arrowX".equals(cr.getGeometry().getName()) ) { return ARROW_X;
return new Vector3f(1,0,0); } else if ("arrowY".equals(cr.getGeometry().getName())) {
} else if ("arrowY".equals(cr.getGeometry().getName()) ) { return ARROW_Y;
return new Vector3f(0,1,0); } else if ("arrowZ".equals(cr.getGeometry().getName())) {
} else if ("arrowZ".equals(cr.getGeometry().getName()) ) { return ARROW_Z;
return new Vector3f(0,1,0);
} }
} else if (pickType == AxisMarkerPickType.axisAndPlane) { } else if (pickType == AxisMarkerPickType.axisAndPlane) {
if ("arrowX".equals(cr.getGeometry().getName()) ) { if ("arrowX".equals(cr.getGeometry().getName())) {
return new Vector3f(1,0,0); return ARROW_X;
} else if ("arrowY".equals(cr.getGeometry().getName()) ) { } else if ("arrowY".equals(cr.getGeometry().getName())) {
return new Vector3f(0,1,0); return ARROW_Y;
} else if ("arrowZ".equals(cr.getGeometry().getName()) ) { } else if ("arrowZ".equals(cr.getGeometry().getName())) {
return new Vector3f(0,1,0); return ARROW_Z;
} else if ("quadXY".equals(cr.getGeometry().getName()) ) { } else if ("quadXY".equals(cr.getGeometry().getName())) {
return new Vector3f(1,1,0); return QUAD_XY;
} else if ("quadXZ".equals(cr.getGeometry().getName()) ) { } else if ("quadXZ".equals(cr.getGeometry().getName())) {
return new Vector3f(1,0,1); return QUAD_XZ;
} else if ("quadYZ".equals(cr.getGeometry().getName()) ) { } else if ("quadYZ".equals(cr.getGeometry().getName())) {
return new Vector3f(0,1,1); return QUAD_YZ;
} }
} }
return null; return null;
} }
private CollisionResult pick(Camera cam, Vector2f mouseLoc, Node node) { private CollisionResult pick(Camera cam, Vector2f mouseLoc, Node node) {
CollisionResults results = new CollisionResults(); CollisionResults results = new CollisionResults();
Ray ray = new Ray(); Ray ray = new Ray();
@ -305,7 +275,7 @@ public abstract class SceneEditTool {
CollisionResult result = results.getClosestCollision(); CollisionResult result = results.getClosestCollision();
return result; return result;
} }
/** /**
* Show what axis or plane the mouse is currently over and will affect. * Show what axis or plane the mouse is currently over and will affect.
* @param axisMarkerPickType * @param axisMarkerPickType
@ -313,34 +283,36 @@ public abstract class SceneEditTool {
protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType) { protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType) {
setDefaultAxisMarkerColors(); setDefaultAxisMarkerColors();
Vector3f picked = pickAxisMarker(camera, screenCoord, axisPickType); Vector3f picked = pickAxisMarker(camera, screenCoord, axisPickType);
if (picked == null) if (picked == null) {
return; return;
}
if (picked.equals(new Vector3f(1,0,0)))
if (picked == ARROW_X) {
axisMarker.getChild("arrowX").setMaterial(orangeMat); axisMarker.getChild("arrowX").setMaterial(orangeMat);
else if (picked.equals(new Vector3f(0,1,0))) } else if (picked == ARROW_Y) {
axisMarker.getChild("arrowY").setMaterial(orangeMat); axisMarker.getChild("arrowY").setMaterial(orangeMat);
else if (picked.equals(new Vector3f(0,0,1))) } else if (picked == ARROW_Z) {
axisMarker.getChild("arrowZ").setMaterial(orangeMat); axisMarker.getChild("arrowZ").setMaterial(orangeMat);
else if (picked.equals(new Vector3f(1,1,0))) } else if (picked == QUAD_XY) {
axisMarker.getChild("quadXY").setMaterial(orangeMat); axisMarker.getChild("quadXY").setMaterial(orangeMat);
else if (picked.equals(new Vector3f(1,0,1))) } else if (picked == QUAD_XZ) {
axisMarker.getChild("quadXZ").setMaterial(orangeMat); axisMarker.getChild("quadXZ").setMaterial(orangeMat);
else if (picked.equals(new Vector3f(0,1,1))) } else if (picked == QUAD_YZ) {
axisMarker.getChild("quadYZ").setMaterial(orangeMat); axisMarker.getChild("quadYZ").setMaterial(orangeMat);
}
} }
/** /**
* Create the axis marker that is selectable * Create the axis marker that is selectable
*/ */
protected Node createAxisMarker() { protected Node createAxisMarker() {
float size = 2; float size = 2;
float arrowSize = size; float arrowSize = size;
float planeSize = size*0.7f; float planeSize = size * 0.7f;
Quaternion YAW090 = new Quaternion().fromAngleAxis(-FastMath.PI/2, new Vector3f(0,1,0)); Quaternion YAW090 = new Quaternion().fromAngleAxis(-FastMath.PI / 2, new Vector3f(0, 1, 0));
Quaternion PITCH090 = new Quaternion().fromAngleAxis(FastMath.PI/2, new Vector3f(1,0,0)); Quaternion PITCH090 = new Quaternion().fromAngleAxis(FastMath.PI / 2, new Vector3f(1, 0, 0));
redMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); redMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
redMat.getAdditionalRenderState().setWireframe(true); redMat.getAdditionalRenderState().setWireframe(true);
redMat.setColor("Color", ColorRGBA.Red); redMat.setColor("Color", ColorRGBA.Red);
@ -371,130 +343,60 @@ public abstract class SceneEditTool {
magentaMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); magentaMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
magentaMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); magentaMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
//magentaMat.getAdditionalRenderState().setDepthTest(false); //magentaMat.getAdditionalRenderState().setDepthTest(false);
orangeMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md"); orangeMat = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
orangeMat.getAdditionalRenderState().setWireframe(false); orangeMat.getAdditionalRenderState().setWireframe(false);
orangeMat.setColor("Color", new ColorRGBA(251f/255f, 130f/255f, 0f, 0.4f)); orangeMat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.4f));
orangeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); orangeMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
orangeMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); orangeMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
Node axis = new Node(); Node axis = new Node();
// create arrows // create arrows
Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize,0,0))); Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0)));
Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0,arrowSize,0))); Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0)));
Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0,0,arrowSize))); Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize)));
axis.attachChild(arrowX); axis.attachChild(arrowX);
axis.attachChild(arrowY); axis.attachChild(arrowY);
axis.attachChild(arrowZ); axis.attachChild(arrowZ);
// create planes // create planes
Geometry quadXY = new Geometry("quadXY", new Quad(planeSize, planeSize) ); quadXY = new Geometry("quadXY", new Quad(planeSize, planeSize));
Geometry quadXZ = new Geometry("quadXZ", new Quad(planeSize, planeSize) ); quadXZ = new Geometry("quadXZ", new Quad(planeSize, planeSize));
quadXZ.setLocalRotation(PITCH090); quadXZ.setLocalRotation(PITCH090);
Geometry quadYZ = new Geometry("quadYZ", new Quad(planeSize, planeSize) ); quadYZ = new Geometry("quadYZ", new Quad(planeSize, planeSize));
quadYZ.setLocalRotation(YAW090); quadYZ.setLocalRotation(YAW090);
axis.attachChild(quadXY); // axis.attachChild(quadXY);
axis.attachChild(quadXZ); // axis.attachChild(quadXZ);
axis.attachChild(quadYZ); // axis.attachChild(quadYZ);
axis.setModelBound(new BoundingBox()); axis.setModelBound(new BoundingBox());
return axis; return axis;
} }
protected void setDefaultAxisMarkerColors() {
axisMarker.getChild("arrowX").setMaterial(redMat);
axisMarker.getChild("arrowY").setMaterial(blueMat);
axisMarker.getChild("arrowZ").setMaterial(greenMat);
axisMarker.getChild("quadXY").setMaterial(yellowMat);
axisMarker.getChild("quadXZ").setMaterial(magentaMat);
axisMarker.getChild("quadYZ").setMaterial(cyanMat);
}
protected void setDefaultSelectionShapeColors() {
if (selectionShape != null) {
Material mat = new Material(SceneApplication.getApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.getAdditionalRenderState().setWireframe(true);
mat.setColor("Color", new ColorRGBA(0.8f,0.8f,0.8f,0.3f));
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
selectionShape.setMaterial(mat);
}
}
protected Spatial createSelectionShape(Node toolNode, Spatial spat) { protected void displayPlanes() {
if (spat == null) axisMarker.attachChild(quadXY);
return null; axisMarker.attachChild(quadXZ);
if (selectionShape != null) { axisMarker.attachChild(quadYZ);
selectionShape.removeFromParent();
selectionShape = null;
}
if (spat instanceof Geometry) {
return getGeometrySelection(toolNode, (Geometry) spat);
} else if (spat.getControl(PhysicsControl.class) != null) {
return getPhysicsSelection(toolNode, spat);
} else {
return getBoxSelection(toolNode, spat);
}
}
protected Geometry getGeometrySelection(Node toolNode, Geometry geom) {
Mesh mesh = geom.getMesh();
if (mesh == null) {
return null;
}
Geometry selectionGeometry = new Geometry("selection_geometry_sceneviewer", mesh);
selectionGeometry.setLocalTransform(geom.getWorldTransform());
toolNode.attachChild(selectionGeometry);
return selectionGeometry;
} }
protected Geometry getBoxSelection(Node toolNode, Spatial geom) { protected void hidePlanes() {
BoundingVolume bound = geom.getWorldBound(); quadXY.removeFromParent();
if (bound instanceof BoundingBox) { quadXZ.removeFromParent();
BoundingBox bbox = (BoundingBox) bound; quadYZ.removeFromParent();
Vector3f extent = new Vector3f();
bbox.getExtent(extent);
WireBox wireBox=new WireBox();
wireBox.fromBoundingBox(bbox);
Geometry selectionGeometry = new Geometry("selection_geometry_sceneviewer", wireBox);
selectionGeometry.setLocalTransform(geom.getWorldTransform());
toolNode.attachChild(selectionGeometry);
return selectionGeometry;
}
return null;
}
protected Spatial getPhysicsSelection(Node toolNode, Spatial geom) {
PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class);
if (control == null) {
control = geom.getControl(VehicleControl.class);
}
if (control == null) {
control = geom.getControl(GhostControl.class);
}
if (control == null) {
control = geom.getControl(CharacterControl.class);
}
if (control == null) {
return null;
}
Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape());
if (selectionGeometry != null) {
selectionGeometry.setLocalTransform(geom.getWorldTransform());
toolNode.attachChild(selectionGeometry);
return selectionGeometry;
}
return null;
} }
protected void detachSelectionShape() { protected void setDefaultAxisMarkerColors() {
if (selectionShape != null) { axisMarker.getChild("arrowX").setMaterial(redMat);
selectionShape.removeFromParent(); axisMarker.getChild("arrowY").setMaterial(blueMat);
selectionShape = null; axisMarker.getChild("arrowZ").setMaterial(greenMat);
} quadXY.setMaterial(yellowMat);
quadXZ.setMaterial(magentaMat);
quadYZ.setMaterial(cyanMat);
} }
public Camera getCamera() { public Camera getCamera() {
return camera; return camera;
} }
@ -502,7 +404,4 @@ public abstract class SceneEditTool {
public void setCamera(Camera camera) { public void setCamera(Camera camera) {
this.camera = camera; this.camera = camera;
} }
} }

@ -4,8 +4,10 @@
*/ */
package com.jme3.gde.scenecomposer.tools; package com.jme3.gde.scenecomposer.tools;
import com.jme3.asset.AssetManager;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit;
import com.jme3.gde.scenecomposer.SceneComposerToolController;
import com.jme3.gde.scenecomposer.SceneEditTool; import com.jme3.gde.scenecomposer.SceneEditTool;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
@ -42,7 +44,7 @@ public class MoveTool extends SceneEditTool {
public MoveTool() { public MoveTool() {
axisPickType = AxisMarkerPickType.planeOnly; axisPickType = AxisMarkerPickType.axisAndPlane;
setOverrideCameraControl(true); setOverrideCameraControl(true);
float size = 1000; float size = 1000;
@ -50,8 +52,18 @@ public class MoveTool extends SceneEditTool {
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
public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) {
super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController);
displayPlanes();
}
@Override @Override
@ -61,7 +73,7 @@ public class MoveTool extends SceneEditTool {
pickedPlane = null; // mouse released, reset selection pickedPlane = null; // mouse released, reset selection
offset = null; offset = null;
if (wasDragging) { if (wasDragging) {
actionPerformed(new MoveUndo(selectedSpatial, startLoc, lastLoc)); actionPerformed(new MoveUndo(toolController.getSelectedSpatial(), startLoc, lastLoc));
wasDragging = false; wasDragging = false;
} }
} }
@ -90,19 +102,19 @@ public class MoveTool extends SceneEditTool {
pickedPlane = null; // mouse released, reset selection pickedPlane = null; // mouse released, reset selection
offset = null; offset = null;
if (wasDragging) { if (wasDragging) {
actionPerformed(new MoveUndo(selectedSpatial, startLoc, lastLoc)); actionPerformed(new MoveUndo(toolController.getSelectedSpatial(), startLoc, lastLoc));
wasDragging = false; wasDragging = false;
} }
return; return;
} }
if (selectedSpatial == 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 = selectedSpatial.getLocalTranslation().clone(); startLoc = toolController.getSelectedSpatial().getLocalTranslation().clone();
if (pickedPlane.equals(new Vector3f(1,1,0))) if (pickedPlane.equals(new Vector3f(1,1,0)))
plane.setLocalRotation(XY); plane.setLocalRotation(XY);
@ -122,8 +134,8 @@ public class MoveTool extends SceneEditTool {
Vector3f newPos = planeHit.subtract(offset); Vector3f newPos = planeHit.subtract(offset);
lastLoc = newPos; lastLoc = newPos;
selectedSpatial.setLocalTranslation(newPos); toolController.getSelectedSpatial().setLocalTranslation(newPos);
updateToolsTransformation(selectedSpatial); updateToolsTransformation();
wasDragging = true; wasDragging = true;
} }

@ -5,6 +5,7 @@
package com.jme3.gde.scenecomposer.tools; package com.jme3.gde.scenecomposer.tools;
import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent;
import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
import com.jme3.gde.scenecomposer.SceneEditTool; import com.jme3.gde.scenecomposer.SceneEditTool;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
@ -31,16 +32,19 @@ public class SelectTool extends SceneEditTool {
public void run() { public void run() {
if (result != null) { if (result != null) {
// System.out.println(rootNode.getChild(result).getName());
// SceneExplorerTopComponent.findInstance().setActivatedNodes(new org.openide.nodes.Node[]{rootNode.getChild(result)});
SceneApplication.getApplication().setCurrentFileNode(rootNode.getChild(result)); SceneApplication.getApplication().setCurrentFileNode(rootNode.getChild(result));
} else { } else {
// SceneExplorerTopComponent.findInstance().setActivatedNodes(new org.openide.nodes.Node[]{rootNode});
SceneApplication.getApplication().setCurrentFileNode(rootNode); SceneApplication.getApplication().setCurrentFileNode(rootNode);
} }
} }
}); });
if (result != null) { if (result != null) {
replaceSelectionShape(result); updateToolsTransformation();
updateToolsTransformation(selectedSpatial);
} }
} }

Loading…
Cancel
Save