Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static 2D text over 3D scene in javafx java

My goal is to overlay 2D text over a 3d scene in javafx as seen in this image

Using a subscene is not a valid choice as I want the 3d model to be able to take up the entire space on the screen.

I tried adding a label to the scene and turning depth buffering off but once the model gets rotated (the actual camera changes position) the correct positioning breaks. (Used code to control the camera )

Can I somehow overlay a static 2D GUI over my 3D scene maybe by using anchor panes and having a 2D scene with transparent background?

On stack overflow I only found these questions:
Question No.1
Question No.2
which don't correspond to my exact needs.

like image 521
Kilian Avatar asked Oct 16 '25 08:10

Kilian


1 Answers

I misunderstood the concept of subscenes as they all showed entirely separated controls. Overlaying 3D Text is possible using the following structure...

  • Root Container (e.g. an Anchor Pane)
    • 2D Content (Label)
    • SubScene
      • perspective camera
      • root 3D
        • 3D content

Code example:

//Add 2D content here
AnchorPane globalRoot = new AnchorPane();
globalRoot.getChildren().add(new Label("Hello World"));
Scene scene = new Scene(globalRoot, 1024, 768, true);

SubScene sub = new 
SubScene(root3D,1024,768,false,SceneAntialiasing.BALANCED);
sub.setCamera(camera);
globalRoot.getChildren().add(sub);

//Add all 3D content to the root3D node    

primaryStage.setScene(scene);
primaryStage.show();
like image 174
Kilian Avatar answered Oct 19 '25 13:10

Kilian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!