/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package meshviewer; import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.*; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.*; import javafx.scene.transform.Rotate; import javafx.stage.Stage; import javafx.util.Duration; public class DepthBufferTest extends Application { double anchorX, anchorY, anchorAngle; Group root; PointLight pointLight1, pointLight2; Shape3D meshViews[]; PhongMaterial materialArr[]; private Timeline timeline; private Group buildScene() { materialArr = new PhongMaterial[]{ new PhongMaterial(Color.RED), new PhongMaterial(Color.YELLOW), new PhongMaterial(Color.BLUE) }; meshViews = new Shape3D[]{ new Cylinder(75, 200), new Cylinder(75, 200), new Cylinder(75, 200) }; for (int i = 0; i < 3; i++) { meshViews[i].setMaterial(materialArr[i]); meshViews[i].setDrawMode(DrawMode.FILL); meshViews[i].setCullFace(CullFace.BACK); }; meshViews[0].setTranslateX(500); meshViews[0].setTranslateY(400); meshViews[1].setTranslateX(600); meshViews[1].setTranslateY(500); meshViews[2].setTranslateX(700); meshViews[2].setTranslateY(600); pointLight1 = new PointLight(Color.ANTIQUEWHITE); pointLight1.setTranslateX(150); pointLight1.setTranslateY(-100); pointLight1.setTranslateZ(-1000); pointLight2 = new PointLight(Color.ANTIQUEWHITE); pointLight2.setTranslateX(-150); pointLight2.setTranslateY(-1000); pointLight2.setTranslateZ(1000); root = new Group(); // root.getChildren().addAll(meshViews[0], meshViews[1], meshViews[2], pointLight1, pointLight2, rect); root.getChildren().addAll(meshViews[0], meshViews[1], meshViews[2], pointLight1, pointLight2); root.setTranslateZ(200); root.setRotationAxis(Rotate.Y_AXIS); root.setOnKeyTyped(new EventHandler() { @Override public void handle(KeyEvent e) { switch (e.getCharacter()) { case "p": if (timeline.getStatus() == Animation.Status.RUNNING) { timeline.pause(); } else { timeline.play(); } break; } } }); return root; } private PerspectiveCamera addCamera() { PerspectiveCamera perspectiveCamera = new PerspectiveCamera(false); return perspectiveCamera; } static final boolean depthBuffer = true; static final boolean useSubScene = true; @Override public void start(Stage primaryStage) { Group mainGroup = buildScene(); Group root = new Group(); if (useSubScene) { SubScene subScene = new SubScene(mainGroup, 800, 800, depthBuffer, depthBuffer); subScene.setCamera(addCamera()); subScene.setFill(Color.PURPLE); root.getChildren().add(subScene); } else { root.getChildren().add(mainGroup); } Scene scene = new Scene(root, 1000, 1000, depthBuffer); scene.setFill(Color.rgb(10, 10, 40)); scene.setCamera(addCamera()); primaryStage.setTitle("Simple Depth Test Viewer"); primaryStage.setScene(scene); primaryStage.show(); mainGroup.requestFocus(); KeyValue kv = new KeyValue (mainGroup.rotateProperty(), Float.valueOf(-360)); KeyFrame kf = new KeyFrame(Duration.seconds(4), kv); timeline = new Timeline(kf); timeline.setCycleCount(Timeline.INDEFINITE); // timeline.play(); } public static void main(String[] args) { System.setProperty("prism.dirtyopts", "false"); launch(args); } }