use of com.jme3.terrain.geomipmap.TerrainQuad.LocationHeight in project jmonkeyengine by jMonkeyEngine.
the class TerrainPatch method setHeight.
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) {
if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
continue;
}
int idx = lh.z * size + lh.x;
if (overrideHeight) {
heightArray[idx] = lh.h;
} else {
float currentHeight = floatBuffer.get(idx * 3 + 1);
heightArray[idx] = currentHeight + lh.h;
}
}
floatBuffer.clear();
geomap.writeVertexArray(floatBuffer, stepScale, false);
vertexBuffer.setUpdateNeeded();
}
use of com.jme3.terrain.geomipmap.TerrainQuad.LocationHeight in project jmonkeyengine by jMonkeyEngine.
the class TerrainQuad method setHeight.
protected void setHeight(List<LocationHeight> locations, boolean overrideHeight) {
if (children == null)
return;
List<LocationHeight> quadLH1 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH2 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH3 = new ArrayList<LocationHeight>();
List<LocationHeight> quadLH4 = new ArrayList<LocationHeight>();
Spatial quad1 = null;
Spatial quad2 = null;
Spatial quad3 = null;
Spatial quad4 = null;
// get the child quadrants
for (int i = children.size(); --i >= 0; ) {
Spatial spat = children.get(i);
int childQuadrant = 0;
if (spat instanceof TerrainQuad) {
childQuadrant = ((TerrainQuad) spat).getQuadrant();
} else if (spat instanceof TerrainPatch) {
childQuadrant = ((TerrainPatch) spat).getQuadrant();
}
if (childQuadrant == 1)
quad1 = spat;
else if (childQuadrant == 2)
quad2 = spat;
else if (childQuadrant == 3)
quad3 = spat;
else if (childQuadrant == 4)
quad4 = spat;
}
int split = (size + 1) >> 1;
// distribute each locationHeight into the quadrant it intersects
for (LocationHeight lh : locations) {
int quad = findQuadrant(lh.x, lh.z);
int col = lh.x;
int row = lh.z;
if ((quad & 1) != 0) {
quadLH1.add(lh);
}
if ((quad & 2) != 0) {
row = lh.z - split + 1;
quadLH2.add(new LocationHeight(lh.x, row, lh.h));
}
if ((quad & 4) != 0) {
col = lh.x - split + 1;
quadLH3.add(new LocationHeight(col, lh.z, lh.h));
}
if ((quad & 8) != 0) {
col = lh.x - split + 1;
row = lh.z - split + 1;
quadLH4.add(new LocationHeight(col, row, lh.h));
}
}
// send the locations to the children
if (!quadLH1.isEmpty()) {
if (quad1 instanceof TerrainQuad)
((TerrainQuad) quad1).setHeight(quadLH1, overrideHeight);
else if (quad1 instanceof TerrainPatch)
((TerrainPatch) quad1).setHeight(quadLH1, overrideHeight);
}
if (!quadLH2.isEmpty()) {
if (quad2 instanceof TerrainQuad)
((TerrainQuad) quad2).setHeight(quadLH2, overrideHeight);
else if (quad2 instanceof TerrainPatch)
((TerrainPatch) quad2).setHeight(quadLH2, overrideHeight);
}
if (!quadLH3.isEmpty()) {
if (quad3 instanceof TerrainQuad)
((TerrainQuad) quad3).setHeight(quadLH3, overrideHeight);
else if (quad3 instanceof TerrainPatch)
((TerrainPatch) quad3).setHeight(quadLH3, overrideHeight);
}
if (!quadLH4.isEmpty()) {
if (quad4 instanceof TerrainQuad)
((TerrainQuad) quad4).setHeight(quadLH4, overrideHeight);
else if (quad4 instanceof TerrainPatch)
((TerrainPatch) quad4).setHeight(quadLH4, overrideHeight);
}
}
Aggregations