Appearance Is Everything
There are many ways to change the way that objects in your scene look.
You can change their color, how much light they reflect. You can paint
them with two-dimensional images, or add rough textures to their
surfaces. The Appearance class contains the functions for making these
changes. This section shows you how to use these functions.
The simplest way of setting the appearance is by specifying only the
color and the shading method. This works for setting an object to being
a simple color, but to make an object look realistic, you need to specify
how an object appears under lights. You do this by creating a Material.
Step Example
1. Create an object Sphere sphere = new Sphere();
2. Create an appearance Appearance ap = new Appearance();
3. Create a color Color3f col = new Color3f(0.0f, 0.0f, 1.0f);
4. Create the coloring attributes ColoringAttributes ca = new ColoringAttributes
(col, ColoringAttributes.NICEST);
5. Add the attributes to the appearance ap.setColoringAttributes(ca);
6. Set the appearance for the object sphere.setAppearance(ap);
Materials
Materials have five properties that enable you to specify how the object appears. There are four colors:
Ambient, Emissive, Diffuse, and Specular. The fifth property is shininess, that you specify with a number.
Each color specifies what light is given off in a certain situation.
Ambient color reflects light that been scattered so much by the environment that the direction is
impossible to determine. This is created by an AmbientLight in Java 3D.
Emissive color is given off even in darkness. You could use this for a neon sign or a glow-in-the-dark
object
Diffuse color reflects light that comes from one direction, so it's brighter if it comes squarely down on
a surface that if it barely glances off the surface. This is used with a DirectionalLight.
Specular light comes from a particular direction, and it tends to bounce off the surface in a preferred
direction. Shiny metal or plastic have a high specular component. The amount of specular light that
reaches the viewer depends on the location of the viewer and the angle of the light bouncing off the
object.
Changing the shininess factor affects not just how shiny the object is, but whether it shines with a small
glint in one area, or a larger area with less of a gleaming look.
For most objects you can use one color for both Ambient and Diffuse components, and black for Emissive
(most things don’t glow in the dark). If it’s a shiny object, you would use a lighter color for Specular
reflections. For example, the material for a red billiard ball might be:
// billiard ball
// ambient emissive diffuse specular shininess
// Material mat = new Material(red, black, red, white, 70f);