vispy.geometry.meshdata module#

class vispy.geometry.meshdata.MeshData(vertices=None, faces=None, edges=None, vertex_colors=None, face_colors=None, vertex_values=None)#

Bases: object

Class for storing and operating on 3D mesh data.

Parameters:
verticesndarray, shape (Nv, 3)

Vertex coordinates. If faces is not specified, then this will instead be interpreted as (Nf, 3, 3) array of coordinates.

facesndarray, shape (Nf, 3)

Indices into the vertex array.

edgesNone

[not available yet]

vertex_colorsndarray, shape (Nv, 4)

Vertex colors. If faces is not specified, this will be interpreted as (Nf, 3, 4) array of colors.

face_colorsndarray, shape (Nf, 4)

Face colors.

vertex_valuesndarray, shape (Nv,)

Vertex values.

Notes

All arguments are optional.

The object may contain:

  • list of vertex locations

  • list of edges

  • list of triangles

  • colors per vertex, edge, or tri

  • normals per vertex or tri

This class handles conversion between the standard [list of vertices, list of faces] format (suitable for use with glDrawElements) and ‘indexed’ [list of vertices] format (suitable for use with glDrawArrays). It will automatically compute face normal vectors as well as averaged vertex normal vectors.

The class attempts to be as efficient as possible in caching conversion results and avoiding unnecessary conversions.

get_bounds()#

Get the mesh bounds

Returns:
boundslist

A list of tuples of mesh bounds.

get_edge_colors()#
get_edges(indexed=None)#

Edges of the mesh

Parameters:
indexedstr | None

If indexed is None, return (Nf, 3) array of vertex indices, two per edge in the mesh. If indexed is ‘faces’, then return (Nf, 3, 2) array of vertex indices with 3 edges per face, and two vertices per edge.

Returns:
edgesndarray

The edges.

get_face_colors(indexed=None)#

Get the face colors

Parameters:
indexedstr | None

If indexed is None, return (Nf, 4) array of face colors. If indexed==’faces’, then instead return an indexed array (Nf, 3, 4) (note this is just the same array with each color repeated three times).

Returns:
colorsndarray

The colors.

get_face_normals(indexed=None)#

Get face normals

Parameters:
indexedstr | None

If None, return an array (Nf, 3) of normal vectors for each face. If ‘faces’, then instead return an indexed array (Nf, 3, 3) (this is just the same array with each vector copied three times).

Returns:
normalsndarray

The normals.

get_faces()#

Array (Nf, 3) of vertex indices, three per triangular face.

If faces have not been computed for this mesh, returns None.

get_vertex_colors(indexed=None)#

Get vertex colors

Parameters:
indexedstr | None

If None, return an array (Nv, 4) of vertex colors. If indexed==’faces’, then instead return an indexed array (Nf, 3, 4).

Returns:
colorsndarray

The vertex colors.

get_vertex_faces()#

List mapping each vertex index to a list of face indices that use it.

get_vertex_normals(indexed=None)#

Get vertex normals

Parameters:
indexedstr | None

If None, return an (N, 3) array of normal vectors with one entry per unique vertex in the mesh. If indexed is ‘faces’, then the array will contain three normal vectors per face (and some vertices may be repeated).

Returns:
normalsndarray

The normals.

get_vertex_values(indexed=None)#

Get vertex colors

Parameters:
indexedstr | None

If None, return an array (Nv,) of vertex values. If indexed==’faces’, then instead return an indexed array (Nf, 3).

Returns:
valuesndarray

The vertex values.

get_vertices(indexed=None)#

Get the vertices

Parameters:
indexedstr | None

If Note, return an array (N,3) of the positions of vertices in the mesh. By default, each unique vertex appears only once. If indexed is ‘faces’, then the array will instead contain three vertices per face in the mesh (and a single vertex may appear more than once in the array).

Returns:
verticesndarray

The vertices.

has_edge_indexed_data()#
has_face_color()#

Return True if this data set has face color information

has_face_indexed_data()#

Return True if this object already has vertex positions indexed by face

has_vertex_color()#

Return True if this data set has vertex color information

has_vertex_value()#

Return True if this data set has vertex value information

is_empty()#

Check if any vertices or faces are defined.

property n_faces#

The number of faces in the mesh

property n_vertices#

The number of vertices in the mesh

reset_normals()#
restore(state)#

Restore the state of a mesh previously saved using save()

Parameters:
statedict

The previous state.

save()#

Serialize this mesh to a string appropriate for disk storage

Returns:
statedict

The state.

set_face_colors(colors, indexed=None)#

Set the face color array

Parameters:
colorsarray

Array of colors. Must have shape (Nf, 4) (indexed by face), or shape (Nf, 3, 4) (face colors indexed by faces).

indexedstr | None

Should be ‘faces’ if colors are indexed by faces.

set_faces(faces)#

Set the faces

Parameters:
facesndarray

(Nf, 3) array of faces. Each row in the array contains three indices into the vertex array, specifying the three corners of a triangular face.

set_vertex_colors(colors, indexed=None)#

Set the vertex color array

Parameters:
colorsarray

Array of colors. Must have shape (Nv, 4) (indexing by vertex) or shape (Nf, 3, 4) (vertices indexed by face).

indexedstr | None

Should be ‘faces’ if colors are indexed by faces.

set_vertex_values(values, indexed=None)#

Set the vertex value array

Parameters:
valuesarray

Array of values. Must have shape (Nv,) (indexing by vertex) or shape (Nf, 3) (vertices indexed by face).

indexedstr | None

Should be ‘faces’ if colors are indexed by faces.

set_vertices(verts=None, indexed=None, reset_normals=True)#

Set the mesh vertices

Parameters:
vertsndarray | None

The array (Nv, 3) of vertex coordinates.

indexedstr | None

If indexed==’faces’, then the data must have shape (Nf, 3, 3) and is assumed to be already indexed as a list of faces. This will cause any pre-existing normal vectors to be cleared unless reset_normals=False.

reset_normalsbool

If True, reset the normals.