Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5045. Append "Angle Units" to properties of node "Revolution Surface" and fix documents. #5046

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions docs/nodes/surface/revolution_surface.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Revolution Surface
==================

.. image:: https://github.com/nortikin/sverchok/assets/14288520/49bc8bfc-cfbc-4ee9-8edc-1bc6511a1ed0
:target: https://github.com/nortikin/sverchok/assets/14288520/49bc8bfc-cfbc-4ee9-8edc-1bc6511a1ed0
.. image:: https://github.com/nortikin/sverchok/assets/14288520/3a410340-d935-4569-8ca5-c6ab77cf4fa9
:target: https://github.com/nortikin/sverchok/assets/14288520/3a410340-d935-4569-8ca5-c6ab77cf4fa9

Functionality
-------------
Expand Down Expand Up @@ -63,8 +63,20 @@ This node has the following parameter:

The default value is **Revolution axis**.

.. image:: https://github.com/nortikin/sverchok/assets/14288520/b582fd3f-65ed-4d39-b2a6-87d9d2ba4de6
:target: https://github.com/nortikin/sverchok/assets/14288520/b582fd3f-65ed-4d39-b2a6-87d9d2ba4de6
.. image:: https://github.com/nortikin/sverchok/assets/14288520/b582fd3f-65ed-4d39-b2a6-87d9d2ba4de6
:target: https://github.com/nortikin/sverchok/assets/14288520/b582fd3f-65ed-4d39-b2a6-87d9d2ba4de6

* **Angle Units**. The units in which values of **T Min**, **T Max** inputs are
measured. The available options are:

* **Rad**. Radians (2*pi is full circle).
* **Deg**. Degrees (360 is full circle).
* **Uni**. Unit circles (1.0 is full circle).

The default value is **Rad**.

.. image:: https://github.com/nortikin/sverchok/assets/14288520/008a1043-33c4-4635-8757-a6efb4a4134f
:target: https://github.com/nortikin/sverchok/assets/14288520/008a1043-33c4-4635-8757-a6efb4a4134f

Outputs
-------
Expand Down
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: 21 additions & 6 deletions nodes/surface/revolution_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,43 @@
from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.utils.sv_transform_helper import AngleUnits, SvAngleHelper
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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SvAngleHelper should be first in the row. Python takes rightmost class first than it takes next left class and overrides methods and so on.

class SvRevolutionSurfaceNodeMK2(SverchCustomTreeNode, bpy.types.Node, SvAngleHelper):
"""
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'

v_min : FloatProperty(
name = "Angle From",
description = "Minimal value of V surface parameter",
default = 0.0,
update = updateNode)
update = SvAngleHelper.update_angle)

v_max : FloatProperty(
name = "Angle To",
description = "Minimal value of V surface parameter",
default = 2*pi,
update = updateNode)
update = SvAngleHelper.update_angle)

# Override properties from SvAngleHelper to set radians as default
angle_units: EnumProperty(
name="Angle Units", description="Angle units (Radians/Degrees/Unities)",
default=AngleUnits.RADIANS, items=AngleUnits.get_blender_enum(),
update=SvAngleHelper.update_angle_units)

def update_angles(self, context, au):
''' Update all the angles to preserve their values in the new units '''
self.v_min = self.v_min * au
self.v_max = self.v_max * au

origins = [
('GLOBAL', "Global origin", "Global origin", 0),
Expand Down Expand Up @@ -59,6 +71,7 @@ def sv_init(self, context):

def draw_buttons(self, context, layout):
layout.prop(self, "origin")
self.draw_angle_units_buttons(context, layout)

def process(self):
if not any(socket.is_linked for socket in self.outputs):
Expand All @@ -80,6 +93,8 @@ def process(self):
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):
au = self.radians_conversion_factor()
v_min, v_max = v_min*au, v_max*au
origin = self.origin == 'GLOBAL'
surface = SvRevolutionSurface.build(curve,
np.array(point), np.array(direction),
Expand All @@ -90,8 +105,8 @@ def process(self):
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 SvRevolutionSurfaceNode(SverchCustomTreeNode, bpy.types.Node):
"""
Triggers: Revolution Surface
Tooltip: Generate a surface of revolution (similar to Spin / Lathe modifier)
"""
bl_idname = 'SvRevolutionSurfaceNodeMK2'
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)

Loading