Browse Source

some fixes to the SDK manipulation tool

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9460 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
bre..ns 13 years ago
parent
commit
0a03b37ff4

+ 31 - 12
jme3-core/src/com/jme3/gde/core/scene/controller/SceneToolController.java

@@ -51,7 +51,6 @@ public class SceneToolController implements AppState {
     protected Spatial selectionShape;
     protected AssetManager manager;
     protected Material blueMat;
-    protected Vector3f selctionShapeOffset = new Vector3f(0, 0, 0);
 
     public SceneToolController(AssetManager manager) {
         this.toolsNode = new Node("ToolsNode");
@@ -143,6 +142,22 @@ public class SceneToolController implements AppState {
         selected = spat;
     }
 
+    public void rebuildSelectionBox() {
+        if (SceneApplication.getApplication().isAwt()) {
+            SceneApplication.getApplication().enqueue(new Callable<Object>() {
+                public Object call() throws Exception {
+                    doUpdateSelection(selected);
+                    return null;
+                }
+            });
+        }
+        else {
+            if (selected != null) {
+                attachSelectionShape(selected);
+            }
+        }
+    }
+    
     public void setCursorLocation(final Vector3f location) {
         SceneApplication.getApplication().enqueue(new Callable<Object>() {
 
@@ -178,7 +193,6 @@ public class SceneToolController implements AppState {
             selectionShape.removeFromParent();
             selectionShape = null;
         }
-        selctionShapeOffset.set(Vector3f.ZERO);
         if (spat instanceof ParticleEmitter) {
             attachBoxSelection(spat);
 
@@ -232,16 +246,23 @@ public class SceneToolController implements AppState {
             bbox.getExtent(extent);
             WireBox wireBox = new WireBox();
             wireBox.fromBoundingBox(bbox);
-            selctionShapeOffset.set(bbox.getCenter()).subtractLocal(geom.getWorldTranslation());
             final Geometry selectionGeometry = new Geometry("selection_geometry_sceneviewer", wireBox);
             selectionGeometry.setMaterial(blueMat);
-            selectionGeometry.setLocalTransform(geom.getWorldTransform());
-            selectionGeometry.setLocalTranslation(bbox.getCenter());
-            selectionShape = selectionGeometry;
+            selectionGeometry.setLocalTranslation( bbox.getCenter().subtract(geom.getWorldTranslation()) );
+            //Vector3f scale = new Vector3f(1,1,1);
+            //scale.x = 1/geom.getWorldScale().x;
+            //scale.y = 1/geom.getWorldScale().y;
+            //scale.z = 1/geom.getWorldScale().z;
+            selectionShape = new Node("SelectionParent");
+            ((Node)selectionShape).attachChild(selectionGeometry);
+            //selectionShape.setLocalTransform(geom.getWorldTransform());
+            //selectionShape.setLocalTranslation(geom.getWorldTranslation());
+            //selectionGeometry.setLocalScale(scale);
+            
             SceneApplication.getApplication().enqueue(new Callable<Object>() {
 
                 public Object call() throws Exception {
-                    toolsNode.attachChild(selectionGeometry);
+                    toolsNode.attachChild(selectionShape);
                     return null;
                 }
             });
@@ -394,12 +415,10 @@ public class SceneToolController implements AppState {
         if (selected == null || selectionShape == null) {
             return;
         }
-        TempVars vars = TempVars.get();
-        vars.vect1.set(selctionShapeOffset);
-        selectionShape.setLocalTranslation(vars.vect1.addLocal(selected.getWorldTranslation()));
-        vars.release();
+        
+        selectionShape.setLocalTranslation(selected.getWorldTranslation());
         selectionShape.setLocalRotation(selected.getWorldRotation());
-        selectionShape.setLocalScale(selected.getWorldScale());
+        //selectionShape.setLocalScale(selected.getWorldScale());
 
     }
 

+ 4 - 0
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java

@@ -22,9 +22,13 @@ import com.jme3.gde.scenecomposer.tools.MoveTool;
 import com.jme3.gde.scenecomposer.tools.RotateTool;
 import com.jme3.gde.scenecomposer.tools.ScaleTool;
 import com.jme3.gde.scenecomposer.tools.SelectTool;
+import com.jme3.input.awt.AwtKeyInput;
+import com.jme3.input.event.KeyInputEvent;
 import com.jme3.math.Vector3f;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.concurrent.Callable;

+ 13 - 2
jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/SelectTool.java

@@ -253,7 +253,7 @@ public class SelectTool extends SceneEditTool {
     
     private boolean checkCommandKey(KeyInputEvent kie) {
         if (kie.getKeyCode() == KeyInput.KEY_D) {
-            if (ctrlDown && shiftDown) {
+            if (shiftDown) {
                 duplicateSelected();
                 return true;
             }
@@ -383,6 +383,7 @@ public class SelectTool extends SceneEditTool {
                         actionPerformed(scaling);
                         scaling = null;
                         clearState(false);
+                        toolController.rebuildSelectionBox();
                     } else if (rotating != null) {
                         rotating.after = selected.getLocalRotation().clone();
                         actionPerformed(rotating);
@@ -408,7 +409,12 @@ public class SelectTool extends SceneEditTool {
         if (pressed) {
             // mouse down
             
-            if (!wasDraggingR && !wasDownR) { // wasn't dragging and was not down already
+            if (moving != null) {
+                moving.sceneUndo();
+                moving = null;
+                clearState();
+            }
+            else if (!wasDraggingR && !wasDownR) { // wasn't dragging and was not down already
                 // pick on the spot
                 Spatial s = pickWorldSpatial(camera, screenCoord, rootNode);
                 if (!toolController.selectTerrain() && isTerrain(s) ) {
@@ -454,6 +460,9 @@ public class SelectTool extends SceneEditTool {
      * TODO: use userData to determine the actual model's parent.
      */
     private Spatial findModelNodeParent(Spatial child) {
+        if (child == null)
+            return null;
+        
         if (child instanceof Node)
             return child;
         
@@ -785,6 +794,8 @@ public class SelectTool extends SceneEditTool {
      * Recursive call.
      */
     protected boolean isTerrain(Spatial s) {
+        if (s == null)
+            return false;
         if (s instanceof Terrain)
             return true;