Iterating with bmesh.verts is sloow

I need to move each selected vert along it’s normal, but I need to collect the selected vert and their normals first because otherwise the normal may be changed by an adjacent vert being moved. This is very slow for large selections. Can anyone suggest a better way to do this (bearing in mind I’m totally winging it and don’t know what I’m doing at all!).

bm = bmesh.from_edit_mesh(mesh)
            
verts = []

for v in bm.verts:
	if v.select:
		verts.append([v, v.normal])
	
for v in verts:
	bmesh.ops.transform(
		bm, 
		matrix = mathutils.Matrix.Translation(VerticesTool.push_vertices_amount * v[1]), 
		space = bpy.context.object.matrix_world, 
		verts = [v[0]]
	)

Yeah, bmesh is super super slow. Hans has said they’re working on a better API but this is what we’ve got for now

if you need raw speed and can get away with it (eg: you don’t need anything specific bmesh is providing) it’s actually much faster to iterate through the data itself in object mode.

your specific example of transforming vertices should be orders of magnitude faster with object data manipulation

1 Like