Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 12 ■ 3D MoDel Design anD priMitives: Using JavaFX 9 shape3D Classes


The Shape3D superclass is a subclass of Node, as are most of the concrete classes that we will be
using in your JavaFXGame code. Like the Camera and LightBase superclasses, this Shape3D superclass
implements both the Styleable and EventTarget interfaces so that its subclasses (objects) can be styled and
process events (can be interactive). The Java 9 class hierarchy therefore spans both Java and JavaFX APIs and
looks like the following:


java.lang.Object



javafx.scene.Node
javafx.scene.shape.Shape3D



The Shape3D base (abstract or not directly instantiated) class was created to provide definitions of
common properties for 3D objects that represent 3D geometric shapes. The three primary 3D properties
include the “Material” (or shader and texture maps) to be applied to the fillable interior of the shape or the
outline of the shape, which we’ll be covering during Chapter 13 ; the “Draw Model” properties, which define
how the JavaFX 9 rendering engine will represent the geometry to the viewer (as a solid or a wireframe
model); and the “Face Culling” properties that define which faces to cull. Face culling is an optimization that
a rendering engine will utilize to get better performance (faster FPS) by not rendering all of the polygons in
the models in the scene. Since a renderer is taking a 3D Scene and rendering a 2D view from the Camera,
this “backface culling” will not render any faces (polygons) on the part of a model facing away from (not
visible to) the Camera. Front-face culling will do the opposite, rendering only the back-facing polygons,
which basically renders the inside of the polygon, with the model front faces (polygons) becoming hidden or
invisible. There is also the CullFace.NONE constant that turns off the Face Culling Optimization Algorithm.
CullFace.BACK is the default setting and is what you’ll usually want to use, unless you are using CullFace.
FRONT to get some special inside volume rendering effect, which, after this chapter is over, you will know
exactly how to experiment with, if you so desire.
As you know, 3D rendering, and therefore any of the Shape3D subclasses, is a conditional feature that
you can check for in your code, as we covered in the previous chapter. Let’s get into the three object settings
(properties, attributes, characteristics) for any Shape3D subclassed object that define how the 3D rendering
engine will render it.
The cullFace ObjectProperty will define which CullFace optimization algorithm (FRONT,
BACK, or NONE) will be used on this Shape3D object. This could very well affect the performance of a pro
Java 9 3D game.
The drawMode ObjectProperty will define the draw mode used to render the Shape3D
object. Your two options include DrawMode.FILL for a solid 3D object and DrawMode.LINE for a wireframe
representation.
The material ObjectProperty defines the material the Shape3D object will be utilizing as
a “skin.” We’ll be learning all about shading algorithms, materials, and texture maps in Chapter 13 , which
covers materials.
The protected (not directly usable) constructor for the abstract Shape3D superclass looks like the
following:


protected Shape3D()


Now let’s get into methods that are going to be part of all your Shape3D subclasses. This is convenient
because we can cover all these methods here in one place. These can be used on any primitive 3D shape or
MeshView.
The .cullFaceProperty() method defines the ObjectProperty for the Shape3D object,
whereas the .getCullFace() method allows you to poll the Shape3D object for its current CullFace constant
setting. There is also the .setCullFace(CullFace value) method, which allows you to change the CullFace
constant setting for a Shape3D object.

Free download pdf