//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author John Miller * @version 2.0 * @date Thu Aug 5 14:50:12 EDT 2021 * @see LICENSE (MIT style license file). * * @title Translation of Jenkov Tutorial from Java to Scala - JavaFX 3D Example * * @see tutorials.jenkov.com/javafx/3d.html * @see alvinalexander.com/source-code/scala-javafx-application-launch-scene-stylesheets/ * @see openjfx.io/javadoc/16/ */ // FIX - fails to launch Application - could be a build.sbt problem package scalation package scala3d import javafx.application.{Application, ConditionalFeature, Platform} import javafx.scene.{Group, PerspectiveCamera, Scene} import javafx.scene.shape.{Box, CullFace} import javafx.scene.transform.Rotate import javafx.stage.Stage //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `Gfx3DExample` companion obejct is use to invoke the `Gfx3DExample` class. * > runMain scalation.scala3d.Gfx3DExample */ object Gfx3DExample: def main (args: Array [String]): Unit = Application.launch (classOf [Gfx3DExample], args :_*) end main end Gfx3DExample //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `Gfx3DExample` class displays a 3D `Box`. */ class Gfx3DExample extends Application: def start (primaryStage: Stage): Unit = val is3DSupported = Platform.isSupported (ConditionalFeature.SCENE3D) if ! is3DSupported then println ("Sorry, 3D is not supported in JavaFX on this platform.") return end if val box = new Box (100, 100, 100) box.setCullFace (CullFace.NONE) box.setTranslateX (250) box.setTranslateY (100) box.setTranslateZ (400) val fixedEyeAtCameraZero = false val camera = new PerspectiveCamera (fixedEyeAtCameraZero) camera.setTranslateX (150) camera.setTranslateY (-100) camera.setTranslateZ (250) val root = new Group (box) root.setRotationAxis (Rotate.X_AXIS) root.setRotate (30) val scene = new Scene (root, 500, 300, true) scene.setCamera (camera) primaryStage.setScene (scene) primaryStage.setTitle ("3D Example") primaryStage.show () end start end Gfx3DExample