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.

Changed in version 0.47: All textures now use 'direct' color_mode by default.

Parameters:
uinputstr, vtkImageData, vtkTexture, sequence[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#

Download Python source code | Download Jupyter notebook

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-07a9afa1d9326ce3_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

Inheritance#

Inherited members are documented on DataObject.

See them all under Inherited Attributes and Inherited Methods.

Wraps vtkTexture.

Attributes#

Texture.color_mode

Return or set the color mode.

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.is_empty

Return True if the texture has no image data.

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.

Inherited Attributes#

DataObject.actual_memory_size

Return the actual size of the dataset object.

DataObject.field_data

Return FieldData as DataSetAttributes.

DataObject.memory_address

Get address of the underlying VTK C++ object.

DataObject.user_dict

Set or return a user-specified data dictionary.

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.get_data_range([name, preference])

Get the min and max of a named array of the texture's image.

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(*[, projection, ...])

Return the texture as a vtkSkybox.

Inherited Methods#

DataObject.add_field_data

Add field data.

DataObject.cast_to_multiblock

Convert this DataObject to a MultiBlock.

DataObject.clear_field_data

Remove all field data.

DataObject.copy_attributes

Copy the data attributes of the input dataset object.

DataObject.copy_meta_from

Copy pyvista meta data onto this object from another object.

DataObject.copy_structure

Copy the structure (geometry and topology) of the input dataset object.

DataObject.deep_copy

Overwrite this data object with another data object as a deep copy.

DataObject.head

Return the header stats of this dataset.

DataObject.save

Save this vtk object to file.

DataObject.shallow_copy

Shallow copy the given mesh to this mesh.