Skip to content

Commit 444588a

Browse files
committed
added reusing position buffer on heightmap changing.
1 parent ed4e614 commit 444588a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/TerrainPatch.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,22 +303,29 @@ public Triangle[] getGridTriangles(float x, float z) {
303303

304304
protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
305305

306+
final float[] heightArray = geomap.getHeightArray();
307+
final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
308+
final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
309+
306310
for (LocationHeight lh : locationHeights) {
307-
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size)
311+
312+
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
308313
continue;
314+
}
315+
309316
int idx = lh.z * size + lh.x;
317+
310318
if (overrideHeight) {
311-
geomap.getHeightArray()[idx] = lh.h;
319+
heightArray[idx] = lh.h;
312320
} else {
313-
float h = getMesh().getFloatBuffer(Type.Position).get(idx*3+1);
314-
geomap.getHeightArray()[idx] = h+lh.h;
321+
float currentHeight = floatBuffer.get(idx * 3 + 1);
322+
heightArray[idx] = currentHeight + lh.h;
315323
}
316-
317324
}
318325

319-
FloatBuffer newVertexBuffer = geomap.writeVertexArray(null, stepScale, false);
320-
getMesh().clearBuffer(Type.Position);
321-
getMesh().setBuffer(Type.Position, 3, newVertexBuffer);
326+
floatBuffer.clear();
327+
geomap.writeVertexArray(floatBuffer, stepScale, false);
328+
vertexBuffer.setUpdateNeeded();
322329
}
323330

324331
/**

0 commit comments

Comments
 (0)