3D Features Planned for Version 8

Introduction

This page contains the list of 3D features schedule for JavaFX 8.0. The information was presented at JavaOne 2012 as part of the 3D Made Easy with JavaFX technical session.

Three umbrella JIRA issues were created to capture most of the work: Movable Camera , 3D Geometry, and 3D Attributes

Proposed Features

Movable cameras and SubScene

Camera Class Hierarchy
  • javafx.scene.Node
    • javafx.scene.Camera (abstract)
      • javafx.scene.ParallelCamera
      • javafx.scene.PerspectiveCamera
    • javafx.scene.SubScene
Code segment

Specifying a fixed Camera (existing 2.2 API)

// Create a camera and add it to the Scene
Camera camera = new PerspectiveCamera();
scene.setCamera(camera);

Specifying a movable Camera

// Create a camera and add it to the Scene
Camera camera = new PerspectiveCamera();
scene.setCamera(camera);

// Add camera to scene graph (so it can move)
Group cameraGroup = new Group();
cameraGroup.getChildren().add(camera);
root.getChildren().add(cameraGroup);

// Rotate the camera
camera.rotate(45);

// Move the cameraGroup (camera moves with it)
cameraGroup.setTranslateZ(-75);

3D primitives

User-defined shapes
Predefined shapes
Shape3D Class Hierarchy
  • javafx.scene.Node
    • javafx.scene.shape3d.Shape3D (abstract)
      • javafx.scene.shape3d.MeshView
      • javafx.scene.shape3d.Box
      • javafx.scene.shape3d.Cylinder
      • javafx.scene.shape3d.Sphere
Mesh Class Hierarchy
  • java.lang.Object
    • javafx.scene.shape3d.Mesh (abstract)
      • javafx.scene.shape3d.TriangleMesh
Code Segment

Defining a MeshView

// Create the arrays of positions, texCoords
float[] positions = createPositions();
float[] texCoords = createUVs();

// Create faces (indices into the positions, texCoord arrays)
int[] faces = createFaces();

// Create a mesh
TriangleMesh mesh = new TriangleMesh();
mesh.setPositions(positions);
mesh.setTexCoords(texCoords);
mesh.setFaces(faces);

// Create meshView
MeshView mv = new MeshView(mesh);

Using Predefined Shapes

// Create a sphere with the given radius
Sphere sphere = new Sphere(10.0);

// Create a sphere with the given radius, number of divisions
Sphere sphere = new Sphere(10.0, 40);

// Create a cylinder with the given radius, and height
Cylinder cylinder = new Cylinder(10.0, 30.0);

// Create a box with the given width, height, and depth
Box box = new Box(1.0, 1.0, 1.0);

// NOTE: Predefined 3D shapes are centered at (0,0,0)

3D attributes

Light
Material
Light Class Hierarchy
  • javafx.scene.Node
    • javafx.scene.light.LightBase (abstract)
      • javafx.scene.light.AmbientLight
      • javafx.scene.light.PointLight
Material Class Hierarchy
  • java.lang.Object
    • javafx.scene.material.Material (abstract)
      • javafx.scene.material.PhongMaterial
Code Segment

Defining Lights

// Create point light and add it to the Scene
PointLight light = new PointLight();
light.setColor(Color.RED);
scene.getLights().add(light);

// Add light to scene graph (so it can move)
Group lightGroup = new Group();
lightGroup.getChildren().add(light);
root.getChildren().add(lightGroup);

// Rotate the light
light.rotate(45);

// Move the lightGroup (light moves with it)
lightGroup.setTranslateZ(-75);

Defining Materials

// Create material
Material mat = new PhongMaterial();
Image diffuseMap = new Image("diffuseMap.png");
Image bumpMap = new Image("normalMap.png");

// Set material properties
mat.setDiffuseMap(diffuseMap);
mat.setBumpMap(normalMap);
mat.setSpecularColor(Color.WHITE);

// Use the material for a shape
shape3d.setMaterial(mat);

3D picking

Loader support