pyvista.Texture#

class Texture(*args, **kwargs)[source]#

Wrap vtkTexture.

Textures can be used to apply images to surfaces, as in the case of Applying Textures.

They can also be used for environment textures to affect the lighting of the scene, or even as a environment cubemap as in the case of Physically Based Rendering and 3D Earth and Celestial Bodies.

Parameters:
uinputstr, vtkImageData, vtkTexture, sequence[pyvista.ImageData], optional

Filename, vtkImageData, vtkTexture, numpy.ndarray or a sequence of images to create a cubemap. If a sequence of images, must be of the same size and in the following order:

  • +X

  • -X

  • +Y

  • -Y

  • +Z

  • -Z

**kwargsdict, optional

Optional arguments when reading from a file. Generally unused.

Examples

Load a texture from file. File should be a “image” or “image-like” file.

>>> from pathlib import Path
>>> import pyvista as pv
>>> from pyvista import examples
>>> path = examples.download_masonry_texture(load=False)
>>> Path(path).name
'masonry.bmp'
>>> texture = pv.Texture(path)
>>> texture
Texture (...)
  Components:   3
  Cube Map:     False
  Dimensions:   256, 256

Create a texture from an RGB array. Note how this is colored per “point” rather than per “pixel”.

>>> import numpy as np
>>> arr = np.array(
...     [
...         [255, 255, 255],
...         [255, 0, 0],
...         [0, 255, 0],
...         [0, 0, 255],
...     ],
...     dtype=np.uint8,
... )
>>> arr = arr.reshape((2, 2, 3))
>>> texture = pv.Texture(arr)
>>> texture.plot()
../../../_images/pyvista-Texture-1_00_00.png

Create a cubemap from 6 images.

>>> px = examples.download_sky(direction='posx')  
>>> nx = examples.download_sky(direction='negx')  
>>> py = examples.download_sky(direction='posy')  
>>> ny = examples.download_sky(direction='negy')  
>>> pz = examples.download_sky(direction='posz')  
>>> nz = examples.download_sky(direction='negz')  
>>> texture = pv.Texture([px, nx, py, ny, pz, nz])  
>>> texture.cube_map  
True

Methods

Texture.copy()

Make a copy of this texture.

Texture.flip_x()

Flip the texture in the x direction.

Texture.flip_y()

Flip the texture in the y direction.

Texture.plot(**kwargs)

Plot the texture as an image.

Texture.rotate_ccw()

Rotate this texture 90 degrees counter-clockwise.

Texture.rotate_cw()

Rotate this texture 90 degrees clockwise.

Texture.to_array()

Return the texture as an array.

Texture.to_grayscale()

Convert this texture as a single component (grayscale) texture.

Texture.to_image()

Return the texture as an image.

Texture.to_skybox()

Return the texture as a vtkSkybox if cube mapping is enabled.

Attributes

Texture.cube_map

Return True if cube mapping is enabled and False otherwise.

Texture.dimensions

Dimensions of the texture.

Texture.interpolate

Return if interpolate is enabled or disabled.

Texture.mipmap

Return if mipmap is enabled or disabled.

Texture.n_components

Return the number of components in the image.

Texture.repeat

Repeat the texture.

Texture.wrap

Return or set the Wrap mode for the texture coordinates.