javafx java 中 3D 场景上的静态 2D 文本

Static 2D text over 3D scene in javafx java

我的目标是在 javafx 中将 2D 文本覆盖在 3d 场景上,如

中所示

使用子场景不是一个有效的选择,因为我希望 3d 模型能够占据屏幕上的整个 space。

我尝试向场景添加标签并关闭深度缓冲,但是一旦模型旋转(实际相机改变位置),正确的定位就会中断。 (使用代码控制 camera

我能否以某种方式在我的 3D 场景上覆盖静态 2D GUI,也许是通过使用锚点窗格和具有透明背景的 2D 场景?

关于堆栈溢出我只发现了这些问题:


这不符合我的确切需求。

我误解了子场景的概念,因为它们都显示了完全独立的控件。使用以下结构可以覆盖 3D 文本...

  • 根容器(例如锚窗格)
    • 2D 内容(标签)
    • 子场景
      • 透视相机
      • 根3D
        • 3D 内容

代码示例:

//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();