這一章主要介紹子場景的資訊。
子場景是場景圖中的一個節點,它是一個特殊的場景,它可以用一個不同的相機來渲染場景的一部分。當你想讓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;
}
上一篇部落格裡有這個例子,大家可以回頭看一下。