From 574d30ed58519d7994d57cc783deb28d9f892ff0 Mon Sep 17 00:00:00 2001 From: ly29 Date: Thu, 19 Jan 2017 08:49:15 +0100 Subject: [PATCH 1/5] first steps --- nodes/modifier_make/polygons_adaptative.py | 6 +++--- utils/sv_bmesh_utils.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/nodes/modifier_make/polygons_adaptative.py b/nodes/modifier_make/polygons_adaptative.py index e8f983dd1..509ab465b 100644 --- a/nodes/modifier_make/polygons_adaptative.py +++ b/nodes/modifier_make/polygons_adaptative.py @@ -83,9 +83,9 @@ class AdaptivePolsNode(bpy.types.Node, SverchCustomTreeNode): versD = Vector_generate(versD_) ##### it is needed for normals of vertices polsR, polsD, versD = match_long_repeat([polsR, polsD, versD]) - bm = bmesh_from_pydata(versR, [], polsR) + bm = bmesh_from_pydata(versR, [], polsR, face_normals=True) - bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) + #bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) bm.verts.ensure_lookup_table() new_ve = bm.verts @@ -99,7 +99,7 @@ class AdaptivePolsNode(bpy.types.Node, SverchCustomTreeNode): vers_out = [] pols_out = [] i = 0 - for vD, pR in zip(versD,polsR): + for vD, pR in zip(versD, polsR): # part of donor to make limits j = i pD = polsD[i] diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index afbc6b2ea..ebee064c2 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -20,8 +20,10 @@ import bmesh from sverchok.data_structure import iterate_process -def bmesh_from_pydata(verts=[], edges=[], faces=[]): - ''' verts is necessary, edges/faces are optional ''' +def bmesh_from_pydata(verts=[], edges=[], faces=[], face_normals=False): + ''' verts is necessary, edges/faces are optional + face_normals=True the normals for each face are calculated + ''' bm = bmesh.new() add_vert = bm.verts.new @@ -34,7 +36,9 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[]): if faces: add_face = bm.faces.new for face in faces: - add_face(tuple(bm.verts[i] for i in face)) + f = add_face(tuple(bm.verts[i] for i in face)) + if face_normals: + f.normal_update() bm.faces.index_update() if edges: @@ -104,4 +108,3 @@ def with_bmesh(method): real_process.__name__ = method.__name__ real_process.__doc__ = method.__doc__ return real_process - -- GitLab From ee81ca27896a6044998312b24c5f7ed079727700 Mon Sep 17 00:00:00 2001 From: ly29 Date: Thu, 19 Jan 2017 09:04:56 +0100 Subject: [PATCH 2/5] some more --- nodes/modifier_make/solidify.py | 4 ++-- utils/sv_bmesh_utils.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nodes/modifier_make/solidify.py b/nodes/modifier_make/solidify.py index 38a702a93..a7284c8bb 100644 --- a/nodes/modifier_make/solidify.py +++ b/nodes/modifier_make/solidify.py @@ -39,9 +39,9 @@ def solidify(vertices, faces, t, mode='accurate'): bm = bmesh_from_pydata(vertices, [], faces) if mode == 'accurate': - for f in bm.faces: - f.normal_update() + bm = bmesh_from_pydata(vertices, [], faces, face_normals=True) else: + bm = bmesh_from_pydata(vertices, [], faces) bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) geom_in = bm.verts[:] + bm.edges[:] + bm.faces[:] diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index ebee064c2..1132afe97 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -39,6 +39,7 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[], face_normals=False): f = add_face(tuple(bm.verts[i] for i in face)) if face_normals: f.normal_update() + bm.faces.index_update() if edges: -- GitLab From 9227802d11a90db8e0f802142ff52c9d0480739b Mon Sep 17 00:00:00 2001 From: ly29 Date: Fri, 20 Jan 2017 08:36:13 +0100 Subject: [PATCH 3/5] also do vertex normals --- nodes/modifier_make/polygons_adaptative.py | 2 +- nodes/modifier_make/solidify.py | 2 +- utils/sv_bmesh_utils.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/nodes/modifier_make/polygons_adaptative.py b/nodes/modifier_make/polygons_adaptative.py index 509ab465b..381b43024 100644 --- a/nodes/modifier_make/polygons_adaptative.py +++ b/nodes/modifier_make/polygons_adaptative.py @@ -83,7 +83,7 @@ class AdaptivePolsNode(bpy.types.Node, SverchCustomTreeNode): versD = Vector_generate(versD_) ##### it is needed for normals of vertices polsR, polsD, versD = match_long_repeat([polsR, polsD, versD]) - bm = bmesh_from_pydata(versR, [], polsR, face_normals=True) + bm = bmesh_from_pydata(versR, [], polsR, normals=True) #bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) bm.verts.ensure_lookup_table() diff --git a/nodes/modifier_make/solidify.py b/nodes/modifier_make/solidify.py index a7284c8bb..761aa3be2 100644 --- a/nodes/modifier_make/solidify.py +++ b/nodes/modifier_make/solidify.py @@ -39,7 +39,7 @@ def solidify(vertices, faces, t, mode='accurate'): bm = bmesh_from_pydata(vertices, [], faces) if mode == 'accurate': - bm = bmesh_from_pydata(vertices, [], faces, face_normals=True) + bm = bmesh_from_pydata(vertices, [], faces, normals=True) else: bm = bmesh_from_pydata(vertices, [], faces) bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index 1132afe97..dd517e989 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -20,9 +20,9 @@ import bmesh from sverchok.data_structure import iterate_process -def bmesh_from_pydata(verts=[], edges=[], faces=[], face_normals=False): +def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=False): ''' verts is necessary, edges/faces are optional - face_normals=True the normals for each face are calculated + if normals=True the normals for each face and vertex are calculated ''' bm = bmesh.new() @@ -36,11 +36,15 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[], face_normals=False): if faces: add_face = bm.faces.new for face in faces: - f = add_face(tuple(bm.verts[i] for i in face)) - if face_normals: - f.normal_update() + if normals: + add_face(tuple(bm.verts[i] for i in face)).normal_update() + else: + add_face(tuple(bm.verts[i] for i in face)) bm.faces.index_update() + if normals: + for v in bm.verts: + v.normal_update() if edges: add_edge = bm.edges.new -- GitLab From f3071d9240e25a397f60206e113e89b298a7e711 Mon Sep 17 00:00:00 2001 From: ly29 Date: Fri, 20 Jan 2017 12:14:33 +0100 Subject: [PATCH 4/5] new bmesh_from_pydata interfcae --- nodes/modifier_make/polygons_adaptative.py | 2 +- nodes/modifier_make/solidify.py | 2 +- utils/sv_bmesh_utils.py | 36 +++++++++++++++++++--- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/nodes/modifier_make/polygons_adaptative.py b/nodes/modifier_make/polygons_adaptative.py index 381b43024..96ee5a08e 100644 --- a/nodes/modifier_make/polygons_adaptative.py +++ b/nodes/modifier_make/polygons_adaptative.py @@ -83,7 +83,7 @@ class AdaptivePolsNode(bpy.types.Node, SverchCustomTreeNode): versD = Vector_generate(versD_) ##### it is needed for normals of vertices polsR, polsD, versD = match_long_repeat([polsR, polsD, versD]) - bm = bmesh_from_pydata(versR, [], polsR, normals=True) + bm = bmesh_from_pydata(versR, [], polsR, normals='vf') #bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) bm.verts.ensure_lookup_table() diff --git a/nodes/modifier_make/solidify.py b/nodes/modifier_make/solidify.py index 761aa3be2..e7a9f8a54 100644 --- a/nodes/modifier_make/solidify.py +++ b/nodes/modifier_make/solidify.py @@ -39,7 +39,7 @@ def solidify(vertices, faces, t, mode='accurate'): bm = bmesh_from_pydata(vertices, [], faces) if mode == 'accurate': - bm = bmesh_from_pydata(vertices, [], faces, normals=True) + bm = bmesh_from_pydata(vertices, [], faces, normals='f') else: bm = bmesh_from_pydata(vertices, [], faces) bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:]) diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index dd517e989..1c8d3f8ef 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -20,11 +20,33 @@ import bmesh from sverchok.data_structure import iterate_process -def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=False): +def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=""): ''' verts is necessary, edges/faces are optional - if normals=True the normals for each face and vertex are calculated + normals is a string of containing {'v', 'e', 'f', 'a'} + so normals="f" will calculate face normals + 'e' and 'v' implies 'f' and 'a' does them all ''' + normals = normals.lower() + + vertex_normals = False + face_normals = False + edge_normals = False + + if 'a' in normals: + vertex_normals = True + face_normals = True + edge_normals = True + else: + if 'f' in normals: + face_normals = True + if 'v' in normals: + vertex_normals = True + face_normals = True + if 'e' in normals: + face_normals = True + edge_normals = True + bm = bmesh.new() add_vert = bm.verts.new [add_vert(co) for co in verts] @@ -36,15 +58,15 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=False): if faces: add_face = bm.faces.new for face in faces: - if normals: + if face_normals: add_face(tuple(bm.verts[i] for i in face)).normal_update() else: add_face(tuple(bm.verts[i] for i in face)) bm.faces.index_update() - if normals: + if vertex_normals: for v in bm.verts: - v.normal_update() + v.normal_update() if edges: add_edge = bm.edges.new @@ -58,6 +80,10 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=False): bm.edges.index_update() + if edge_normals: + for e in bm.edges: + e.normal_update() + return bm -- GitLab From cbf936fd0b961b49b34b20dddde35764bc0cfeef Mon Sep 17 00:00:00 2001 From: ly29 Date: Sun, 22 Jan 2017 09:42:57 +0100 Subject: [PATCH 5/5] trimming --- nodes/modifier_make/solidify.py | 2 -- utils/sv_bmesh_utils.py | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/nodes/modifier_make/solidify.py b/nodes/modifier_make/solidify.py index e7a9f8a54..c346567fc 100644 --- a/nodes/modifier_make/solidify.py +++ b/nodes/modifier_make/solidify.py @@ -36,8 +36,6 @@ def solidify(vertices, faces, t, mode='accurate'): verlen = set(range(len(vertices))) - bm = bmesh_from_pydata(vertices, [], faces) - if mode == 'accurate': bm = bmesh_from_pydata(vertices, [], faces, normals='f') else: diff --git a/utils/sv_bmesh_utils.py b/utils/sv_bmesh_utils.py index 1c8d3f8ef..f425e019b 100644 --- a/utils/sv_bmesh_utils.py +++ b/utils/sv_bmesh_utils.py @@ -20,7 +20,7 @@ import bmesh from sverchok.data_structure import iterate_process -def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=""): +def bmesh_from_pydata(verts=None, edges=None, faces=None, normals=""): ''' verts is necessary, edges/faces are optional normals is a string of containing {'v', 'e', 'f', 'a'} so normals="f" will calculate face normals @@ -51,9 +51,7 @@ def bmesh_from_pydata(verts=[], edges=[], faces=[], normals=""): add_vert = bm.verts.new [add_vert(co) for co in verts] bm.verts.index_update() - - if hasattr(bm.verts, "ensure_lookup_table"): - bm.verts.ensure_lookup_table() + bm.verts.ensure_lookup_table() if faces: add_face = bm.faces.new -- GitLab