0
$\begingroup$

I am trying to subdivide a face, using bmesh.ops.bisect_edges, followed by bmesh.ops.connect_verts. I collect a list of vertices, before subdividing further, but after I use bmesh.ops.bisect_edges again, the list contains only dead vertices (although different vertices I think as they have different addresses). I am using Blender v2.79 on Windows 10. See code and generated output.

import bpy
import bmesh

# Get the active mesh
startmode='OBJECT'
obj = bpy.context.object
if obj!=None:
    startmode=obj.mode 
    if startmode=='EDIT':
        bpy.ops.object.mode_set(mode='OBJECT')
    del obj

bpy.ops.mesh.primitive_plane_add()
obj=bpy.context.object
me = obj.data
bm = bmesh.new()   # create an empty BMesh
bm.from_mesh(me) 


for face in bm.faces:
    if face.select and len(face.verts)==4:
        ret1=bmesh.ops.bisect_edges(bm,edges=[edge for edge in face.edges[:]],cuts=1)
        ret2=bmesh.ops.bisect_edges(bm,edges=[edge for edge in face.edges[:2]],cuts=3)
        #Now there should be 14 edges and 14 verts in face
        print("=======Face",face)
        outside_verts=[vert for vert in face.verts] #Construct my list as face will soon be different
        ret3=[]
        for i in [3,5,1,7]:
            ret3.append(bmesh.ops.connect_verts(bm,verts=[outside_verts[11],outside_verts[i]])['edges'][0])
        print(outside_verts) #All 14 verts fine here
        ret4=bmesh.ops.bisect_edges(bm,edges=ret3[:1],cuts=2)#['geom_split']
        print(outside_verts) #14 dead verts here, but they are not even the same verts...?
        print(ret4) #vertices 10 and 6 are still alive here.
        #bmesh.ops.connect_verts(bm,verts=[outside_verts[2],ret4[0]])# This would generate an error

bm.to_mesh(me)
bm.free()
if startmode=='EDIT':
    bpy.ops.object.mode_set(mode='EDIT')

OUTPUT:
=======Face <BMFace(0x0000022F99011030), index=0, totverts=14>
[<BMVert(0x0000022F98E7C190), index=0>, <BMVert(0x0000022F98E7C350), index=8>, <BMVert(0x0000022F98E7C388), index=9>, <BMVert(0x0000022F98E7C3C0), index=10>, <BMVert(0x0000022F98E7C270), index=4>, <BMVert(0x0000022F98E7C3F8), index=11>, <BMVert(0x0000022F98E7C430), index=12>, <BMVert(0x0000022F98E7C468), index=13>, <BMVert(0x0000022F98E7C1C8), index=1>, <BMVert(0x0000022F98E7C2A8), index=5>, <BMVert(0x0000022F98E7C238), index=3>, <BMVert(0x0000022F98E7C2E0), index=6>, <BMVert(0x0000022F98E7C200), index=2>, <BMVert(0x0000022F98E7C318), index=7>]
[<BMVert dead at 0x0000022F98928BE8>, <BMVert dead at 0x0000022F97A92300>, <BMVert dead at 0x0000022F97A92AD0>, <BMVert dead at 0x0000022F97A92828>, <BMVert dead at 0x0000022F98928B48>, <BMVert dead at 0x0000022F97A92800>, <BMVert dead at 0x0000022F97A92A08>, <BMVert dead at 0x0000022F97A92A30>, <BMVert dead at 0x0000022F989283F0>, <BMVert dead at 0x0000022F98928788>, <BMVert dead at 0x0000022F98928878>, <BMVert dead at 0x0000022F98928490>, <BMVert dead at 0x0000022F989287D8>, <BMVert dead at 0x0000022F989288A0>]
{'geom_split': [<BMVert(0x0000022F98E7C4A0), index=14>, <BMVert(0x0000022F98E7C4D8), index=15>, <BMEdge(0x0000022F98F9B2B0), index=14, verts=(0x0000022F98E7C4D8/15, 0x0000022F98E7C2E0/6)>, <BMEdge(0x0000022F98F9B3F0), index=18, verts=(0x0000022F98E7C3C0/10, 0x0000022F98E7C4A0/14)>, <BMEdge(0x0000022F98F9B440), index=19, verts=(0x0000022F98E7C4A0/14, 0x0000022F98E7C4D8/15)>]}
$\endgroup$
  • $\begingroup$ Not fixed by upgrading to Blender v2.79b $\endgroup$ – Tonyfai Apr 20 '18 at 9:44
  • $\begingroup$ Yes, your vertices and faces also change with bisect operator. I believe the intended way is to grab the return value from operators that give you access to the newly created geometry (geom_split: newly created vertices and edges). $\endgroup$ – kheetor Apr 20 '18 at 10:07
  • $\begingroup$ Thanks Kheetor, however the return value doesn't include all the edges of the adjacent faces, only the new edges which replace the edge which was split. $\endgroup$ – Tonyfai Apr 20 '18 at 11:57
  • $\begingroup$ I can't dig deeper into this at the moment, but obviously you should be able to subdivide existing geometry without losing all references in bmesh. $\endgroup$ – kheetor Apr 20 '18 at 12:00
  • $\begingroup$ And further, if I tack on the following code before bm.to_mesh(me): a_new_edge=[e for e in ret4['geom_split'] if isinstance(e,bmesh.types.BMEdge)][0] for face in a_new_edge.link_faces: print (face.verts[:]) many of the resulting verts are in my original outside_verts list, and not dead. $\endgroup$ – Tonyfai Apr 20 '18 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.