I have a function that returns several faces from a mesh using ray_cast under the mouse pointer. Some surrounding faces are collected based on the angle from the hit face and passed to another function, most of this is done in
In this function I want to copy the passed faces to a new bmesh to create a new object from them.
The best way I've found is to pass in the original bmesh with the faces I want to copy, iterate over it and append the new faces to a list:
def make_copy(self, context, bm_orig, faces_linked):
# this gets called with bm_orig as the original bmesh in its entirety of type BMesh,
# and faces_linked as the faces of that bmesh that I want to copy to a new bmesh as a list of type BMFace
bm_copy = bm_orig.copy()
faces_linked_copy = 
for face_orig in faces_linked:
for face_copy in bm_copy.faces:
if face_orig.index == face_copy.index:
# then this makes a list of all the faces, checks them against the
# list of faces I wan to keep (faces_linked_copy) and removes the rest from the list
delete_list = 
for face in bm_copy.faces:
for face_delete in bm_copy.faces:
for face_save in faces_linked_copy:
if face_delete == face_save:
# finally using delete_list to remove all the faces I don't want
bmesh.ops.delete(bm_copy, geom=delete_list, context="FACES")
From this I can delete all other faces in
bm_copy and be left with the faces I need.
This works but it's extremely slow when operating on dense meshes.
This needs to happen every mouse move in a modal so with denser meshes this becomes unusable.
I've tried using
bmesh.ops.duplicate with the
dest=bm_new option but this always gives
keyword "dest" type 4 not working yet! which it has done forever... (Am I doing something wrong with that?? or will they simply never implement it??)
Is there a better way to copy some faces from one bmesh to another without having to copy and iterate over the original??
Collects the faces, then makes the blue faces from it.
But now seeing it work I probably wont use it this way 😝
But I have learned some things, so thanks again for your help