- fix terrain deserialization for old files

- fix GeomMap / LODGeomap signature to be backwards compatible

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8740 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 2f45134fd5
commit 8b60ba35b2
  1. 27
      engine/src/terrain/com/jme3/terrain/GeoMap.java
  2. 5
      engine/src/terrain/com/jme3/terrain/geomipmap/LODGeomap.java
  3. 10
      engine/src/terrain/com/jme3/terrain/geomipmap/TerrainPatch.java

@ -39,12 +39,10 @@ import com.jme3.export.Savable;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;
import java.io.IOException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@ -58,6 +56,11 @@ public class GeoMap implements Savable {
public GeoMap() {}
@Deprecated
public GeoMap(FloatBuffer heightData, int width, int height, int maxval){
this(heightData.array(), width, height, maxval);
}
public GeoMap(float[] heightData, int width, int height, int maxval){
this.hdata = heightData;
this.width = width;
@ -65,10 +68,16 @@ public class GeoMap implements Savable {
this.maxval = maxval;
}
public float[] getHeightData(){
@Deprecated
public FloatBuffer getHeightData(){
if (!isLoaded())
return null;
return BufferUtils.createFloatBuffer(hdata);
}
public float[] getHeightArray(){
if (!isLoaded())
return null;
return hdata;
}
@ -334,7 +343,7 @@ public class GeoMap implements Savable {
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
oc.write(hdata, "hdata", null);
oc.write(hdata, "hdataarray", null);
oc.write(width, "width", 0);
oc.write(height, "height", 0);
oc.write(maxval, "maxval", 0);
@ -342,7 +351,13 @@ public class GeoMap implements Savable {
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
hdata = ic.readFloatArray("hdata", null);
hdata = ic.readFloatArray("hdataarray", null);
if (hdata == null) {
FloatBuffer buf = ic.readFloatBuffer("hdata", null);
if (buf != null) {
hdata = buf.array();
}
}
width = ic.readInt("width", 0);
height = ic.readInt("height", 0);
maxval = ic.readInt("maxval", 0);

@ -70,6 +70,11 @@ public class LODGeomap extends GeoMap {
public LODGeomap() {
}
@Deprecated
public LODGeomap(int size, FloatBuffer heightMap) {
this(size, heightMap.array());
}
public LODGeomap(int size, float[] heightMap) {
super(heightMap, size, size, 1);
}

@ -215,11 +215,11 @@ public class TerrainPatch extends Geometry {
@Deprecated
public FloatBuffer getHeightmap() {
return BufferUtils.createFloatBuffer(geomap.getHeightData());
return BufferUtils.createFloatBuffer(geomap.getHeightArray());
}
public float[] getHeightMap() {
return geomap.getHeightData();
return geomap.getHeightArray();
}
/**
@ -302,10 +302,10 @@ public class TerrainPatch extends Geometry {
continue;
int idx = lh.z * size + lh.x;
if (overrideHeight) {
geomap.getHeightData()[idx] = lh.h;
geomap.getHeightArray()[idx] = lh.h;
} else {
float h = getMesh().getFloatBuffer(Type.Position).get(idx*3+1);
geomap.getHeightData()[idx] = h+lh.h;
geomap.getHeightArray()[idx] = h+lh.h;
}
}
@ -1059,7 +1059,7 @@ public class TerrainPatch extends Geometry {
//clone.lodCalculator = lodCalculator.clone();
//clone.lodCalculator.setTerrainPatch(clone);
//clone.setLodCalculator(lodCalculatorFactory.clone());
clone.geomap = new LODGeomap(size, geomap.getHeightData());
clone.geomap = new LODGeomap(size, geomap.getHeightArray());
clone.setLocalTranslation(getLocalTranslation().clone());
Mesh m = clone.geomap.createMesh(clone.stepScale, Vector2f.UNIT_XY, clone.offset, clone.offsetAmount, clone.totalSize, false);
clone.setMesh(m);

Loading…
Cancel
Save