Well well well, already got something. Terrain need smooth. I did this way cause I failed to understand the way tou said. Anyways, itâs still buggy though, as this shouldnât be applied after/before the markers. It lacks smoothing, and when the radius is too big, the same level is applied incorrectly to the neighbours. Could you tell me what you think @Sploreg ?
Patch source dir is located at: trunksdkjme3-terrain-editorsrc
Edit: To use it, right click somewhere (top of the hill), then right click somewhere else (bottom of the hill), and then start clicking (dragging) with the left cursor down between the red and the blue marker (buggy for now if you go beyond them).
[patch]Index: com/jme3/gde/terraineditor/TerrainEditorTopComponent.form
===================================================================
â com/jme3/gde/terraineditor/TerrainEditorTopComponent.form (revisĂŁo 9571)
+++ com/jme3/gde/terraineditor/TerrainEditorTopComponent.form (cĂłpia de trabalho)
@@ -1,4 +1,4 @@
-<?xml version=â1.1â encoding=âUTF-8â ?>
+<?xml version=â1.0â encoding=âUTF-8â ?>
<Form version=â1.6â maxVersion=â1.7â type=âorg.netbeans.modules.form.forminfo.JPanelFormInfoâ>
<NonVisualComponents>
@@ -53,7 +53,7 @@
<EmptySpace max="-2" attributes=â0â/>
<Component id=âhintPanelâ max=â32767â attributes=â0â/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@@ -65,7 +65,7 @@
<Component id="hintPanel" max="32767" attributes="1"/>
<Component id="paintingPanel" alignment="0" max="32767" attributes="1"/>
<Component id="toolSettingsPanel" alignment="0" pref="128" max="32767" attributes="1"/>
</Group>
</Group>
</Group>
@@ -213,6 +213,28 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="levelTerrainButtonActionPerformed"/>
</Events>
</Component>
-
<Component class="javax.swing.JToggleButton" name="shirkitButton"><br />
-
<Properties><br />
-
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor"><br />
-
<ComponentRef name="terrainModButtonGroup"/><br />
-
</Property><br />
-
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor"><br />
-
<Image iconType="3" name="/com/jme3/gde/terraineditor/TerraMonkey.png"/><br />
-
</Property><br />
-
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"><br />
-
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.shirkitButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/><br />
-
</Property><br />
-
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"><br />
-
<ResourceString bundle="com/jme3/gde/terraineditor/Bundle.properties" key="TerrainEditorTopComponent.shirkitButton.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/><br />
-
</Property><br />
-
<Property name="focusable" type="boolean" value="false"/><br />
-
<Property name="horizontalTextPosition" type="int" value="0"/><br />
-
<Property name="verticalTextPosition" type="int" value="3"/><br />
-
</Properties><br />
-
<Events><br />
-
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="shirkitButtonActionPerformed"/><br />
-
</Events><br />
-
</Component><br />
<Component class="javax.swing.JToolBar$Separator" name="jSeparator2">
</Component>
<Component class="javax.swing.JButton" name="addTextureButton">
@@ -352,7 +374,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@@ -671,7 +693,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
Index: com/jme3/gde/terraineditor/tools/ShirkitTool.java
===================================================================
â com/jme3/gde/terraineditor/tools/ShirkitTool.java (revisĂŁo 0)
+++ com/jme3/gde/terraineditor/tools/ShirkitTool.java (cĂłpia de trabalho)
@@ -0,0 +1,76 @@
+/*
-
- To change this template, choose Tools | Templates
-
- and open the template in the editor.
- */
+package com.jme3.gde.terraineditor.tools;
+
+import com.jme3.asset.AssetManager;
+import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.Mesh;
+import com.jme3.scene.Node;
+import com.jme3.scene.shape.Sphere;
+import org.openide.loaders.DataObject;
+
+/**
- *
-
- */
+public class ShirkitTool extends TerrainTool {
+
- private Vector3f point1, point2;
- private Geometry markerThird;
- private int doit;
+
-
@Override
- public void activate(AssetManager manager, Node parent) {
-
super.activate(manager, parent);<br />
-
addMarkerSecondary(parent);<br />
-
addMarkerThird(parent);<br />
- }
+
- public void addMarkerThird(Node parent) {
-
if (markerThird == null) {<br />
-
markerThird = new Geometry("edit marker secondary");<br />
-
Mesh m2 = new Sphere(8, 8, 0.5f);<br />
-
markerThird.setMesh(m2);<br />
-
Material mat2 = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");<br />
-
mat2.getAdditionalRenderState().setWireframe(false);<br />
-
markerThird.setMaterial(mat2);<br />
-
markerThird.setLocalTranslation(0, 0, 0);<br />
-
mat2.setColor("Color", ColorRGBA.Blue);<br />
-
}<br />
-
parent.attachChild(markerThird);<br />
- }
+
-
@Override
- public void actionPrimary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
-
if (point1 != null && point2 != null) {<br />
-
ShirkitToolAction action = new ShirkitToolAction(point, point1, point2, radius, weight);<br />
-
action.actionPerformed(rootNode, dataObject);<br />
-
}<br />
- }
+
-
@Override
- public void actionSecondary(Vector3f point, int textureIndex, AbstractSceneExplorerNode rootNode, DataObject dataObject) {
-
if (doit == 0) {<br />
-
point2 = point;<br />
-
markerSecondary.setLocalTranslation(point);<br />
-
} else if (doit == 2) {<br />
-
point1 = point;<br />
-
markerThird.setLocalTranslation(point);<br />
-
}<br />
-
doit++;<br />
-
if (doit == 5) {<br />
-
doit = -1;<br />
+
-
point2 = null;<br />
-
point1 = null;<br />
-
markerSecondary.setLocalTranslation(Vector3f.ZERO);<br />
-
markerThird.setLocalTranslation(Vector3f.ZERO);<br />
-
}<br />
- }
+}
Index: com/jme3/gde/terraineditor/tools/ShirkitToolAction.java
===================================================================
â com/jme3/gde/terraineditor/tools/ShirkitToolAction.java (revisĂŁo 0)
+++ com/jme3/gde/terraineditor/tools/ShirkitToolAction.java (cĂłpia de trabalho)
@@ -0,0 +1,118 @@
+/*
-
- To change this template, choose Tools | Templates
-
- and open the template in the editor.
- */
+package com.jme3.gde.terraineditor.tools;
+
+import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
+import com.jme3.math.Vector2f;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Node;
+import com.jme3.terrain.Terrain;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
- *
-
- */
+public class ShirkitToolAction extends AbstractTerrainToolAction {
+
- private final Vector3f current;
- private Vector3f point1;
- private Vector3f point2;
- private final float radius;
- private final float weight;
+
- public ShirkitToolAction(Vector3f current, Vector3f point1, Vector3f point2, float radius, float weight) {
-
this.current = current;<br />
-
this.point1 = point1;<br />
-
this.point2 = point2;<br />
-
this.radius = radius;<br />
-
this.weight = weight;<br />
-
name = "Shirkit terrain";<br />
- }
+
-
@Override
- protected Object doApplyTool(AbstractSceneExplorerNode rootNode) {
-
Terrain terrain = getTerrain(rootNode.getLookup().lookup(Node.class));<br />
-
if (terrain == null) {<br />
-
return null;<br />
-
}<br />
+
+
+
+
+
+
+
+
+
-
// see if it is in the radius of the tool<br />
-
if (ToolUtils.isInRadius(locX - current.x, locZ - current.z, radius)) {<br />
+
-
Vector2f terrainLoc = new Vector2f(locX, locZ);<br />
-
// adjust height based on radius of the tool<br />
-
float terrainHeightAtLoc = terrain.getHeightmapHeight(terrainLoc) * ((Node) terrain).getWorldScale().y;<br />
-
float radiusWeight = ToolUtils.calculateRadiusPercent(radius, locX - current.x, locZ - current.z);<br />
+
+
+
+
-
// test if adjusting too far and then cap it<br />
-
if (adj > 0 && ToolUtils.floatGreaterThan((terrainHeightAtLoc + adj), desiredHeight, epsilon)) {<br />
-
adj = desiredHeight - terrainHeightAtLoc;<br />
-
} else if (adj < 0 && ToolUtils.floatLessThan((terrainHeightAtLoc + adj), desiredHeight, epsilon)) {<br />
-
adj = terrainHeightAtLoc - desiredHeight;<br />
-
}<br />
+
-
if (!ToolUtils.floatEquals(adj, 0, 0.001f)) {<br />
-
locs.add(terrainLoc);<br />
-
heights.add(adj);<br />
-
}<br />
+
+
+
jSeparator2 = new javax.swing.JToolBar.Separator();
addTextureButton = new javax.swing.JButton();
removeTextureButton = new javax.swing.JButton();
@@ -354,6 +347,20 @@
}
});
jToolBar1.add(levelTerrainButton);
+
-
terrainModButtonGroup.add(shirkitButton);<br />
-
shirkitButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/terraineditor/TerraMonkey.png"))); // NOI18N<br />
-
org.openide.awt.Mnemonics.setLocalizedText(shirkitButton, org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.shirkitButton.text")); // NOI18N<br />
-
shirkitButton.setToolTipText(org.openide.util.NbBundle.getMessage(TerrainEditorTopComponent.class, "TerrainEditorTopComponent.shirkitButton.toolTipText")); // NOI18N<br />
-
shirkitButton.setFocusable(false);<br />
-
shirkitButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);<br />
-
shirkitButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);<br />
-
shirkitButton.addActionListener(new java.awt.event.ActionListener() {<br />
-
public void actionPerformed(java.awt.event.ActionEvent evt) {<br />
-
shirkitButtonActionPerformed(evt);<br />
-
}<br />
-
});<br />
-
jToolBar1.add(shirkitButton);<br />
jToolBar1.add(jSeparator2);
addTextureButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/terraineditor/icon_terrain-add-texture.png"))); // NOI18N
@@ -448,7 +455,7 @@
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -637,7 +644,7 @@
hintPanel.setLayout(hintPanelLayout);
hintPanelLayout.setHorizontalGroup(
hintPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
);
hintPanelLayout.setVerticalGroup(
hintPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -656,7 +663,7 @@
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(hintPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -667,7 +674,7 @@
.addComponent(hintPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(paintingPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(toolSettingsPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
-
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))<br />
);
}// </editor-fold>//GEN-END:initComponents
@@ -860,6 +867,17 @@
// TODO add your handling code here:
}//GEN-LAST:event_scaleFieldActionPerformed
- private void shirkitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shirkitButtonActionPerformed
-
if (shirkitButton.isSelected()) {<br />
-
ShirkitTool tool = new ShirkitTool();<br />
-
toolController.setTerrainEditButtonState(tool);<br />
-
setHintText(tool);<br />
-
} else {<br />
-
toolController.setTerrainEditButtonState(null);<br />
-
setHintText((TerrainTool) null);<br />
-
}<br />
- }//GEN-LAST:event_shirkitButtonActionPerformed
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addTextureButton;
private javax.swing.JButton createTerrainButton;
@@ -896,6 +914,7 @@
private javax.swing.JTextField scaleField;
private javax.swing.JLabel scaleLabel;
private javax.swing.JTextField shininessField;
- private javax.swing.JToggleButton shirkitButton;
private javax.swing.JToggleButton smoothTerrainButton;
private javax.swing.ButtonGroup terrainModButtonGroup;
private javax.swing.JFileChooser textureFileChooser;
Index: com/jme3/gde/terraineditor/Bundle.properties
===================================================================
â com/jme3/gde/terraineditor/Bundle.properties (revisĂŁo 9571)
+++ com/jme3/gde/terraineditor/Bundle.properties (cĂłpia de trabalho)
@@ -119,3 +119,5 @@
CreateTerrainVisualPanel2.jLabel6.text=Smooth
CreateTerrainVisualPanel2.jLabel7.text=Height Scale:
CreateTerrainVisualPanel2.heightScale.text=1
+TerrainEditorTopComponent.shirkitButton.toolTipText=Shirkit terrain
+TerrainEditorTopComponent.shirkitButton.text=
[/patch]