add_vertex_data
- Mesh.add_vertex_data(name, attr, data, default=None)[source]
Add vertex data.
The data object has to allow access to vertex data using index notation. The data block as a whole can be accessed via
self.name
and the valuedata[v]
asv.attr
.- Parameters:
- Raises:
ValueError – If a data block of the same name already exists.
To add a vector field (one vector per vertex) to a mesh we can do the following:
1 # Allocate data block of appropriate size and type. 2 vecs = np.array_like(mesh.points) 3 4 # Compute values for each vertex of the mesh. 5 for v in mesh.vertices: 6 vecs[v] = ... 7 8 # Add the data block to the mesh. The vecs array can now be 9 # accessed as mesh.vecs (we could have used any other name). 10 mesh.add_vertex_data('vecs', 'vec', vecs) 11 print(mesh.vecs is vecs) 12 13 # Rows of the data block can now be accessed locally just 14 # like the rows of the vertex coordinate array. 15 for v in mesh.vertices: 16 print(v.vec == vecs[v])
Note
A mutable default value has the same drawbacks as mutable default function arguments.