3D Features Planned for Version 8
Introduction
This page presents the list of 3D features schedule for JavaFX 8.0. This information was presented at this year JavaOne as part of the 3D Made Easy with JavaFX technical session.
Three umbrella JIRA issues were created to capture most of this work: Movable Camera , 3D Geometry, and 3D Attributes
Proposed Features
Movable cameras and SubScene
- Camera is now a Node
- Camera can be added to a scene graph
- Camera's position and aim (or orientation) is set using standard Node transform properties and methods
- For backward compatibility, fixed camera need not be added to the scene
- Added new properties for near & far clipping plane
- SubScene is a special Node for scene separation
- It can be used to render part of the Scene with different camera
- Possible use cases are:
- Picture in picture
- Overlay or "heads-up" display for UI controls in a scene with a moving camera
Camera Class Hierarchy
- javafx.scene.Node
- javafx.scene.Camera (abstract)
- javafx.scene.ParallelCamera
- javafx.scene.PerspectiveCamera
- javafx.scene.SubScene
- javafx.scene.Camera (abstract)
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
- Added two type of 3D shapes, extending from an abstract Shape3D base class:
- User-defined shapes (MeshView)
- Predefined shapes
User-defined shapes
- User defined mesh (geometry) of a shape by specifying a set of points, texture coordinates, and faces (triangles that describe the topology)
- User defined smoothing group to specify group of faces that are part of the same curved surface
- A mesh is sharable among mutiple user-defined shapes
Predefined shapes
- Three commonly used predefined 3D shapes are introduced: Box, Cylinder and Sphere
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
- javafx.scene.shape3d.Shape3D (abstract)
Mesh Class Hierarchy
- java.lang.Object
- javafx.scene.shape3d.Mesh (abstract)
- javafx.scene.shape3d.TriangleMesh
- javafx.scene.shape3d.Mesh (abstract)
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
- Added lights and 3D materials to add realism for 3D shapes.
- Material specifies the appearance of a 3D shape
- Light interacts with the geometry of a Shape3D and its material to provide the rendering result
- A Shape3D can be rendered as a filled shape or as a wireframe
- A Shape3D has a face culling property (front, back or none)
Light
- Light is defined as a node in the scene graph
- A scene contains a set of active lights
- A default light is provided when the set of active light is empty
- Each light contains a set of affected nodes
- If a Parent is in the set, all its children are affected
- Default is the root node of the Scene
- Added 2 type of light sources:
- AmbientLight and PointLight
- May add more in the future
Material
- Material contains a set of rendering properties
- PhongMaterial is a concrete subclass of Material
- It has the following properties:
- Ambient color
- Diffuse color, diffuse map
- Specular color, specular map
- Specular power
- Bump map
- Self-illumination map
- It has the following properties:
- Sharable among multiple Shape3D nodes
Light Class Hierarchy
- javafx.scene.Node
- javafx.scene.light.LightBase (abstract)
- javafx.scene.light.AmbientLight
- javafx.scene.light.PointLight
- javafx.scene.light.LightBase (abstract)
Material Class Hierarchy
- java.lang.Object
- javafx.scene.material.Material (abstract)
- javafx.scene.material.PhongMaterial
- javafx.scene.material.Material (abstract)
Code Segment
Defining Lights
XXXXXXXXXXx
Overview
Content Tools
ThemeBuilder