Коммит 0be64023 создал по автору Ilya Portnov's avatar Ilya Portnov
Просмотр файлов

Add old node documentation for now.

владелец 0da94955
Mask from Index
==============
*destination after Beta:*
Functionality
-------------
It can create mask list and set certain index positions to True. Length of mask list can be set using
either data list, or by setting int value.
Inputs
------
This node has the following inputs:
- **Index** - List of indices of values inside of mask list to set True.
- **Mask Length** - Length of mask list. Seen only when **Data Mask** mode not used.
- **Data to Mask** - Data from which mask lists will be formed. Seen only when **Data Mask** mode is used.
Outputs
-------
This node has the following outputs:
- **Mask** - Mask list with values of indices from Index list set to True, and others set to False.
Examples of usage
-----------------
.. image:: https://cloud.githubusercontent.com/assets/22656834/25303147/32c29ce8-2766-11e7-8671-7d96a0e0dcbf.png
.. image:: https://cloud.githubusercontent.com/assets/22656834/25303145/2c8349cc-2766-11e7-8d98-ffbba971ca49.png
Color by formula
========
Functionality
-------------
available variables: **r**, **g**, **b**, **a** for access to initial colors from first input socket. If second input color socket is connected, **R**, **G**, **B**, **A**
variables can be used to access its values.
And **i** for access to index of current color to be evaluated. It is also possible
to get index of current object list of colors evaluated as **I** variable.
So **i** for index of color, and **I** for index of list of colors.
Internally imported everything from Python **math** module.
Blender Py API also accessible (like **bpy.context.scene.frame_current**)
Inputs
------
- **Colors(rgba)**
- **Colors(RGBA)**
Outputs
-------
**Colors**.
resulted colors to red, green, blue and alpha elements of which was applied expression.
Example of usage
----------------
.. image:: https://user-images.githubusercontent.com/22656834/37774133-44806c24-2e01-11e8-85ba-361a18315ff9.png
Cylinder
========
Functionality
-------------
Cylinder generator, as well as circle, is used to create a big variety of polyhedra based on the cyliner form: two polygons connected by a body. In the examples will see some possibilities.
Inputs
------
All inputs are vectorized and they will accept single or multiple values.
There is three inputs:
- **Radius Top**
- **Radius Bottom**
- **Vertices**
- **Height**
- **Subdivisions**
Parameters
----------
All parameters except **Separate** and **Caps** can be given by the node or an external input.
+-------------------+---------------+-------------+--------------------------------------------------------+
| Param | Type | Default | Description |
+===================+===============+=============+========================================================+
| **Radius Top** | Float | 1.00 | radius of the top polygon |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Radius Bottom** | Float | 1.00 | radius of the bottom polygon |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Vertices** | Int | 32 | number of vertices to generate top and bottom poygons |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Height** | Float | 2.00 | height of the cylinder |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Subdivisions** | Int | 0 | number of the height subdivisions |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Separate** | Bollean | False | grouping vertices by V direction |
+-------------------+---------------+-------------+--------------------------------------------------------+
| **Caps** | Bollean | True | turn on and off top and bottom cap |
+-------------------+---------------+-------------+--------------------------------------------------------+
Outputs
-------
**Vertices**, **Edges** and **Polygons**.
All outputs will be generated. Depending on the type of the inputs, the node will generate only one or multiples independant cylinders.
If **Separate** is True, the only the top and the bottom polygons will be generated.
With **Caps** with can enable or disable the top and bottom caps.
Example of usage
----------------
.. image:: https://cloud.githubusercontent.com/assets/5990821/4186892/cb062d3e-3764-11e4-95c3-511fd668ce1e.png
:alt: CylinderDemo1.PNG
In this example with can see some examples of what can be done with this node.
Deform by formula
========
Functionality
-------------
available variables: **x**, **y**, **z** for access to initial (xyz) coordinates.
MK2 version of this node have second input socket - access its vertices using **X**, **Y** or **Z** variables.
Use **i** for access to index of current vertex to be evaluated. It is also possible
to get index of current object list evaluated as **I** variable.
So **i** for index of vertex, and **I** for index of object.
Internally imported everything from Python **math** module.
Blender Py API also accessible (like **bpy.context.scene.frame_current**)
Inputs
------
- **Verts**
Outputs
-------
**Verts**.
resulted vertices to X,Y,Z elements of which was applied expression.
Example of usage
----------------
.. image:: https://user-images.githubusercontent.com/22656834/34645578-6feb7138-f373-11e7-87e7-54d4307c9b0a.png
Delaunay 2D
===========
\ No newline at end of file
Extrude Edges
=============
*This node testing is in progress, so it can be found under Beta menu*
Functionality
-------------
This node applies Extrude operator to edges of input mesh. After that, matrix transformation can be applied to new vertices.
It is possible to provide specific transformation matrix for each of extruded vertices.
Inputs
------
This node has the following inputs:
- **Vertices**
- **Edges**
- **Polygons**
- **ExtrudeEdges**. Edges of input mesh that are to be extruded. If this input is empty or not connected, then by default all edges will be processed.
- **Matrices**. Transformation matrices to be applied to extruded vertices. This input can contain separate matrix for each vertex. In simplest case, it can contain one matrix to be applied to all vertices.
Outputs
-------
This node has the following outputs:
- **Vertices**
- **Edges**
- **Polygons**. All faces of resulting mesh.
- **NewVertices**. Newly created vertices only.
- **NewEdges**. Newly created edges only.
- **NewFaces**. Newly created faces only.
Examples of usage
-----------------
Extrude only boundary edges of plane grid, along Z axis:
.. image:: https://cloud.githubusercontent.com/assets/284644/6318599/6ee0d474-babc-11e4-8d3a-f9f86963bf10.png
Extrude all edges of bitted circle, and scale new vertices:
.. image:: https://cloud.githubusercontent.com/assets/284644/6318598/6eb0c3ba-babc-11e4-8cab-ccb2d4fe39a9.png
Find UV Coordinate on Mesh
========
Functionality
-------------
outputs uvmap object wich can be used to visually understend where input vertices lie on uv texture.
Translates vectors from UV space to object local space.
Works most accurately on triangulated meshes. Quads are ok if not distorted much. Object must have UV layer unwraped.
Inputs
------
- **Point on UV** points in 1x1 unit UV texture space (look on uvmap object to know where to place them)
Outputs
-------
- **Point on mesh**. Points on UV transformed to local space of object.
- **UVMapVert**. vertices of uvmap object.
- **UVMapPoly**. polygons of uvmap object.
Example of usage
----------------
.. image:: https://user-images.githubusercontent.com/22656834/37982776-f237ce18-320a-11e8-93eb-84e143e8a6c2.png
Float
=====
Functionality
-------------
Float digit. Has maximum/minimum values and flexible labeling. Cached in Sverchok 3Dtoolbox.
Inputs & Parameters
-------------------
**float**
Extended parameters
-------------------
**to-3d** - boolean flag makes float catched in 3D toolbox
**minimum** - defines minimum value
**maximum** - defines maximum value
Outputs
-------
**float** - only one digit.
Examples
--------
Three cases of float. With output, as router and as input (not functional). Only first case will be catched in 'scan for propertyes' in 3Dtoolbox of sverchok.
.. image:: https://cloud.githubusercontent.com/assets/5783432/4505625/26ac1a58-4af8-11e4-90c7-161736cfe43e.png
:alt: float.PNG
This is 3D toolbox scanned float. Max and min values appears in 3d and node toolboxes (last in extended interface in propertyes panel). Label of node will apear in 3Dtoolbox and sorted depend on it. Flag 'to_3d' makes node catchable in 3D.
.. image:: https://cloud.githubusercontent.com/assets/5783432/4505626/26b5021c-4af8-11e4-9e5b-8ad09846cb08.png
:alt: float2.PNG
Notes
-----
Float output only one digit, for ranges and lists reroute use route node.
Formula
=======
Functionality
-------------
**Formula2 - support next operations:**
- vector*vector, define hierarhy and calculate respectfully to it.
- Vector*scalar, the same. And output to vector.
- Moreover, you can define lists with formula, i.e. ```0,1,2,3,4,5``` for series or ```(1,2,3),(1,2,3)``` for vertices.
- Supporting expressions beside * / - +:
- acos()
- acosh()
- asin()
- asinh()
- atan()
- atan2()
- atanh()
- ceil()
- copysign()
- cos()
- cosh()
- degrees()
- e
- erf()
- erfc()
- exp()
- expm1()
- fabs()
- factorial()
- floor()
- fmod()
- frexp()
- fsum()
- gamma()
- hypot()
- isfinite()
- isinf()
- isnan()
- ldexp()
- lgamma()
- log()
- log10()
- log1p()
- log2()
- modf()
- pi
- pow()
- radians()
- sin()
- sinh()
- sqrt()
- str()
- tan()
- tanh()
- trunc()
- ==
- !=
- <, >
- for, in, if, else
- []
Inputs
------
**X** - main x that defines sequence. it can be range of vertices or range of floats/integers.
If x == one number, than other veriables will be the same - one number, if two - two.
**n[0,1,2,3,4]** - multisocket for veriables.
Parameters
----------
**Formula** - the string line, defining formula, i.e. ```x>n[0]``` or ```x**n[0]+(n[1]/n[2])``` are expressions.
May have ```x if x>n[0] else n[1]```
Outputs
-------
**Result** - what we got as result.
Usage
-----
.. image:: https://cloud.githubusercontent.com/assets/7894950/4606629/51fd445c-5228-11e4-815b-d12866da7794.png
.. image:: https://cloud.githubusercontent.com/assets/7894950/4688830/e1e9680a-5694-11e4-9062-6ee03356b533.png
.. image:: https://cloud.githubusercontent.com/assets/5783432/4689948/6d4c9fcc-56d4-11e4-9628-22eeffed4eed.png
.. image:: https://cloud.githubusercontent.com/assets/5783432/4689947/6d4be5e6-56d4-11e4-911f-86494b69f182.png
.. image:: https://cloud.githubusercontent.com/assets/5783432/4689951/6d590226-56d4-11e4-9519-67b2c871e9c8.png
.. image:: https://cloud.githubusercontent.com/assets/5783432/4689950/6d58321a-56d4-11e4-8ba9-1d28426b8307.png
.. image:: https://cloud.githubusercontent.com/assets/5783432/4689949/6d57503e-56d4-11e4-9df9-9224b8f645cb.png
.. image:: https://cloud.githubusercontent.com/assets/7894950/4732337/74f49ce6-59ba-11e4-8406-77d55c55ff02.png
GText
=====
Functionality
-------------
Creates Text in NodeView using GreasePencil strokes.
It has full basic English and Cyrillic Character map and several extended character types::
[ ] \ / ( ) ~ ! ? @ # $ % & ^ > < | 1234567890 - + * = _
Inputs
------
Gtext will display whatever text is currently in the system buffer / clipboard.
UI & Parameters
---------------
**Node UI**
+------------+---------------------------------------------------------------------------------+
| Parameter | Function |
+============+=================================================================================+
| Set | If clipboard has text, then Set will display that text beside the GText node. |
+------------+---------------------------------------------------------------------------------+
| Clear | This erases the GreasePencil strokes |
+------------+---------------------------------------------------------------------------------+
GText Node will display the context of the clipboard after pressing the `Set` button. If no text is found in the clipboard
it will write placeholder 'your text here'.
**N-panel**
+---------------------+-------------------------------------------------------------------------------------------------+
| Parameter | Function |
+=====================+=================================================================================================+
| Get from Clipboard | Gets and sets in one action, takes text from clipboard and writes to NodeView with GreasePencil |
+---------------------+-------------------------------------------------------------------------------------------------+
| Thickness | sets pixel width of the GreasePencil strokes |
+---------------------+-------------------------------------------------------------------------------------------------+
| Font Size | Scales up text and line-heights |
+---------------------+-------------------------------------------------------------------------------------------------+
**Moving GText**
To move GText strokes around in NodeView you must move the GText Node then press Set again. This may not be entirely intuitive but it hasn't bugged us enough to do anything about it.
Outputs
-------
Outputs only to NodeView
Examples
--------
Integer
=======
Functionality
-------------
Integer digit. Has maximum/minimum values and flexible labeling. Cached in Sverchok 3Dtoolbox.
Inputs & Parameters
-------------------
**int**
Extended parameters
-------------------
**to-3d** - boolean flag makes integer catched in 3D toolbox
**minimum** - defines minimum value
**maximum** - defines maximum value
Outputs
-------
**int** - only one digit.
Examples
--------
Three cases of integer. With output, as router and as input (not functional). Only first case will be catched in 'scan for propertyes' in 3Dtoolbox of sverchok.
.. image:: https://cloud.githubusercontent.com/assets/5783432/4505625/26ac1a58-4af8-11e4-90c7-161736cfe43e.png
:alt: float.PNG
This is 3D toolbox scanned integer. Max and min values appears in 3d and node toolboxes (last in extended interface in propertyes panel). Label of node will apear in 3Dtoolbox and sorted depend on it. Flag 'to_3d' makes node catchable in 3D.
.. image:: https://cloud.githubusercontent.com/assets/5783432/4505626/26b5021c-4af8-11e4-9e5b-8ad09846cb08.png
:alt: float2.PNG
Notes
-----
Integer output only one digit, for ranges and lists reroute use route node.
Vector Evaluate
===============
Functionality
-------------
Vector Evaluate need two groups of vertices (or just 2) as inputs to evaluate al the global positions between them.
Inputs
------
- **Factor**
- **Vertice A**
- **Vertice B**
Only **Factor** can be set inside the node. There is no default values for Vertice A or B.
Parameters
----------
All parameters need to proceed from an external node.
+------------------+---------------+-------------+-----------------------------------------------+
| Param | Type | Default | Description |
+==================+===============+=============+===============================================+
| **Vertice A** | Vertices | None | first group of vertices |
+------------------+---------------+-------------+-----------------------------------------------+
| **Vectice B** | Vertices | None | second group of vertices |
+------------------+---------------+-------------+-----------------------------------------------+
| **Factor** | Float | 0.50 | distance percentage between vertices A and B |
+------------------+---------------+-------------+-----------------------------------------------+
Outputs
-------
**EvPoint** will need Vertices A and B to be generated. The output will be a new group of vertices between groups A and B, based on the factor setting. See example below.
Example of usage
----------------
.. image:: https://cloud.githubusercontent.com/assets/5990821/4188727/aaceebe4-3775-11e4-85cd-df80606b1509.gif
In this example just two vertices are evaluated. The gif shows the output based on the factor setting.
\ No newline at end of file
Centers Polygons
================
Functionality
-------------
Analizing geometry and finding centers of polygons, normals (from global zero), normals from local centers of polygons and matrices that find polygons rotation. Not works with edges.
Inputs
------
**Vertices** and **Polygons** from object that we analizing.
Outputs
-------
**Normals** is normals from global zero coordinates, vector. **Norm_abs** is normals shifted to centers of polygons. **Origins** centers of polygons. **Centers** matrices that has rotation and location of polygons.
Example of usage
----------------
.. image:: https://cloud.githubusercontent.com/assets/5783432/4222939/b86a1d3e-3917-11e4-8e03-c24980672404.jpg
:alt: Centers_of_polygons_normals.jpg
.. image:: https://cloud.githubusercontent.com/assets/5783432/4222936/b863cb46-3917-11e4-9cfe-0d863c4850b6.jpg
:alt: Centers_of_polygons_normalsabs.jpg
.. image:: https://cloud.githubusercontent.com/assets/5783432/4222937/b864c8fc-3917-11e4-9368-b5260703e4c5.jpg
:alt: Centers_of_polygons_locations.jpg
.. image:: https://cloud.githubusercontent.com/assets/5783432/4222949/c5874906-3917-11e4-9c9c-94c016560f98.jpg
:alt: Centers_of_polygons_matrices.jpg
Problems
--------
The code of matrix rotation based on Euler rotation, so when you rotate to plane X-oriented, it makes wrong. We need spherical coordinates and quaternion rotation here, needed help or something
=======================
Profile Parametric Node
=======================
**Profile Node** implements a useful subset of the SVG path section commands. Currently the following segment types are available:
+---------+------+---------------------------------------------------------------------------------+
| name | cmd | parameters |
+=========+======+=================================================================================+
| MoveTo | M, m| <2v coordinate> |
+---------+------+---------------------------------------------------------------------------------+
| LineTo | L, l| <2v coordinate 1> <2v coordinate 2> <2v coordinate n> [z] |
+---------+------+---------------------------------------------------------------------------------+
| CurveTo | C, c| <2v control1> <2v control2> <2v knot2> <int num_verts> <int even_spread> [z] |
+---------+------+---------------------------------------------------------------------------------+
| ArcTo | A, a| <2v rx,ry> <float rot> <int flag1> <int flag2> <2v x,y> <int num_verts> [z] |
+---------+------+---------------------------------------------------------------------------------+
| Close | X | |
+---------+------+---------------------------------------------------------------------------------+
| comment | # | must be first thing on the line, no trailing comment instructions. |
+---------+------+---------------------------------------------------------------------------------+
::
<> : mandatory field
[] : optional field
2v : two point vector `a,b`
- no space between ,
- no backticks
- a and b can be
- number literals
- lowercase 1-character symbols for variables
int : means the value will be cast as an int even if you input float
flags generally are 0 or 1.
z : is optional for closing a line
X : as a final command to close the edges (cyclic) [-1, 0]
in addition, if the first and last vertex share coordinate space
the last vertex is dropped and the cycle is made anyway.
# : single line comment prefix
**Mode 0:** default behaviour, variables may be negated
::
M a,-a
L a,a -a,a -a,-a z
There are 2 slightly more elaborate evaluation modes:
**Mode 1:** Requires the use or parentheses to indicate where extra operations take place.
Mode 1 is restrictive and only allows addition and subtraction
::
(a+b-c)
**Mode 2:** Also requires parentheses but allows a more liberal evaluation of operations. Allowed operations are:
::
(a*b(c/d))
To use Mode 2, you must enable the *extended parsing* switch in the N-panel for the Profile node.
Parameters
----------
This node has the following parameters:
- **Axis**. Available values are **X**, **Y**, **Z**. This parameter specifies
the plane in which the curve will be produced. For example, default value of
**Z** means that all points will belong to XOY plane.
- **File name**. Name of Blender text buffer, containing profile description.
- **Extended parsing**. Toggles extended parsing node. See also description
above. By default this parameter is unchecked. This parameter is available
only in the N panel.
- **Precision**. Number of decimal places used for points coordinates when
generating a profile by **from selection** operator. Default value is 8. This
parameter is only available in the N panel.
- **Curve points count**. Default number of points for curve segment commands,
generated by **from selection** operator (see num_verts in description
above). Default value is 20. This parameter is available only in the N panel.
Operators
---------
As you know there are three types of curves in Blender - Polylines, Bezier curves and NURBS curves.
This node has one operator button: **from selection**. This operator works only with Bezier curves.
It takes an active Curve object, generates profile description from it and sets up the node
to use this generated profile. You can adjust the profile by editing created Blender's text bufrfer.
If you want to import other type of curve you have to convert one to Bezier type.
Fortunately it is possible to do in edit mode with button *Set Spline Type* in the *T* panel.
More information about conversion looks `here <https://docs.blender.org/manual/en/dev/modeling/curves/editing/introduction.html#set-spline-type>`_.
.. image:: https://user-images.githubusercontent.com/28003269/41649336-67dc2d1c-748c-11e8-9989-5b7d8d212b1c.png
Examples
--------
If you have experience with SVG paths most of this will be familiar. The biggest difference is that only the
LineTo command accepts many points, and we always start the profile with a M <pos>,<pos>.
::
M 0,0
L a,a b,0 c,0 d,d e,-e
CurveTo and ArcTo only take enough parameters to complete one Curve or Arc,
unlike real SVG commands which take a whole sequence of chained CurveTo or ArcTo commands. The decision to keep
it at one segment type per line is mainly to preserve readability.
The CurveTo and ArcTo segment types allow you to specify how many vertices are used to generate the segment. SVG
doesn't let you specify such things, but it makes sense to allow it for the creation of geometry.
the fun bit about this is that all these variables / components can be dynamic
::
M 0,0
L 0,3 2,3 2,4
C 2,5 2,5 3,5 10 0
L 5,5
C 7,5 7,5 7,3 10 0
L 7,2 5,0
X
or
::
M a,a
L a,b c,b -c,d
C c,e c,e b,e g 0
L e,e
C f,e f,e f,-b g 0
L f,c e,a
X
More Info
---------
The node started out as a thought experiment and turned into something quite useful, you can see how it evolved in the `github thread <https://github.com/nortikin/sverchok/issues/350>`_
Example usage:
.. image:: https://cloud.githubusercontent.com/assets/619340/3905771/193b5d86-22ec-11e4-93e5-724863a30bbc.png
.. image:: https://cloud.githubusercontent.com/assets/619340/3895396/81f3b96c-224d-11e4-9ca7-f07756f40a0e.png
Gotchas
-------
The update mechanism doesn't process inputs or anything until the following conditions are satisfied:
* Profile Node has at least one input socket connected
* The file field on the Node points to an existing Text File.
Keyboard Shortcut to refresh Profile Node
-----------------------------------------
Updates made to the profile path text file are not propagated automatically to any nodes that might be reading that file.
To refresh a Profile Node simply hit ``Ctrl+Enter`` In TextEditor while you are editing the file, or click one of the
inputs or output sockets of Profile Node. There are other ways to refresh (change a value on one of the incoming nodes,
or clicking the sockets of the incoming nodes)
Math
====
This is the mk1 version. Go to scalar_mk2.rst for a description of this node.
Scripted Node (Generator)
=========================
aka Script Node or SN. (iteration 1)
- Introduction
- Features
- Structure
- Templates
- Conveniences
- Examples
- Techniques to improve Python performance
- Limitations
- Future
Introduction
------------
When you want to express an idea in written form and the concept is suitable
for a one line Python expression then often you can use a Formula node. If you
need access to imports, classes, temporary variables, and functions then you can
write a script to load into ScriptNode.
ScriptNode (SN) allows you to write multi-line python programs that define
the functionality of a Node, while avoiding some of the boilerplate associated
with a regular Node. SN can be used as an environment for experimenting
with algorithms. Scripts written for SN are easily converted to full PyNodes.
It's a prototype so bug reports are welcome.
Here's a short tutorial to SN1, see :ref:`scripted-tutorial`
Features
--------
allows:
- Loading/Reloading scripts currently in TextEditor
- imports and aliasing, ie anything you can import from console works in SN
- nested functions and lambdas
- named inputs and outputs
- named operators (buttons to action something upon button press)
Structure
---------
At present all scripts for SN must (strict list - general):
- have 1 `sv_main` function as the main workhorse
- `sv_main` must take 1 or more arguments (even if you don't use it)
- all function arguments for ``sv_main`` must have defaults.
- each script shall define ``in_sockets`` and ``out_sockets``
- `ui_operators` is an optional third output parameter
**sv_main()**
``sv_main()`` can take int, float and list or nested list.
Here are some legal examples::
def sv_main(vecs_in_multi=[[]], vecs_in_flat=[], some_var=1, some_ratio=1.2):
pass
[[]] # for nested input (lists of lists of any data type currently supported)
[] # for flat (one list)
int, float # for single value input
**in_sockets**
::
in_sockets = [
[type, 'socket name on ui', input_variable],
[type, 'socket name on ui 2', input_variable2],
# ...
]
**out_sockets**
::
out_sockets = [
[type, 'socket name on ui', output_variable],
[type, 'socket name on ui 2', output_variable2],
# ...
]
**in_sockets and out_sockets**
- Each *socket name on ui* string shall be unique.
- **type** are currently limited to
+---------+-------------------------------------+
| type id | type data |
+=========+=====================================+
| 's' | floats, ints, edges, faces, strings |
+---------+-------------------------------------+
| 'v' | vertices, vectors, 3-tuples |
+---------+-------------------------------------+
| 'm' | matrices, 4 x 4 nested lists |
+---------+-------------------------------------+
**ui_operators**
::
ui_operators = [
['button_name', func1]
]
- Here `func1` is the function you want to call when pressing the button.
- Each `"button_name"` is the text you want to appear on the button.
For simplicity it must be a unique and valid python variable name
- with no special characters (``|().\/...etc``)
- doesn't start with a number
- contains no spaces, use single underscores if you need word separation. The UI code replaces underscores with spaces.
**return**
Simple, only two flavours are allowed at the moment. ::
return in_sockets, out_sockets
return in_sockets, out_sockets, ui_operators
Templates
---------
Sverchok includes a list of easily accessible examples and templates. They can be accessed
from the SN node if nothing is loaded, or from the `Template Menu` in `TextEditor` as ``sv NodeScripts``.
Conveniences
------------
We vale our time, i'm sure you do too, so features have been added to help speed up the
script creation process.
**Text Editor**
- has automatic ``in_sockets`` list creation when the key cursor is over ``sv_main``.
(please note: it doesn't attempt to detect if you want nested verts or edge/polygon so it assumes you want 'v')
- kb shortcut: ``Ctrl+I -> Generate in_sockets``
.. image:: https://cloud.githubusercontent.com/assets/619340/2854040/e6351180-d14b-11e3-8055-b3d8c707675d.gif
- can also convert a template description (like `kv lang` if you know Kivy) into
valid ScriptNode ready python. Example `available here <https://github.com/nortikin/sverchok/issues/376#issuecomment-54062710>`_
- kb shortcut: ``Ctrl+I -> Convert svlang``
- can refresh the Script Node which currently loads that script by hitting ``Ctrl+Enter``
Examples
--------
The best way to get familiarity with SN is to go through the templates folder.
They are intended to be lightweight and educational, but some of them will show
advanced use cases. The images and animations on this `thread on github
<https://github.com/nortikin/sverchok/issues/85>`_.
may also provide some insight into what's possible.
A typical nodescript may look like this::
from math import sin, cos, radians, pi
from mathutils import Vector, Euler
def sv_main(n_petals=8, vp_petal=20, profile_radius=1.3, amp=1.0):
in_sockets = [
['s', 'Num Petals', n_petals],
['s', 'Verts per Petal', vp_petal],
['s', 'Profile Radius', profile_radius],
['s', 'Amp', amp],
]
# variables
z_float = 0.0
n_verts = n_petals * vp_petal
section_angle = 360.0 / n_verts
position = (2 * (pi / (n_verts / n_petals)))
# consumables
Verts = []
# makes vertex coordinates
for i in range(n_verts):
# difference is a function of the position on the circumference
difference = amp * cos(i * position)
arm = profile_radius + difference
ampline = Vector((arm, 0.0, 0.0))
rad_angle = radians(section_angle * i)
myEuler = Euler((0.0, 0.0, rad_angle), 'XYZ')
# changes the vector in place, successive calls are accumulative
# we reset at the start of the loop.
ampline.rotate(myEuler)
x_float = ampline.x
y_float = ampline.y
Verts.append((x_float, y_float, z_float))
# makes edge keys, ensure cyclic
Edges = [[i, i + 1] for i in range(n_verts - 1)]
Edges.append([i, 0])
out_sockets = [
['v', 'Verts', [Verts]],
['s', 'Edges', [Edges]],
]
return in_sockets, out_sockets
but we are not forced to have all code inside sv_main, we can also do::
def lorenz(N, verts):
add_vert = verts.append
h = 0.01
a = 10.0
b = 28.0
c = 8.0 / 3.0
x0 = 0.1
y0 = 0
z0 = 0
for i in range(N):
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
x0, y0, z0 = x1, y1, z1
add_vert((x1,y1,z1))
def sv_main(N=1000):
verts = []
in_sockets = [['s', 'N', N]]
out_sockets = [['v','verts', [verts]]]
lorenz(N, verts)
return in_sockets, out_sockets
We can even define classes inside the .py file, or import from elsewhere.
Here's a `ui_operator` example, it acts like a throughput (because in and out
are still needed by design). You'll notice that inside `func1` the node's input
socket is accessed using `SvGetSockeyAnyType(...)`. It is probably more logical
if we could access the input data directly from the variable `items_in`,
currently this is not possible -- therefor the solution is to use what
sverchok nodes use in their internal code too. The upshot, is that this exposes
you to how you might access the socket content of other nodes. Experiment :)
::
def sv_main(items_in=[[]]):
in_sockets = [
['v', 'items_in', items_in]]
def func1():
# directly from incoming Object_in socket.
sn = bpy.context.node
# safe? or return early
if not (sn.inputs and sn.inputs[0].links):
return
verts = SvGetSocketAnyType(sn, sn.inputs['items_in'])
print(verts)
out_sockets = [['v', 'Verts', items_in]]
ui_operators = [['print_names', func1]]
return in_sockets, out_sockets, ui_operators
Breakout Scripts
----------------
For lack of a better term, SN scripts written in this style let you pass
variables to a script located in ``/sverchok-master/..`` or
``/sverchok-master/your_module_name/some_library``. To keep your sverchok-master
folder organized I recommend using a module folder. In the example below,
I made a folder inside sverchok-master called ``sv_modules`` and inside that I
have a file called `sv_curve_utils`, which contains a function `loft`. This way
of coding requires a bit of setup work, but then you can focus purely on
the algorithm inside `loft`. ::
from mathutils import Vector, Euler, Matrix
import sv_modules
from sv_modules.sv_curve_utils import loft
def sv_main(verts_p=[], edges_p=[], verts_t=[], edges_t=[]):
in_sockets = [
['v', 'verts_p', verts_p],
['s', 'edges_p', edges_p],
['v', 'verts_t', verts_t],
['s', 'edges_t', edges_t]]
verts_out = []
def out_sockets():
return [['v', 'verts_out', verts_out]]
if not all([verts_p, edges_p, verts_t, edges_t]):
return in_sockets, out_sockets()
# while developing, it can be useful to uncomment this
if 'loft' in globals():
import imp
imp.reload(sv_modules.sv_curve_utils)
from sv_modules.sv_curve_utils import loft
verts_out = loft(verts_p[0], verts_t[0]) # this is your break-out code
# here the call to out_sockets() will pick up verts_out
return in_sockets, out_sockets()
Techniques to improve Python performance
----------------------------------------
There are many ways to speed up python code. Some slowness will be down to
innefficient algorithm design, other slowness is caused purely by how much
processing is minimally required to solve a problem. A decent read regarding
general methods to improve python code performance can be found
on `python.org <https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_.
If you don't know where the cycles are being consumed, then you don't know
if your efforts to optimize will have any significant impact.
Read these 5 rules by Rob Pike before any optimization.
http://users.ece.utexas.edu/~adnan/pike.html
Limitations
-----------
Most limitations are voided by increasing your Python and ``bpy`` skills.
Future
------
SN iteration 1 is itself a prototype and is a testing ground for iteration 2.
The intention was always to provide multiple programming language interfaces,
initially coffeescript because it's a lightweight language with crazy expressive
capacity. iteration 2 might work a little different, perhaps working from
within a class but trying to do extra introspection to reduce boilerplate.
The only reason in_sockets needs to be declared at the moment is if you want
to have socket names that are different than the function arguments. It
would be possible to allow `sv_main()` to take zero arguments too.
So possible configurations should be::
sv_main()
sv_main() + in_sockets
sv_main() + out_sockets
sv_main(a=[],..)
sv_main(a=[],..) + in_sockets
sv_main(a=[],..) + out_sockets
sv_main(a=[],..) + in_socket + out_sockets
etc, with ui_operators optional to all combinations
That's it for now.
Scripted Node 2(Generator)
=========================
aka Script Node MK2
- Introduction
- Features
- Structure
- Templates
- Conveniences
- Examples
- Techniques to improve Python performance
- Limitations
Introduction
------------
When you want to express an idea in written form and the concept is suitable
for a one line Python expression then often you can use a Formula node. If you
need access to imports, classes, temporary variables, and functions then you can
write a script to load into Script Node 2.
Script Node MK2 differs from Script Node iteratrion 1 in that offers more control.
It also has a prototype system where you could for example reuse the behavior of
a generator and the template takes care of all the details leaving you to focus
on the function. Scripts using the templates automatically becomes more powerful.
It's a prototype so bug reports, questions and feature request are very welcome.
Features
--------
allows:
- Loading/Reloading scripts currently in TextEditor
- imports and aliasing, ie anything you can import from console works in SN2
- nested functions and lambdas
- named inputs and outputs
- named operators (buttons to action something upon button press)
Structure
---------
At present all scripts for SN2 must:
- be subclasses SvScript
- include a function called process in the class
- have member attributes called ``inputs`` and ``outputs``
- have one Script class per file, if more than one, last one found will be used
**process(self)**
``process(self)`` is the main flow control function. It is called when all sockets
without defaults are connected. Usually the template provides a ``process`` function
for you.
**inputs**
Default can be a float or integer value, not other types are usable yet::
inputs = [
[type, 'socket name on ui', default],
[type, 'socket name on ui2', default],
# ...
]
**outputs**
::
outputs = [
[type, 'socket name on ui'],
[type, 'socket name on ui 2'],
# ...
]
**inputs and outputs**
- Each *socket name on ui* string shall be unique.
- **type** are currently limited to
+---------+-------------------------------------+
| type id | type data |
+=========+=====================================+
| 's' | floats, ints, edges, faces, strings |
+---------+-------------------------------------+
| 'v' | vertices, vectors, 3-tuples |
+---------+-------------------------------------+
| 'm' | matrices, 4 x 4 nested lists |
+---------+-------------------------------------+
There are a series of names that have special meaning that scripts should
avoid as class attributes or only used for the intended meaning. To be described:
``node`` ``draw_buttons`` ``update`` ``process`` ``enum_func`` ``inputs``
``outputs``
Templates
---------
Sverchok includes a series of examples for the different templates.
Conveniences
------------
We value our time, we are sure you do too, so features have been added to help speed up the
script creation process.
**Text Editor**
- can refresh the Script Node which currently loads that script by hitting ``Ctrl+Enter``
Main classes for your subclasses are:
- ``SvScript``
- ``SvScriptSimpleGenerator``
- ``SvScriptSimpleFunction``
Limitations
-----------
Using ``SvScriptSimpleGenerator`` and ``SvScriptSimpleFunction`` you limit inputs to deal with one object.
For plane, for example, you'll get next data:
[(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0)] [(0, 1, 3, 2)]
If you need Full support of Sverchok data - you'd better use ``SvScript``
class and ``self.node.inputs[0].sv_get()`` function.
Examples
--------
The best way to get familiarity with Script Node 2 is to go through the templates folder.
They are intended to be lightweight and educational, but some of them will show
advanced use cases. The images and animations on this `thread on github
<https://github.com/nortikin/sverchok/issues/439>`_.
may also provide some insight into what's possible.
A typical nodescript using the ``SvScriptSimpleGenerator`` may look like this, note that
the third argument for outputs is specific to this template::
import numpy
import itertools
class GridGen(SvScriptSimpleGenerator):
inputs = [("s", "Size", 10.0),
("s", "Subdivs", 10)]
outputs = [("v", "verts", "make_verts"),
("s", "edges", "make_edges")]
@staticmethod
def make_verts(size, sub):
side = numpy.linspace(-size / 2, size / 2, sub)
return tuple((x, y, 0) for x, y in itertools.product(side, side))
@staticmethod
def make_edges(size, sub):
edges = []
for i in range(sub):
for j in range(sub - 1):
edges.append((sub * i + j, sub * i + j + 1))
edges.append((sub * j + i, sub * j + i + sub))
return edges
Note that here the name of the method that should be called for producing data
for each socket in the final last arguments to ``outputs`` but we are not forced
to have all code inside the class, we can also do
::
def lorenz(N, verts, h, a, b, c):
add_vert = verts.append
x0 = 0.1
y0 = 0
z0 = 0
for i in range(N):
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
x0, y0, z0 = x1, y1, z1
add_vert((x1,y1,z1))
class LorenzAttractor(SvScriptSimpleGenerator):
inputs = [
['s', 'N', 1000],
['s', 'h', 0.01],
['s', 'a', 10.0],
['s', 'b', 28.0],
['s', 'c', 8.0/3.0]
]
@staticmethod
def make_verts(N, h, a, b, c):
verts = []
lorenz(N, verts, h, a, b, c)
return verts
@staticmethod
def make_edges(N, h a, b, c:
edges = [(i, i+1) for i in range(N-1)]
return edges
outputs = [
['v','verts', "make_verts"],
['s','edges', "make_edges"]
]
Here is a simple script for deleting loose vertices from mesh data, it also serves as an
illustration for a type of script that uses the ```SvScriptSimpleFunction``` template that
has one main function that decomposes into separate sockets. The methods don't have be static
but in general it is good practice to keep them free from side effects.
::
from itertools import chain
class DeleteLooseVerts(SvScriptSimpleFunction):
inputs = [
('v', 'verts'),
('s', 'pol')
]
outputs = [
('v', 'verts'),
('s', 'pol')
]
# delete loose verts
@staticmethod
def function(*args, **kwargs):
ve, pe = args
# find used indexes
v_index = sorted(set(chain.from_iterable(pe)))
# remap the vertices
v_out = [ve[i] for i in v_index]
# create a mapping from old to new vertices index
mapping = dict(((j, i) for i, j in enumerate(v_index)))
# apply mapping to input polygon index
p_out = [tuple(map(mapping.get, p)) for p in pe]
return v_out, p_out
Breakout Scripts
----------------
Scripts that needs to access the node can do so via the ```self.node``` variable
that is automatically set.
::
class Breakout(SvScript):
def process(self):
pass
def update(self):
node = self.node
node_group = self.node.id_data
# here you can do anything to the node or node group
# that real a real node could do including multisocket
# adaptive sockets etc. templates and examples for this are
# coming
Admit, you can call sockets data directly when using ```SvScript``` as ```self.node.inputs[0].sv_get()```.
And other ```self.node.``` operations possible from this class.
Techniques to improve Python performance
----------------------------------------
There are many ways to speed up python code. Some slowness will be down to
innefficient algorithm design, other slowness is caused purely by how much
processing is minimally required to solve a problem. A decent read regarding
general methods to improve python code performance can be found
on `python.org <https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_.
If you don't know where the cycles are being consumed, then you don't know
if your efforts to optimize will have any significant impact.
Read these 5 rules by Rob Pike before any optimization.
http://users.ece.utexas.edu/~adnan/pike.html
Limitations
-----------
Most limitations are voided by increasing your Python and ``bpy`` skills. But
one should also realize what is approriate for a node script to do.
That's it for now.
Scripted Node 2(Generator)
==========================
aka Script Node MK2
- Introduction
- Features
- Structure
- Templates
- Conveniences
- Examples
- Techniques to improve Python performance
- Limitations
Introduction
------------
When you want to express an idea in written form and the concept is suitable
for a one line Python expression then often you can use a Formula node. If you
need access to imports, classes, temporary variables, and functions then you can
write a script to load into Script Node 2.
Script Node MK2 differs from Script Node iteratrion 1 in that offers more control.
It also has a prototype system where you could for example reuse the behavior of
a generator and the template takes care of all the details leaving you to focus
on the function. Scripts using the templates automatically becomes more powerful.
It's a prototype so bug reports, questions and feature request are very welcome.
Features
--------
allows:
- Loading/Reloading scripts currently in TextEditor
- imports and aliasing, ie anything you can import from console works in SN2
- nested functions and lambdas
- named inputs and outputs
- named operators (buttons to action something upon button press)
Structure
---------
At present all scripts for SN2 must:
- be subclasses SvScript
- include a function called process in the class
- have member attributes called ``inputs`` and ``outputs``
- have one Script class per file, if more than one, last one found will be used
**process(self)**
``process(self)`` is the main flow control function. It is called when all sockets
without defaults are connected. Usually the template provides a ``process`` function
for you.
**inputs**
Default can be a float or integer value, not other types are usable yet::
inputs = [
[type, 'socket name on ui', default],
[type, 'socket name on ui2', default],
# ...
]
**outputs**
::
outputs = [
[type, 'socket name on ui'],
[type, 'socket name on ui 2'],
# ...
]
**inputs and outputs**
- Each *socket name on ui* string shall be unique.
- **type** are currently limited to
+---------+-------------------------------------+
| type id | type data |
+=========+=====================================+
| 's' | floats, ints, edges, faces, strings |
+---------+-------------------------------------+
| 'v' | vertices, vectors, 3-tuples |
+---------+-------------------------------------+
| 'm' | matrices, 4 x 4 nested lists |
+---------+-------------------------------------+
There are a series of names that have special meaning that scripts should
avoid as class attributes or only used for the intended meaning. To be described:
``node`` ``draw_buttons`` ``update`` ``process`` ``enum_func`` ``inputs``
``outputs``
Templates
---------
Sverchok includes a series of examples for the different templates.
Conveniences
------------
We value our time, we are sure you do too, so features have been added to help speed up the
script creation process.
**Text Editor**
- can refresh the Script Node which currently loads that script by hitting ``Ctrl+Enter``
Main classes for your subclasses are:
- ``SvScript``
- ``SvScriptSimpleGenerator``
- ``SvScriptSimpleFunction``
Limitations
-----------
Using ``SvScriptSimpleGenerator`` and ``SvScriptSimpleFunction`` you limit inputs to deal with one object.
For plane, for example, you'll get next data:
[(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0)] [(0, 1, 3, 2)]
If you need Full support of Sverchok data - you'd better use ``SvScript``
class and ``self.node.inputs[0].sv_get()`` function.
Examples
--------
The best way to get familiarity with Script Node 2 is to go through the templates folder.
They are intended to be lightweight and educational, but some of them will show
advanced use cases. The images and animations on this `thread on github
<https://github.com/nortikin/sverchok/issues/439>`_.
may also provide some insight into what's possible.
A typical nodescript using the ``SvScriptSimpleGenerator`` may look like this, note that
the third argument for outputs is specific to this template::
import numpy
import itertools
class GridGen(SvScriptSimpleGenerator):
inputs = [("s", "Size", 10.0),
("s", "Subdivs", 10)]
outputs = [("v", "verts", "make_verts"),
("s", "edges", "make_edges")]
@staticmethod
def make_verts(size, sub):
side = numpy.linspace(-size / 2, size / 2, sub)
return tuple((x, y, 0) for x, y in itertools.product(side, side))
@staticmethod
def make_edges(size, sub):
edges = []
for i in range(sub):
for j in range(sub - 1):
edges.append((sub * i + j, sub * i + j + 1))
edges.append((sub * j + i, sub * j + i + sub))
return edges
Note that here the name of the method that should be called for producing data
for each socket in the final last arguments to ``outputs`` but we are not forced
to have all code inside the class, we can also do
::
def lorenz(N, verts, h, a, b, c):
add_vert = verts.append
x0 = 0.1
y0 = 0
z0 = 0
for i in range(N):
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
x0, y0, z0 = x1, y1, z1
add_vert((x1,y1,z1))
class LorenzAttractor(SvScriptSimpleGenerator):
inputs = [
['s', 'N', 1000],
['s', 'h', 0.01],
['s', 'a', 10.0],
['s', 'b', 28.0],
['s', 'c', 8.0/3.0]
]
@staticmethod
def make_verts(N, h, a, b, c):
verts = []
lorenz(N, verts, h, a, b, c)
return verts
@staticmethod
def make_edges(N, h a, b, c:
edges = [(i, i+1) for i in range(N-1)]
return edges
outputs = [
['v','verts', "make_verts"],
['s','edges', "make_edges"]
]
Here is a simple script for deleting loose vertices from mesh data, it also serves as an
illustration for a type of script that uses the ```SvScriptSimpleFunction``` template that
has one main function that decomposes into separate sockets. The methods don't have be static
but in general it is good practice to keep them free from side effects.
::
from itertools import chain
class DeleteLooseVerts(SvScriptSimpleFunction):
inputs = [
('v', 'verts'),
('s', 'pol')
]
outputs = [
('v', 'verts'),
('s', 'pol')
]
# delete loose verts
@staticmethod
def function(*args, **kwargs):
ve, pe = args
# find used indexes
v_index = sorted(set(chain.from_iterable(pe)))
# remap the vertices
v_out = [ve[i] for i in v_index]
# create a mapping from old to new vertices index
mapping = dict(((j, i) for i, j in enumerate(v_index)))
# apply mapping to input polygon index
p_out = [tuple(map(mapping.get, p)) for p in pe]
return v_out, p_out
Breakout Scripts
----------------
Scripts that needs to access the node can do so via the ```self.node``` variable
that is automatically set.
::
class Breakout(SvScript):
def process(self):
pass
def update(self):
node = self.node
node_group = self.node.id_data
# here you can do anything to the node or node group
# that real a real node could do including multisocket
# adaptive sockets etc. templates and examples for this are
# coming
Admit, you can call sockets data directly when using ```SvScript``` as ```self.node.inputs[0].sv_get()```.
And other ```self.node.``` operations possible from this class.
Techniques to improve Python performance
----------------------------------------
There are many ways to speed up python code. Some slowness will be down to
innefficient algorithm design, other slowness is caused purely by how much
processing is minimally required to solve a problem. A decent read regarding
general methods to improve python code performance can be found
on `python.org <https://wiki.python.org/moin/PythonSpeed/PerformanceTips>`_.
If you don't know where the cycles are being consumed, then you don't know
if your efforts to optimize will have any significant impact.
Read these 5 rules by Rob Pike before any optimization.
http://users.ece.utexas.edu/~adnan/pike.html
Limitations
-----------
Most limitations are voided by increasing your Python and ``bpy`` skills. But
one should also realize what is approriate for a node script to do.
That's it for now.
.. _scripted-tutorial:
An introduction and tutorial for the Scripted Nodes
===================================================
> Dealga Mcardle | 2014 | October
In my opinion new users should avoid the Script Nodes until they understand a majority of the existing nodes and the Sverchok `Eco-system` as a concept. This suggestion applies to everyone, even competent coders.
Script Nodes are great when you want to encapsulate a behaviour which may not be easy to achieve with existing nodes alone. They are my prefered way to either 1) prototype code, or 2) write custom nodes that are too specific to be submitted as regular nodes.
At the moment Sverchok has 2 Scripted Node implementations: SN and SN2. Exactly how they differ from eachother will be shown later. Both offer `practical shorthand` ways to define what a node does, which sliders and sane defaults it might have, and what socket types can connect to it. These scripts have a minimal interface, are stored inside the `.blend` file as plain text python, and can be shared easily.
If you've ever written code for a Blender addon or script, you will be familiar with registration of classes. Nodes normally also need to be registered so Blender can find them, but Script Nodes don't because they are in essence a shell for your code -- and the shell is already registered, all you have to do is write code to process input into output.
Scripted Node 1 -- an informal introduction
-------------------------------------------
Here is a classic 'Hello World' style example used to demonstrate graphics coding. It's called a Lorenz Attractor. ::
def lorenz(N, verts):
add_vert = verts.append
h = 0.01
a = 10.0
b = 28.0
c = 8.0 / 3.0
x0 = 0.1
y0 = 0
z0 = 0
for i in range(N):
x1 = x0 + h * a * (y0 - x0)
y1 = y0 + h * (x0 * (b - z0) - y0)
z1 = z0 + h * (x0 * y0 - c * z0)
x0, y0, z0 = x1, y1, z1
add_vert((x1,y1,z1))
def sv_main(N=1000):
verts = []
in_sockets = [['s', 'N', N]]
out_sockets = [['v','verts', [verts]]]
lorenz(N, verts)
return in_sockets, out_sockets
Here's what this code produces.
.. image:: https://cloud.githubusercontent.com/assets/619340/5219883/5d3e1252-765d-11e4-87e8-56e1eef2d5ae.png
Infact, here's the Node Interface that the script produces too
.. image:: https://cloud.githubusercontent.com/assets/619340/5219902/a310c824-765d-11e4-9836-c34cb0d8a7b4.png
Compare the code with the image of the node and you might get a fair idea where the sockets are defined and where the default comes from. Look carefully at
``in_sockets`` and ``out_sockets``, two of the elements are strings (socket type and socket name), and the third element is the Python variable that we automatically bind to those sockets.
Brief Guided Explanation
-------------------------
You've probably got a fair idea already from the example script. SN1 has a few conventions which let you quickly define sockets and defaults. What follows are short remarks about the elements that make up these scripts, aimed at someone who is about to write their first script for SN1.
Sockets
-------
Sverchok at present has 3 main socket types: SvVerticesSocket, SvStringsSocket and SvMatrixSocket. Script Nodes refer to these socket types with only their first letter in lowercase. 's','v','m'::
's' to hold: floats, ints, edges, faces, strings
'v' to hold: vertices, vectors, 3-tuples
'm' to hold: matrices, 4 x 4 nested lists
Socket Names
------------
Each socket has a name. Take a minute to think about a good descriptive name for each. Socket names can always be changed later, but my advice is to use clear names from the very beginning.
Variable names
--------------
Variable names are used to expose the values of the associated socket to your script. If the socket is unconnected then the value of the variable will be taken from the specified default.
node function `(sv_main)`
-------------------------
The main function for SN1 is ``sv_main``, in the body of this function is where we declare socket types, socket names, and variable names for input and output sockets. These are declared in two arrays ``in_sockets`` and ``out_sockets``.
The argument list of ``sv_main`` is where you provide defaults values or the nestedness of an incoming datatype. (don't worry if this makes no sense, read it again later).
That's great, show me!
----------------------
The easiest way to get started is to first load an existing script. Here are some steps:
- Go to `Generators / Scripted Node` and add it to the NodeView.
- Open a Blender TextEditor window so you can see the TextEditor and the NodeView at the same time.
- Paste the Lorenz Attractor script (from above) into the TextEditor and call it 'attractor.py'
- In NodeView look at the field on the second row of the Scripted Node. This is a file selector which shows all Text files in blender. When you click on it you will see "attractor.py"
- Select "attractor.py" press the button the right, the one that looks like a powersocket.
- This changes the way the Node appears. The node will now have 1 input socket and one output socket. It might even have changed to a light blue.
That's pretty much all there is to loading a script. All you do now is hook the output Verts to a Viewer Node and you'll see a classic Lorenz Attractor point set.
Study the sv_main
-----------------
If you look carefully in ``sv_main`` there's not a lot to the whole process. ``sv_main`` has two **required** lists; ``in_sockets`` and ``out_sockets``. sv_main also has a argument list which you must fill with defaults, here the only variable is N so the argument list was ``sv_main(N=1000)``.
The lorenz function takes 2 arguments:
- **N**, to set the number of vertices.
- **verts**, a list-variable to store the vertices generated by the algorithm.
In this example the ``verts`` variable is also what will be sent to the output socket, because it says so in ``out_sockets``. Notice that the lorenz function doesn't return the verts variable. All the lorenz function does is fill that list with values. Just to be clear about this example. At the time ``sv_main`` ends, the content of ``verts`` is full, but before ``lorenz()`` is called, ``verts`` is an empty list.
Here is the same lorenz attractor with more parameters exposed, see can you load it?
https://github.com/nortikin/sverchok/blob/master/node_scripts/templates/zeffii/LorenzAttractor2.py
Lastly
------
If none of this makes sense, spend time learning about Python and dig through the ``node_scripts/templates`` directory.
Set_dataobject
==============
*destination after Beta:*
Functionality
-------------
*It works with a list of objects and a list of Values*
*multiple lists can be combined into one with the help of ListJoin node*
MK2 version can work with multiple nested lists
When there is only one socket Objects- performs **(Object.str)**
If the second socket is connected Values- performs **(Object.str=Value)**
If the second socket is connected OutValues- performs **(OutValue=Object.str)**
*Do not connect both the Values sockets at the same time*
*First word in str must be property or metod of object*
*Use i. prefix in str to bring second property of same object*
Inputs
------
This node has the following inputs:
- **Objects** - only one list of python objects, like **bpy.data.objects** or **mathutils.Vector**
- **values** - only one list of any type values like **tupple** or **float** or **bpy.data.objects**
Outputs
-------
This node has the following outputs:
- **outvalues** - the list of values returned by the **str** expression for each object
Examples of usage
-----------------
.. image:: https://cloud.githubusercontent.com/assets/7894950/7807360/92f00446-0393-11e5-80e5-21f2679a602a.png
.. image:: https://cloud.githubusercontent.com/assets/7894950/7807387/d2ddd2d6-0393-11e5-9c6b-1a6880fd3c65.png
.. image:: https://cloud.githubusercontent.com/assets/7894950/7807409/0b8ad44e-0394-11e5-930f-2416debba804.png
.. image:: https://cloud.githubusercontent.com/assets/7894950/7901468/a50b74ba-0791-11e5-8fb7-296e866e7db4.png
.. image:: https://cloud.githubusercontent.com/assets/22656834/21178380/56ea8b88-c200-11e6-8c38-be16d880f105.png
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать