From 3d396faf917a59785d5fbe5b9b0285ac43c50e04 Mon Sep 17 00:00:00 2001 From: Victor Doval <10011941+vicdoval@users.noreply.github.com> Date: Tue, 16 Jun 2020 15:39:23 +0200 Subject: [PATCH 1/3] right click connect to viewer draw understands curves and surfaces --- ui/nodeview_rclick_menu.py | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ui/nodeview_rclick_menu.py b/ui/nodeview_rclick_menu.py index 1aefb1fd3..98205b979 100644 --- a/ui/nodeview_rclick_menu.py +++ b/ui/nodeview_rclick_menu.py @@ -10,6 +10,7 @@ import bpy from sverchok.utils.sv_node_utils import frame_adjust from sverchok.menu import draw_add_node_operator from sverchok.ui.presets import node_supports_presets +from sverchok.core.sockets import SvCurveSocket, SvSurfaceSocket, SvStringsSocket sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} supported_mesh_viewers = {'SvBmeshViewerNodeMK2', 'ViewerNode2'} @@ -42,7 +43,7 @@ def has_outputs(node): def get_verts_edge_poly_output_sockets(node): """ because of inconsistent socket naming, we will use pattern matching (ignoring capitalization) - - verts: verts, vers, vertices, vectors, vecs (ve) + - verts: verts, vers, vertices, vectors, vecs (ver, vec) - edges: edges, edgs, edgpol (edg) - faces: faces, poly, pols, edgpol, (pol, fac) @@ -58,12 +59,14 @@ def get_verts_edge_poly_output_sockets(node): got_verts = False got_edges = False got_faces = False - + got_curves = False + got_surface = False # we can surely use regex for this, but for now this will work. for socket in node.outputs: + socket_name = socket.name.lower() - if not got_verts and 've' in socket_name: + if not got_verts and ('ver' in socket_name or 'vec' in socket_name): output_map['verts'] = socket.name got_verts = True @@ -71,10 +74,18 @@ def get_verts_edge_poly_output_sockets(node): output_map['edges'] = socket.name got_edges = True - elif not got_faces and ('face' in socket_name or 'pol' in socket_name): + elif not got_faces and ('face' in socket_name or 'pol' in socket_name) and isinstance(socket, SvStringsSocket): output_map['faces'] = socket.name got_faces = True + elif not got_curves and isinstance(socket, SvCurveSocket): + output_map['curve'] = socket.name + got_curves = True + + elif not got_surface and isinstance(socket, SvSurfaceSocket): + output_map['surface'] = socket.name + got_surface = True + return output_map def offset_node_location(existing_node, new_node, offset): @@ -126,7 +137,26 @@ def add_connection(tree, bl_idname_new_node, offset): links.new(outputs[output_map['faces']], inputs[2]) if 'edges' in output_map: links.new(outputs[output_map['edges']], inputs[1]) - + elif 'curve' in output_map: + + eval_node = nodes.new('SvExEvalCurveNode') + offset_node_location(existing_node, eval_node, offset) + frame_adjust(existing_node, eval_node) + offset_node_location(eval_node, new_node, offset) + frame_adjust(eval_node, new_node) + links.new(outputs[output_map['curve']], eval_node.inputs[0]) + links.new(eval_node.outputs[0], inputs[0]) + links.new(eval_node.outputs[1], inputs[1]) + + elif 'surface' in output_map: + eval_node = nodes.new('SvExEvalSurfaceNode') + offset_node_location(existing_node, eval_node, offset) + frame_adjust(existing_node, eval_node) + offset_node_location(eval_node, new_node, offset) + frame_adjust(eval_node, new_node) + links.new(outputs[output_map['surface']], eval_node.inputs[0]) + links.new(eval_node.outputs[0], inputs[0]) + links.new(eval_node.outputs[1], inputs[1]) tree.sv_process = previous_state tree.update() # existing_node.process_node(None) -- GitLab From 48a29b0ab11315e2246997ab0621b8debeccbef0 Mon Sep 17 00:00:00 2001 From: Victor Doval <10011941+vicdoval@users.noreply.github.com> Date: Tue, 16 Jun 2020 15:43:23 +0200 Subject: [PATCH 2/3] expanding docstring --- ui/nodeview_rclick_menu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/nodeview_rclick_menu.py b/ui/nodeview_rclick_menu.py index 98205b979..caf3da684 100644 --- a/ui/nodeview_rclick_menu.py +++ b/ui/nodeview_rclick_menu.py @@ -46,6 +46,7 @@ def get_verts_edge_poly_output_sockets(node): - verts: verts, vers, vertices, vectors, vecs (ver, vec) - edges: edges, edgs, edgpol (edg) - faces: faces, poly, pols, edgpol, (pol, fac) + For curves and surfaces checks if they belong to the corresponding class > generally the first 3 outputs of a node will contain these > generally if a node outputs polygons, it won't be necessary to connect edges -- GitLab From 8eb9c0f5a3f346141a141f78f8828bfbf4147435 Mon Sep 17 00:00:00 2001 From: Victor Doval <10011941+vicdoval@users.noreply.github.com> Date: Wed, 17 Jun 2020 11:13:59 +0200 Subject: [PATCH 3/3] function renaming --- ui/nodeview_rclick_menu.py | 4 ++-- ui/sv_temporal_viewers.py | 4 ++-- ui/sv_vep_connector.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/nodeview_rclick_menu.py b/ui/nodeview_rclick_menu.py index caf3da684..688131e8d 100644 --- a/ui/nodeview_rclick_menu.py +++ b/ui/nodeview_rclick_menu.py @@ -40,7 +40,7 @@ def valid_active_node(nodes): def has_outputs(node): return node and len(node.outputs) -def get_verts_edge_poly_output_sockets(node): +def get_output_sockets_map(node): """ because of inconsistent socket naming, we will use pattern matching (ignoring capitalization) - verts: verts, vers, vertices, vectors, vecs (ver, vec) @@ -97,7 +97,7 @@ def add_connection(tree, bl_idname_new_node, offset): nodes = tree.nodes links = tree.links - output_map = get_verts_edge_poly_output_sockets(nodes.active) + output_map = get_output_sockets_map(nodes.active) existing_node = nodes.active diff --git a/ui/sv_temporal_viewers.py b/ui/sv_temporal_viewers.py index 7cb72d893..dfca233ab 100644 --- a/ui/sv_temporal_viewers.py +++ b/ui/sv_temporal_viewers.py @@ -19,7 +19,7 @@ import bpy from bpy.types import Operator -from sverchok.ui.nodeview_rclick_menu import get_verts_edge_poly_output_sockets +from sverchok.ui.nodeview_rclick_menu import get_output_sockets_map from sverchok.utils.sv_node_utils import frame_adjust sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} @@ -33,7 +33,7 @@ def add_temporal_viewer_draw(tree, nodes, links, existing_node, cut_links): previous_state = tree.sv_process tree.sv_process = False bl_idname_new_node = 'SvVDExperimental' - output_map = get_verts_edge_poly_output_sockets(existing_node) + output_map = get_output_sockets_map(existing_node) try: new_node = nodes['Temporal Viewer'] if cut_links or ('verts' in output_map and 'faces' in output_map): diff --git a/ui/sv_vep_connector.py b/ui/sv_vep_connector.py index 7aa9e65c4..d338aa763 100644 --- a/ui/sv_vep_connector.py +++ b/ui/sv_vep_connector.py @@ -18,7 +18,7 @@ # ##### END GPL LICENSE BLOCK ##### import bpy -from sverchok.ui.nodeview_rclick_menu import get_verts_edge_poly_output_sockets +from sverchok.ui.nodeview_rclick_menu import get_output_sockets_map from sverchok.utils.sv_node_utils import frame_adjust sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'} -- GitLab