Skip to content

Commit

Permalink
Merge pull request #4740 from nortikin/curve_segment_native_flag
Browse files Browse the repository at this point in the history
"Curve Segment" node: add "NURBS if possible" flag
  • Loading branch information
portnov authored Nov 4, 2022
2 parents a37b6e5 + 70f80c7 commit d3ea178
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion docs/nodes/curve/curve_segment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ This node has the following inputs:
Parameters
----------

This node has the following parameter:
This node has the following parameters:

* **Join**. If checked, the node will always output single flat list of curves.
* **NURBS if possible**. If checked, for NURBS and NURBS-like curves, the node
will calculate a new NURBS curve representing the segment of initial curve.
If not checked, the node will always return a generic Curve object. Checked
by default. This parameter is available in the N panel only.
* **Rescale to 0..1**. If checked, then the generated curve will have the
domain (allowed range of T parameter values) of `[0.0 .. 1.0]`. Otherwise,
the domain of generated curve will be defined by node's inputs, i.e. `[TMin
Expand Down
13 changes: 12 additions & 1 deletion nodes/curve/curve_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class SvCurveSegmentNode(SverchCustomTreeNode, bpy.types.Node):
default = False,
update = updateNode)

use_nurbs : BoolProperty(
name = "NURBS if possible",
description = "If checked, for NURBS curves, calculate a new NURBS curve representing the segment of the old curve. Otherwise, always return a generic Curve object.",
default = True,
update = updateNode)

join : BoolProperty(
name = "Join",
description = "Output single flat list of curves",
Expand All @@ -50,6 +56,10 @@ def draw_buttons(self, context, layout):
layout.prop(self, "join")
layout.prop(self, "rescale")

def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)
layout.prop(self, "use_nurbs")

def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
Expand All @@ -67,7 +77,8 @@ def process(self):
for curves, tmins, tmaxs in zip_long_repeat(curve_s, tmin_s, tmax_s):
new_curves = []
for curve, t_min, t_max in zip_long_repeat(curves, tmins, tmaxs):
new_curve = curve_segment(curve, t_min, t_max, self.rescale)
new_curve = curve_segment(curve, t_min, t_max,
use_native = self.use_nurbs, rescale = self.rescale)
new_curves.append(new_curve)
if self.join:
curve_out.extend(new_curves)
Expand Down
6 changes: 3 additions & 3 deletions utils/curve/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,14 +1026,14 @@ def split_curve(curve, splits, rescale=False):
result.append(segment)
return result

def curve_segment(curve, new_t_min, new_t_max, rescale=False):
def curve_segment(curve, new_t_min, new_t_max, use_native=True, rescale=False):
"""
Cut a segment out of the curve.
"""
t_min, t_max = curve.get_u_bounds()
if hasattr(curve, 'cut_segment'):
if use_native and hasattr(curve, 'cut_segment'):
return curve.cut_segment(new_t_min, new_t_max, rescale=rescale)
elif hasattr(curve, 'split_at') and (new_t_min > t_min or new_t_max < t_max):
elif use_native and hasattr(curve, 'split_at') and (new_t_min > t_min or new_t_max < t_max):
if new_t_min > t_min:
start, curve = curve.split_at(new_t_min)
if new_t_max < t_max:
Expand Down

0 comments on commit d3ea178

Please sign in to comment.