javaFX初探(子场景)

来源:互联网 发布:kingdee数据在那里 编辑:程序博客网 时间:2024/05/21 10:40

这一章主要介绍子场景的信息。

子场景是场景图中的一个节点,它是一个特殊的场景,它可以用一个不同的相机来渲染场景的一部分。当你想让Y-up3D对象和yY-down2D对

象出现在你的布局中的话,你可以使用子场景。一些可能得子场景应用实例:
 

UI控件覆盖

 背景衬托

 平视显示器

 Y-up 3 d对象和Y-down 2 d界面。

 

创建子场景

下面先看一下构造子场景的两个构造函数:

// Creates a SubScene for a specific root Node with a specific size.//public SubScene(Parent root, double width, double height)// // Constructs a SubScene consisting of a root, with a dimension of width and // height, specifies whether a depth buffer is created for this scene and // specifies whether scene anti-aliasing is requested.public SubScene(Parent root, double width, double height, boolean depthBuffer,          SceneAntialiasing antiAliasing)


一旦子场景建立了,你就可以通过可用的方法来修改它,或者获得它的高、根节点以及背景色,也可以利用相机渲染子场景,

一个子场景的实例:

...SubScene msaa = createSubScene("MSAA = true", cylinder2,                Color.TRANSPARENT,                new PerspectiveCamera(), true);......private static SubScene createSubScene(String title, Node node,            Paint fillPaint, Camera camera, boolean msaa) {        Group root = new Group();         PointLight light = new PointLight(Color.WHITE);        light.setTranslateX(50);        light.setTranslateY(-300);        light.setTranslateZ(-400);        PointLight light2 = new PointLight(Color.color(0.6, 0.3, 0.4));        light2.setTranslateX(400);        light2.setTranslateY(0);        light2.setTranslateZ(-400);         AmbientLight ambientLight = new AmbientLight(Color.color(0.2, 0.2, 0.2));        node.setRotationAxis(new Point3D(2, 1, 0).normalize());        node.setTranslateX(180);        node.setTranslateY(180);        root.getChildren().addAll(setTitle(title), ambientLight, light, light2, node);         SubScene subScene = new SubScene(root, 500, 400, true,                 msaa ? SceneAntialiasing.BALANCED : SceneAntialiasing.DISABLED);        subScene.setFill(fillPaint);        subScene.setCamera(camera);         return subScene;    }


 

上一篇博客里有这个例子,大家可以回头看一下。

 

0 0