I am executing following script on the quad face:
import bmesh
import bpy
bm = bmesh.new()
bm.from_mesh(bpy.context.object.data)
bm.faces.ensure_lookup_table()
face = bm.faces[0]
edge0 = face.edges[0]
edge1 = face.edges[2]
ret = bmesh.ops.subdivide_edges(bm, edges=[edge0], cuts=1)
newVerts = [elem for elem in ret["geom"] if isinstance(elem, bmesh.types.BMVert)]
assert len(newVerts) == 1
vert0 = newVerts[0]
print("vert0 before 2nd subdivision: " + str(vert0))
ret = bmesh.ops.subdivide_edges(bm, edges=[edge1], cuts=1)
print("vert0 after 2nd subdivision: " + str(vert0))
print("face verts after subdivisions:")
for vert in face.verts:
print(vert)
I am getting following output:
vert0 before 2nd subdivision: <BMVert(0x00000085864B1240), index=4>
vert0 after 2nd subdivision: <BMVert dead at 0x000000858621D1E8>
face verts after subdivisions:
<BMVert(0x00000085864B1160), index=0>
<BMVert(0x00000085864B1240), index=4>
<BMVert(0x00000085864B1198), index=1>
<BMVert(0x00000085864B11D0), index=2>
<BMVert(0x00000085864B1278), index=5>
<BMVert(0x00000085864B1208), index=3>
So in vert0 I save the vertex which was created by first subdivision. And it looks like second subdivision (of the edge which is not adjacent to the vert0) magically modifies vert0 variable somehow from 0x00000085864B1240 to 0x000000858621D1E8 which is dead location. And what is more the face vertex list after both subdivisions still contains original location stored in vert0 (0x00000085864B1240). Anyway vert0 value is useless…
I am wondering what is the reason for such unpredictable behavior of BMesh operations, assuming it is not a bug. Anyway - is there any way of saving vertex from the first subdivision so it is not lost after second subdivision?
blend file in attachment.
Attachments
bmesh-issue.blend (454 KB)