Package javax.media.j3d
Class Material
java.lang.Object
javax.media.j3d.SceneGraphObject
javax.media.j3d.NodeComponent
javax.media.j3d.Material
The Material object defines the appearance of an object under
illumination.
If the Material object in an Appearance object is
null
,
lighting is disabled for all nodes that use that Appearance object.
The properties that can be set for a Material object are:
- Ambient color - the ambient RGB color reflected off the surface of the material. The range of values is 0.0 to 1.0. The default ambient color is (0.2, 0.2, 0.2).
- Diffuse color - the RGB color of the material when illuminated. The range of values is 0.0 to 1.0. The default diffuse color is (1.0, 1.0, 1.0).
- Specular color - the RGB specular color of the material (highlights). The range of values is 0.0 to 1.0. The default specular color is (1.0, 1.0, 1.0).
- Emissive color - the RGB color of the light the material emits, if any. The range of values is 0.0 to 1.0. The default emissive color is (0.0, 0.0, 0.0).
- Shininess - the material's shininess, in the range [1.0, 128.0] with 1.0 being not shiny and 128.0 being very shiny. Values outside this range are clamped. The default value for the material's shininess is 64.
- Color target - the material color target for per-vertex colors, one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or AMBIENT_AND_DIFFUSE. The default target is DIFFUSE.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
For material object, specifies that Material allows reading individual component field information.static final int
For material object, specifies that Material allows reading individual component field information.static final int
Specifies that per-vertex colors replace the ambient material color.static final int
Specifies that per-vertex colors replace both the ambient and the diffuse material color.static final int
Specifies that per-vertex colors replace the diffuse material color.static final int
Specifies that per-vertex colors replace the emissive material color.static final int
Specifies that per-vertex colors replace the specular material color. -
Constructor Summary
ConstructorsConstructorDescriptionMaterial()
Constructs and initializes a Material object using default parameters.Material
(javax.vecmath.Color3f ambientColor, javax.vecmath.Color3f emissiveColor, javax.vecmath.Color3f diffuseColor, javax.vecmath.Color3f specularColor, float shininess) Constructs and initializes a new material object using the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.replaced with cloneNodeComponent(boolean forceDuplicate)void
getAmbientColor
(javax.vecmath.Color3f color) Retrieves this material's ambient color.int
Retrieves the current color target for this material.void
getDiffuseColor
(javax.vecmath.Color3f color) Retrieves this material's diffuse color.void
getEmissiveColor
(javax.vecmath.Color3f color) Retrieves this material's emissive color and stores it in the argument provided.boolean
Retrieves the state of the lighting enable flag.float
Retrieves this material's shininess.void
getSpecularColor
(javax.vecmath.Color3f color) Retrieves this material's specular color.void
setAmbientColor
(float r, float g, float b) Sets this material's ambient color.void
setAmbientColor
(javax.vecmath.Color3f color) Sets this material's ambient color.void
setColorTarget
(int colorTarget) Sets the color target for per-vertex colors.void
setDiffuseColor
(float r, float g, float b) Sets this material's diffuse color.void
setDiffuseColor
(float r, float g, float b, float a) Sets this material's diffuse color plus alpha.void
setDiffuseColor
(javax.vecmath.Color3f color) Sets this material's diffuse color.void
setEmissiveColor
(float r, float g, float b) Sets this material's emissive color.void
setEmissiveColor
(javax.vecmath.Color3f color) Sets this material's emissive color.void
setLightingEnable
(boolean state) Enables or disables lighting for this appearance component object.void
setShininess
(float shininess) Sets this material's shininess.void
setSpecularColor
(float r, float g, float b) Sets this material's specular color.void
setSpecularColor
(javax.vecmath.Color3f color) Sets this material's specular color.toString()
Returns a String representation of this Materials values.Methods inherited from class javax.media.j3d.NodeComponent
cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, updateNodeReferences
-
Field Details
-
ALLOW_COMPONENT_READ
public static final int ALLOW_COMPONENT_READFor material object, specifies that Material allows reading individual component field information.- See Also:
-
ALLOW_COMPONENT_WRITE
public static final int ALLOW_COMPONENT_WRITEFor material object, specifies that Material allows reading individual component field information.- See Also:
-
AMBIENT
Specifies that per-vertex colors replace the ambient material color.- Since:
- Java 3D 1.3
- See Also:
-
EMISSIVE
Specifies that per-vertex colors replace the emissive material color.- Since:
- Java 3D 1.3
- See Also:
-
DIFFUSE
Specifies that per-vertex colors replace the diffuse material color. This is the default target.- Since:
- Java 3D 1.3
- See Also:
-
SPECULAR
Specifies that per-vertex colors replace the specular material color.- Since:
- Java 3D 1.3
- See Also:
-
AMBIENT_AND_DIFFUSE
Specifies that per-vertex colors replace both the ambient and the diffuse material color.- Since:
- Java 3D 1.3
- See Also:
-
-
Constructor Details
-
Material
public Material()Constructs and initializes a Material object using default parameters. The default values are as follows:-
lighting enable : true
ambient color : (0.2, 0.2, 0.2)
emmisive color : (0.0, 0.0, 0.0)
diffuse color : (1.0, 1.0, 1.0)
specular color : (1.0, 1.0, 1.0)
shininess : 64
color target : DIFFUSE -
Material
public Material(javax.vecmath.Color3f ambientColor, javax.vecmath.Color3f emissiveColor, javax.vecmath.Color3f diffuseColor, javax.vecmath.Color3f specularColor, float shininess) Constructs and initializes a new material object using the specified parameters. Lighting is enabled by default.- Parameters:
ambientColor
- the material's ambient coloremissiveColor
- the material's emissive colordiffuseColor
- the material's diffuse color when illuminated by a lightspecularColor
- the material's specular color when illuminated to generate a highlightshininess
- the material's shininess in the range [1.0, 128.0] with 1.0 being not shiny and 128.0 being very shiny. Values outside this range are clamped.
-
-
Method Details
-
setAmbientColor
public void setAmbientColor(javax.vecmath.Color3f color) Sets this material's ambient color. This specifies how much ambient light is reflected by the surface. The ambient color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is either AMBIENT or AMBIENT_AND_DIFFUSE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's ambient color in the lighting equation.- Parameters:
color
- the material's ambient color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
setAmbientColor
public void setAmbientColor(float r, float g, float b) Sets this material's ambient color. This specifies how much ambient light is reflected by the surface. The ambient color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is either AMBIENT or AMBIENT_AND_DIFFUSE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's ambient color in the lighting equation.- Parameters:
r
- the new ambient color's red componentg
- the new ambient color's green componentb
- the new ambient color's blue component- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
getAmbientColor
public void getAmbientColor(javax.vecmath.Color3f color) Retrieves this material's ambient color.- Parameters:
color
- that will contain the material's ambient color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setEmissiveColor
public void setEmissiveColor(javax.vecmath.Color3f color) Sets this material's emissive color. This is the color of light, if any, that the material emits. The emissive color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is EMISSIVE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's emissive color in the lighting equation.- Parameters:
color
- the new emissive color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
setEmissiveColor
public void setEmissiveColor(float r, float g, float b) Sets this material's emissive color. This is the color of light, if any, that the material emits. The emissive color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is EMISSIVE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's emissive color in the lighting equation.- Parameters:
r
- the new emissive color's red componentg
- the new emissive color's green componentb
- the new emissive color's blue component- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
getEmissiveColor
public void getEmissiveColor(javax.vecmath.Color3f color) Retrieves this material's emissive color and stores it in the argument provided.- Parameters:
color
- the vector that will receive this material's emissive color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setDiffuseColor
public void setDiffuseColor(javax.vecmath.Color3f color) Sets this material's diffuse color. This is the color of the material when illuminated by a light source. The diffuse color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's diffuse color in the lighting equation.- Parameters:
color
- the new diffuse color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
setDiffuseColor
public void setDiffuseColor(float r, float g, float b) Sets this material's diffuse color. This is the color of the material when illuminated by a light source. The diffuse color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's diffuse color in the lighting equation.- Parameters:
r
- the new diffuse color's red componentg
- the new diffuse color's green componentb
- the new diffuse color's blue component- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
setDiffuseColor
public void setDiffuseColor(float r, float g, float b, float a) Sets this material's diffuse color plus alpha. This is the color of the material when illuminated by a light source. The diffuse color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's diffuse color in the lighting equation.- Parameters:
r
- the new diffuse color's red componentg
- the new diffuse color's green componentb
- the new diffuse color's blue componenta
- the alpha component used to set transparency- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
getDiffuseColor
public void getDiffuseColor(javax.vecmath.Color3f color) Retrieves this material's diffuse color.- Parameters:
color
- the vector that will receive this material's diffuse color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setSpecularColor
public void setSpecularColor(javax.vecmath.Color3f color) Sets this material's specular color. This is the specular highlight color of the material. The specular color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is SPECULAR, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's specular color in the lighting equation.- Parameters:
color
- the new specular color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
setSpecularColor
public void setSpecularColor(float r, float g, float b) Sets this material's specular color. This is the specular highlight color of the material. The specular color in this Material object may be overridden by per-vertex colors in some cases. If vertex colors are present in the geometry, and lighting is enabled, and the colorTarget is SPECULAR, and vertex colors are not being ignored, then the vertex colors are used in place of this Material's specular color in the lighting equation.- Parameters:
r
- the new specular color's red componentg
- the new specular color's green componentb
- the new specular color's blue component- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- See Also:
-
getSpecularColor
public void getSpecularColor(javax.vecmath.Color3f color) Retrieves this material's specular color.- Parameters:
color
- the vector that will receive this material's specular color- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setShininess
public void setShininess(float shininess) Sets this material's shininess. This specifies a material specular scattering exponent, or shininess. It takes a floating point number in the range [1.0, 128.0] with 1.0 being not shiny and 128.0 being very shiny. Values outside this range are clamped.- Parameters:
shininess
- the material's shininess- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
getShininess
public float getShininess()Retrieves this material's shininess.- Returns:
- the material's shininess
- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setLightingEnable
public void setLightingEnable(boolean state) Enables or disables lighting for this appearance component object.- Parameters:
state
- true or false to enable or disable lighting- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
getLightingEnable
public boolean getLightingEnable()Retrieves the state of the lighting enable flag.- Returns:
- true if lighting is enabled, false if lighting is disabled
- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph
-
setColorTarget
public void setColorTarget(int colorTarget) Sets the color target for per-vertex colors. When lighting is enabled and per-vertex colors are present (and not ignored) in the geometry for a given Shape3D node, those per-vertex colors are used in place of the specified material color(s) for this Material object. The color target is ignored when lighting is disabled or when per-vertex colors are not used. The ColorInterpolator behavior also uses the color target to determine which color in the associated Material is modified. The default target is DIFFUSE.- Parameters:
colorTarget
- one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or AMBIENT_AND_DIFFUSE.- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- Since:
- Java 3D 1.3
- See Also:
-
getColorTarget
public int getColorTarget()Retrieves the current color target for this material.- Returns:
- one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or AMBIENT_AND_DIFFUSE.
- Throws:
CapabilityNotSetException
- if appropriate capability is not set and this object is part of live or compiled scene graph- Since:
- Java 3D 1.3
-
toString
Returns a String representation of this Materials values. If the scene graph is live only those values with their Capability read bit set will be displayed.- Overrides:
toString
in classSceneGraphObject
-
cloneNodeComponent
Deprecated.replaced with cloneNodeComponent(boolean forceDuplicate)- Overrides:
cloneNodeComponent
in classNodeComponent
-