I see that BMesh has several functions for allowing custom float/int/string layers on verts/edges/faces/loops.
I can add a layer:
my_layer = bm.verts.layers.int.new('my_integer')
How do I use it? When I access the newly created layer, it has only a “name” attribute, and nothing else. I can’t set its values or even see its values.
Perhaps I’m misunderstanding what is meant by “custom data layers”?
Just to give some context, I’d like to pre-compute a weight at each vertex, store it, and then subdivide the mesh based on those weights.
I can’t compute the weights on the fly, because they need to correspond to the undeformed mesh.
I’d rather not store the weights in a separate array, because then how will I know which vertex each weight corresponds to, after having done some mesh modifications?
Turns out the proper way to set/access Bmesh custom data is:
import bpy
import bmesh
ob = bpy.context.object
bm = bmesh.new()
bm.from_mesh(ob.data)
# Make a vertex float layer
key1 = bm.verts.layers.float.new('super_important_vert_data')
# Get an edge integer layer
key2 = bm.edges.layers.int.get('super_important_edge_data')
# Set/retrieve the values at a particular vert/edge/face/loop
what = bm.verts[42][key1]
bm.edges[42][key2] = this
bm.to_mesh(ob.data)
bm.free()
Currently all custom data manipulation must be done on a B-mesh. You can neither access nor modify the data using the regular mesh API, but the data is saved with the regular mesh when you call “to_mesh()”.