add_vertex_data#
- Mesh.add_vertex_data(name, attr, data, default=None)#
Add vertex data.
Add a data block as mesh attribute and make it accessible on a per vertex level. The data object has to allow access to data items using index notation.
- Parameters:
- name, attrstr
Name of the data block and name of vertex attribute. The data block as a whole can be accessed as
mesh.nameand the valuedata[v]asv.attr.- datalist or dict or ndarray
Data object.
- defaultobject, optional
Immutable default vertex attribute value.
Examples
Add a vector field (one vector per vertex) to a mesh. Allocate and fill data block:
>>> vecs = np.zeros_like(mesh.points)
Add the data block to the mesh. The vecs array can now be accessed as
mesh.vecs(we could have used any other name).>>> mesh.add_vertex_data('vecs', 'vec', vecs) >>> mesh.vecs is vecs True
Rows of the data block can now be accessed by dot notation:
>>> for v in mesh.vertices: >>> print(v.vec)
Special care has to be taken when adding data to an empty mesh. Assume that we want to add data items of a given shape to vertices. An empty data block of type
ndarrayof the correct shape can be added via>>> mesh.add_vertex_data('some_data', 'data', np.zeros((0, *shape)))