Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Let’s continue to add code to the createBoardGameNodes() method to set backface culling for the
primitive objects. First, we will need to change the drawMode property for your primitives back to FILL for
solid modeling using .setDrawMode(DrawMode.FILL) on each of your sphere, box, and pole objects. Right
after this method call on each of your primitive objects, add a .setCullFace(CullFace.BACK) method call on
that object. If you use the pop-up helper work process in NetBeans 9, you will see that it writes your code
using the default CullFace.NONE setting, so you will have to change this to CullFace.BACK in order to turn
on this rendering pipeline optimization algorithm.
The Java code for your backface culling statements are highlighted at the bottom of Figure 12-17 and
should look like the following Java code:


sphere.setDrawMode(DrawMode.FILL);
sphere.setCullFace(CullFace.BACK);
box.setDrawMode(DrawMode.FILL);
box.setCullFace(CullFace.BACK);
pole.setDrawMode(DrawMode.FILL);
pole.setCullFace(CullFace.BACK);


Figure 12-18 shows a Run ➤ Project Java code testing work process, showing the backface culling
algorithm installed and operating on the 3D Scene primitives. Notice on your Sphere that a reduced
geometry resolution (fewer divisions) causes some smoothing problems on the mesh where the mesh
topology is showing through the smoothing algorithm. I’d increase Sphere divisions to 24 to mitigate this,
which is still a 100 percent optimization on the default setting.


Figure 12-17. Add method calls to .setCullFace() with the value CullFace.BACK off of all of the primitives in
your Scene

Free download pdf