Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Now it’s time to use a Run ➤ Project work process and render our Scene. As you can see in Figure 12-16,
our 3D primitives are closer to the center of the 3D Scene, are easily viewable, and are using far less data to
construct. As you saw in Figure 12-13, the Sphere was using 48 divisions to construct. This uses several hundred
polygons and can be calculated as 48 × 48 × 2 = 192; 192 polygons takes a lot of memory to process (storing
and rendering) as each polygon has a lot of data to define it (location in model, size, orientation, color, normal
direction, smoothing groups).


When we render these primitives in the next section on face culling, you will see the cube and cylinder
have not really changed in appearance, so the cylinder’s 100 percent decrease in divisions (24 to 12) was
a successful optimization. The Sphere reduction of 200 percent (from 48 to 12) was a bit drastic, and the
illusion of smoothness falls apart a bit around the perimeter of the Sphere, especially when rendered from
the top, which is why I rotated it forward (X) 90 degrees.
Next, let’s take a look at optimization for the rendering algorithm using back-face culling and how a
lower resolution (fewer divisions) can affect the visual quality of the 3D primitives once they are rendered
using solid mode.


Shape3D Face Culling Property: Optimize the Rendering Pipeline


The Shape3D cullFace property and the CullFace class are used to control face and polygon rendering
optimization for your 3D Scene. The default is CullFace.NONE, so you will need to turn this optimization
on using code, which I’m going to show you how to do in this section of the chapter. I think the models look
better (more contrast) with face culling off, and if you optimize your pro Java 9 game well enough, it should
play well on all platforms and devices without having to cull half the faces off of your model. That said, once
you know how to do this, it should be easy enough for you to experiment during the testing phase to see how
it affects visual quality versus smoothness of gameplay.


Figure 12-16. Your primitives are now centered in the 3D Scene Camera view, and you can see the Sphere
construction

Free download pdf