diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/LODGeomap.java b/engine/src/terrain/com/jme3/terrain/geomipmap/LODGeomap.java index b434f4795..b0077ce18 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/LODGeomap.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/LODGeomap.java @@ -660,29 +660,39 @@ public class LODGeomap extends GeoMap { Vector2f t2 = new Vector2f(); Vector2f t3 = new Vector2f(); - scale = Vector3f.UNIT_XYZ; + //scale = Vector3f.UNIT_XYZ; for (int r = 0; r < getHeight(); r++) { for (int c = 0; c < getWidth(); c++) { int texIdx = ((getHeight() - 1 - r) * getWidth() + c) * 2; // pull from the end - int texIdxPrev = ((getHeight() - 1 - (r - 1)) * getWidth() + c) * 2; // pull from the end + int texIdxAbove = ((getHeight() - 1 - (r - 1)) * getWidth() + c) * 2; // pull from the end int texIdxNext = ((getHeight() - 1 - (r + 1)) * getWidth() + c) * 2; // pull from the end v1.set(c, getValue(c, r), r); t1.set(textureBuffer.get(texIdx), textureBuffer.get(texIdx + 1)); - if (r == 0) { // first row - v3.set(c, getValue(c, r), r); // ??? - t3.set(textureBuffer.get(texIdxNext), textureBuffer.get(texIdxNext + 1)); // ??? + // below + if (r == getHeight()-1) { // last row + v3.set(c, getValue(c, r), r + 1); + float u = textureBuffer.get(texIdx) - textureBuffer.get(texIdxAbove); + u += textureBuffer.get(texIdx); + float v = textureBuffer.get(texIdx + 1) - textureBuffer.get(texIdxAbove + 1); + v += textureBuffer.get(texIdx + 1); + t3.set(u, v); } else { - v3.set(c, getValue(c, r - 1), r - 1); - t3.set(textureBuffer.get(texIdxPrev), textureBuffer.get(texIdxPrev + 1)); + v3.set(c, getValue(c, r + 1), r + 1); + t3.set(textureBuffer.get(texIdxNext), textureBuffer.get(texIdxNext + 1)); } - - if (c == getWidth() - 1) { // last column - v2.set(c + 1, getValue(c, r), r); // use same height - t2.set(textureBuffer.get(texIdx), textureBuffer.get(texIdx + 1)); + + //right + if (c == getWidth()-1) { // last column + v2.set(c + 1, getValue(c, r), r); + float u = textureBuffer.get(texIdx) - textureBuffer.get(texIdx - 2); + u += textureBuffer.get(texIdx); + float v = textureBuffer.get(texIdx + 1) - textureBuffer.get(texIdx - 1); + v += textureBuffer.get(texIdx - 1); + t2.set(u, v); } else { v2.set(c + 1, getValue(c + 1, r), r); // one to the right t2.set(textureBuffer.get(texIdx + 2), textureBuffer.get(texIdx + 3)); @@ -699,8 +709,8 @@ public class LODGeomap extends GeoMap { /** * - * @param v Takes 3 vertexes: root, right, top - * @param t Takes 3 tex coords: root, right, top + * @param v Takes 3 vertices: root, right, bottom + * @param t Takes 3 tex coords: root, right, bottom * @param tangent that will store the result * @return the tangent store */ @@ -827,7 +837,7 @@ public class LODGeomap extends GeoMap { } else if (c == getWidth() - 1) { // last column topPoint.set(c, getValue(c, r - 1), r - 1); leftPoint.set(c - 1, getValue(c - 1, r), r); - bottomPoint.set(c, getValue(c, r + 1), r + 1); + bottomPoint.set(c, getValue(c, r + 1), r + 1); //XXX wrong normal.set( getNormal(topPoint, rootPoint, leftPoint, scale, tmp1) ); normal.add( getNormal(leftPoint, rootPoint, bottomPoint, scale, tmp1) ); diff --git a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java index e38684ad8..e1d746a86 100644 --- a/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java +++ b/engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java @@ -316,7 +316,7 @@ public class TerrainPatch extends Geometry { } /** - * recalculate all of this normal vectors in this terrain patch + * recalculate all of the normal vectors in this terrain patch */ protected void updateNormals() { FloatBuffer newNormalBuffer = geomap.writeNormalArray(null, getWorldScale()); @@ -342,6 +342,9 @@ public class TerrainPatch extends Geometry { * *---x---* * | * * + * It works across the right side of the patch, from the top down to + * the bottom. Then it works on the bottom side of the patch, from the + * left to the right. */ protected void fixNormalEdges(TerrainPatch right, TerrainPatch bottom, @@ -356,310 +359,171 @@ public class TerrainPatch extends Geometry { Vector3f rightPoint = new Vector3f(); Vector3f leftPoint = new Vector3f(); Vector3f topPoint = new Vector3f(); + Vector3f bottomPoint = new Vector3f(); + Vector2f rootTex = new Vector2f(); Vector2f rightTex = new Vector2f(); Vector2f leftTex = new Vector2f(); Vector2f topTex = new Vector2f(); Vector2f bottomTex = new Vector2f(); - Vector3f normal = new Vector3f(); + Vector3f tangent = new Vector3f(); + Vector3f binormal = new Vector3f(); + Vector3f normal = new Vector3f(); int s = this.getSize()-1; - if (right != null) { // right side + if (right != null) { // right side, works its way down for (int i=0; i