Read more about this book |
(For more resources on 3D, see here.)
The reader will comprehend this article better by referring the previous articles on:
Light materials can be illuminated by an external light source. There are three different types of lights that can be applied to these materials: ambient, point, and directional. Also, remember that these materials will not necessarily recognize each type of light, or more than one light source. The table under the Lights and materials section lists which light sources can be applied to which materials.
The WhiteShadingBitmapMaterial class uses flat shading to apply lighting over a bitmap texture. As the class name suggests, the lighting is always white in color, ignoring the color of the source light.
protected function applyWhiteShadingBitmapMaterial():void
{
initSphere();
initPointLight();
materialText.text = "WhiteShadingBitmapMaterial";
var newMaterial:WhiteShadingBitmapMaterial =
new WhiteShadingBitmapMaterial(
Cast.bitmap(EarthDiffuse)
);
currentPrimitive.material = newMaterial;
}
The WhiteShadingBitmapMaterial class extends the BitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the BitmapMaterial are also valid for the WhiteShadingBitmapMaterial.
The ShadingColorMaterial class uses flat shading to apply lighting over a solid base color.
protected function applyShadingColorMaterial():void
{
initSphere();
initPointLight();
materialText.text = "ShadingColorMaterial";
var newMaterial:ShadingColorMaterial =
new ShadingColorMaterial(
Cast.trycolor("deepskyblue")
);
currentPrimitive.material = newMaterial;
}
The ShadingColorMaterial class extends the ColorMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the ColorMaterial class are also valid for the ShadingColorMaterial class.
The color parameter can accept an int or String value. However, due to a bug in the ColorMaterial class, only an int value will work correctly. In the previous example, we have manually converted the color represented by the string deepskyblue into an int with the trycolor() function from the Cast class.
The PhongBitmapMaterial uses phong shading to apply lighting over a TransformBitmapMaterial base material.
protected function applyPhongBitmapMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongBitmapMaterial";
var newMaterial:PhongBitmapMaterial =
new PhongBitmapMaterial(Cast.bitmap(EarthDiffuse));
currentPrimitive.material = newMaterial;
}
PhongBitmapMaterial is a composite material that passes the init object to a contained instance of the TransformBitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the TransformBitmapMaterial are also valid for the PhongBitmapMaterial.
The PhongColorMaterial uses phong shading to apply lighting over a solid color base material.
protected function applyPhongColorMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongColorMaterial";
var newMaterial:PhongColorMaterial =
new PhongColorMaterial("deepskyblue");
currentPrimitive.material = newMaterial;
}
The PhongMovieMaterial uses phong shading to apply lighting over an animated MovieMaterial base material.
protected function applyPhongMovieMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "PhongMovieMaterial";
var newMaterial:PhongMovieMaterial =
new PhongMovieMaterial(new Bear());
currentPrimitive.material = newMaterial;
}
PhongMovieMaterial is a composite material that passes the init object to a contained instance of the MovieMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the PhongMovieMaterial are also valid for the MovieMaterial.
The Dot3BitmapMaterial uses normal mapping to add depth to a 3D object.
protected function applyDot3BitmapMaterial():void
{
initSphere();
initDirectionalLight();
materialText.text = "Dot3BitmapMaterial";
var newMaterial:Dot3BitmapMaterial =
new Dot3BitmapMaterial(
Cast.bitmap(EarthDiffuse),
Cast.bitmap(EarthNormal)
);
currentPrimitive.material = newMaterial;
}
Dot3BitmapMaterial is a composite material that passes the init object to a contained instance of the BitmapMaterial class. This means that in addition to those parameters in the following list, the init object parameters listed for the BitmapMaterial are also valid for the Dot3BitmapMaterial.