From a0a803d5dab858efde0964422e4a1d934fff4493 Mon Sep 17 00:00:00 2001 From: satabol Date: Sun, 5 Nov 2023 19:44:39 +0300 Subject: [PATCH 1/2] fix #5047 node "Revolution Surface" not good result --- index.yaml | 2 +- menus/full_by_data_type.yaml | 2 +- menus/full_nortikin.yaml | 2 +- nodes/surface/revolution_surface.py | 27 +++++--- old_nodes/revolution_surface.py | 97 +++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 old_nodes/revolution_surface.py diff --git a/index.yaml b/index.yaml index f8ca4cf9ff..dc5ef7262b 100644 --- a/index.yaml +++ b/index.yaml @@ -177,7 +177,7 @@ - SvSurfaceElevateDegreeNode - SvSurfaceReduceDegreeNode - --- - - SvExRevolutionSurfaceNode + - SvRevolutionSurfaceNodeMK2 - SvExTaperSweepSurfaceNode - SvBendCurveSurfaceNode - SvExExtrudeCurveVectorNode diff --git a/menus/full_by_data_type.yaml b/menus/full_by_data_type.yaml index 46c02c6102..dffd188384 100644 --- a/menus/full_by_data_type.yaml +++ b/menus/full_by_data_type.yaml @@ -337,7 +337,7 @@ - SvExMinimalSurfaceNode - SvExMinSurfaceFromCurveNode - --- - - SvExRevolutionSurfaceNode + - SvRevolutionSurfaceNodeMK2 - SvExTaperSweepSurfaceNode - SvBendCurveSurfaceNode - SvExExtrudeCurveVectorNode diff --git a/menus/full_nortikin.yaml b/menus/full_nortikin.yaml index b4dfad91e1..0e573b2c5c 100644 --- a/menus/full_nortikin.yaml +++ b/menus/full_nortikin.yaml @@ -313,7 +313,7 @@ - --- - SvSurfaceElevateDegreeNode - SvSurfaceReduceDegreeNode - - SvExRevolutionSurfaceNode + - SvRevolutionSurfaceNodeMK2 - SvExTaperSweepSurfaceNode - SvBendCurveSurfaceNode - SvExExtrudeCurveVectorNode diff --git a/nodes/surface/revolution_surface.py b/nodes/surface/revolution_surface.py index 1b8992f1b6..358d1ffeaf 100644 --- a/nodes/surface/revolution_surface.py +++ b/nodes/surface/revolution_surface.py @@ -11,15 +11,21 @@ from sverchok.utils.surface.algorithms import SvRevolutionSurface -class SvRevolutionSurfaceNode(SverchCustomTreeNode, bpy.types.Node): +class SvRevolutionSurfaceNodeMK2(SverchCustomTreeNode, bpy.types.Node): """ Triggers: Revolution Surface Tooltip: Generate a surface of revolution (similar to Spin / Lathe modifier) """ - bl_idname = 'SvExRevolutionSurfaceNode' + bl_idname = 'SvRevolutionSurfaceNodeMK2' bl_label = 'Revolution Surface' bl_icon = 'MOD_SCREW' + use_nurbs : BoolProperty( + name = "NURBS", + description = "Process NURBS curves and output a NURBS surface", + default = False, + update = updateNode) + v_min : FloatProperty( name = "Angle From", description = "Minimal value of V surface parameter", @@ -58,6 +64,7 @@ def sv_init(self, context): self.origin = 'POINT' def draw_buttons(self, context, layout): + layout.prop(self, 'use_nurbs') layout.prop(self, "origin") def process(self): @@ -81,17 +88,21 @@ def process(self): for curves, points, directions, v_mins, v_maxs in zip_long_repeat(curve_s, point_s, direction_s, v_min_s, v_max_s): for curve, point, direction, v_min, v_max in zip_long_repeat(curves, points, directions, v_mins, v_maxs): origin = self.origin == 'GLOBAL' - surface = SvRevolutionSurface.build(curve, - np.array(point), np.array(direction), - v_min, v_max, - global_origin=origin) + if self.use_nurbs: + surface = SvRevolutionSurface.build(curve, + np.array(point), np.array(direction), + v_min, v_max, + global_origin=origin) + else: + surface = SvRevolutionSurface(curve, np.array(point), np.array(direction), global_origin=origin) + surface.v_bounds = (v_min, v_max) surface_out.append(surface) self.outputs['Surface'].sv_set(surface_out) def register(): - bpy.utils.register_class(SvRevolutionSurfaceNode) + bpy.utils.register_class(SvRevolutionSurfaceNodeMK2) def unregister(): - bpy.utils.unregister_class(SvRevolutionSurfaceNode) + bpy.utils.unregister_class(SvRevolutionSurfaceNodeMK2) diff --git a/old_nodes/revolution_surface.py b/old_nodes/revolution_surface.py new file mode 100644 index 0000000000..1b8992f1b6 --- /dev/null +++ b/old_nodes/revolution_surface.py @@ -0,0 +1,97 @@ + +import numpy as np +from math import pi + +import bpy +from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty + +from sverchok.node_tree import SverchCustomTreeNode +from sverchok.data_structure import updateNode, zip_long_repeat, ensure_nesting_level +from sverchok.utils.curve import SvCurve +from sverchok.utils.surface.algorithms import SvRevolutionSurface + + +class SvRevolutionSurfaceNode(SverchCustomTreeNode, bpy.types.Node): + """ + Triggers: Revolution Surface + Tooltip: Generate a surface of revolution (similar to Spin / Lathe modifier) + """ + bl_idname = 'SvExRevolutionSurfaceNode' + bl_label = 'Revolution Surface' + bl_icon = 'MOD_SCREW' + + v_min : FloatProperty( + name = "Angle From", + description = "Minimal value of V surface parameter", + default = 0.0, + update = updateNode) + + v_max : FloatProperty( + name = "Angle To", + description = "Minimal value of V surface parameter", + default = 2*pi, + update = updateNode) + + origins = [ + ('GLOBAL', "Global origin", "Global origin", 0), + ('POINT', "Revolution axis", "Rotation axis", 1) + ] + + origin : EnumProperty( + name = "Origin", + items = origins, + default = 'GLOBAL', # default for pre-existing nodes + update = updateNode) + + def sv_init(self, context): + self.inputs.new('SvCurveSocket', "Profile") + p = self.inputs.new('SvVerticesSocket', "Point") + p.use_prop = True + p.default_property = (0.0, 0.0, 0.0) + p = self.inputs.new('SvVerticesSocket', "Direction") + p.use_prop = True + p.default_property = (0.0, 0.0, 1.0) + self.inputs.new('SvStringsSocket', 'AngleFrom').prop_name = 'v_min' + self.inputs.new('SvStringsSocket', 'AngleTo').prop_name = 'v_max' + self.outputs.new('SvSurfaceSocket', "Surface") + # default for newly created nodes + self.origin = 'POINT' + + def draw_buttons(self, context, layout): + layout.prop(self, "origin") + + def process(self): + if not any(socket.is_linked for socket in self.outputs): + return + + point_s = self.inputs['Point'].sv_get() + direction_s = self.inputs['Direction'].sv_get() + curve_s = self.inputs['Profile'].sv_get() + v_min_s = self.inputs['AngleFrom'].sv_get() + v_max_s = self.inputs['AngleTo'].sv_get() + + if isinstance(curve_s[0], SvCurve): + curve_s = [curve_s] + point_s = ensure_nesting_level(point_s, 3) + direction_s = ensure_nesting_level(direction_s, 3) + v_min_s = ensure_nesting_level(v_min_s, 2) + v_max_s = ensure_nesting_level(v_max_s, 2) + + surface_out = [] + for curves, points, directions, v_mins, v_maxs in zip_long_repeat(curve_s, point_s, direction_s, v_min_s, v_max_s): + for curve, point, direction, v_min, v_max in zip_long_repeat(curves, points, directions, v_mins, v_maxs): + origin = self.origin == 'GLOBAL' + surface = SvRevolutionSurface.build(curve, + np.array(point), np.array(direction), + v_min, v_max, + global_origin=origin) + surface_out.append(surface) + + self.outputs['Surface'].sv_set(surface_out) + +def register(): + bpy.utils.register_class(SvRevolutionSurfaceNode) + +def unregister(): + bpy.utils.unregister_class(SvRevolutionSurfaceNode) + From d8743e6343abeb14ed29f18cbfbe91de425e2ac2 Mon Sep 17 00:00:00 2001 From: satabol Date: Sun, 5 Nov 2023 19:57:16 +0300 Subject: [PATCH 2/2] fix #5047 node "Revolution Surface" not good result - Append property "NURBS" to use NURBS if needed - fix old_nodes registration --- old_nodes/revolution_surface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/old_nodes/revolution_surface.py b/old_nodes/revolution_surface.py index 1b8992f1b6..aafe13a471 100644 --- a/old_nodes/revolution_surface.py +++ b/old_nodes/revolution_surface.py @@ -11,7 +11,7 @@ from sverchok.utils.surface.algorithms import SvRevolutionSurface -class SvRevolutionSurfaceNode(SverchCustomTreeNode, bpy.types.Node): +class SvExRevolutionSurfaceNode(SverchCustomTreeNode, bpy.types.Node): """ Triggers: Revolution Surface Tooltip: Generate a surface of revolution (similar to Spin / Lathe modifier) @@ -90,8 +90,8 @@ def process(self): self.outputs['Surface'].sv_set(surface_out) def register(): - bpy.utils.register_class(SvRevolutionSurfaceNode) + bpy.utils.register_class(SvExRevolutionSurfaceNode) def unregister(): - bpy.utils.unregister_class(SvRevolutionSurfaceNode) + bpy.utils.unregister_class(SvExRevolutionSurfaceNode)