From 692d3e484a7e43e1f570dbdda9ff8cc7559dbe51 Mon Sep 17 00:00:00 2001 From: durman Date: Tue, 10 Dec 2019 14:25:12 +0400 Subject: [PATCH 1/2] new node --- index.md | 6 ++- nodes/analyzer/chess_selection.py | 72 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 nodes/analyzer/chess_selection.py diff --git a/index.md b/index.md index 6bc8d0f35..f9626f40c 100644 --- a/index.md +++ b/index.md @@ -70,8 +70,6 @@ SvBvhOverlapNodeNew SvMeshFilterNode SvEdgeAnglesNode - SvMeshSelectNode - SvSelectSimilarNode SvPointInside SvProportionalEditNode SvRaycasterLiteNode @@ -79,6 +77,10 @@ SvDeformationNode SvLinkedVertsNode SvProjectPointToLine + --- + SvMeshSelectNode + SvSelectSimilarNode + SvChessSelection ## Transforms SvRotationNodeMK2 diff --git a/nodes/analyzer/chess_selection.py b/nodes/analyzer/chess_selection.py new file mode 100644 index 000000000..773eb164c --- /dev/null +++ b/nodes/analyzer/chess_selection.py @@ -0,0 +1,72 @@ +# This file is part of project Sverchok. It's copyrighted by the contributors +# recorded in the version control history of the file, available from +# its original location https://github.com/nortikin/sverchok/commit/master +# +# SPDX-License-Identifier: GPL3 +# License-Filename: LICENSE + + +import bpy +from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata + +from sverchok.node_tree import SverchCustomTreeNode + + +def get_selection(verts, faces): + bm = bmesh_from_pydata(verts, faces=faces) + mark_faces(bm) + return [face.select for face in bm.faces] + + +def mark_faces(bm): + # https://en.wikipedia.org/wiki/Depth-first_search + used = set() + for face in bm.faces: + if face in used: + continue + stack = [(face, 'add')] + while stack: + next_face, type_face = stack.pop() + if next_face in used: + continue + used.add(next_face) + if type_face == 'add': + next_face.select = True + for edge in next_face.edges: + for twin_face in edge.link_faces: + if twin_face in used: + continue + stack.append((twin_face, 'sub' if type_face == 'add' else 'add')) + + +class SvChessSelection(bpy.types.Node, SverchCustomTreeNode): + """ + Triggers: ... + Tooltip: ... + + ... + """ + bl_idname = 'SvChessSelection' + bl_label = 'Chess seletion' + bl_icon = 'MESH_GRID' + + def sv_init(self, context): + self.inputs.new('SvVerticesSocket', 'Verts') + self.inputs.new('SvStringsSocket', "Faces") + self.outputs.new('SvStringsSocket', "Face mask") + + def process(self): + if not all([sock.is_linked for sock in self.inputs]): + return + out = [] + for v, f in zip(self.inputs['Verts'].sv_get(), self.inputs['Faces'].sv_get()): + out.append(get_selection(v, f)) + self.outputs['Face mask'].sv_set(out) + + +def register(): + bpy.utils.register_class(SvChessSelection) + + +def unregister(): + bpy.utils.unregister_class(SvChessSelection) -- GitLab From d441762344380a5d2760b097f8ff2029d68ee89a Mon Sep 17 00:00:00 2001 From: durman Date: Tue, 10 Dec 2019 16:28:30 +0400 Subject: [PATCH 2/2] some fixes and documentation --- docs/nodes/analyzer/analyzer_index.rst | 1 + docs/nodes/analyzer/chess_selection.rst | 34 +++++++++++++++++++++++++ nodes/analyzer/chess_selection.py | 20 ++++++++++----- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 docs/nodes/analyzer/chess_selection.rst diff --git a/docs/nodes/analyzer/analyzer_index.rst b/docs/nodes/analyzer/analyzer_index.rst index 0e07ddb6c..f29767430 100644 --- a/docs/nodes/analyzer/analyzer_index.rst +++ b/docs/nodes/analyzer/analyzer_index.rst @@ -35,3 +35,4 @@ Analyzers volume raycaster_lite image_components + chess_selection diff --git a/docs/nodes/analyzer/chess_selection.rst b/docs/nodes/analyzer/chess_selection.rst new file mode 100644 index 000000000..fecfc5ab2 --- /dev/null +++ b/docs/nodes/analyzer/chess_selection.rst @@ -0,0 +1,34 @@ +Chess selection +=============== + +.. image:: https://user-images.githubusercontent.com/28003269/70528861-9f37bb80-1b68-11ea-9f23-6e7a76ec779b.png + +Functionality +------------- +The node creates face selection mask with pattern like chess board. + +.. image:: https://user-images.githubusercontent.com/28003269/70528961-dc9c4900-1b68-11ea-9d3a-b8036f7f2649.png + +Category +-------- + +Analysers -> Chess selection + +Inputs +------ + +- **Vertices** - vertices of base mesh +- **Faces** - faces of base mesh + +Outputs +------- + +- **Face mask** - list of True or False per give faces for usage with other nodes + + +Usage +----- + +Can be used with 3D primitives. + +.. image:: https://user-images.githubusercontent.com/28003269/70521681-11080900-1b59-11ea-9a86-cfe5585a14c2.png diff --git a/nodes/analyzer/chess_selection.py b/nodes/analyzer/chess_selection.py index 773eb164c..9502be88c 100644 --- a/nodes/analyzer/chess_selection.py +++ b/nodes/analyzer/chess_selection.py @@ -13,9 +13,17 @@ from sverchok.node_tree import SverchCustomTreeNode def get_selection(verts, faces): + """ + Returns face mask like chess board. + :param verts: list of vertices + :param faces: list of faces + :return: list of bool per given face + """ bm = bmesh_from_pydata(verts, faces=faces) mark_faces(bm) - return [face.select for face in bm.faces] + out_mask = [face.select for face in bm.faces] + bm.free() + return out_mask def mark_faces(bm): @@ -41,14 +49,14 @@ def mark_faces(bm): class SvChessSelection(bpy.types.Node, SverchCustomTreeNode): """ - Triggers: ... - Tooltip: ... + Triggers: returns selection like chess board + Tooltip: can be used with 3d objects like torus and other primitives - ... + Topology of input mesh should be in an appropriate view for getting expecting result """ bl_idname = 'SvChessSelection' - bl_label = 'Chess seletion' - bl_icon = 'MESH_GRID' + bl_label = 'Chess selection' + bl_icon = 'TEXTURE' def sv_init(self, context): self.inputs.new('SvVerticesSocket', 'Verts') -- GitLab