Floating Spheres
Sphere
is a utility class from Java 3D's com.sun.j3d.utils.geometry package, a subclass of the Primitive
class, which is a Group node with a Shape3D child (see Figure 15-3). Its geometry is stored in a Java 3D TriangleStripArray, which specifies the sphere as an array of connected triangles. I don't have to adjust this geometry, but the sphere's appearance and position do require changes.
The Appearance node is a container for references of to much information, including coloring
, line, point, polygon, rendering, transparency, and texture attributes.
ColouringAttributes fixes the color of a shape and is unaffected by scene lighting. For a shape requiring interaction between color and light, the Material component is employed. For light to affect a shape's color, three conditions must be met:
The shape's geometry must include normals.
The shape's
Appearancenode must have aMaterialcomponent.The
Materialcomponent must have enabled lighting withsetLightingEnable().
The utility Sphere class can automatically creates normals, so the first condition is easily satisfied.
Coloring the Spheres
The Java 3D Material component controls what color a shape exhibits when lit by different kinds of lights:
Material mat = new Material(ambientColor, emissiveColor,
diffuseColor, specularColor, shininess);The ambient color argument specifies the shape's color when lit by ambient light: this gives the object a uniform color. The emissive color contributes the color that the shape produces ...