jdub1581
jdub1581

Reputation: 669

Javafx 8 3d Heightmap from TriangleMesh

just made this little app and wanted to share ...

I took code from several samples and adapted it to suit my needs you can get the source here: gitHub source

Here are a couple screenshots for ya ... screenShot 1

enter image description here

If you find it interesting or useful or want to help improve it... feel free to do or say so!

EDIT: OK, It seems that on some Images introduce a lot of lag, I tried implementing a Timeline to hopefully push some of the processing to the GPU.. (I believe thats how it works).. Can anyone think of a better way to create the update thread ?

Timeline defaultTimeline = new Timeline();
    defaultTimeline.getKeyFrames().addAll(new KeyFrame(new Duration(14 - (System.currentTimeMillis() % 14)), (ActionEvent t) -> {

        Timeline everySecond = new Timeline();
        everySecond.setCycleCount(Timeline.INDEFINITE);
        everySecond.getKeyFrames().addAll(new KeyFrame(Duration.valueOf(14 + "ms"), (ActionEvent event) -> {
            update();                  
        }));
        everySecond.play();
        System.err.println("Playing");
    }));
    defaultTimeline.play();

and the update method:

 private void update() {
    if(pixelSkipSlider.isValueChanging()){
        if(meshView.getMesh() != null){
            meshView.setMesh(MeshUtils.createHeightMap(meshImageView.getImage(), (int)pixelSkipSlider.getValue() , (float)maxHeightSlider.getValue(), (float)scaleSlider.getValue()));
        }
    }
    if(maxHeightSlider.isValueChanging()){
        if(meshView.getMesh() != null){
            meshView.setMesh(MeshUtils.createHeightMap(meshImageView.getImage(), (int)pixelSkipSlider.getValue() , (float)maxHeightSlider.getValue(), (float)scaleSlider.getValue()));
        }
    }
    if(scaleSlider.isValueChanging()){
        if(meshView.getMesh() != null){
            meshView.setMesh(MeshUtils.createHeightMap(meshImageView.getImage(), (int)pixelSkipSlider.getValue() , (float)maxHeightSlider.getValue(), (float)scaleSlider.getValue()));
        }
    }
}    

Upvotes: 3

Views: 1258

Answers (1)

jdub1581
jdub1581

Reputation: 669

At the Time this was asked I was unaware of the invalidated() method of JavaFX properties, Overriding this method, and using it is my preferred method of updating properties.

In doing so, the platform performs as it should and my issues have gone away.

Upvotes: 1

Related Questions