2

Hello, People [...]

概括

  • 每当我在我的BorderPane或任何组件/控件/元素上使用阴影效果时,3D 图形性能(如下面的预览部分所示)变得太低了。

  • 令人困惑”的部分是,当效果应用于与我的选项卡、子场景甚至我的移动按钮无关的东西时,它甚至会降低性能,在某种程度上[...]

  • 我使用jdk-12.0.1

️ 预览

演示/预览 .GIF

⚠️ 重现问题

所需文件:

应用程序.java | 主.fxml | AnchorPane.css | MathUtils.java | SimpleFPSCamera.java

通用代码

(您也可以参考重新创建问题部分以获取更多信息)

AnchorPane.css

#BorderPane1 {
    -fx-effect: dropshadow(three-pass-box, rgb(26, 26, 26), 50, 0.6, 0, 0); /* Comment it*/
}

应用程序.java

public class App extends Application {
    @FXML
    
    public Parent root;
    public TabPane TabPane1;
    public BorderPane BorderPane1;
    
    public static void main(String[] args) throws Exception {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
        loader.setController(this);

        root = loader.load();
        Scene RootScene = new Scene(root, 1120, 540);

        primaryStage.setScene(RootScene);

        Thread t = new Thread() {
            public void run() {

                //Setting NewButton2
                Button NewButton2 = new Button();

                NewButton2.setId("Button2");
                NewButton2.setText("test2");
                NewButton2.setPrefWidth(150);
                NewButton2.setPrefHeight(50);
                NewButton2.setTranslateX(-75);
                NewButton2.setTranslateY(-25);
                NewButton2.setTranslateZ(900);

                // Setting group
                Group SubRootGroup = new Group(NewButton2);

                SubRootGroup.setTranslateX(0);
                SubRootGroup.setTranslateY(0);
                SubRootGroup.setTranslateZ(0);

                // Setting Scene
                SubScene SubScene1 = new SubScene(SubRootGroup, 0, 0, true, SceneAntialiasing.BALANCED);

                SubScene1.setId("SubScene1");
                SubScene1.setFill(Color.WHITE);
                SubScene1.heightProperty().bind(RootScene.heightProperty());
                SubScene1.widthProperty().bind(RootScene.widthProperty());

                // Initializing Camera
                SimpleFPSCamera SimpleFPSCam = new SimpleFPSCamera();
                
                // Setting Camera To The Scene
                SubScene1.setCamera(SimpleFPSCam.getCamera());

                // Adding Scene To Stage-TabPane.Tab(0)
                TabPane1.getTabs().add(new Tab("Without Shadows"));
                TabPane1.getTabs().get(0).setContent(SubScene1);

                // Loading Mouse & Keyboard Events
                SimpleFPSCam.loadControlsForSubScene(SubScene1);
            }
        };
        t.setDaemon(true);
        t.run();

        primaryStage.show();

    }
}

到目前为止我尝试过的事情

setCache(true);
setCacheShape(true);
setCacheHint(CacheHint.SPEED);

(我尝试将它与所有组件一起使用但没有任何成功[这也可能是我对 javaFX 的了解很差,[以错误的方式使用它?]])

  • ...

奥特罗

任何想法?提前致谢,任何帮助将不胜感激,[...]
George。

4

1 回答 1

1

很可能,你现在已经明白了,但由于我过去也对同样的问题大发雷霆,所以这是你的答案:

阴影效果“昂贵”并且绘制速度很慢。如果在后代很多的节点上使用,并且移动其中的任何一个后代,都会导致效果在父节点上重新计算,所以整个动画变慢(不管父节点本身是否动画)。

我通过使用 StackPane 作为最顶层容器解决了这个问题,我在其中添加了一个 Pane 作为第一个子项(具有 css 阴影效果),并将实际控件的普通顶层容器作为第二个子项。

这样,当某些东西在布局树下动画时,“阴影”窗格不会更新,瞧,你有一个有效的投影效果而不会影响性能:-)

于 2020-04-29T18:41:46.183 回答