/* * 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. */ import javafx.animation.Interpolator; import javafx.animation.RotateTransition; import javafx.animation.Timeline; import javafx.application.Application; import javafx.geometry.Point3D; import javafx.scene.*; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.*; import javafx.stage.Stage; import javafx.util.Duration; public class SmallTriangleMesh extends Application { Group root; PointLight pointLight; MeshView meshView; TriangleMesh triMesh; static TriangleMesh buildMesh() { float[] points = new float[]{-0.001f, 0.142854f, -0.025393f, -0.001f, 0.142603f, -0.025318f, -0.000951f, 0.142652f, -0.025057f}; float[] pointsScaled = new float[]{-0.01f, 1.42854f, -0.25393f, -0.01f, 1.42603f, -0.25318f, -0.00951f, 1.42652f, -0.25057f}; float[] texCoords = new float[]{0.0f, 0.0f}; int[] faces = new int[]{0, 0, 1, 0, 2, 0}; TriangleMesh triaMesh = new TriangleMesh(points, texCoords, faces); return triaMesh; } private Group buildScene() { triMesh = buildMesh(); int scale = 1000000; meshView = new MeshView(triMesh); meshView.setMaterial(new PhongMaterial(Color.YELLOW)); meshView.setScaleX(scale); meshView.setScaleY(scale); meshView.setScaleZ(scale); meshView.setTranslateX(300); meshView.setTranslateY(300); meshView.setTranslateZ(10); RotateTransition rotTrans = new RotateTransition(Duration.seconds(35), meshView); // rotTrans.setAutoReverse(true); rotTrans.setAxis(new Point3D(1, 1, 1).normalize()); rotTrans.setInterpolator(Interpolator.EASE_BOTH); rotTrans.setCycleCount(Timeline.INDEFINITE); rotTrans.setByAngle(360); rotTrans.setDuration(Duration.seconds(5)); rotTrans.play(); pointLight = new PointLight(Color.ANTIQUEWHITE); pointLight.setTranslateX(150); pointLight.setTranslateY(-100); pointLight.setTranslateZ(-1000); root = new Group(meshView, pointLight); return root; } private PerspectiveCamera addCamera(Scene scene) { PerspectiveCamera perspectiveCamera = new PerspectiveCamera(false); scene.setCamera(perspectiveCamera); return perspectiveCamera; } @Override public void start(Stage primaryStage) { Scene scene = new Scene(buildScene(), 800, 800, true); scene.setFill(Color.rgb(10, 10, 40)); addCamera(scene); primaryStage.setTitle("SmallTriangleMesh"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { System.setProperty("prism.dirtyopts", "false"); launch(args); } }