trimesh.visual.texture

Classes:

PBRMaterial([name, emissiveFactor, …])

Create a material for physically based rendering as specified by GLTF 2.0: https://git.io/fhkPZ

SimpleMaterial([image, diffuse, ambient, …])

Hold a single image texture.

TextureVisuals([uv, material, image])

Visuals()

Parent of Visual classes.

Functions:

empty_material([color])

Return an empty material set to a single color

power_resize(image[, resample, square])

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

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

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

Bases: trimesh.visual.base.Visuals

Methods:

concatenate(others)

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

copy()

Return a copy of the current TextureVisuals object.

crc()

Get a CRC of the stored data.

face_subset(face_index)

Get a copy of

to_color()

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

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.

Attributes:

defined

Check if any data is stored

kind

Return the type of visual data stored

uv

Get the stored UV coordinates.

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()

Return a copy of the current TextureVisuals object.

Returns

copied – Contains the same information in a new object

Return type

TextureVisuals

crc()

Get a CRC of the stored data.

Returns

crc – Hash of items in self.vertex_attributes

Return type

int

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

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