The Annotated VRML 97 Reference

1 Intro     Concepts     3 Nodes     4 Fields/Events    Conformance
A Grammar     B Java     C JavaScript     D Examples     E Related Info    References
Quick Java         Quick JavaScript         Quick Nodes   
 

  About the Book
  
Help
  Copyright © 1997-99
  Purchase the book from Amazon.com

Chapter 3:
Node Reference


Intro
Anchor
Appearance
AudioClip
Background
Billboard
Box
Collision
Color
ColorInterpolator
Cone
Coordinate
CoordinateInterpolator
Cylinder
CylinderSensor
DirectionalLight
ElevationGrid
Extrusion
Fog
FontStyle
Group
ImageTexture
IndexedFaceSet
IndexedLineSet
Inline
LOD
Material
MovieTexture
NavigationInfo
Normal
NormalInterpolator
OrientationInterpolator
PixelTexture
PlaneSensor
PointLight
PointSet
PositionInterpolator
ProximitySensor
ScalarInterpolator
Script
Shape
Sound
Sphere
SphereSensor
SpotLight
Switch
Text
TextureCoordinate
TextureTransform
TimeSensor
TouchSensor
Transform
Viewpoint
VisibilitySensor
WorldInfo

+3.33 PixelTexture

PixelTexture { 
  exposedField SFImage  image      0 0 0    # see "4.5 SFImage"
  field        SFBool   repeatS    TRUE
  field        SFBool   repeatT    TRUE
}

The PixelTexture node defines a 2D image-based texture map as an explicit array of pixel values (image field) and parameters controlling tiling repetition of the texture onto geometry.

Texture maps are defined in a 2D coordinate system (s, t) that ranges from 0.0 to 1.0 in both directions. The bottom edge of the pixel image corresponds to the S-axis of the texture map, and left edge of the pixel image corresponds to the T-axis of the texture map. The lower-left pixel of the pixel image corresponds to s=0.0, t=0.0, and the top-right pixel of the image corresponds to s = 1.0, t = 1.0.

See "2.6.11 Texture maps" for a general description of texture maps.

Image space of a texture map

Figure 3-40: Texture Map Image Space

See "2.14 Lighting model" for a description of how the texture values interact with the appearance of the geometry. Section "4.5 SFImage" describes the specification of an image.

The repeatS and repeatT fields specify how the texture wraps in the S and T directions. If repeatS is TRUE (the default), the texture map is repeated outside the 0-to-1 texture coordinate range in the S direction so that it fills the shape. If repeatS is FALSE, the texture coordinates are clamped in the S direction to lie within the 0.0 to 1.0 range. The repeatT field is analogous to the repeatS field.

TIP: See Figure 3-40 for an illustration of the image space of a texture map image (specified in the image field). Notice how the image defines the 0.0 to 1.0 s and t boundaries. Regardless of the size and aspect ratio of the texture map image, the left edge of the image always represents s = 0; the right edge, s = 1.0; the bottom edge, t = 0.0; and the top edge, t = 1.0. Also, notice how we have illustrated the texture map infinitely repeating in all directions. This shows what happens conceptually when s and t values, specified by the TextureCoordinate node, are outside the 0.0 to 1.0 range.


TIP: See the ImageTexture section for important tips on texture mapping tricks.


TIP: PixelTexture can also be used to replace ImageTexture nodes if you want to make a VRML file self-contained. However, using the data: protocol (see "2.5.4, Data Protocol") to insert a compressed JPEG or PNG into the url field of the ImageTexture will probably result in a smaller file.

TECHNICAL NOTE: The SFImage format for pictures used by PixelTexture is intentionally very simple and is not designed for efficient transport of large images. PixelTextures are expected to be useful mainly as placeholders for textures that are algorithmically generated by Script nodes, either once in the Script's initialize() method or repeatedly as the Script receives events from a TimeSensor to generate an animated texture. Downloading just the Script code to generate textures and the parameters to control the generation can be much more bandwidth efficient than transmitting a lot of texture images across the network.

