* added the LOD control to terrain in the editor

* increased terrain default scale
* fixed a bug in the paint tool when terrain scale was not 1

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7785 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
bre..ns 14 years ago
parent bac511ac59
commit 9568cf0ea6
  1. 42
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java
  2. 2
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java
  3. 2
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/LevelTerrainToolAction.java
  4. 16
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/PaintTerrainToolAction.java

@ -689,7 +689,7 @@ public class TerrainEditorController {
{ {
AssetManager manager = SceneApplication.getApplication().getAssetManager(); AssetManager manager = SceneApplication.getApplication().getAssetManager();
TerrainQuad terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations Terrain terrain = new TerrainQuad("terrain-"+sceneName, patchSize, totalSize, heightmapData); //TODO make this pluggable for different Terrain implementations
com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); com.jme3.material.Material mat = new com.jme3.material.Material(manager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
String assetFolder = ""; String assetFolder = "";
@ -708,7 +708,7 @@ public class TerrainEditorController {
File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/"); File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
if (!alphaFolder.exists()) if (!alphaFolder.exists())
alphaFolder.mkdir(); alphaFolder.mkdir();
String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+terrain.getName()+"-alphablend"+i+".png"; String alphaBlendFileName = "/Textures/terrain-alpha/"+sceneName+"-"+((Node)terrain).getName()+"-alphablend"+i+".png";
File alphaImageFile = new File(assetFolder+alphaBlendFileName); File alphaImageFile = new File(assetFolder+alphaBlendFileName);
ImageIO.write(alphaBlend, "png", alphaImageFile); ImageIO.write(alphaBlend, "png", alphaImageFile);
Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false)); Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
@ -727,23 +727,21 @@ public class TerrainEditorController {
mat.setFloat("DiffuseMap_0_scale", DEFAULT_TEXTURE_SCALE); mat.setFloat("DiffuseMap_0_scale", DEFAULT_TEXTURE_SCALE);
mat.setBoolean("WardIso", true); mat.setBoolean("WardIso", true);
terrain.setMaterial(mat); ((Node)terrain).setMaterial(mat);
terrain.setModelBound(new BoundingBox()); ((Node)terrain).setModelBound(new BoundingBox());
terrain.updateModelBound(); ((Node)terrain).updateModelBound();
terrain.setLocalTranslation(0, 0, 0); ((Node)terrain).setLocalTranslation(0, 0, 0);
terrain.setLocalScale(1f, 1f, 1f); ((Node)terrain).setLocalScale(4f, 1f, 4f);
// add the lod control // add the lod control
List<Camera> cameras = new ArrayList<Camera>(); TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
cameras.add(SceneApplication.getApplication().getCamera()); ((Node)terrain).addControl(control);
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
//terrain.addControl(control); // removing this until we figure out a way to have it get the cameras when saved/loaded
parent.attachChild(terrain); parent.attachChild((Node)terrain);
setNeedsSave(true); setNeedsSave(true);
addSpatialUndo(parent, terrain, jmeNodeParent); addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
return terrain; return terrain;
} }
@ -1081,6 +1079,24 @@ public class TerrainEditorController {
setNeedsSave(true); setNeedsSave(true);
} }
/**
* Re-attach the camera to the LOD control.
* Called when the scene is opened and will only
* update the control if there is already a terrain present in
* the scene.
*/
protected void enableLodControl() {
Terrain terrain = (Terrain) getTerrain(null);
if (terrain == null)
return;
TerrainQuad t = (TerrainQuad)terrain;
TerrainLodControl control = t.getControl(TerrainLodControl.class);
if (control != null) {
control.setCamera(SceneApplication.getApplication().getCamera());
}
}
} }

@ -1022,6 +1022,8 @@ public final class TerrainEditorTopComponent extends TopComponent implements Sce
terrainDeletedNodeListener = new TerrainNodeListener(); terrainDeletedNodeListener = new TerrainNodeListener();
editorController.enableTextureButtons(); editorController.enableTextureButtons();
editorController.enableLodControl();
} }
// run on GL thread // run on GL thread

@ -109,7 +109,7 @@ public class LevelTerrainToolAction extends AbstractTerrainToolAction {
Vector2f terrainLoc = new Vector2f(locX, locZ); Vector2f terrainLoc = new Vector2f(locX, locZ);
// adjust height based on radius of the tool // adjust height based on radius of the tool
float terrainHeightAtLoc = terrain.getHeightmapHeight(terrainLoc)*terrain.getSpatial().getWorldScale().y; float terrainHeightAtLoc = terrain.getHeightmapHeight(terrainLoc)*((Node)terrain).getWorldScale().y;
float radiusWeight = ToolUtils.calculateRadiusPercent(radius, locX-worldLoc.x, locZ-worldLoc.z); float radiusWeight = ToolUtils.calculateRadiusPercent(radius, locX-worldLoc.x, locZ-worldLoc.z);
float epsilon = 0.1f*height; // rounding error for snapping float epsilon = 0.1f*height; // rounding error for snapping

@ -87,10 +87,10 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
Texture tex = getAlphaTexture(terrain, alphaIdx); Texture tex = getAlphaTexture(terrain, alphaIdx);
Image image = tex.getImage(); Image image = tex.getImage();
Vector2f UV = terrain.getPointPercentagePosition(markerLocation.x, markerLocation.z); Vector2f UV = getPointPercentagePosition(terrain, markerLocation);
// get the radius of the brush in pixel-percent // get the radius of the brush in pixel-percent
float brushSize = toolRadius/((TerrainQuad)terrain).getTotalSize(); float brushSize = toolRadius/(terrain.getTerrainSize()*((Node)terrain).getLocalScale().x);
int texIndex = selectedTextureIndex - ((selectedTextureIndex/4)*4); // selectedTextureIndex/4 is an int floor, do not simplify the equation int texIndex = selectedTextureIndex - ((selectedTextureIndex/4)*4); // selectedTextureIndex/4 is an int floor, do not simplify the equation
boolean erase = toolWeight<0; boolean erase = toolWeight<0;
if (erase) if (erase)
@ -101,6 +101,18 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
tex.getImage().setUpdateNeeded(); tex.getImage().setUpdateNeeded();
} }
public Vector2f getPointPercentagePosition(Terrain terrain, Vector3f worldLoc) {
Vector2f uv = new Vector2f(worldLoc.x,worldLoc.z);
float scale = ((Node)terrain).getLocalScale().x;
uv.subtractLocal(((Node)terrain).getLocalTranslation().x*scale, ((Node)terrain).getLocalTranslation().z*scale); // center it on 0,0
float scaledSize = terrain.getTerrainSize()*scale;
uv.addLocal(scaledSize/2, scaledSize/2); // shift the bottom left corner up to 0,0
uv.divideLocal(scaledSize); // get the location as a percentage
return uv;
}
private Texture getAlphaTexture(Terrain terrain, int alphaLayer) { private Texture getAlphaTexture(Terrain terrain, int alphaLayer) {
if (terrain == null) if (terrain == null)
return null; return null;

Loading…
Cancel
Save