相互重叠的 JavaFX 3D 框
JavaFX 3D boxes overlapping each other
我遇到了JavaFX 3D的问题,问题如下:
当我转动透视相机时,最后添加的框(蓝色框)与第一个添加的框(红色框)重叠,这是截图:
谁能告诉我为什么会这样?有没有办法解决它? (这些盒子实际上是 2 个盒子 classes
,带有 width
、height
、depth
、position
和 color
)
最小的可复制示例,因为有人要求它:
Box box1 = new Box();
Box box2 = new Box();
box1.setWidth(300);
box2.setWidth(300);
box1.setHeight(300);
box2.setHeight(300);
box1.setDepth(300);
box2.setDepth(300);
box1.setTranslateX(300);
box2.setTranslateX(300);
box1.setTranslateY(300);
box2.setTranslateX(300);
Group root = new Group();
root.getChildren().addAll(box, box2);
PerspectiveCamera cam = new PerspectiveCamera();
Scene scene = new Scene(root);
scene.setCamera(camera);
stage.setScene(scene);
stage.show();
其中 stage 是 public void start(Stage stage) 中的阶段,JavaFX 的默认 运行 方法(任何扩展 Application 的 class 都应该实现它)
您可能需要添加一个启用了深度缓冲区的子场景。参见:https://openjfx.io/javadoc/15/javafx.graphics/javafx/scene/SubScene.html#%3Cinit%3E(javafx.scene.Parent,double,double,boolean,javafx.scene.SceneAntialiasing)
解决方案:
我使用了以下构造函数:
new Scene(root, WIDTH, HEIGHT, true, SceneAntialiasing.BALANCED);
而不是:
new Scene(root);
我遇到了JavaFX 3D的问题,问题如下:
当我转动透视相机时,最后添加的框(蓝色框)与第一个添加的框(红色框)重叠,这是截图:
谁能告诉我为什么会这样?有没有办法解决它? (这些盒子实际上是 2 个盒子 classes
,带有 width
、height
、depth
、position
和 color
)
最小的可复制示例,因为有人要求它:
Box box1 = new Box();
Box box2 = new Box();
box1.setWidth(300);
box2.setWidth(300);
box1.setHeight(300);
box2.setHeight(300);
box1.setDepth(300);
box2.setDepth(300);
box1.setTranslateX(300);
box2.setTranslateX(300);
box1.setTranslateY(300);
box2.setTranslateX(300);
Group root = new Group();
root.getChildren().addAll(box, box2);
PerspectiveCamera cam = new PerspectiveCamera();
Scene scene = new Scene(root);
scene.setCamera(camera);
stage.setScene(scene);
stage.show();
其中 stage 是 public void start(Stage stage) 中的阶段,JavaFX 的默认 运行 方法(任何扩展 Application 的 class 都应该实现它)
您可能需要添加一个启用了深度缓冲区的子场景。参见:https://openjfx.io/javadoc/15/javafx.graphics/javafx/scene/SubScene.html#%3Cinit%3E(javafx.scene.Parent,double,double,boolean,javafx.scene.SceneAntialiasing)
解决方案:
我使用了以下构造函数:
new Scene(root, WIDTH, HEIGHT, true, SceneAntialiasing.BALANCED);
而不是:
new Scene(root);