* added smooth brush to terrain editor

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7653 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 14 years ago
parent 1ad174f7b5
commit bb916a02c2
  1. 3
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/Bundle.properties
  2. 69
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java
  3. 4
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.form
  4. 16
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java
  5. 1
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainToolController.java

@ -57,7 +57,7 @@ TerrainEditorTopComponent.lowerTerrainButton.toolTipText=Lower terrain
TerrainEditorTopComponent.lowerTerrainButton.actionCommand=Lower TerrainEditorTopComponent.lowerTerrainButton.actionCommand=Lower
TerrainEditorTopComponent.smoothTerrainButton.toolTipText=Smooth terrain TerrainEditorTopComponent.smoothTerrainButton.toolTipText=Smooth terrain
TerrainEditorTopComponent.smoothTerrainButton.actionCommand=Smooth TerrainEditorTopComponent.smoothTerrainButton.actionCommand=Smooth
TerrainEditorTopComponent.roughTerrainButton.toolTipText=Rough terrain TerrainEditorTopComponent.roughTerrainButton.toolTipText=Rough terrain (not implemented)
TerrainEditorTopComponent.roughTerrainButton.actionCommand=Rough TerrainEditorTopComponent.roughTerrainButton.actionCommand=Rough
TerrainEditorTopComponent.createTerrainButton.toolTipText=Add Terrain TerrainEditorTopComponent.createTerrainButton.toolTipText=Add Terrain
TerrainEditorTopComponent.genEntropiesButton.toolTipText=Pre-calculate the terrain entropy values. This will improve launch startup time TerrainEditorTopComponent.genEntropiesButton.toolTipText=Pre-calculate the terrain entropy values. This will improve launch startup time
@ -104,3 +104,4 @@ TerrainEditorTopComponent.toolHint.none=
TerrainEditorTopComponent.toolHint.default=Switch between camera and tool controls by holding down SHIFT TerrainEditorTopComponent.toolHint.default=Switch between camera and tool controls by holding down SHIFT
TerrainEditorTopComponent.toolHint.smooth= TerrainEditorTopComponent.toolHint.smooth=
TerrainEditorTopComponent.toolHint.level=Right click to set desired height value, left click to adjust height to that desired value. TerrainEditorTopComponent.toolHint.level=Right click to set desired height value, left click to adjust height to that desired value.
TerrainEditorTopComponent.levelTerrainButton.toolTipText=Level terrain

