【问题标题】:Why does a 3d model render differently in a SubScene than in Scene为什么 3d 模型在 SubScene 中的渲染与在 Scene 中的渲染不同
【发布时间】:2018-03-29 05:42:20
【问题描述】:

渲染时将标志设置为 true,相机设置为子场景,并且 然后旋转:

SubScene 中渲染的木琴:

场景中渲染的木琴:

使用 Oracle 的 Xylophone 3D 示例,我遇到了一个奇怪的问题。 (Xylophone.java) 当它在场景中渲染时,它看起来是正确的。当它在 SubScene 中呈现时,它不会。有没有人遇到过这个?是否有解决方案或解决方法?

这是创建子场景的修改代码:

final SubScene sub = new SubScene(camOffset, 800,600, false, SceneAntialiasing.BALANCED);
    AnchorPane pane = new AnchorPane();
    pane.setDepthTest(DepthTest.ENABLE);
    pane.getChildren().add(sub);
    final Scene scene = new Scene(pane, 800, 600, true);

【问题讨论】:

    标签: javafx javafx-8 javafx-3d


    【解决方案1】:

    尝试在您的 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)));
    

    此代码适用于我的机器。

    【讨论】:

    • 谢谢,但它不起作用。我添加了木琴的第三张图像,深度缓冲区标志设置为 true,然后旋转以匹配其他 2 张图片的位置。相机已分配给子场景。
    • 谢谢。我对源代码所做的唯一修改是我发布的内容。这个问题出现在其他项目和其他机器上。不限于我的机器。
    • 是的,它也适用于我。我只补充两点:背面有一个错字,应该是backFace.setTranslateZ(0.5*size);。由于Cube 类没有使用适当的 3D 立方体,而是使用一堆 2D 矩形,因此可以轻松地替换为:Box box = new Box(size, size, size); box.setMaterial(new PhongMaterial(color)); getChildren().add(box);。
    猜你喜欢
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    相关资源
    最近更新 更多