H3DU.Texture
H3DU.Texture(name)
Specifies a texture, which can serve as image data applied to the surface of a shape, or even a 2-dimensional array of pixels used for some other purpose, such as a depth map, a height map, a bump map, a specular map, and so on.
For best results, any textures to be used in WebGL should have width and height each equal to a power of 2, such as 2, 4, 8, 16, and 32.
Parameters
name
(Type: string)
URL of the texture data. Based on the URL, the texture may be loaded via the JavaScript DOM's Image class. However, this constructor will not load that image yet.
Methods
- dispose
Disposes resources used by this texture. - fromUint8Array
Creates a texture from a byte array specifying the texture data. - getHeight
Gets this texture's known height. - getName
Gets the name of this texture. - getWidth
Gets this texture's known width. - loadTexture
Loads a texture by its URL. - setClamp
Deprecated: Use the TextureInfo class's "wrapS" and "wrapT" parameters instead.
H3DU.Texture#dispose()
Disposes resources used by this texture.
Return Value
This method doesn't return a value. (Type: void)
(static) H3DU.Texture.fromUint8Array(array, width, height)
Creates a texture from a byte array specifying the texture data.
Parameters
array
(Type: Uint8Array)
A byte array containing the texture data, with the pixels arranged in left-to-right rows from top to bottom. Each pixel takes 4 bytes, where the bytes are the red, green, blue, and alpha components, in that order.width
(Type: number)
Width, in pixels, of the texture.height
(Type: number)
Height, in pixels, of the texture.
Return Value
The new H3DU.Texture object. (Type: H3DU.Texture)
H3DU.Texture#getHeight()
Gets this texture's known height.
Return Value
This texture's height in pixels. Will be 0 if the texture's image data wasn't loaded yet. (Type: number)
H3DU.Texture#getName()
Gets the name of this texture.
Return Value
Return value. (Type: string)
H3DU.Texture#getWidth()
Gets this texture's known width.
Return Value
This texture's width in pixels. Will be 0 if the texture's image data wasn't loaded yet. (Type: number)
(static) H3DU.Texture.loadTexture(info, [textureCache])
Loads a texture by its URL.
Parameters
info
(Type: String | H3DU.TextureInfo | H3DU.Texture)
An H3DU.Texture object, an H3DU.TextureInfo object, or a string with the URL of the texture data. Images with a TGA extension that use the RGBA or grayscale format are supported. Images supported by the browser will be loaded via the JavaScript DOM's Image class.textureCache
(Type: Object) (optional)
An object whose keys are the names of textures already loaded. This will help avoid loading the same texture more than once.
Return Value
A promise that resolves when the texture is fully loaded. If it resolves, the result will be an H3DU.Texture object. (Type: Promise)
H3DU.Texture#setClamp(clamp)
Deprecated: Use the TextureInfo class's "wrapS" and "wrapT" parameters instead.
Sets the wrapping behavior of texture coordinates that fall out of range when using this texture. This setting will only have an effect on textures whose width and height are both powers of two. For other textures, this setting is ignored and out-of-range texture coordinates are always clamped.
Parameters
clamp
(Type: Boolean)
If true, the texture's texture coordinates will be clamped to the range [0, 1]. If false, the fractional parts of the texture coordinates' be used as the coordinates (causing wraparound). The default is false.
Return Value
This object. (Type: H3DU.Texture)