From 444588a363f1dfc0ecd1bf9fdcb1f21822aa197c Mon Sep 17 00:00:00 2001 From: javasabr Date: Sat, 18 Feb 2017 18:48:42 +0300 Subject: [PATCH] added reusing position buffer on heightmap changing. --- .../jme3/terrain/geomipmap/TerrainPatch.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java index 44ad5cb30..626eb4fd5 100644 --- a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java +++ b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java @@ -303,22 +303,29 @@ public class TerrainPatch extends Geometry { protected void setHeight(List 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) { - 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; + } + int idx = lh.z * size + lh.x; + if (overrideHeight) { - geomap.getHeightArray()[idx] = lh.h; + heightArray[idx] = lh.h; } else { - float h = getMesh().getFloatBuffer(Type.Position).get(idx*3+1); - geomap.getHeightArray()[idx] = h+lh.h; + float currentHeight = floatBuffer.get(idx * 3 + 1); + heightArray[idx] = currentHeight + lh.h; } - } - FloatBuffer newVertexBuffer = geomap.writeVertexArray(null, stepScale, false); - getMesh().clearBuffer(Type.Position); - getMesh().setBuffer(Type.Position, 3, newVertexBuffer); + floatBuffer.clear(); + geomap.writeVertexArray(floatBuffer, stepScale, false); + vertexBuffer.setUpdateNeeded(); } /**