2
0
Эх сурвалжийг харах

* 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

bre..ns 14 жил өмнө
parent
commit
89a558dc29

+ 29 - 13
jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorController.java

@@ -689,7 +689,7 @@ public class TerrainEditorController {
     {
         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");
 
         String assetFolder = "";
@@ -708,7 +708,7 @@ public class TerrainEditorController {
             File alphaFolder = new File(assetFolder+"/Textures/terrain-alpha/");
             if (!alphaFolder.exists())
                 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);
             ImageIO.write(alphaBlend, "png", alphaImageFile);
             Texture tex = manager.loadAsset(new TextureKey(alphaBlendFileName, false));
@@ -727,23 +727,21 @@ public class TerrainEditorController {
         mat.setFloat("DiffuseMap_0_scale", DEFAULT_TEXTURE_SCALE);
         mat.setBoolean("WardIso", true);
 
-        terrain.setMaterial(mat);
-        terrain.setModelBound(new BoundingBox());
-        terrain.updateModelBound();
-        terrain.setLocalTranslation(0, 0, 0);
-        terrain.setLocalScale(1f, 1f, 1f);
+        ((Node)terrain).setMaterial(mat);
+        ((Node)terrain).setModelBound(new BoundingBox());
+        ((Node)terrain).updateModelBound();
+        ((Node)terrain).setLocalTranslation(0, 0, 0);
+        ((Node)terrain).setLocalScale(4f, 1f, 4f);
 
         // add the lod control
-        List<Camera> cameras = new ArrayList<Camera>();
-	cameras.add(SceneApplication.getApplication().getCamera());
-        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
+        TerrainLodControl control = new TerrainLodControl(terrain, SceneApplication.getApplication().getCamera());
+	((Node)terrain).addControl(control);
 
-        parent.attachChild(terrain);
+        parent.attachChild((Node)terrain);
 
         setNeedsSave(true);
 
-        addSpatialUndo(parent, terrain, jmeNodeParent);
+        addSpatialUndo(parent, (Node)terrain, jmeNodeParent);
         
         return terrain;
     }
@@ -1081,6 +1079,24 @@ public class TerrainEditorController {
         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());
+        }
+    }
+
     
 
 }

+ 2 - 0
jme3-terrain-editor/src/com/jme3/gde/terraineditor/TerrainEditorTopComponent.java

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

+ 1 - 1
jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/LevelTerrainToolAction.java

@@ -109,7 +109,7 @@ public class LevelTerrainToolAction extends AbstractTerrainToolAction {
 
                     Vector2f terrainLoc = new Vector2f(locX, locZ);
                     // 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 epsilon = 0.1f*height; // rounding error for snapping

+ 14 - 2
jme3-terrain-editor/src/com/jme3/gde/terraineditor/tools/PaintTerrainToolAction.java

@@ -87,10 +87,10 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
         Texture tex = getAlphaTexture(terrain, alphaIdx);
         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
-        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
         boolean erase = toolWeight<0;
         if (erase)
@@ -101,6 +101,18 @@ public class PaintTerrainToolAction extends AbstractTerrainToolAction {
         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) {
         if (terrain == null)
             return null;