EXAMPLE (click to run): The following example illustrates four variations of the PixelTexture node (see Figure 3-41). Each of the four maps a PixelTexture onto a simple, rectangular IndexedFaceSet. The first three use the same TextureCoordinate node to repeat the texture three times along both axes of the rectangle. The first object shows how to specify a one-component, gray-scale texture and how the diffuseColor of the Material can be used to tint or brighten the texture. The second PixelTexture uses a three-component, full-color texture and illustrates how to turn lighting off (by not specifying a Material). The third object shows a four-component texture with lighting on. The fourth PixelTexture illustrates the effect of setting the repeatS and repeatT fields to FALSE:

#VRML V2.0 utf8
Group { children [
  Transform {
    translation -2.5 0 0.5
    rotation 0 1 0 0.5
    children Shape {
      appearance Appearance {
        texture PixelTexture { # One component (gray scale)
          image 4 4 1 0x00 0xDD 0xAA 0xFF
                      0xDD 0x00 0xDD 0x00
                      0xAA 0xDD 0x00 0x00
                      0xFF 0x00 0x00 0x00
        }
        # Notice how the diffuseColor darkens the texture
        material DEF M Material { diffuseColor .7 .7 .7 }
      }
      geometry DEF IFS IndexedFaceSet {
        coord Coordinate {
        point [ -1.1 -1 0, 1 -1 0, 1 1 0, -1.1 1 0 ] }
        coordIndex [ 0 1 2 3 ]
        texCoord TextureCoordinate {
          point [ 0 0, 3 0, 3 3, 0 3 ]
        }
      }
    }
  }
  Transform {
    translation 0 0 0
    children Shape {
      appearance Appearance {
        # For faster rendering, do not specify a Material
        # and avoid lighting calculations on the texture.
        texture PixelTexture {
          image 2 2 3 0xFFFFFF 0xAAAAAA 0xDDDDDD  0x000000
        }
      }
      geometry USE IFS 
    }
  }
  Transform {
    translation 2.5 0 0
    children Shape {
      appearance Appearance {
        texture PixelTexture {
          image 2 2 4
            0xFFFFFF00 0xAAAAAAA0 0xDDDDDDA0 0x000000AA
        }
        material DEF M Material {
          diffuseColor 0 0 0 # diffuseColor and transp have no
          transparency 1.0   # effect-replaced by image values.
          shininess  0.5     # All other fields work fine.
          ambientIntensity 0.0
        }
      }
      geometry USE IFS 
    }
  }
  Transform {
    translation 5 0 0
    children Shape {
      appearance Appearance {
        texture PixelTexture {    # repeat fields
          image 4 4 1 0x00 0xDD 0xAA 0xFF
                      0xDD 0x00 0xDD 0x00
                      0xAA 0xDD 0x00 0x00
                      0xFF 0x00 0x00 0x00
          repeatS FALSE
          repeatT FALSE
        }
        material DEF M Material { diffuseColor 1 1 1 }
      }
      geometry IndexedFaceSet {
        coord Coordinate {
          point [ -1 -1 0, 1 -1 0, 1 1 0, -1 1 0 ]
        }
        coordIndex [ 0 1 2 3 ]
        texCoord TextureCoordinate {
          point [ -0.25 -0.5, 1.25 -0.5, 1.25 1.5, -0.25 1.5 ]
        }
      }
    }
  }
  Background {
    skyColor [ 1 1 1, 1 1 1, .5 .5 .5,
               1 1 1, .2 .2 .2, 1 1 1 ]
    skyAngle [ 1.35, 1.4, 1.45, 1.5, 1.55 ]
    groundColor [ 1 1 1, 1 1 1, 0.4 0.4 0.4 ]
    groundAngle [ 1.3, 1.57 ]
  }
  NavigationInfo { type "EXAMINE" }
  Viewpoint { position  0 1 6 orientation -.707 0 -.707 0 }
]}

 

PixelTexture example

Figure 3-41: PixelTexture Node Example