< Zurück | Inhalt | Weiter >

9.3 ColoringAttributes

java.lang.Object

|

+−−javax.media.j3d.SceneGraphObject

|

+−−javax.media.j3d.NodeComponent

|

+−−javax.media.j3d.ColoringAttributes

Table 9.1 Capability bits for the ColoringAttributes class


COLOR

SHADE_MODE

OpenGL Reference: glColor

The ColoringAttributes within a Shape3D’s Appearance are used to control the color of a Shape3D if a Material has not also been assigned to the Appearance. If a Material has been assigned, the ColoringAttributes are ignored and the more complex color and lighting information within the Material class are used instead. See table 9.1.


The colors of any vertices within the Shape3D that have per−vertex colors applied are unchanged by the

ColoringAttributes.


The next example, from AppearanceTest.java, creates a standard Box and then replaces the LEFT face with a new face created with new geometry and per−vertex colors. When a ColoringAttributes object is assigned to the Appearance for the Box it will set the color for the five original faces but will not effect the LEFT face which has per−vertex colors assigned, as illustrated in figure 9.2.


image


Figure 9.2 A Box primitive with an applied ColoringAttribute. The LEFT face has been removed and replaced with a QuadArray that includes per−vertex colors that are unaffected by the ColoringAttributes


int nScale = 50;


Box box = new Box( nScale,nScale,nScale,

Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS,

m_Appearance);


Shape3D frontFace = box.getShape( Box.LEFT );


//create a new LEFT face so we can assign per−vertex colors GeometryArray geometry =

new QuadArray( 4, GeometryArray.COORDINATES |

GeometryArray.NORMALS | GeometryArray.COLOR_4 | GeometryArray.TEXTURE_COORDINATE_2 );

nScale = 40;


final float[] verts =

{

// new LEFT face

−1.0f * nScale, −1.0f * nScale, 1.0f * nScale,

−1.0f * nScale, 1.0f * nScale, 1.0f * nScale,

−1.0f * nScale, 1.0f * nScale, −1.0f * nScale,

−1.0f * nScale, −1.0f * nScale, −1.0f * nScale

};


final float[] colors =

{

// left face 1,0,0,0,

0,1,0,0.2f,

0,0,1,0.8f,

0,0,0,1,

};


float[] tcoords =

{

// texture coordinates for LEFT face 1, 0,

1, 1,

0, 1,

0, 0

};


Vector3f normalVector = new Vector3f(−1.0f, 0.0f, 0.0f);


geometry.setColors( 0, colors, 0, 4 );


for( int n = 0; n <4; n++ ) geometry.setNormal( n, normalVector );


geometry.setTextureCoordinates( 0, tcoords, 0, 4 ); geometry.setCoordinates( 0, verts );