Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


As you know, your PhongMaterial object can be configured with color values and loaded up with cool
effect texture maps (Image objects), but unless you utilize the Shape3D class setMaterial(Material) method
call (which you learned about in the previous chapter) to wire the 3D primitive and the Phong shader
definition together, you won’t see the shader applied to the 3D object’s surface.
After the sphere object instantiation, add a setMaterial(phongMaterial) method call off of the sphere
object using dot notation, as shown highlighted in yellow in Figure 13-2. Add this same method call to your
pole Cylinder object and the box Box object as well. I clicked the phongMaterial shader object to highlight
all of the uses of it, from declaration to instantiation to usage, in yellow in NetBeans 9 before I took the
screenshot. The Java code for the statements that you have added should look like the following:


sphere.setMaterial(phongMaterial);
box.setMaterial(phongMaterial);
pole.setMaterial(phongMaterial);


Figure 13-1. Declare and instantiate your phongMaterial object and configure its diffuse color value to be
Color.GOLD

Free download pdf