I want to add vertices to a face. Can I only do this by redrawing the whole face with bmesh.faces.new(loop_vertices) or can I also just add some to an existing face? The documentation states that the BMVert sequence of a face is read-only.
- 249
- 1
- 8
1 Answers
Subdivide an edge or edges.
Just as with using the UI to add another vertex to a face would require subdividing an edge.
The loop vertices that define a face, will also be a part of another faces loop verts, if connected via an edge. Bmesh gives us a quick API into all the loops and linked geometry of each element. In most cases these are read only.
To add a single vert to an existing faces verts, requires subdividing one edge. Using the bmesh subdivide edges operator will ensure that the links and loops are correctly maintained.
Simple example, using active face and subdividing the zeroth edge.
f = bmesh.faces.active # the active face
bmesh.ops.subdivide_edges(
bm, # the bmesh
edges=[f.edges[0]] if f else [], # zeroth edge if face
)
This will ofcourse add an edge also. If another face shares the edge it will also share the newly created geometry.
How to subdivide mesh with Python and Blender 2.8?
How to use "bmesh.ops.subdivide_edges" on selected edges
import bpy
import bmesh
ob = bpy.context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)
f = bm.faces.active
e = f.edges[0]
bmesh.ops.subdivide_edges(
bm,
edges=[e],
cuts=1,
edge_percents={e : 0.33},
)
bmesh.update_edit_mesh(me)
- 84,216
- 10
- 108
- 233
edge.verts[0]. First in edges BMVertSeq. Easy enough to test... – batFINGER Jul 29 '20 at 17:08