Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 12 ■ 3D MoDel Design anD priMitives: Using JavaFX 9 shape3D Classes

There are two overloaded constructor methods. One creates an empty MeshView to be loaded with
Mesh object (3D data) in the future, which would of course utilize the following Java statement format:


meshView = new MeshView();


The second overloaded constructor method call both instantiates the MeshView object and loads
it with a Mesh object (3D geometry data) at the same time, using the following object instantiation Java
statement format:


meshView = new MeshView(yourMeshNameHere);


The MeshView class has three method calls for working with Mesh objects, including a getMesh(Mesh)
method call that will get the Mesh object value of the property mesh, the ObjectProperty
meshProperty() method call that will specify the 3D mesh (Mesh object) data for any MeshView that this
method is called off of, and the void setMesh(Mesh value) method call that will set the Mesh object value
for the MeshView property mesh.
Before we cover the TriangleMesh class, let’s take a look at the VertexFormat class, which will define
vertex data, by specifying a vertex data format to use with a given 3D model (that is, the Mesh object and its
3D model data).


JavaFX VertexFormat Class: Define Your 3D Vertex Data Format


The public final VertexNormal class also extends the Java Object master class, which means the class was
scratch-coded to define a format for the Array of data points, their texture coordinates, and their normals,
if any are provided by the external 3D models exported in a variety of data formats supported by JavaFX
import/export software. This class is a utility class for the Mesh, TriangleMesh, and MeshView classes, as
you can tell by its final modifier, which means that it cannot be subclassed. As with the other six we have
covered, it is kept in the javafx.scene.shape package in the javafx.graphics module, and its class hierarchy
looks like the following:


java.lang.Object



javafx.scene.shape.VertexFormat



The VertexFormat class (object) defines two different data format constants that reflect the type of 3D
data that is contained in each vertex in a 3D Mesh object. The static VertexFormat POINTNORMAL
TEXCOORD field will specify a format for a vertex that contains data for the point coordinates, a normal,
and texture coordinates. A static VertexFormat POINT_TEXCOORD field will specify a format for a vertex
that contains data for the point coordinates and for texture coordinates. I recommend using the format
that supports normals as the more data that you can use to define your 3D models, the more the renderer
can render them accurately and, therefore, more professionally.
There are five methods in this class for working with vertices and their normal, point, and texture
coordinate data components. The .getVertexIndexSize() method will return the integer number of
component indices that will represent a vertex index. The .getNormalIndexOffset() method will
return the integer index offset for the face array of the normal component within a given vertex. The
.getPointIndexOffset() method will return your integer index offset in the face array of the point component
within a given vertex. The .getTexCoordIndexOffset() method will return the index offset in a face array of
the texture coordinates component within a vertex. The String toString() method will return the string (text)
data for the VertexFormat, allowing you to look at the vertex data in a readable format.
Next, let’s take a look at the TriangleMesh object, which is the most complicated; it allows you to do 3D
model creation using Java code. We will not be looking at an example of this during this chapter because it is
not the most efficient way to get quick, professional i3D game development 3D model creation result.

Free download pdf