6 Material
This chapter describes the Material class of the JavaFX 3D Graphics library.
The Material class contains a set of rendering properties. Example 6-1 shows the Material class hierarchy and that the PhongMaterial class is sub-classed from the Material class.
Example 6-1 Material Class Hierarchy
java.lang.Object javafx.scene.paint.Material (abstract) javafx.scene.paint.PhongMaterial
The PhongMaterial class provides definitions of properties that represent a form of Phong shaded material:
-
Diffuse color
-
Diffuse map
-
Specular map
-
Specular color
-
Specular power
-
Bump map or normal map
-
Self-illumination map
Materials are shareable among multiple Shape3D nodes.
Example 6-2 shows how to create a PhongMaterial object, set its diffuseMap properties, and use the material for a shape.
Example 6-2 Working with Material
//Create Material Material mat = new PhongMaterial(); Image diffuseMap = new Image("diffuseMap.png"); Image normalMap = new Image("normalMap.png"); // Set material properties mat.setDiffuseMap(diffuseMap); mat.setBumpMap(normalMap); mat.setSpecularColor(Color.WHITE); // Use the material for a shape shape3d.setMaterial(mat);
The MSAAApp.java application and buildMolecule() method show how the PhongMaterial API is used. Both are available in the appendices sections.