I am trying to figure out why this does not update the mesh's data.
The goal of this is to ensure that boundary edges of meshes imported from SVG are never longer than a certain amount. This is followed by code that triangulates the mesh.
if obj.mode != 'EDIT': bpy.ops.object.mode_set(mode='EDIT')
bm_s = bmesh.from_edit_mesh(obj.data)
bm_s.edges.ensure_lookup_table()
print("Vertices before subdiv: {}".format(len(obj.data.vertices)))
print("Vertices in bmesh before subdiv: {}".format(len(bm_s.verts)))
edges_outside = [ e for e in bm_s.edges if len(e.link_faces) <= 1]
for e in [ e for e in edges_outside if e.calc_length() >= 2 * avg_length_inside ]:
d = int(e.calc_length() / avg_length_inside)
bmesh.ops.subdivide_edges(bm_s, edges=[e], cuts=d, use_grid_fill=True)
print("Vertices in bmesh after subdiv: {}".format(len(bm_s.verts)))
bmesh.update_edit_mesh(obj.data)
print("Vertices after subdiv: {}".format(len(obj.data.vertices)))
poly = triangulate.obj_to_poly(bm_s)
bm_s.free()
This prints - for example:
Vertices before subdiv: 100
Vertices in bmesh before subdiv: 100
Vertices in bmesh after subdiv: 148
Vertices after subdiv: 100
The funny thing is: if I run this code and it is not followed by anything, it updates the mesh exactly like I want, but of code follows right after, the object's data will not be updated.
Why is that?