Skip to content

Commit

Permalink
Merge pull request #5048 from nortikin/fix_5047_node_Revolution_Surfa…
Browse files Browse the repository at this point in the history
…ce_not_good_result

fix #5047
  • Loading branch information
satabol authored Nov 5, 2023
2 parents 6b35679 + d8743e6 commit 3f3e65a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 11 deletions.
2 changes: 1 addition & 1 deletion index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
- SvSurfaceElevateDegreeNode
- SvSurfaceReduceDegreeNode
- ---
- SvExRevolutionSurfaceNode
- SvRevolutionSurfaceNodeMK2
- SvExTaperSweepSurfaceNode
- SvBendCurveSurfaceNode
- SvExExtrudeCurveVectorNode
Expand Down
2 changes: 1 addition & 1 deletion menus/full_by_data_type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
- SvExMinimalSurfaceNode
- SvExMinSurfaceFromCurveNode
- ---
- SvExRevolutionSurfaceNode
- SvRevolutionSurfaceNodeMK2
- SvExTaperSweepSurfaceNode
- SvBendCurveSurfaceNode
- SvExExtrudeCurveVectorNode
Expand Down
2 changes: 1 addition & 1 deletion menus/full_nortikin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
- ---
- SvSurfaceElevateDegreeNode
- SvSurfaceReduceDegreeNode
- SvExRevolutionSurfaceNode
- SvRevolutionSurfaceNodeMK2
- SvExTaperSweepSurfaceNode
- SvBendCurveSurfaceNode
- SvExExtrudeCurveVectorNode
Expand Down
27 changes: 19 additions & 8 deletions nodes/surface/revolution_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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)

97 changes: 97 additions & 0 deletions old_nodes/revolution_surface.py
Original file line number Diff line number Diff line change
@@ -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 SvExRevolutionSurfaceNode(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(SvExRevolutionSurfaceNode)

def unregister():
bpy.utils.unregister_class(SvExRevolutionSurfaceNode)

0 comments on commit 3f3e65a

Please sign in to comment.