trimesh.rendering

rendering.py

Functions to convert trimesh objects to pyglet/opengl objects.

trimesh.rendering.colors_to_gl(colors, count)

Given a list of colors (or None) return a GL-acceptable list of colors.

Parameters:

colors ((count, (3 or 4)) float) – Input colors as an array

Returns:

  • colors_type (str) – Color type

  • colors_gl ((count,) list) – Colors to pass to pyglet

trimesh.rendering.convert_to_vertexlist(geometry, **kwargs)

Try to convert various geometry objects to the constructor args for a pyglet indexed vertex list.

Parameters:

obj (Trimesh, Path2D, Path3D, (n,2) float, (n,3) float) – Object to render

Returns:

args – Args to be passed to pyglet indexed vertex list constructor.

Return type:

tuple

trimesh.rendering.light_to_gl(light, transform, lightN)

Convert trimesh.scene.lighting.Light objects into args for gl.glLightFv calls

Parameters:
  • light (trimesh.scene.lighting.Light) – Light object to be converted to GL

  • transform ((4, 4) float) – Transformation matrix of light

  • lightN (int) – Result of gl.GL_LIGHT0, gl.GL_LIGHT1, etc

Returns:

multiarg – List of args to pass to gl.glLightFv eg: [gl.glLightfb(*a) for a in multiarg]

Return type:

[tuple]

trimesh.rendering.material_to_texture(material, upsize=True)

Convert a trimesh.visual.texture.Material object into a pyglet-compatible texture object.

Parameters:
  • material (trimesh.visual.texture.Material) – Material to be converted

  • upsize (bool) – If True, will upscale textures to their nearest power of two resolution to avoid weirdness

Returns:

texture – Texture loaded into pyglet form

Return type:

pyglet.image.Texture

trimesh.rendering.matrix_to_gl(matrix)

Convert a numpy row-major homogeneous transformation matrix to a flat column-major GLfloat transformation.

Parameters:

matrix ((4,4) float) – Row-major homogeneous transform

Returns:

glmatrix – Transform in pyglet format

Return type:

(16,) gl.GLfloat

trimesh.rendering.mesh_to_vertexlist(mesh, group=None, smooth=True, smooth_threshold=60000)

Convert a Trimesh object to arguments for an indexed vertex list constructor.

Parameters:
  • mesh (trimesh.Trimesh) – Mesh to be rendered

  • group (str) – Rendering group for the vertex list

  • smooth (bool) – Should we try to smooth shade the mesh

  • smooth_threshold (int) – Maximum number of faces to smooth shade

Returns:

args – Args for vertex list constructor

Return type:

(7,) tuple

trimesh.rendering.path_to_vertexlist(path, group=None, **kwargs)

Convert a Path3D object to arguments for a pyglet indexed vertex list constructor.

Parameters:
  • path (trimesh.path.Path3D object) – Mesh to be rendered

  • group (str) – Rendering group for the vertex list

Returns:

args – Args for vertex list constructor

Return type:

(7,) tuple

trimesh.rendering.points_to_vertexlist(points, colors=None, group=None, **kwargs)

Convert a numpy array of 3D points to args for a vertex list constructor.

Parameters:
  • points ((n, 3) float) – Points to be rendered

  • colors ((n, 3) or (n, 4) float) – Colors for each point

  • group (str) – Rendering group for the vertex list

Returns:

args – Args for vertex list constructor

Return type:

(7,) tuple

trimesh.rendering.vector_to_gl(array, *args)

Convert an array and an optional set of args into a flat vector of gl.GLfloat