Getting Started with JavaFX 3D Graphics
Beta Draft: 2013-09-17
This chapter describes the Light API included in the JavaFX 3D graphics library.
Light is now also defined as a node in the scene graph. A default light is provided if the set of active lights contained in the scene is empty. Each light contains a set of affected nodes. If a set of nodes is empty, all nodes on the scene (or subscene) are affected. If a Parent node is in that set of nodes, then all of its children are also affected.
Light interacts with the geometry of a Shape3D object and its material to provide rendering result. Currently, there are two types of light sources:
AmbientLight- a light source that seems to come from all directions.
PointLight- an attenuated light source that has a fixed point in space and radiates light equally in all directions away from itself.
Example 5-1 shows the Light Class Hierarchy.
Example 5-1 Light Class Hierarchy
javafx.scene.Node javafx.scene.LightBase (abstract) javafx.scene.AmbientLight javafx.scene.PointLight
To create point light and add it to the Scene, do the following:
PointLight light = new PointLight(); light.setColor(Color.RED);
Use the following to add light to the scene graph:
Group lightGroup = new Group(); lightGroup.getChildren().add(light); root.getChildren().add(lightGroup);
Rotate the light 45 degrees with the following line of code:
To move the lightGroup and have light moves with it, use something similar to the following code.
setTranslateZ() method sets the value of the property
translateZ, which is set to -75 in the example code above. This value will be added to any translation defined by the transforms