14.1.1 Static mapping using per−vertex texture coordinates

Static mapping defines a static relationship between vertex coordinates and texture coordinates. This is usually implemented by simply assigning a texture coordinate to each vertex in the model (table 14.1).

Table 14.1 Static mapping

 Vertex 143: coordinate: 3,–6,7 color: red = 184, green = 242, blue = 32 normal vector 0.5, 0.2, −0.3 texture coordinate: 0.3, 0.6

Vertex 143 has been assigned a number of attributes: coordinate (position), color, normal vector, and a texture coordinate.

The TextureTest example that follows can be used to experiment with the relationship among images, texture coordinates, and 3D vertex coordinates (figure 14.4).

TextureTest loads the following information from a simple ASCII text file:

Name of texture image

Size of geometry in the x direction

Geometry y scaling factor

Number of vertices

Texture coordinates for Vertex 1

Texture coordinates for Vertex 2

Texture coordinates for Vertex N

For example, the data for the image in figure 14.4 is shown in table 14.2.

Table 14.2 Static mapping

 Width 400Height 400 Vertex x y x' y' tx ty 0 159 99 159 301 0.40 0.75 1 125 126 125 274 0.31 0.69 2 110 163 110 237 0.28 0.59 3 102 243 102 157 0.26 0.39 4 118 304 118 96 0.30 0.24 5 179 363 179 37 0.45 0.09 6 220 364 220 36 0.55 0.09 7 264 335 264 65 0.66 0.16 8 287 289 287 111 0.72 0.28 9 295 204 295 196 0.74 0.49 10 279 132 279 268 0.70 0.67 11 253 104 253 296 0.63 0.74 12 207 95 207 305 0.52 0.76

Figure 14.4 The TextureTest example loads an image and a list of texture coordinates and displays a portion of the image in a 3D scene by texture mapping it onto a TriangleArray

The x, y columns are the pixel locations in the image that are returned by a bitmap editor. The origin for these 2D coordinates is at the top−left of the image. The x' and y' coordinates compensate for this by flipping the y coordinate (y' = height – y). The texture coordinates tx and ty are suitable for Java 3D (tx = x'/width and ty = y'/height). It is very easy to perform the coordinate conversions using a spreadsheet.

The ASCII file is therefore:

daniel.gif (name of the image file)

5 (size in the x direction)

1.0 (y scale factor)

13 (number of texture coordinates)

 0.4 0.75 (texture coordinate 1, x y) 0.31 0.69 0.28 0.59 0.26 0.39 0.3 0.24 0.45 0.09 0.55 0.09 0.66 0.16 0.72 0.28 0.74 0.49 0.7 0.67 0.63 0.74 0.52 0.76 (texture coordinate 13, x y)

The Microsoft Excel spread sheet file daniel coords.xls with the TextureTest example contains the formulae necessary for the coordinate transformation (figure 14.5).

Figure 14.5 The TextureTest example in action. Four texture−mapped TriangleArrays have been created from two sets of texture coordinate data and images. The TriangleArrays are rotated using an Interpolator

 Impressum und Datenschutz    Copyright ©2018 eir.me Siebel Articles Python Perl 5 Documentation Manuel PHP7 français Java Das PHP7 Handbuch PHP7 Manual English Linux and Unix Jobs