Work in progress, the perlin noise is now generated, however, a good colour should be selected as well as using a subject3d instead of a imageview #story[1261]
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package visualiser.layout;
|
||||
|
||||
import javafx.geometry.Point3D;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.image.PixelWriter;
|
||||
import javafx.scene.image.WritableImage;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.PhongMaterial;
|
||||
import javafx.scene.shape.MeshView;
|
||||
import javafx.scene.shape.TriangleMesh;
|
||||
import visualiser.utils.PerlinNoiseGenerator;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 10/09/17.
|
||||
*/
|
||||
public class SeaSurface {
|
||||
private float[][] noiseArray;
|
||||
private ImageView surface;
|
||||
|
||||
public SeaSurface(int size){
|
||||
noiseArray = PerlinNoiseGenerator.createNoise(size);
|
||||
createSurface();
|
||||
}
|
||||
|
||||
private void createSurface(){
|
||||
Image diffuseMap = createImage(noiseArray.length, noiseArray);
|
||||
|
||||
PhongMaterial material = new PhongMaterial();
|
||||
material.setDiffuseMap(diffuseMap);
|
||||
material.setSpecularColor(Color.WHITE);
|
||||
|
||||
// testing / debugging stuff: show diffuse map on chart
|
||||
ImageView iv = new ImageView(diffuseMap);
|
||||
//iv.setTranslateX(-0.5 * noiseArray.length);
|
||||
//iv.setTranslateY(-0.10 * noiseArray.length);
|
||||
iv.setRotate(90);
|
||||
//iv.setRotationAxis(new Point3D(1, 0, 0));
|
||||
surface = iv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create texture for uv mapping
|
||||
* @param size
|
||||
* @param noise
|
||||
* @return
|
||||
*/
|
||||
private Image createImage(double size, float[][] noise) {
|
||||
|
||||
int width = (int) size;
|
||||
int height = (int) size;
|
||||
|
||||
WritableImage wr = new WritableImage(width, height);
|
||||
PixelWriter pw = wr.getPixelWriter();
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
|
||||
float value = noise[x][y];
|
||||
|
||||
double gray = normalizeValue(value, -.5, .5, 0., 1.);
|
||||
|
||||
gray = clamp(gray, 0, 1);
|
||||
|
||||
Color lightBlue = new Color(0.2, 0.2, 1, 1);
|
||||
Color lighterBlue = new Color(0.25, 0.225, 1, 1);
|
||||
|
||||
Color color = lighterBlue.interpolate(lightBlue, gray);
|
||||
|
||||
pw.setColor(x, y, color);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return wr;
|
||||
|
||||
}
|
||||
|
||||
private static double normalizeValue(double value, double min, double max, double newMin, double newMax) {
|
||||
|
||||
return (value - min) * (newMax - newMin) / (max - min) + newMin;
|
||||
|
||||
}
|
||||
|
||||
private static double clamp(double value, double min, double max) {
|
||||
|
||||
if (Double.compare(value, min) < 0)
|
||||
return min;
|
||||
|
||||
if (Double.compare(value, max) > 0)
|
||||
return max;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public ImageView getSurface(){
|
||||
return surface;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class View3D extends Pane {
|
||||
|
||||
scene.widthProperty().bind(this.widthProperty());
|
||||
scene.heightProperty().bind(this.heightProperty());
|
||||
scene.setFill(new Color(0.2, 0.6, 1, 1));
|
||||
//scene.setFill(new Color(0.2, 0.6, 1, 1));
|
||||
|
||||
scene.setCamera(buildCamera());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user