Java Reference
In-Depth Information
They define three read-write object properties:
material
,
drawMode
, and
cullFace
. They control the surface
material, the drawing mode, and the face culling setting for the
Shape3D
. The object type of the
material
property
is the class
javafx.scene.paint.Material
. The type of the
drawMode
property is the enum
javafx.scene.shape.DrawMode
. The type of the
cullFace
property is the enum
javafx.scene.shape.CullFace
.
The
Material
class contains a set of rendering properties that control how the 3D shape reacts to lights. It gives
the 3D shape its unique look. We cover the
Material
class hierarchy in a later section. For now, it is sufficient to
know that there is one concrete class in the hierarchy called
PhongMaterial
, and that it has a constructor that takes
a single
Color
parameter for its diffuse color. The
DrawMode
enum has two declarators:
LINE
and
FILL
. A
drawMode
property of
DrawMode.LINE
will cause the JavaFX runtime to render the 3D shape as a wireframe. A
drawMode
property
of
DrawMode.FILL
will cause the JavaFX runtime to render the 3D shape as a solid. The
CullFace
enum has three
declarators:
NONE
,
BACK
, and
FRONT
. It controls how the JavaFX runtime renders each constituent polygon (also called
a
face
) of the 3D shape. Through a process called
face culling
, the JavaFX runtime might remove some of the faces in a
3D shape from being rendered, thus improving the performance of the 3D model. A
cullFace
property of
CullFace.NONE
will cause the JavaFX runtime to not perform any face culling. A
cullFace
property of
CullFace.BACK
will cause the
JavaFX runtime to cull all back side faces. A
cullFace
property of
CullFace.FRONT
will cause the JavaFX runtime to
cull all front side faces. We discuss faces of 3D shapes in more detail in the section about user-defined 3D shapes.
The program in Listing 10-2 allows you to experiment with the effects of altering the
material
,
drawMode
, and
cullFace
properties.
Listing 10-2.
Shape3DPropertiesExample.java
import javafx.application.Application;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Material;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class Shape3DPropertiesExample extends Application {
private Model model;
private View view;
public Shape3DPropertiesExample() {
model = new Model();
}
@Override
public void start(Stage stage) throws Exception {
view = new View(model);
hookupEvents();
Search WWH ::
Custom Search