trimesh.visual.texture

class trimesh.visual.texture.TextureVisuals(uv=None, material=None, image=None, face_materials=None)

Bases: Visuals

__init__(uv=None, material=None, image=None, face_materials=None)

Store a single material and per-vertex UV coordinates for a mesh.

If passed UV coordinates and a single image it will create a SimpleMaterial for the image.

Parameters:
  • uv ((n, 2) float) – UV coordinates for the mesh

  • material (Material) – Store images and properties

  • image (PIL.Image) – Can be passed to automatically create material

concatenate(others)

Concatenate this TextureVisuals object with others and return the result without modifying this visual.

Parameters:

others ((n,) Visuals) – Other visual objects to concatenate

Returns:

concatenated – Concatenated visual objects

Return type:

TextureVisuals

copy(uv=None)

Return a copy of the current TextureVisuals object.

Returns:

copied – Contains the same information in a new object

Return type:

TextureVisuals

property defined

Check if any data is stored

Returns:

defined – Are UV coordinates and images set?

Return type:

bool

face_subset(face_index)

Get a copy of

property kind

Return the type of visual data stored

Returns:

kind – What type of visuals are defined

Return type:

str

to_color()

Convert textured visuals to a ColorVisuals with vertex color calculated from texture.

Returns:

vis – Contains vertex color from texture

Return type:

trimesh.visuals.ColorVisuals

update_faces(mask)

Apply a mask to remove or duplicate face properties, not applicable to texture visuals.

update_vertices(mask)

Apply a mask to remove or duplicate vertex properties.

Parameters:

mask ((len(vertices),) bool or (n,) int) – Mask which can be used like: vertex_attribute[mask]

property uv

Get the stored UV coordinates.

Returns:

uv – Pixel position per-vertex.

Return type:

(n, 2) float or None

trimesh.visual.texture.power_resize(image, resample=1, square=False)

Resize a PIL image so every dimension is a power of two.

Parameters:
  • image (PIL.Image) – Input image

  • resample (int) – Passed to Image.resize

  • square (bool) – If True, upsize to a square image

Returns:

resized – Input image resized

Return type:

PIL.Image

trimesh.visual.texture.unmerge_faces(faces, *args, **kwargs)

Textured meshes can come with faces referencing vertex indices (v) and an array the same shape which references vertex texture indices (vt) and sometimes even normal (vn).

Vertex locations with different values of any of these can’t be considered the “same” vertex, and for our simple data model we need to not combine these vertices.

Parameters:
  • faces ((n, d) int) – References vertex indices

  • *args ((n, d) int) – Various references of corresponding values This is usually UV coordinates or normal indexes

  • maintain_faces (bool) – Do not alter original faces and return no-op masks.

Returns:

  • new_faces ((m, d) int) – New faces for masked vertices

  • mask_v ((p,) int) – A mask to apply to vertices

  • mask_* ((p,) int) – A mask to apply to vt array to get matching UV coordinates Returns as many of these as args were passed