From e8c977ae60b6d09b64238de936d22e203bbe44ac Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 26 Jun 2022 14:52:35 +0200 Subject: [PATCH 1/5] apparently duration decorator is not perfect --- utils/context_managers.py | 18 ++++++++++++++++++ utils/sv_bmesh_utils.py | 19 +++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/utils/context_managers.py b/utils/context_managers.py index b164dd3f85..fcdf6e35eb 100644 --- a/utils/context_managers.py +++ b/utils/context_managers.py @@ -1,7 +1,10 @@ +import time from contextlib import contextmanager import bpy import sverchok +from sverchok.utils.logging import info +from sverchok.utils.ascii_print import str_color @contextmanager @@ -34,3 +37,18 @@ def addon_preferences(addon_name): addon = bpy.context.preferences.addons.get(addon_name) if addon and hasattr(addon, "preferences"): yield addon.preferences + +@contextmanager +def timed(func): + start_time = time.time() + + #result = func(*args, **kwargs) + yield func + + duration = (time.time() - start_time) * 1000 + + func_name = str_color(func.__name__, 31) + duration = str_color(f"{duration:.5g} ms", 32) + + msg = f"\n{func_name}: {duration}" # + display_args + display_kwargs + info(msg) \ No newline at end of file diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index fa30f667ec..1450d05867 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -63,12 +63,18 @@ def bmesh_from_edit_mesh(mesh) -> ContextManager[bmesh.types.BMesh]: finally: bmesh.update_edit_mesh(mesh) +def bmesh_from_pydata( + verts=None, edges=[], faces=[], + markup_face_data=False, markup_edge_data=False, markup_vert_data=False, + normal_update=False, index_edges=False): -def bmesh_from_pydata(verts=None, edges=[], faces=[], markup_face_data=False, markup_edge_data=False, - markup_vert_data=False, normal_update=False): - ''' verts is necessary, edges/faces are optional - normal_update, will update verts/edges/faces normals at the end - ''' + """ + verts : necessary + edges / faces : optional + normal_update : optional - will update verts/edges/faces normals at the end + index_edges (bool) : optional - will make it possible for users of the bmesh to manually + iterate over any edges or do index lookups + """ bm = bmesh.new() bm_verts = bm.verts @@ -105,7 +111,8 @@ def bmesh_from_pydata(verts=None, edges=[], faces=[], markup_face_data=False, ma if markup_edge_data: bm_edge[initial_index_layer] = idx - bm.edges.index_update() + if has_element(edges) or index_edges: + bm.edges.index_update() if markup_vert_data: bm_verts.ensure_lookup_table() From 3e75feeceb4887f224dcfcad1da134b2728f5572 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 26 Jun 2022 15:11:28 +0200 Subject: [PATCH 2/5] remove decorator --- utils/context_managers.py | 17 ----------------- utils/decorators.py | 6 +++++- utils/sv_bmesh_utils.py | 1 + 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/utils/context_managers.py b/utils/context_managers.py index fcdf6e35eb..b22195b70e 100644 --- a/utils/context_managers.py +++ b/utils/context_managers.py @@ -1,9 +1,7 @@ -import time from contextlib import contextmanager import bpy import sverchok -from sverchok.utils.logging import info from sverchok.utils.ascii_print import str_color @@ -37,18 +35,3 @@ def addon_preferences(addon_name): addon = bpy.context.preferences.addons.get(addon_name) if addon and hasattr(addon, "preferences"): yield addon.preferences - -@contextmanager -def timed(func): - start_time = time.time() - - #result = func(*args, **kwargs) - yield func - - duration = (time.time() - start_time) * 1000 - - func_name = str_color(func.__name__, 31) - duration = str_color(f"{duration:.5g} ms", 32) - - msg = f"\n{func_name}: {duration}" # + display_args + display_kwargs - info(msg) \ No newline at end of file diff --git a/utils/decorators.py b/utils/decorators.py index 603caa3bfc..24fc09c38c 100644 --- a/utils/decorators.py +++ b/utils/decorators.py @@ -118,6 +118,10 @@ def wrapped(*args, **kwargs): duration = str_color(f"{duration:.5g} ms", 32) msg = f"\n{func_name}: {duration}" # + display_args + display_kwargs - info(msg) + try: + info(msg) + except: + print(msg) + return result return wrapped diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index 1450d05867..9d528d98a2 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -30,6 +30,7 @@ from sverchok.data_structure import zip_long_repeat, has_element from sverchok.utils.logging import debug +from sverchok.utils.decorators import duration @contextmanager def empty_bmesh(use_operators=True): From 2ab3f1b49164e59131d9bcec7743607bf915229e Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 26 Jun 2022 15:15:30 +0200 Subject: [PATCH 3/5] added dep --- utils/context_managers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/context_managers.py b/utils/context_managers.py index b22195b70e..b164dd3f85 100644 --- a/utils/context_managers.py +++ b/utils/context_managers.py @@ -2,7 +2,6 @@ import bpy import sverchok -from sverchok.utils.ascii_print import str_color @contextmanager From e2451dab5828230ea3c7e07b1295322987e219bb Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 26 Jun 2022 15:16:26 +0200 Subject: [PATCH 4/5] rm duration decorator --- utils/sv_bmesh_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index 9d528d98a2..1450d05867 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -30,7 +30,6 @@ from sverchok.data_structure import zip_long_repeat, has_element from sverchok.utils.logging import debug -from sverchok.utils.decorators import duration @contextmanager def empty_bmesh(use_operators=True): From f93e934baf18017f5e874159e9dfc170ad343846 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 26 Jun 2022 15:21:17 +0200 Subject: [PATCH 5/5] fix clipverts --- nodes/modifier_make/clip_verts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodes/modifier_make/clip_verts.py b/nodes/modifier_make/clip_verts.py index 7d99e11bc2..5575a329ba 100644 --- a/nodes/modifier_make/clip_verts.py +++ b/nodes/modifier_make/clip_verts.py @@ -55,7 +55,7 @@ def process(self): edges_out = [] faces_out = [] for verts, edges, faces in zip_long_repeat(verts_s, edges_s, faces_s): - bm = bmesh_from_pydata(verts, edges, faces, normal_update=True) + bm = bmesh_from_pydata(verts, edges, faces, normal_update=True, index_edges=True) new_bm = truncate_vertices(bm) bm.free() new_verts, new_edges, new_faces = pydata_from_bmesh(new_bm)