I have a n x n terrain height array which has values from -0.5 to 1
, where 0 is sea level. I have generated this array using simplex noise and want to display it using FXyz
in Java. With the following code I can correctly display the array, but I have no idea how to set up the different colours according to their height in my code. Anyone know how I can implement this feature?
Also I think I have a little bug in my code, which displays the terrain upside down.
@Override public void start(Stage primaryStage) {
Group group = new Group();
Tile[][] tiles = new GenerateSimplexTiles(SIZE, SIZE, 8, .5).getTiles();
TriangleMesh terrainMesh = new TriangleMesh();
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
float x = (float) (i * SCALE);+
float y = (float) (tiles[i][j].value * SCALE * 5);
float z = (float) (j * SCALE);
terrainMesh.getPoints().addAll(x, y, z);
terrainMesh.getTexCoords().addAll(0, 150,255);
}
}
for (int i = 0; i < SIZE - 1; i++) {
for (int j = 0; j < SIZE - 1; j++) {
int p0 = i * SIZE + j;
int p1 = i * SIZE + j + 1;
int p2 = (i + 1) * SIZE + j + 1;
int p3 = (i + 1) * SIZE + j;
terrainMesh.getFaces().addAll(p0, 0, p3, 0, p1, 0);
terrainMesh.getFaces().addAll(p1, 0, p3, 0, p2, 0);
}
}
MeshView terrain = new MeshView(terrainMesh);
terrain.setCullFace(CullFace.BACK);
terrain.setDrawMode(DrawMode.FILL);
group.getChildren().add(terrain);
Scene scene = new Scene(group, WIDTH, HEIGHT, true);
primaryStage.setScene(scene);
primaryStage.setTitle("3D Visualize");
primaryStage.show();
}