Fixed issue with tool.Blender.apply_bmesh

This commit is contained in:
Andrej730
2023-04-03 12:06:56 +05:00
parent 4ad9ecb7db
commit 2bc60b87f2
3 changed files with 13 additions and 5 deletions
@@ -102,7 +102,7 @@ class Annotator:
new_verts = [bm.verts.new(v) for v in verts_local] new_verts = [bm.verts.new(v) for v in verts_local]
bm.faces.new([new_verts[i] for i in face_verts]) bm.faces.new([new_verts[i] for i in face_verts])
tool.Blender.apply_bmesh(obj.data, bm) tool.Blender.apply_bmesh(obj.data, bm, obj)
return obj return obj
@staticmethod @staticmethod
+1 -1
View File
@@ -83,7 +83,7 @@ class Blender:
def update_viewport(cls): pass def update_viewport(cls): pass
def get_default_selection_keypmap(cls): pass def get_default_selection_keypmap(cls): pass
def get_object_bounding_box(cls, obj): pass def get_object_bounding_box(cls, obj): pass
def apply_bmesh(cls, mesh, bm): pass def apply_bmesh(cls, mesh, bm, obj=None): pass
def get_bmesh_for_mesh(cls, mesh, clean=False): pass def get_bmesh_for_mesh(cls, mesh, clean=False): pass
def bmesh_join(cls, bm_a, bm_b, callback=None): pass def bmesh_join(cls, bm_a, bm_b, callback=None): pass
+11 -3
View File
@@ -180,10 +180,12 @@ class Blender:
## BMESH UTILS ## ## BMESH UTILS ##
@classmethod @classmethod
def apply_bmesh(cls, mesh, bm): def apply_bmesh(cls, mesh, bm, obj=None):
"""`obj` argument is not optional if you plan to update mesh in EDIT mode
and it's possible that that mesh object won't be currenly active."""
import bmesh import bmesh
if bpy.context.object and bpy.context.object.mode == "EDIT": if mesh.is_editmode:
# better to be safe because otherwise mesh won't be updated # better to be safe because otherwise mesh won't be updated
# and you won't get any errors # and you won't get any errors
if not bm.is_wrapped or hash(bmesh.from_edit_mesh(mesh)) != hash(bm): if not bm.is_wrapped or hash(bmesh.from_edit_mesh(mesh)) != hash(bm):
@@ -192,7 +194,13 @@ class Blender:
"For applying bmesh in edit mode bmesh should be acquired with `bmesh.from_edit_mesh(me)`." "For applying bmesh in edit mode bmesh should be acquired with `bmesh.from_edit_mesh(me)`."
) )
bmesh.update_edit_mesh(mesh) bmesh.update_edit_mesh(mesh)
bpy.context.object.update_from_editmode() if not obj:
if not bpy.context.object and bpy.context.object.data != mesh:
raise Exception(
"Error applying bmesh in EDIT object - object is "
"not provided and can't be acquired from the context. "
)
obj.update_from_editmode()
else: else:
bm.to_mesh(mesh) bm.to_mesh(mesh)
# only freeing bmesh if object is in OBJECT mode # only freeing bmesh if object is in OBJECT mode