我正在使用我的 IDE 和 Java FX Scene Builder 使用 JavaFX 构建应用程序。
“Scene”对象在扩展Application 的类中定义。在此类的一个嵌套面板内,我加载另一个 .fxml 文件。
另一个 .fxml 文件与 Java 类配对,包含一些我想要显示的形状。
如果我将相机添加到场景对象,相机将应用于 GUI 中的所有面板、菜单和其余元素。我只希望相机应用于包含形状的内部面板,但是当我查找文档时,相机始终添加到场景中。
这是 Application 类中的代码,也是我第一次尝试添加相机,正如我之前所解释的,它会给出奇怪的结果,因为相机适用于应用程序窗口内的所有内容:
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
addCameraAndLights(scene, null);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
最佳答案
使用 SubScene以包含您的 3D 形状。
The SubScene class is the container for content in a scene graph. SubScene provides separation of different parts of a scene, each of which can be rendered with a different camera, depth buffer, or scene anti-aliasing. A SubScene is embedded into the main scene or another sub-scene.
您可以set a camera在与根场景上应用的任何相机分开的子场景上。
以下问题的答案中提供了 SubScene 使用的示例:
关于java - 在 JavaFX 中为面板中的对象设置相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45314025/