Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Also notice that the shading contrast on the cube (Box) primitive has far less contrast (difference in
shading color between faces) when backface culling is turned on. This will become less of a problem (less
noticeable) the more custom texture mapping you do (covered in the next chapter and thereafter), but it
may be why the default is NONE for the FaceCull class, and for this method call, because the face culling
optimization may be affecting contrast (quality) in some way in the current algorithm code. I set up the
chapter in this way so that you could see this because one of the most basic primitives is showing a distinct
reduction in contrast between faces, using a default medium gray shader color, as you can see if you
compare Figure 12-10 and Figure 12-18, where contrast goes from high to almost none whatsoever.
Next, let’s take a look at the three mesh-related classes, Mesh, TriangleMesh, and MeshView, to see
what these do, and how they interrelate, as they will allow you to render complex mesh objects created using
3D software.


JavaFX Mesh Superclass: Construct a TriangleMesh


It is important to understand the abstract Mesh superclass and how it relates to its TriangleMesh subclass,
which can be used to “hand-code” complex mesh objects into existence, and how it relates to the MeshView
class, which is actually a subclass of Shape3D and not of Mesh! This is so that MeshView can inherit (extend)
the cullFace, drawMode, and material properties of Shape3D, which are, of course, crucial to making a mesh
object realistic (especially the material property and Material class). The MeshView constructor takes a
Mesh object, as you will see. That is the core class (algorithm) that complex 3D objects is based on, so Mesh
and MeshView are the most key classes to use for pro Java 9 games development. If, for some reason, you
want to code complex polygonal geometry, also called “a triangle mesh,” which is not an optimal workflow,
you can use TriangleMesh, which we will cover in detail.


Figure 12-18. The renderer is now rendering half as much 3D data, and your lower resolution can be seen on
the Sphere

Free download pdf