0
$\begingroup$

I have a list of a centre vertice along with all its surrounding vertices.

listOfVectors = [ vertice, neighbour1, neighbour2, neighbour3, ... ]

I need to remove all edges and faces regarding those vertices to create further geometry and move the centre vertice around.

I'm actually creating a valley by dragging down a vertice inside a circle (with some cubic bézier parameters).

Currently, I'm iterating every face and edge on the mesh to see if every vector is contained in listOfVectors and removing them from the BMesh object. The problem is that my mesh has over 310,000 faces.

I've tried using bmesh.ops.delete(bm, geom = verticeList, context = DEL_EDGESFACES) (see below for list of constants), but that accomplishes exactly nothing. No errors, no changes.

Is there a way to make bmesh do the hard work for me? Or some approach to get the faces that's better than iterating on each one?

References

Constants used:

DEL_VERTS = 1 DEL_EDGES = 2 DEL_ONLYFACES = 3 DEL_EDGESFACES = 4 DEL_FACES = 5 DEL_ALL = 6 DEL_ONLYTAGGED = 7

Source for the constants: https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h

bmesh.ops.delete reference: https://docs.blender.org/api/blender_python_api_2_71_release/bmesh.ops.html#bmesh.ops.delete

$\endgroup$
2
$\begingroup$

I think that parameter geom is wrong.
geom (list of (bmesh.types.BMVert, bmesh.types.BMEdge, bmesh.types.BMFace))

import bpy
import bmesh

if bpy.context.mode != 'OBJECT':
    bpy.ops.object.mode_set()

bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16)
bpy.ops.object.mode_set(mode='EDIT')

bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_random(percent=50.0, seed=0, action='SELECT')

obj = bpy.context.active_object
me = obj.data
bm = bmesh.from_edit_mesh(me)

list = [v for v in bm.verts if v.select]
list += [e for e in bm.edges if e.select]
list += [f for f in bm.faces if f.select]

bmesh.ops.delete(bm, geom=list, context=4)

bmesh.update_edit_mesh(me)
$\endgroup$
1
$\begingroup$

I would say your issue is you are passing a list of verts to delete, and trying to delete edges and faces. One way to get the faces and edges from a vert selection in bmesh is to set the select mode to include edges and faces, bm.select_mode = {'VERT', 'EDGE', 'FACE'}. Then if we select our verts, a call to bm.select_flush_mode() will ensure the associated edges and faces will be selected also.

Simple test script that "defaces" a whole mesh, using the list of selected edges flushed from the selected vertices. Removing one or both of lines mentioned above often results in the script doing nothing as no edge is selected even though both its verts are selected. This is an object mode bmesh test script. In object mode cannot use bpy.ops.mesh.select... operators.

import bpy
import bmesh
context = bpy.context
DEL_EDGESFACES = 4

bm = bmesh.new()
bm.from_mesh(context.object.data)
verts = bm.verts[:]
bm.select_mode = {'VERT', 'EDGE', 'FACE'}
for v in verts:
    v.select = True
bm.select_flush_mode()
edges = [e for e in bm.edges if e.select]
bmesh.ops.delete(bm, geom=edges, context=DEL_EDGESFACES)
bm.to_mesh(context.object.data)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.