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.48 TextureCoordinate

TextureCoordinate { 
  exposedField MFVec2f point  []      # (-INF,INF)
}

The TextureCoordinate node specifies a set of 2D texture coordinates used by vertex-based geometry nodes (e.g., IndexedFaceSet and ElevationGrid) to map textures to vertices. Textures are two dimensional colour functions that, given an (s, t) coordinate, return a colour value colour(s, t). Texture map values (ImageTexture, MovieTexture, and PixelTexture) range from [0.0, 1.0] along the S-axis and T-axis. However, TextureCoordinate values, specified by the point field, may be in the range (-INF,INF). Texture coordinates identify a location (and thus a colour value) in the texture map. The horizontal coordinate s is specified first, followed by the vertical coordinate t.

If the texture map is repeated in a given direction (S-axis or T-axis), a texture coordinate C (s or t) is mapped into a texture map that has N pixels in the given direction as follows:

    Texture map location = (C - floor(C)) × N

If the texture map is not repeated, the texture coordinates are clamped to the 0.0 to 1.0 range as follows:

    Texture map location = N,     if C > 1.0,
                         = 0.0,   if C < 0.0,
                         = C × N, if 0.0 <= C <= 1.0.

Details on repeating textures are specific to texture map node types described in 3.22 ImageTexture, 3.28 MovieTexture, and 3.33 PixelTexture.

TIP: See Figure 3-58 for an illustration of how TextureCoordinate values are used to map points in a texture map image into points in 3D space (e.g., on a polygon). Notice that the texture map image repeats infinitely in both the s and t directions, and thus TextureCoordinate values can range from –infinity to +infinity.

 

TextureCoordinate node figure

Figure 3-58: TextureCoordinate Node

TIP: See Figure 3-28 for a conceptual illustration of how texture coordinates map into the texture map space.

TIP: TextureCoordinate nodes are specified in the texCoord field of IndexedFaceSet or ElevationGrid nodes. Animating texture coordinates can produce interesting effects. However, there is no equivalent of the CoordinateInterpolator node for texture coordinates, so you must write a Script to perform the animation interpolation.

EXAMPLE (click to run): The following example illustrates three cases of the TextureCoordinate node (see Figure 3-59). The first TextureCoordinate node repeats the texture map in a reversed x direction across the rectangle. It illustrates what happens when TextureCoordinate values exceed the 0.0 to 1.0 boundaries of the texture map. The second TextureCoordinate is the simplest and most common. It applies the texture map to a rectangle with no distortion or stretching. In this case, it is important for the aspect ratio of the rectangle to match the aspect ratio of the texture map.
#VRML V2.0 utf8
Group { children [
  Transform {
    translation -2.5 0 0.5
    rotation 0 1 0 0.5
    children Shape {
      appearance DEF A1 Appearance {
        texture ImageTexture { url "marble2.gif" }
        material Material { diffuseColor 1 1 1 }
      }
      geometry IndexedFaceSet {
        coord DEF C Coordinate {
          point [ -1 -1 0, 1 -1 0, 1 1 0, -1 1 0 ]
        }
        coordIndex [ 0 1 2 3 ]
        texCoord TextureCoordinate {
          point [ 3 0, 0 0, 0 3, 3 3 ]
        }
      }
    }
  }
  Shape {
    appearance USE A1
    geometry IndexedFaceSet {
      coord USE C
      coordIndex [ 0 1 2 3 ]
      texCoord TextureCoordinate {
        point [ 0 0, 1 0, 1 1, 0 1 ]
      }
    }
  }
  Transform {
    translation 2.5 0 0.5
    rotation 0 1 0 -0.5
    children Shape {
      appearance USE A1
      geometry IndexedFaceSet {
        coord USE C
        coordIndex [ 0 1 2 3 ]
        texCoord TextureCoordinate {
          point [ .3 .3, .6 .3, .6 .6, .3 .6 ]
        }
      }
    }
  }
  Background { skyColor 1 1 1 }
  NavigationInfo { type "EXAMINE" }
]}

TextureCoordinate node example

Figure 3-59: TextureCoordinate Node Example