@ -1294,7 +1294,74 @@ public class TerrainEditorController {
* @param heightToolRadius * @param heightToolRadius
* @param smoothAmount * @param smoothAmount
*/ */
protected void doSmoothTerrain(Vector3f markerLocation, float heightToolRadius, float smoothAmount) { protected void doSmoothTerrain(Vector3f worldLoc, float radius, float weight) {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
setNeedsSave(true);
int radiusStepsX = (int)(radius / ((Node)terrain).getLocalScale().x);
int radiusStepsZ = (int)(radius / ((Node)terrain).getLocalScale().z);
float xStepAmount = ((Node)terrain).getLocalScale().x;
float zStepAmount = ((Node)terrain).getLocalScale().z;
List<Vector2f> locs = new ArrayList<Vector2f>();
List<Float> heights = new ArrayList<Float>();
for (int z=-radiusStepsZ; z<radiusStepsZ; z++) {
for (int x=-radiusStepsZ; x<radiusStepsX; x++) {
float locX = worldLoc.x + (x*xStepAmount);
float locZ = worldLoc.z + (z*zStepAmount);
// see if it is in the radius of the tool
if (isInRadius(locX-worldLoc.x,locZ-worldLoc.z,radius)) {
Vector2f terrainLoc = new Vector2f(locX, locZ);
// adjust height based on radius of the tool
float center = terrain.getHeightmapHeight(terrainLoc);
float left = terrain.getHeightmapHeight(new Vector2f(terrainLoc.x-1, terrainLoc.y));
float right = terrain.getHeightmapHeight(new Vector2f(terrainLoc.x+1, terrainLoc.y));
float up = terrain.getHeightmapHeight(new Vector2f(terrainLoc.x, terrainLoc.y+1));
float down = terrain.getHeightmapHeight(new Vector2f(terrainLoc.x, terrainLoc.y-1));
int count = 1;
float amount = center;
if (left != Float.NaN) {
amount += left;
count++;
}
if (right != Float.NaN) {
amount += right;
count++;
}
if (up != Float.NaN) {
amount += up;
count++;
}
if (down != Float.NaN) {
amount += down;
count++;
}
amount /= count; // take average
// weigh it
float diff = amount-center;
diff *= weight;
amount = center+diff;
locs.add(terrainLoc);
heights.add(amount);
}
}
}
// do the actual height adjustment
terrain.setHeight(locs, heights);
((Node)terrain).updateModelBound(); // or else we won't collide with it where we just edited
} }

@ -513,8 +513,10 @@
<Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.smoothTerrainButton.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.smoothTerrainButton.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
<Property name="enabled" type="boolean" value="false"/>
</Properties> </Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="smoothTerrainButtonActionPerformed"/>
</Events>
</Component> </Component>
<Component class="javax.swing.JToggleButton" name="roughTerrainButton"> <Component class="javax.swing.JToggleButton" name="roughTerrainButton">
<Properties> <Properties>

@ -470,7 +470,11 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
org.openide.awt.Mnemonics.setLocalizedText(smoothTerrainButton, org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(smoothTerrainButton, org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.text")); // NOI18N
smoothTerrainButton.setToolTipText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.toolTipText")); // NOI18N smoothTerrainButton.setToolTipText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.toolTipText")); // NOI18N
smoothTerrainButton.setActionCommand(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.actionCommand")); // NOI18N smoothTerrainButton.setActionCommand(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.smoothTerrainButton.actionCommand")); // NOI18N
smoothTerrainButton.setEnabled(false); smoothTerrainButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
smoothTerrainButtonActionPerformed(evt);
}
});
jToolBar1.add(smoothTerrainButton); jToolBar1.add(smoothTerrainButton);
terrainModButtonGroup.add(roughTerrainButton); terrainModButtonGroup.add(roughTerrainButton);
@ -674,6 +678,16 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
toolController.setHeightToolHeight(heightSlider.getValue()); // should always be values upto and over 100, because it will be divided by 100 toolController.setHeightToolHeight(heightSlider.getValue()); // should always be values upto and over 100, because it will be divided by 100
}//GEN-LAST:event_heightSliderStateChanged }//GEN-LAST:event_heightSliderStateChanged
private void smoothTerrainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smoothTerrainButtonActionPerformed
if (smoothTerrainButton.isSelected()) {
toolController.setTerrainEditButtonState(TerrainEditButton.smoothTerrain);
setHintText(TerrainEditButton.smoothTerrain);
} else {
toolController.setTerrainEditButtonState(TerrainEditButton.none);
setHintText(TerrainEditButton.none);
}
}//GEN-LAST:event_smoothTerrainButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addTextureButton; private javax.swing.JButton addTextureButton;
private javax.swing.JButton createTerrainButton; private javax.swing.JButton createTerrainButton;

@ -99,6 +99,7 @@ public class TerrainToolController extends SceneToolController {
public void setHeightToolHeight(float heightToolHeight) { public void setHeightToolHeight(float heightToolHeight) {
this.heightAmount = heightToolHeight/100f; this.heightAmount = heightToolHeight/100f;
this.levelAmount = heightToolHeight/200f; this.levelAmount = heightToolHeight/200f;
this.smoothAmount = heightToolHeight/200f;
this.paintAmount = heightToolHeight/200f; this.paintAmount = heightToolHeight/200f;
} }

Loading…
Cancel
Save