Java Reference
In-Depth Information
You can test if the system supports the JavaFX 3D graphics API using the Platform.isSupported() method for
ConditionalFeature.SCENE3D :
boolean supported = Platform.isSupported(ConditionalFeature.SCENE3D);
The rest of the examples in this chapter will work only if this test results in true .
As our first foray into the JavaFX 3D world, we consider a first JavaFX 3D example in Listing 10-1.
Listing 10-1. First3DExample.java
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class First3DExample extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("First 3D Example");
stage.setScene(makeScene());
stage.show();
}
private Scene makeScene() {
Sphere sphere = new Sphere(100);
Group root = new Group(sphere);
root.setTranslateX(320);
root.setTranslateY(240);
Scene scene = new Scene(root, 640, 480);
return scene;
}
public static void main(String[] args) {
launch(args);
}
}
Although the only 3D element in this very simple program is the Sphere class, which represents a sphere in the
three-dimensional space, its presence in the scene triggers several responses from the JavaFX runtime system. It
adds a camera and a light to the scene. It also gives the sphere a material quality. The camera, the light, the 3D object,
and the material quality of the 3D object are the basic ingredients of a 3D model . They work together to bring the 3D
model to our two-dimensional screen.
When the program in Listing 10-1 is run, the First 3D Example window in Figure 10-1 is displayed.
 
Search WWH ::




Custom Search