added Scale tool to scene composer

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8146 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 13 years ago
parent 31e151fec1
commit 028f9d86f6
  1. 16
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form
  2. 25
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.java
  3. 25
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneEditTool.java
  4. 137
      sdk/jme3-scenecomposer/src/com/jme3/gde/scenecomposer/tools/ScaleTool.java

@ -33,7 +33,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="sceneInfoPanel" max="32767" attributes="0"/>
</Group>
<Component id="jToolBar1" alignment="0" pref="731" max="32767" attributes="0"/>
<Component id="jToolBar1" alignment="0" pref="737" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -189,11 +189,13 @@
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.scaleButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="enabled" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="scaleButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToolBar$Separator" name="jSeparator5">
</Component>
@ -357,12 +359,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="190" max="32767" attributes="0"/>
<EmptySpace min="0" pref="321" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="21" max="32767" attributes="0"/>
<EmptySpace min="0" pref="23" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -395,9 +397,9 @@
<EmptySpace min="10" pref="10" max="10" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="emitButton" pref="232" max="32767" attributes="0"/>
<Component id="emitButton" pref="267" max="32767" attributes="0"/>
</Group>
<Component id="jSeparator6" alignment="0" pref="302" max="32767" attributes="0"/>
<Component id="jSeparator6" alignment="0" pref="322" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -416,7 +418,7 @@
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="emitButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="38" max="32767" attributes="0"/>
<EmptySpace pref="39" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

@ -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;

@ -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);
}
}

@ -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();
}
}
}
Loading…
Cancel
Save