尝试在您的 SubScene-Constructor 中将 depthBuffer-flag(第 4 个参数)设置为 true:
final SubScene sub = new SubScene(camOffset, 800,600, true, SceneAntialiasing.BALANCED);
在 3d 场景中,深度排序渲染需要 depthBuffer(参见例如https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html)。
此外(如果尚未完成)相机应分配给 subScene 而不是场景:
sub.setCamera(new PerspectiveCamera());
然后一切都应该按预期工作。
编辑:
此外,对子场景填充应用渐变似乎不起作用,请参阅
https://bugs.openjdk.java.net/browse/JDK-8088605
https://www.youtube.com/watch?v=LGx4CV_K5U8&feature=youtu.be
一种可能的解决方法是将渐变应用到包含子场景的窗格。
总的来说,在Xylophone-class replace的start-method中
final Scene scene = new Scene(camOffset, 800, 600, true);
scene.setFill(new RadialGradient(225, 0.85, 300, 300, 500, false,
CycleMethod.NO_CYCLE, new Stop[]
{ new Stop(0f, Color.BLUE),
new Stop(1f, Color.LIGHTBLUE) }));
scene.setCamera(new PerspectiveCamera());
与
final SubScene sub = new SubScene(camOffset, 800,600, true, SceneAntialiasing.BALANCED); // set depthBuffer = true
sub.setCamera(new PerspectiveCamera());
AnchorPane pane = new AnchorPane();
pane.setDepthTest(DepthTest.ENABLE);
pane.getChildren().add(sub);
final Scene scene = new Scene(pane, 800, 600, true);
// Shift the RadialGradient from the Scene to the AnchorPane (and NOT to the SubScene).
RadialGradient radialGradient = new RadialGradient(225, 0.85, 300, 300, 500, false,
CycleMethod.NO_CYCLE, new Stop[]
{ new Stop(0f, Color.BLUE),
new Stop(1f, Color.LIGHTBLUE) });
pane.setBackground(new Background(new BackgroundFill(radialGradient, CornerRadii.EMPTY, Insets.EMPTY)));
此代码适用于我的机器。