Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 13 ■ 3D MoDel ShaDer Creation: USing the JavaFX 9 phongMaterial ClaSS

There’s a little white on the edges (JavaFX currently does not allow per-side Box object mapping), which
we’ll minimize in future chapters by adjusting the camera.setRotate() method call value until this becomes
less evident.
There’s one last point I want to make, before I finish up with shader pipeline creation and texture maps
for this chapter, on how to skin your 3D primitives with JavaFX. You’re probably wondering why I used a
PNG24 (24-bit) image format for this texture, instead of the more optimized PNG8 format. Well, this PNG24
codec did a pretty great job of compressing 256 × 256 × 3 (196,608) bytes into 680 bytes, which is a 290 : 1 or
99.67 percent reduction in data!
On the more technical side of the equation, Java will use a 24-bit RGB color representation in memory,
and therefore, if we had used an indexed 8-bit color image, it would have simply been transmuted back
into a 24-bit color value image when it was loaded into memory. Therefore, my inclination is to use PNG24
and PNG32 images whenever possible, especially for 3D texture maps that are primarily going to be 32x32,
64x64, 128x128, 256x256, and 512x512 for pro Java 9 game design and development applications anyway. For
photographic imagery, you can also use JPEG.


Summary


In this thirteenth chapter, we learned about the classes in the javafx.scene.paint package that allow you
to work with 3D shaders, texture maps, and materials, including the PhongMaterial class based on the
abstract Material superclass. We learned that the Material class is basically an “empty” class or a “shell”
to hold a “material” object (attribute in the Shape3D class) and that the heavy lifting (algorithms) is in a
PhongMaterial subclass. We looked at the properties, constructors, and method calls in this class in a fair
amount of detail so that you would know what the PhongMaterial object can do, and then we looked at how
to implement these in Java code (other than bumpMap, which isn’t working in the current JavaFX 9 code
base I am using, so we’ll revisit this later during the book).
You learned how to create texture map assets using GIMP (currently at version 2.8.22 for this book, but
I am expecting 2.10 to be out in 2017 and 3.0 to be out in 2018) and how to be surgically accurate by using
GIMP’s tools in an optimal workflow to create balanced, pixel-precise, power-of-two texture maps optimized
for professional 3D game development.
We then took a look at how to implement these texture map assets in four current texture map
“channels,” which are currently afforded to us via the JavaFX 9 PhongMaterial class. We saw how these
texture map channels allow us to fine-tune how our material attribute is rendered, allowing us to create a far
more professional appearance for our Java 9 games.
Finally, we created the diffuseColor property texture map for our game board square, transmuted
the box Box object into one of these game board squares, and applied the new texture map to the new 3D
primitive “plane” object in preparation for what we are going to be doing in the next chapter (creating our
gameBoard branch in the SceneGraph) so that it will look like a game board as we are creating it. As you
know, I recommend going about your pro Java 9 games development in such a way that you see what JavaFX
9 is going to do as you are writing your Java 9 code, creating your new media assets, and “morphing” your pro
Java 9 game content and deliverable into what you ultimately want it to be. Pro Java 9 Games Development
is a refinement process, so that is how I am writing this book. I’m showing you how I actually “vaporize a 3D
board game application out of thin air” using the NetBeans 9 IDE and the Java 9 and JavaFX 9 APIs.
In Chapter 14 , we are going to further refine our Java code organization, creating new methods
and reorganizing some existing methods, to create and incorporate the core of our i3D board game, the
gameboard. We will create a nested Group 3D hierarchy under the gameBoard Group Node (branch)
and look at 3D primitive X,Y,Z positioning and related concepts that apply to seamlessly laying out
a 3D gameboard in such a way that future Java code can access and reference its components and
subcomponents in a logical, optimal fashion. Just like database design, how you design your SceneGraph
greatly affects how your Pro Java 9 3D Game functions in the future. The simpler and more straightforward
we can keep the design, hierarchy, and 3D object naming schema, the better shape we will be in when
crafting future code for interactivity, animation, movement, collision detection, and the like. At this point,
you should be starting to get excited about the possibilities that Java 9 and JavaFX 9 afford you.

Free download pdf