Pro Java 9 Games Development Leveraging the JavaFX APIs

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

As you will see when we render this code in the 3D Scene, the order you add objects to your
SceneGraph in 3D compositing turns out to be similar to what happens regarding 2D asset layer order in
a 2D compositing StackPane as the 3D primitives will appear to be “in front of each other.” The later that
objects are added to the gameBoard Group in the SceneGraph, the later they will be rendered to the screen.
Thus, the last primitive added to a SceneGraph will be rendered on top of all of the other primitives before it,
and the first primitive added to a SceneGraph will be rendered first (that is, below or behind all of the other
3D primitives).
In most 3D software packages, three primitives located at 0,0,0 (Scene center) would render inside of
each other. This tells us something very important as 3D artists regarding JavaFX, which is that you cannot
perform Constructive Solids Geometry (CSG) modeling using JavaFX primitives. CSG was one of the early
forms of modeling in 3D and involves using the basic 3D primitives in conjunction with boolean operations
in order to create more complex 3D models.
Let’s use your Run ➤ Project work process and see how JavaFX is rendering these three primitives
located at 0, 0, 0. As you can see in Figure 12-6, the Cylinder object is in front of a Box object, which is in front
of a Sphere object. Most 3D software packages would render this as a Box inside of a Sphere, possibly with the
corners of the Box poking through the Sphere (depending on scale) and the ends of the Cylinder would be
coming out of the top and bottom of the Sphere. I did this exercise in this particular order because it is critical
for the developer to realize what they can do and what they cannot do as they build their Java 9 game. You can
achieve this boolean effect in JavaFX by using a mesh object imported from a 3D modeler such as MOI3D,
SILO or Blender where the Boolean operations have been done outside of JavaFX 9.


Figure 12-6. Use the Run ➤ Project to see these three primitives in the Z-order that you added them to the
SceneGraph

Free download pdf