0

I want to show 3D mesh after generating it in a Java FX thread but in the final view I can see both - this mesh and unexpected plane which is interrupting the proper shape/mesh.

How do I find the problem? Firstly, I've created a test Java FX application in which I wanted to show generated mesh. It worked correctly as you can see here:

good

and code for this something like this:

public class Main extends Application {

@Override
public void start(Stage arg0) throws Exception {
    Group meshGroup = new Group();

    TriangleMesh detectedMesh = new TriangleMesh();

    detectedMesh.getTexCoords().addAll(0, 0);

    // ... adding points and faces to the mesh from double[][] data

    MeshView mv = new MeshView(detectedMesh);

    // ... some MeshView settings

    meshGroup.getChildren().addAll(mv);

    StackPane root = new StackPane();
    root.getChildren().add(meshGroup);
    Scene scene = new Scene(root, 800, 600, true, SceneAntialiasing.BALANCED);
    scene.setCamera(new PerspectiveCamera());

    Stage primaryStage = new Stage();
    primaryStage.setScene(scene);
    primaryStage.show();
}
}

Next, I wanted to use this code in the proper app which shows this mesh in the new window after some calculations. This time, the problem occured as you can see here:

bad

Code for this is almost the same but this time it's not an independent application but the window is created by another Java FX thread. It's important that in both cases I've used the same double[][] data.

public class ChartGenerator {

double[][] data;

public ChartGenerator(double[][] data) {
    this.data = data;
}

public void show() {
    Group meshGroup = new Group();

    TriangleMesh detectedMesh = new TriangleMesh();

    detectedMesh.getTexCoords().addAll(0, 0);

    // ... adding points and faces to the mesh from double[][] data

    MeshView mv = new MeshView(detectedMesh);

    // ... some MeshView settings

    meshGroup.getChildren().addAll(mv);

    StackPane root = new StackPane();
    root.getChildren().add(meshGroup);
    Scene scene = new Scene(root, 800, 600, true, SceneAntialiasing.BALANCED);
    scene.setCamera(new PerspectiveCamera());

    Stage primaryStage = new Stage();
    primaryStage.setScene(scene);
    primaryStage.show();
}
}

I will be thankful for any ideas or suggestions.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • do both canvas/panes/ display the same empty area if your mesh is not there? – bichito May 07 '17 at 20:32
  • If you mean whether this not-wanted plane is shown when mesh is not added the answer is: yes, they do. For check this, I removed line: `root.getChildren().add(meshGroup);` – mariushdbk May 07 '17 at 21:08
  • In your first code snippet, `Stage primaryStage = new Stage();` is not actually there, is it? In the second one, you have a primary stage and you show the meshView in a second stage (window)? – José Pereda May 07 '17 at 21:22
  • I'm not sure if I understand your first question. In both cases when I use newly created Stage object or use default one (passed as `arg0` variable) I get the same effect. I just wanted to add the least different snippets. For the second question, indeed I create a `ChartGenerator` object in the root controller of primary stage and then I call `show()` method which creates a second stage with the mesh – mariushdbk May 07 '17 at 21:48
  • I don't see in your snippets any difference, so it's very hard to say what's wrong. For me, I'd say there's a 2D plane from a possible node added to the scene, in `z=0`, that cuts the mesh. You could add a rotation to the camera and try to see from both sides of that plane? Also you can check with [ScenicView](http://fxexperience.com/scenic-view/), and find out where that node comes from. – José Pereda May 07 '17 at 22:27

0 Answers0