From 028f9d86f666fd8853f214b829658303523d9721 Mon Sep 17 00:00:00 2001 From: "bre..ns" Date: Thu, 1 Sep 2011 17:26:24 +0000 Subject: [PATCH] added Scale tool to scene composer git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8146 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../SceneComposerTopComponent.form | 16 +- .../SceneComposerTopComponent.java | 25 +++- .../jme3/gde/scenecomposer/SceneEditTool.java | 25 +++- .../gde/scenecomposer/tools/ScaleTool.java | 137 ++++++++++++++++++ 4 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form index 0f80c4e54..bff79de5c 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form @@ -33,7 +33,7 @@ - + @@ -189,11 +189,13 @@ - + + + @@ -357,12 +359,12 @@ - + - + @@ -395,9 +397,9 @@ - + - + @@ -416,7 +418,7 @@ - + diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java index 0a11ef68c..a80a7ba6b 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java @@ -18,6 +18,7 @@ import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial; import com.jme3.gde.core.sceneexplorer.nodes.NodeUtility; import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent; import com.jme3.gde.scenecomposer.tools.MoveTool; +import com.jme3.gde.scenecomposer.tools.ScaleTool; import com.jme3.gde.scenecomposer.tools.SelectTool; import com.jme3.math.Vector3f; import com.jme3.scene.Node; @@ -193,10 +194,14 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce scaleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/scenecomposer/icon_arrow_inout.png"))); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(scaleButton, org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.scaleButton.text")); // NOI18N scaleButton.setToolTipText(org.openide.util.NbBundle.getMessage(SceneComposerTopComponent.class, "SceneComposerTopComponent.scaleButton.toolTipText")); // NOI18N - scaleButton.setEnabled(false); scaleButton.setFocusable(false); scaleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); scaleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + scaleButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + scaleButtonActionPerformed(evt); + } + }); jToolBar1.add(scaleButton); jToolBar1.add(jSeparator5); @@ -300,11 +305,11 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 190, Short.MAX_VALUE) + .addGap(0, 321, Short.MAX_VALUE) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 21, Short.MAX_VALUE) + .addGap(0, 23, Short.MAX_VALUE) ); jToolBar1.add(jPanel3); @@ -384,8 +389,8 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce .addGap(10, 10, 10) .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(emitButton, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)) - .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)) + .addComponent(emitButton, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)) + .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)) .addContainerGap()) ); jPanel4Layout.setVerticalGroup( @@ -400,7 +405,7 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(emitButton)) - .addContainerGap(38, Short.MAX_VALUE)) + .addContainerGap(39, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); @@ -411,7 +416,7 @@ public final class SceneComposerTopComponent extends TopComponent implements Sce .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sceneInfoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 731, Short.MAX_VALUE) + .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 737, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -503,6 +508,12 @@ private void emitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }); }//GEN-LAST:event_emitButtonActionPerformed + +private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scaleButtonActionPerformed + ScaleTool tool = new ScaleTool(); + toolController.showEditTool(tool); +}//GEN-LAST:event_scaleButtonActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton camToCursorSelectionButton; private javax.swing.JButton createPhysicsMeshButton; diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java index 8fff2dcf9..967acc63b 100644 --- a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java @@ -299,6 +299,15 @@ public abstract class SceneEditTool { * @param axisMarkerPickType */ protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType) { + highlightAxisMarker(camera, screenCoord, axisMarkerPickType, false); + } + + /** + * Show what axis or plane the mouse is currently over and will affect. + * @param axisMarkerPickType + * @param colorAll highlight all parts of the marker when only one is selected + */ + protected void highlightAxisMarker(Camera camera, Vector2f screenCoord, AxisMarkerPickType axisMarkerPickType, boolean colorAll) { setDefaultAxisMarkerColors(); Vector3f picked = pickAxisMarker(camera, screenCoord, axisPickType); if (picked == null) { @@ -307,15 +316,21 @@ public abstract class SceneEditTool { if (picked == ARROW_X) { axisMarker.getChild("arrowX").setMaterial(orangeMat); - } else if (picked == ARROW_Y) { + } + else if (picked == ARROW_Y) { axisMarker.getChild("arrowY").setMaterial(orangeMat); - } else if (picked == ARROW_Z) { + } + else if (picked == ARROW_Z) { axisMarker.getChild("arrowZ").setMaterial(orangeMat); - } else if (picked == QUAD_XY) { + } + + if (picked == QUAD_XY || colorAll) { axisMarker.getChild("quadXY").setMaterial(orangeMat); - } else if (picked == QUAD_XZ) { + } + if (picked == QUAD_XZ || colorAll) { axisMarker.getChild("quadXZ").setMaterial(orangeMat); - } else if (picked == QUAD_YZ) { + } + if (picked == QUAD_YZ || colorAll) { axisMarker.getChild("quadYZ").setMaterial(orangeMat); } } diff --git a/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java new file mode 100644 index 000000000..0fd0bf315 --- /dev/null +++ b/sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java @@ -0,0 +1,137 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.jme3.gde.scenecomposer.tools; + +import com.jme3.asset.AssetManager; +import com.jme3.gde.core.sceneexplorer.nodes.JmeNode; +import com.jme3.gde.core.undoredo.AbstractUndoableSceneEdit; +import com.jme3.gde.scenecomposer.SceneComposerToolController; +import com.jme3.gde.scenecomposer.SceneEditTool; +import com.jme3.math.Vector2f; +import com.jme3.math.Vector3f; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import org.openide.loaders.DataObject; + +/** + * + * @author sploreg + */ +public class ScaleTool extends SceneEditTool { + + private Vector3f pickedPlane; + private Vector2f lastScreenCoord; + private Vector3f startScale; + private Vector3f lastScale; + private boolean wasDragging = false; + + public ScaleTool() { + axisPickType = AxisMarkerPickType.axisAndPlane; + setOverrideCameraControl(true); + } + + @Override + public void activate(AssetManager manager, Node toolNode, Node onTopToolNode, Spatial selectedSpatial, SceneComposerToolController toolController) { + super.activate(manager, toolNode, onTopToolNode, selectedSpatial, toolController); + displayPlanes(); + } + + @Override + public void actionPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { + if (!pressed) { + setDefaultAxisMarkerColors(); + pickedPlane = null; // mouse released, reset selection + lastScreenCoord = null; + if (wasDragging) { + actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); + wasDragging = false; + } + } + } + + @Override + public void actionSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject dataObject) { + + } + + @Override + public void mouseMoved(Vector2f screenCoord) { + if (pickedPlane == null) { + highlightAxisMarker(camera, screenCoord, axisPickType, true); + } + /*else { + pickedPlane = null; + lastScreenCoord = null; + }*/ + } + + @Override + public void draggedPrimary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + if (!pressed) { + setDefaultAxisMarkerColors(); + pickedPlane = null; // mouse released, reset selection + lastScreenCoord = null; + + if (wasDragging) { + actionPerformed(new ScaleUndo(toolController.getSelectedSpatial(), startScale, lastScale)); + wasDragging = false; + } + return; + } + + if (toolController.getSelectedSpatial() == null) + return; + if (pickedPlane == null) { + pickedPlane = pickAxisMarker(camera, screenCoord, axisPickType); + if (pickedPlane == null) + return; + startScale = toolController.getSelectedSpatial().getLocalScale().clone(); + } + + if (lastScreenCoord == null) { + lastScreenCoord = screenCoord; + } else { + float diff = screenCoord.y-lastScreenCoord.y; + diff *= 0.1f; + lastScreenCoord = screenCoord; + Vector3f scale = toolController.getSelectedSpatial().getLocalScale().add(diff, diff, diff); + lastScale = scale; + toolController.getSelectedSpatial().setLocalScale(scale); + updateToolsTransformation(); + } + + wasDragging = true; + } + + @Override + public void draggedSecondary(Vector2f screenCoord, boolean pressed, JmeNode rootNode, DataObject currentDataObject) { + + } + + private class ScaleUndo extends AbstractUndoableSceneEdit { + + private Spatial spatial; + private Vector3f before,after; + + ScaleUndo(Spatial spatial, Vector3f before, Vector3f after) { + this.spatial = spatial; + this.before = before; + this.after = after; + } + + @Override + public void sceneUndo() { + spatial.setLocalScale(before); + toolController.selectedSpatialTransformed(); + } + + @Override + public void sceneRedo() { + spatial.setLocalScale(after); + toolController.selectedSpatialTransformed(); + } + + } +}