Skip to content

Commit

Permalink
Control Points Output to Curve Mapper (#3994)
Browse files Browse the repository at this point in the history
* Control Points Output to Curve Mapper

* update docs
  • Loading branch information
vicdoval authored Mar 28, 2021
1 parent efc6c32 commit e78e7be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/nodes/number/curve_mapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This node has the following outputs:
always lying in XOY plane along the OX axis. The domain of the curve is
defined by **Min X** and **Max X** parameters, which are defined in the curve
editor widget.
* **Control Points: Location over the XOY Plane of the control points of the widget.
It can be used as a 2D slider.
Examples
--------
Expand All @@ -40,9 +42,8 @@ Basic range remapping:

Using the node to define the column profile:

.. image:: https://raw.githubusercontent.com/vicdoval/sverchok/docs_images/images_for_docs/number/Curve%20Mapper/curve_mapper_sverchok__blender_example_2.png
.. image:: https://raw.githubusercontent.com/vicdoval/sverchok/docs_images/images_for_docs/number/Curve%20Mapper/curve_mapper_sverchok__blender_example_2.png

Example of the Curve output usage:

.. image:: https://user-images.githubusercontent.com/284644/80520701-4051d200-89a3-11ea-92fd-2f2f2004e4e7.png

11 changes: 8 additions & 3 deletions nodes/number/curve_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
get_valid_node,
CURVE_NODE_TYPE,
set_rgb_curve,
get_rgb_curve)
get_rgb_curve,
get_points_from_curve)

from sverchok.utils.curve import SvScalarFunctionCurve

Expand Down Expand Up @@ -71,6 +72,7 @@ def sv_init(self, context):

self.outputs.new('SvStringsSocket', "Value")
self.outputs.new('SvCurveSocket', "Curve")
self.outputs.new('SvVerticesSocket', "Control Points")
_ = get_evaluator(node_group_name, self._get_curve_node_name())


Expand Down Expand Up @@ -111,6 +113,9 @@ def process(self):
curve = SvScalarFunctionCurve(evaluate)
curve.u_bounds = (curve_node.mapping.clip_min_x, curve_node.mapping.clip_max_x)
self.outputs['Curve'].sv_set([curve])
if 'Control Points' in self.outputs:
points = get_points_from_curve(node_group_name, curve_node_name)
self.outputs['Control Points'].sv_set(points)

# no outputs, end early.
if not outputs['Value'].is_linked:
Expand Down Expand Up @@ -138,8 +143,8 @@ def save_to_json(self, node_data: dict):
node_data['curve_data'] = data_json_str

def sv_copy(self, other):
'''
self: is the new node, other: is the old node
'''
self: is the new node, other: is the old node
by the time this function is called the new node has a new empty n_id
a new n_id will be generated as a side effect of _get_curve_node_name
'''
Expand Down
17 changes: 16 additions & 1 deletion utils/sv_manual_curves_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_rgb_curve(group_name, node_name):

def set_rgb_curve(data_dict, curve_node_name):
'''
stores RGB Curves data into json
stores RGB Curves data into json
'''

group_name = data_dict['group_name']
Expand All @@ -130,3 +130,18 @@ def set_rgb_curve(data_dict, curve_node_name):
curve.points[pidx].handle_type = handle_type
curve.points[pidx].location = location
node.mapping.update()

def get_points_from_curve(group_name, node_name):
'''
get control points from curve
'''
node_groups = bpy.data.node_groups
group = node_groups.get(group_name)
node = group.nodes.get(node_name)

out_list = []

points = node.mapping.curves[-1].points
out_list.append([[p.location[0], p.location[1], 0] for p in points])

return out_list

0 comments on commit e78e7be

Please sign in to comment.