Skip to content

Commit

Permalink
Loop in and Loop out nodes (#3745)
Browse files Browse the repository at this point in the history
* Loop In and Loop Out Nodes

* faster loop

* for_each method implemented

* for each method implemented 2

* better exceptions

* better exceptions 2

* break the loop feature

* skip this feature

* custom socket label

* docs

* update docs

* typo in docs [skip-ci]

* Durman suggestions

* cleaning
  • Loading branch information
vicdoval authored Dec 8, 2020
1 parent f0cc421 commit b132edc
Show file tree
Hide file tree
Showing 8 changed files with 649 additions and 77 deletions.
26 changes: 17 additions & 9 deletions core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def update_unwrap_flag(self, context):
self.use_wrap = False
finally:
self.skip_wrap_mode_update = False

process_from_socket(self, context)

def update_wrap_flag(self, context):
Expand All @@ -115,7 +115,7 @@ def update_wrap_flag(self, context):
self.use_unwrap = False
finally:
self.skip_wrap_mode_update = False

process_from_socket(self, context)

use_unwrap : BoolProperty(
Expand All @@ -139,7 +139,7 @@ def update_flatten_flag(self, context):
self.use_simplify = False
finally:
self.skip_simplify_mode_update = False

process_from_socket(self, context)

def update_simplify_flag(self, context):
Expand All @@ -153,7 +153,7 @@ def update_simplify_flag(self, context):
self.use_flatten = False
finally:
self.skip_simplify_mode_update = False

process_from_socket(self, context)

# Only one of properties can be set to true: use_flatten or use_simplfy
Expand Down Expand Up @@ -610,7 +610,7 @@ def setup_parameter_node(self, param_node):
param_node.x_ = value[0]
param_node.y_ = value[1]
param_node.z_ = value[2]


# this property is needed for back capability, after renaming prop to default_property
# should be removed after https://github.com/nortikin/sverchok/issues/3514
Expand Down Expand Up @@ -664,7 +664,7 @@ def does_support_link_input_menu(self, context, layout, node):

class SvVerticesSocketInterface(bpy.types.NodeSocketInterface):
"""
This socket will be created in tree.inputs to tree.outputs collection
This socket will be created in tree.inputs to tree.outputs collection
when normal socket will be connected to input or output group nodes
"""
# The only reason of existing this class
Expand Down Expand Up @@ -940,7 +940,7 @@ def draw_group_property(self, layout, text, interface_socket):

class SvStringsSocketInterface(bpy.types.NodeSocketInterface):
"""
This socket will be created in tree.inputs to tree.outputs collection
This socket will be created in tree.inputs to tree.outputs collection
when normal socket will be connected to input or output group nodes
"""
bl_idname = "SvStringsSocketInterface"
Expand Down Expand Up @@ -1000,6 +1000,14 @@ class SvPulgaForceSocket(NodeSocket, SvSocketCommon):

color = (0.4, 0.3, 0.6, 1.0)

class SvLoopControlSocket(NodeSocket, SvSocketCommon):
'''For loop in-loop out node pair'''
bl_idname = "SvLoopControlSocket"
bl_label = "Loop Control Socket"

color = (0.1, 0.1, 0.1, 1.0)
quick_link_to_node = 'SvLoopInNode'

class SvDictionarySocket(NodeSocket, SvSocketCommon):
'''For dictionary data'''
bl_idname = "SvDictionarySocket"
Expand Down Expand Up @@ -1357,7 +1365,8 @@ def invoke(self, context, event):
SvColorSocket, SvQuaternionSocket, SvDummySocket, SvSeparatorSocket,
SvTextSocket, SvObjectSocket, SvDictionarySocket, SvChameleonSocket,
SvSurfaceSocket, SvCurveSocket, SvScalarFieldSocket, SvVectorFieldSocket,
SvSolidSocket, SvSvgSocket, SvPulgaForceSocket, SvLinkNewNodeInput,
SvSolidSocket, SvSvgSocket, SvPulgaForceSocket, SvLoopControlSocket,
SvLinkNewNodeInput,
SvStringsSocketInterface, SvVerticesSocketInterface,
SvSocketHelpOp, SvInputLinkMenuOp
]
Expand Down Expand Up @@ -1400,4 +1409,3 @@ def draw(self, context, layout):


register, unregister = bpy.utils.register_classes_factory(classes + list(socket_interface_classes()))

2 changes: 2 additions & 0 deletions docs/nodes/logic/logic_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Logic
input_switch_mod
custom_switcher
range_switch
loop_in
loop_out
61 changes: 61 additions & 0 deletions docs/nodes/logic/loop_in.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Loop In
=======

This node in conjunction with the Loop out node can create loops with nodes

Offers two different modes 'Range' and 'For Each'

Range
-----

In this mode the all the data inputted to the Loop In node will be processed every iteration.

For Each
--------

In this mode the inputted data will be splitted before being processed and there will be one loop per every level 1 object.

Operators
---------

**Create Loop Out**: creates a Loop out node and links the Loop In - Loop Out socket.


Inputs
------

**Iterations**: Number of repetitions (only in Range mode).

Data0, Data1... inputs will be created when the last one is linked

Options
-------

**Max Iterations**: Maximum iterations (in N-panel and Contextual Sverchok Menu)
**Socket Labels**: To change sockets names (in N-panel)

Outputs
-------

**Loop Out**: Socket to link with the Loop Out node.

**Loop Number / Item Number**: Actual Repetition / Item.

**Total Loops / Total Items**: Total Repetitions / Items.

Data0, Data1... output sockets will be created when the last input is linked

Examples
--------

Range mode example, Break used to control the maximum vertices.

.. image:: https://user-images.githubusercontent.com/10011941/101332093-22234d00-3875-11eb-819a-68e86ef8c2c2.png

For Each mode example, Skip input used to mask the results.

.. image:: https://user-images.githubusercontent.com/10011941/101334215-e047d600-3877-11eb-89df-cfaaf73dd427.png

You can change the socket labels in the N-Panel

.. image:: https://user-images.githubusercontent.com/10011941/101360702-519a7f80-389e-11eb-826d-0e1c5a7152d1.png
39 changes: 39 additions & 0 deletions docs/nodes/logic/loop_out.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Loop In
=======

This node in conjunction with the Loop In node can create loops with nodes

Offers two different modes 'Range' and 'For Each'


Operators
---------

**Create Loop In**: creates a Loop In node and links the Loop In - Loop Out socket.


Inputs
------

**Loop Out**: Socket to link with the Loop Out node.

**Break**: If a True value is inputted the loop will stop (Only if Loop In is in Range Mode).

**Skip**: If a True value is inputted the loop the result wont be added to the output, like a internal mask. (Only if Loop In is in For Each Mode).

Data0, Data1... inputs will be created coping the Loop in Outputs


Outputs
-------


Data0, Data1... inputs will be created coping the Loop in Outputs


Examples
--------

.. image:: https://user-images.githubusercontent.com/10011941/101332093-22234d00-3875-11eb-819a-68e86ef8c2c2.png

.. image:: https://user-images.githubusercontent.com/10011941/101334215-e047d600-3877-11eb-89df-cfaaf73dd427.png
3 changes: 3 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,9 @@
SvCustomSwitcher
SvRangeSwitchNode
---
SvLoopInNode
SvLoopOutNode
---
SvEvolverNode
SvGenesHolderNode

Expand Down
Loading

0 comments on commit b132edc

Please sign in to comment.