Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 13 ■ 3D MoDel ShaDer Creation: USing the JavaFX 9 phongMaterial ClaSS


Next, let’s take a look at how to use what we have learned thus far and create some of the shader’s
texture map components in GIMP 2.8.22, for use in the gameBoard Group Node hierarchy that we are going
to create in Chapter 14 as we start to build our i3D game using the JavaFX 9 APIs in Java 9.


GameBoard Texturing: Creating a GameBoardSquare


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, so that is the core class (algorithm) that complex 3D objects
are based on; therefore, Mesh and MeshView are the key classes to use for pro Java 9 games development. If,
for some reason, you want to code complex polygonal geometry, also called “Triangle Mesh” (which is not
an optimal workflow), you can use TriangleMesh, which we will cover in detail.
A better workflow is using an external 3D software package and “importing” your 3D object directly
into a Mesh object, which is then referenced by a MeshView object. This is a workflow we will dedicate an
entire chapter to how to “model” a 3D game using these JavaFX classes, so that you do not have to import
any “data heavy” mesh objects. Importing 3D assets can be a much faster way to get an advanced i3D game
up and running quickly and efficiently, as well as a way to bring specialized artisans into an i3D game
development workflow.


Getting Ready to Create the GameBoard: Code Reconfiguration


Let’s get ready for what we are going to be doing in the next chapter (building our i3D game board) and
reconfigure our Java code bodies for our gameButton event handler, createBoardGameNodes() method,
addNodesToSceneGraph() method, and loadImageAssets() method. Let’s switch from Camera object
dollying, set Camera Z = 0, and instead use FOV to zoom in and out of the scene. Since we’re going to delete
the Sphere and Cylinder primitives for now, we’ll set the X and Y translate properties to -500 and rotate the
camera around the x-axis 45 degrees so that it looks down onto the game board. The Java code to do these
camera adjustments is shown in Figure 13-19 and looks like the following:


camera.setTranslateZ( 0 );
camera.setTranslateY(-500);
camera.setTranslateX(-500);
camera.setRotationAxis(Rotate.X_AXIS);
camera.setRotate(-45);
camera.setFieldOfView( 1 );

Free download pdf