The texture field of the Appearance node can contain one of the various types of texture nodes: ImageTexture, MovieTexture, or PixelTexture. With ImageTexture you can wrap or tile an image around the shape, with MovieTexture you can do the same with time-dependent texture-files (MPEG movies). Both ImageTexture and MovieTexture nodes load the texture from an external (image or video)file, and place them on the object according to the mapping parameters, specified inside the node. The PixelTexture node defines everything "inside" the VRML file: the node must contain 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. In any cases the Appearance node's texture field wraps the image or movie around geometry.
Note that texture color overrides material node color.
First let's examine ImageTextures:
Appearance { material Material {} texture ImageTexture { url "myimage.jpg" repeatS TRUE repeatT TRUE } }
The ImageTexture node defines a texture map by specifying an image file and parameters for mapping it onto geometry. Texture maps are defined in a special 2D coordinate system (s, t instead of x,y not to confuse with the 3D coordinate system) that ranges from [0.0,1.0] in both directions. The bottom edge of the image corresponds to the S-axis of the texture map, and left edge of the image corresponds to the T-axis of the texture map. The lower-left pixel of the image corresponds to s=0, t=0, and the top-right pixel of the image corresponds to s=1, t=1. For example:
The lower left is s=0, t=0 | The upper right is s=1, t=1 |
The texture is read from the URL specified by the url field. When the url field contains no values ([]), texturing is disabled. You can use JPEG (Joint Photographic Experts Group), PNG (Portable Network Graphics), and GIF (Graphics Interchange Format) images as textures.
The repeatS and repeatT fields specify how the texture wraps in the S and T directions. (These fields have no effect on textures mapped onto primitives: to use these effects you must use "coordinate-based geometry": IndexefFaceSet, ElevationGrid of Extrusion.) If repeatS is TRUE (the default), the texture map is repeated outside the [0.0, 1.0] 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, 1.0] range. The repeatT field is analogous to the repeatS field.
In the following example you can examine how the same texture map is mapped on the different primitives:
#VRML V2.0 utf8 #ImageTexture example Transform { translation -3.0 0.0 0.0 children [ Shape{ appearance Appearance{ texture ImageTexture { url "../images/smalltexture.gif" } } geometry Sphere { } } ] } Transform { translation -1 0 0 children[ Shape{ appearance Appearance{ texture ImageTexture { url "../images/smalltexture.gif" } } geometry Box { } } ] } Transform { translation 1 0 0 children[ Shape{ appearance Appearance{ texture ImageTexture { url "../images/smalltexture.gif" } } geometry Cone { } } ] } Transform { translation 3 0 0 children[ Shape{ appearance Appearance{ texture ImageTexture { url "../images/smalltexture.gif" } } geometry Cylinder { } } ] }
The MovieTexture node defines a time dependent texture map (contained in a movie file) and
parameters for controlling the movie and the texture mapping. A MovieTexture node can also be used as the source of sound data for a Sound node. In this special case, the MovieTexture node doesn't create any visible effect: it is not used for rendering, only to create the audible environment.
The MovieTexture node works analogous way to ImageTexture with some exeptions: some fields are missing, and there are some new ones. The 2D coordinate-system for texture-maps work the same way like in the ImageTexture node: the 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 image corresponds to the S-axis of the texture map, and left edge of the image corresponds to the T-axis of the texture map.
You can use MPEG-1 movies without any restriction, and MPEG-2 movies without sound. The MovieTexture node and the field's default values look like:
MovieTexture { loop FALSE speed 1.0 # (-,) startTime 0 # (-,) stopTime 0 # (-,) url [] repeatS TRUE repeatT TRUE }
The speed indicates how fast the movie shall be played: a value of 2 indicates the movie plays twice as fast, a negative speed implies that the movie will play backwards.
The playback of MPEG movies work only on some systems(equipped with special cards or strong processing power), so we will not pay attention to this feature. Some fields (like starttime and stoptime) are discussed later. For the complete description refer to the VRML/ISO Draft for International Standard (DIS) Node Reference.
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. The 2D coordinate system of textures (s, t), repeatS and repeatT fields are the same like the previous texture-nodes.
The PixelTexture node contains data stored as width, height, number of channels, followed by width*height hex values representing the image. Consider the following 2x4 RGB image:
PixelTexture { image 2 4 3 0xFF0000 0x00FF00 0 0 0 0 0xFFFFFF 0xFFFF00 }
In the following example we use the 2x4 image shown above mapped onto a simple cube:
#VRML V2.0 utf8 #PixelTexture example Shape{ appearance Appearance{ texture PixelTexture { image 2 4 3 #size of image is 2x4, depth is rgb(3) 0xFF0000 0x00FF00 #the two pixel's color in the first row (red and green) 0 0 #the two pixel's color in the second row (black) 0 0 #the two pixel's color in the third row 0xFFFFFF 0xFFFF00 #the two pixel's color in the fourth row (white and yellow) } } geometry Box { } }
You can use the textureTransform node to control how textures are mapped on objects. You can use textureTransform on "coordinate-based" geometry only: it doesn't have any effect on textures mapped on primitives(you must use IndexefFaceSet, ElevationGrid of Extrusion). The transformation consists of (in order):
textureTransform { center 0 0 rotation 0 scale 1 1 translation 0 0 }
Note that these transformations appear "reversed" when viewed on the surface of geometry. For example, a scale value of (2 2) will scale the texture coordinates(not the image) and have the net effect of shrinking the texture size by a factor of 2 (texture coordinates are twice as large and thus cause the texture to repeat). A translation of (0.5 0.0) translates the texture coordinates +.5 units along the S-axis and has the net effect of translating the texture -0.5 along the S-axis on the geometry's surface. A rotation of 1.57 of the texture coordinates results in a -1.57 rotation of the texture on the geometry.
The center field specifies a translation offset in texture coordinate space about which the rotation and scale fields are applied. The scale field specifies a scaling factor in S and T of the texture coordinates about the center point. The rotation field specifies a rotation in radians of the texture coordinates about the center point after the scale has been applied. A positive rotation value makes the texture coordinates rotate counterclockwise about the centre, thereby rotating the appearance of the texture itself clockwise. The translation field specifies a translation of the texture coordinates.
In the following example you can examine an imagetexture mapped on a 4x4 size square, scaled 6 times in the S(x) and 2 times in T(y) directions and rotated 45 degrees.
#VRML V2.0 utf8 #ImageTexture example Shape{ appearance Appearance { material Material { emissiveColor 1.0 1.0 1.0 } texture ImageTexture { url "../images/smalltexture.gif" } textureTransform TextureTransform { scale 6.0 2.0 #scale it in X 6 times, in Y 2 times rotation 0.785 #rotate it by 45 degrees } } geometry IndexedFaceSet { coord Coordinate { point [ # bottom -4.0 -4.0 0.0, #vertex 0 4.0 -4.0 0.0, #vertex 1 4.0 4.0 0.0, #vertex 2 -4.0 4.0 0.0, #vertex 3 ] } coordIndex [ 0, 1, 2, 3 -1] } }In the next example you can examine the same imagetexture mapped on our pyramid (from one of the previous examples) but shifted by it's half(translation 0.5 0.0) in the S(x) direction and scaled by half in the X(S) dimension.
#VRML V2.0 utf8 #ImageTexture example Shape{ appearance Appearance { material Material { emissiveColor 1.0 1.0 1.0 } texture ImageTexture { url "../images/smalltexture.gif" } textureTransform TextureTransform { translation 0.5 0.0 #image is shifted by 0.5X scale 2.0 1.0 #image is scaled bu 1/2.0 in X } } geometry IndexedFaceSet { coord Coordinate { point [ # bottom -1.0 -1.0 1.0, #vertex 0 1.0 -1.0 1.0, #vertex 1 1.0 -1.0 -1.0, #vertex 2 -1.0 -1.0 -1.0, #vertex 3 # top 0.0 1.0 0.0 #vertex 4 ] } coordIndex [ #bottom square 0, 3, 2, 1, 0, -1, #side1 0, 1, 4, -1, #side2 1, 2, 4, -1, #side3 2, 3, 4, -1, #side1 3, 0, 4, -1, ] } }
The textureCoodinate node lets you to specify a portion of an image to be the subject of Texture and textureTransform nodes. It is very useful to either precisely position parts of a texture on parts of an object, or to use different parts of the same image on different shapes in the scene. This is a very advanced and rarely used feature: the description is under construction(sorry).