trimesh.visual.material
material.py
Store visual materials as objects.
- class trimesh.visual.material.Material(*args, **kwargs)
Bases:
ABC
- __init__(*args, **kwargs)
- copy()
- abstract property main_color
The “average” color of this material.
- Returns
color – Average color of this material.
- Return type
(4,) uint8
- property name
- class trimesh.visual.material.MultiMaterial(materials=None, **kwargs)
Bases:
Material
- __init__(materials=None, **kwargs)
Wrapper for a list of Materials.
- Parameters
materials (Optional[List[Material]]) – List of materials with which the container to be initialized.
- add(material)
Adds new material to the container.
- Parameters
material (Material) – The material to be added.
- get(idx)
Get material by index.
- Parameters
idx (int) – Index of the material to be retrieved.
- Return type
The material on the given index.
- property main_color
The “average” color of this material.
- Returns
color – Average color of this material.
- Return type
(4,) uint8
- to_pbr()
TODO : IMPLEMENT
- class trimesh.visual.material.PBRMaterial(name=None, emissiveFactor=None, emissiveTexture=None, baseColorFactor=None, metallicFactor=None, roughnessFactor=None, normalTexture=None, occlusionTexture=None, baseColorTexture=None, metallicRoughnessTexture=None, doubleSided=False, alphaMode=None, alphaCutoff=None, **kwargs)
Bases:
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
- __init__(name=None, emissiveFactor=None, emissiveTexture=None, baseColorFactor=None, metallicFactor=None, roughnessFactor=None, normalTexture=None, occlusionTexture=None, baseColorTexture=None, metallicRoughnessTexture=None, doubleSided=False, alphaMode=None, alphaCutoff=None, **kwargs)
- property alphaCutoff
Specifies the cutoff threshold when in MASK alpha mode. If the alpha value is greater than or equal to this value then it is rendered as fully opaque, otherwise, it is rendered as fully transparent. A value greater than 1.0 will render the entire material as fully transparent. This value MUST be ignored for other alpha modes. When alphaMode is not defined, this value MUST NOT be defined.
- Returns
alphaCutoff – Value of cutoff.
- Return type
float
- property alphaMode
The material alpha rendering mode enumeration specifying the interpretation of the alpha value of the base color.
- Returns
alphaMode – One of ‘OPAQUE’, ‘MASK’, ‘BLEND’
- Return type
str
- property baseColorFactor
The factors for the base color of the material. This value defines linear multipliers for the sampled texels of the base color texture.
- Returns
color – RGBA color
- Return type
(4,) uint8
- property baseColorTexture
The base color texture image.
- Returns
image – Color texture.
- Return type
PIL.Image
- copy()
- property doubleSided
Specifies whether the material is double sided.
- Returns
doubleSided – Specifies whether the material is double sided.
- Return type
bool
- property emissiveFactor
The factors for the emissive color of the material. This value defines linear multipliers for the sampled texels of the emissive texture.
- Returns
emissiveFactor – Ech element in the array MUST be greater than or equal to 0 and less than or equal to 1.
- Return type
(3,) float
- property main_color
The “average” color of this material.
- Returns
color – Average color of this material.
- Return type
(4,) uint8
- property metallicFactor
The factor for the metalness of the material. This value defines a linear multiplier for the sampled metalness values of the metallic-roughness texture.
- Returns
metallicFactor – How metally is the material
- Return type
float
- property roughnessFactor
The factor for the roughness of the material. This value defines a linear multiplier for the sampled roughness values of the metallic-roughness texture.
- Returns
roughnessFactor – Roughness of material.
- Return type
float
- to_color(uv)
Get the rough color at a list of specified UV coordinates.
- Parameters
uv ((n, 2) float) – UV coordinates on the material
- 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
- class trimesh.visual.material.SimpleMaterial(image=None, diffuse=None, ambient=None, specular=None, glossiness=None, **kwargs)
Bases:
Material
Hold a single image texture.
- __init__(image=None, diffuse=None, ambient=None, specular=None, glossiness=None, **kwargs)
- property glossiness
- property main_color
Return the most prominent color.
- to_color(uv)
- to_obj(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
- 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
- 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