Merge pull request #622 from JavaSaBr/fix_memory_cost_on_terrain_changes

added reusing position buffer on heightmap changing.
This commit is contained in:
empirephoenix 2017-03-02 10:08:11 +01:00 committed by GitHub
commit 78a3e2408e

View File

@ -303,22 +303,29 @@ public class TerrainPatch extends Geometry {
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) { protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
final float[] heightArray = geomap.getHeightArray();
final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
for (LocationHeight lh : locationHeights) { for (LocationHeight lh : locationHeights) {
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size)
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
continue; continue;
}
int idx = lh.z * size + lh.x; int idx = lh.z * size + lh.x;
if (overrideHeight) { if (overrideHeight) {
geomap.getHeightArray()[idx] = lh.h; heightArray[idx] = lh.h;
} else { } else {
float h = getMesh().getFloatBuffer(Type.Position).get(idx*3+1); float currentHeight = floatBuffer.get(idx * 3 + 1);
geomap.getHeightArray()[idx] = h+lh.h; heightArray[idx] = currentHeight + lh.h;
}
} }
} floatBuffer.clear();
geomap.writeVertexArray(floatBuffer, stepScale, false);
FloatBuffer newVertexBuffer = geomap.writeVertexArray(null, stepScale, false); vertexBuffer.setUpdateNeeded();
getMesh().clearBuffer(Type.Position);
getMesh().setBuffer(Type.Position, 3, newVertexBuffer);
} }
/** /**