3D Features

compared with
Current by Daniel Blaukopf
on Jul 09, 2013 09:08.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (2)

View Page History
h2. 3D Features Planned for Version 8


h3. Introduction

This page contains the list of 3D features schedule for JavaFX 8.0

We have been thinking about the possible 3D features for JavaFX 8 for a while. We are now ready to present the plan to the community for review. This information has also been presented at this year's JavaOne *{_}3D Made Easy with JavaFX{_}* technical session.

Three umbrella JIRA issues were created to capture most of the work: [Movable Camera |http://javafx-jira.kenai.com/browse/RT-24655], [3D Geometry|http://javafx-jira.kenai.com/browse/RT-17401], and [3D Attributes|http://javafx-jira.kenai.com/browse/RT-24008]

























h3. [Proposed API]


h3. Proposed Features


h4. 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

h6. Camera Class Hierarchy


{panel}
* javafx.scene.Node
** javafx.scene.Camera (abstract)
*** javafx.scene.ParallelCamera
*** javafx.scene.PerspectiveCamera
** javafx.scene.SubScene
{panel}

h5. Code segment

Specifying a fixed Camera (existing 2.2 API)

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

{code}
// 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);
{code}

h4. 3D primitives

* Added two type of 3D shapes, extending from an abstract Shape3D base class:
** User-defined shapes (MeshView)
** Predefined shapes

h5. 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

h5. Predefined shapes

*  Three commonly used predefined 3D shapes are introduced: Box, Cylinder and Sphere

h6. Shape3D Class Hierarchy


{panel}
* javafx.scene.Node
** javafx.scene.shape.Shape3D (abstract)
*** javafx.scene.shape.MeshView
*** javafx.scene.shape.Box
*** javafx.scene.shape.Cylinder
*** javafx.scene.shape.Sphere
{panel}

h6. Mesh Class Hierarchy

{panel}
* java.lang.Object
** javafx.scene.shape.Mesh (abstract)
*** javafx.scene.shape.TriangleMesh
{panel}

h5. Code Segment

Defining a MeshView

{code}
// 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);
{code}
Using Predefined Shapes

{code}
// 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)
{code}

h4. 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)

h5. 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

h5. 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
* Sharable among multiple Shape3D nodes

h6. Light Class Hierarchy

{panel}
* javafx.scene.Node
** javafx.scene.LightBase (abstract)
*** javafx.scene.AmbientLight
*** javafx.scene.PointLight
{panel}

h6. Material Class Hierarchy

{panel}
* java.lang.Object
** javafx.scene.paint.Material (abstract)
*** javafx.scene.paint.PhongMaterial
{panel}

h5. Code Segment

Defining Lights



{code}
// 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);
{code}
Defining Materials

{code}
// 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);
{code}

h4. 3D picking

* 3D ray picking already used for 2D primitives with PerspectiveCamera
* Existing limitation when used with depth buffer will be fixed (JIRA: [RT-13740|http://javafx-jira.kenai.com/browse/RT-13740])
* We will add support for picking 3D geometry (JIRA: [RT-24646|http://javafx-jira.kenai.com/browse/RT-24646])

Proposed API to support 3D picking: [Picking3dAPI]






*Methods added to Node*


* A LOD helper method that returns the area of the Node projected onto the physical screen in pixel units.

{code}
public double computeAreaInScreen()
{code}


* A set of 3D transform  methods


{code}
public Point3D sceneToLocal(Point3D scenePoint)
public Point3D sceneToLocal(double sceneX, double sceneY, double sceneZ)
public Point3D localToScene(Point3D localPoint)
public Point3D localToScene(double x, double y, double z)
public Point3D parentToLocal(Point3D parentPoint)
public Point3D parentToLocal(double parentX, double parentY, double parentZ)
public Point3D localToParent(Point3D localPoint)
public Point3D localToParent(double x, double y, double z)
{code}



h4. Loader support

* Many 3D file formats exist, such as:
**  Obj, Maya, 3D Studio Max, Collada, KRML
* We will not provide a loader as part of the JavaFX runtime
* We will make sample code available for one or two popular formats
The OpenJFX wiki has moved to [https://wiki.openjdk.java.net/display/OpenJFX]

The individuals who post here are part of the extended Oracle community and they might not be employed or in any way formally affiliated with Oracle. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Oracle nor any other party necessarily agrees with them.