trimesh.visual.material

material.py

Store visual materials as objects.

Classes

Material(*args, **kwargs)

PBRMaterial([name, emissiveFactor, …])

Create a material for physically based rendering as

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

Hold a single image texture.

Functions

empty_material([color])

Return an empty material set to a single color

from_color(vertex_colors)

Convert vertex colors into UV coordinates and materials.

pack(materials, uvs[, deduplicate])

Pack multiple materials with texture into a single material.

class trimesh.visual.material.Material(*args, **kwargs)

Bases: object

Methods

copy()

Attributes

main_color

copy()
property main_color
class trimesh.visual.material.PBRMaterial(name=None, emissiveFactor=None, emissiveTexture=None, normalTexture=None, occlusionTexture=None, baseColorTexture=None, baseColorFactor=None, metallicFactor=None, roughnessFactor=None, metallicRoughnessTexture=None, doubleSided=False, alphaMode='OPAQUE', alphaCutoff=0.5)

Bases: trimesh.visual.material.Material

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

Parameters with Texture in them must be PIL.Image objects

Methods

copy()

to_color(uv)

Get the rough color at a list of specified UV coordinates.

to_simple()

Get a copy of the current PBR material as a simple material.

Attributes

main_color

copy()
property main_color
to_color(uv)

Get the rough color at a list of specified UV coordinates.

Parameters

uv ((n, 2) float) – UV coordinates on the material

Returns

Return type

colors

to_simple()

Get a copy of the current PBR material as a simple material.

Returns

simple – Contains material information in a simple manner

Return type

SimpleMaterial

class trimesh.visual.material.SimpleMaterial(image=None, diffuse=None, ambient=None, specular=None, glossiness=None, **kwargs)

Bases: trimesh.visual.material.Material

Hold a single image texture.

Attributes

glossiness

main_color

Return the most prominent color.

Methods

to_color(uv)

to_obj([tex_name, mtl_name])

Convert the current material to an OBJ format material.

to_pbr()

Convert the current simple material to a PBR material.

property glossiness
property main_color

Return the most prominent color.

to_color(uv)
to_obj(tex_name=None, mtl_name=None)

Convert the current material to an OBJ format material.

Parameters

name (str or None) – Name to apply to the material

Returns

  • tex_name (str) – Name of material

  • mtl_name (str) – Name of mtl file in files

  • files (dict) – Data as {file name : bytes}

to_pbr()

Convert the current simple material to a PBR material.

Returns

pbr – Contains material information in PBR format.

Return type

PBRMaterial

trimesh.visual.material.empty_material(color=None)

Return an empty material set to a single color

Parameters

color (None or (3,) uint8) – RGB color

Returns

material – Image is a a one pixel RGB

Return type

SimpleMaterial

trimesh.visual.material.from_color(vertex_colors)

Convert vertex colors into UV coordinates and materials.

TODO : pack colors

Parameters

vertex_colors ((n, 3) float) – Array of vertex colors

Returns

  • material (SimpleMaterial) – Material containing color information

  • uvs ((n, 2) float) – UV coordinates

trimesh.visual.material.pack(materials, uvs, deduplicate=True)

Pack multiple materials with texture into a single material.

Parameters
  • materials ((n,) Material) – List of multiple materials

  • uvs ((n, m, 2) float) – Original UV coordinates

Returns

  • material (Material) – Combined material

  • uv ((p, 2) float) – Combined UV coordinates