Pro Java 9 Games Development Leveraging the JavaFX APIs

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

This is because using professional 3D modelling, texturing, rendering, and animation software packages
such as the open source Blender.org, Autodesk 3D Studio Max, Maya, or NewTek Lightwave is the most
logical work process to create a professional 3D model.
Because of the significant number of 3D data import file formats, 3D models can more quickly be
created, and then pro Java 9 game developers can use one of the JavaFX 9 importer formats to bring that
high-quality 3D data into JavaFX as a Mesh object.
We will look at this work process during Chapter 14 , after we look at texture mapping in Chapter 13 ,
so that we understand more about what texture mapping is since it is also used in third-party 3D modeling
software packages. Using third-party development tools such as Fusion, Blender, Audacity, Gimp, and
Inkscape often yields better results.


JavaFX TriangleMesh Class: Create a 3D Polygonal Mesh Object


The public TriangleMesh class is a subclass of the Mesh superclass and does not implement any interfaces
as it is used to create 3D data intended to be stored inside of the Mesh object, much like 3D models that are
imported into JavaFX using a number of popular 3D file format importers that we’ll be covering in Chapter 14.
The TriangleMesh is stored in the javafx.scene.shape package in the javafx.graphics module, and its Java class
hierarchy looks like the following:


java.lang.Object



javafx.scene.shape.Mesh
javafx.scene.shape.TriangleMesh



A TriangleMesh object is used to define a 3D polygonal mesh. This object will use one of two
VertexFormat constants and include a set of separate data array objects containing vertex components,
including points, normals, texture coordinates, and an array of faces that define the individual triangles of
the mesh. As I have mentioned in this chapter more than once, this low-level complexity can be avoided
altogether, and accelerated past, by using an external 3D software package that supports modeling, such as
Blender, Hexagon, Lightwave, Maya, or 3D Studio Max.
Note that the JavaFX term point equates to the 3D software term vertex. JavaFX 9 uses vertex to refer to
the vertex (point) and all of its associated attributes, including its normal position and associated UV texture
map coordinates. So, the point referred to in the TriangleMesh method names and method descriptions that
we will be covering later during this section of the chapter actually refers to 3D point (x, y, z) locational data
in 3D space, representing the spatial positioning for one single vertex.
Similarly, the term points (or a collection of point) is used to indicate sets of 3D points representing
multiple vertices. The term normal is used to indicate a 3D vector (nx, ny, nz) in 3D space that represents a
direction of a single vertex, which tells the rendering engine which way the face is facing so it can render the
texture on the correct side of the face. The term normals (or a collection of normal data) is used to indicate
sets of 3D vectors for multiple vertices.
The term texCoord is used to indicate one single pair of 2D texture coordinates (u,v) for a single vertex,
while the term texCoords (a collection of texCoord) is used to indicate sets of texture coordinates across
multiple vertices.
Finally, the term face is used to indicate a set of three interleaving points, normals (these are optional
and will depend on the associated VertexFormat field type specified), and texture coordinates that together
would represent the geometric topology of one single triangle. The term faces (a collection of face) is used
to indicate a set of triangles (each represented using a face), which is generally what a 3D polygonal model
is comprised of. Confused yet? As I said, using an import/export workflow and letting the advanced 3D
modeling software user interface do all of the work is a better way to get incredible results rather than trying
to use Java to place points, normal, and UV coordinates into 3D space. What I am trying to do in this book
is show you the fastest, easiest, and most optimized way to create a hybrid 2D and 3D game so that you can
create the pro Java 9 game on the market which has never been experienced before by any game player.

Free download pdf