From 362e2a494eeed2f0453ec72e8c1397b82d095ce4 Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Fri, 4 Nov 2022 18:51:57 +0500 Subject: [PATCH 1/2] "Nurbs if possible" flag for "Curve segment" node. refs #4722. --- nodes/curve/curve_segment.py | 10 +++++++++- utils/curve/algorithms.py | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nodes/curve/curve_segment.py b/nodes/curve/curve_segment.py index 00c07fcad3..8cd66bc3fd 100644 --- a/nodes/curve/curve_segment.py +++ b/nodes/curve/curve_segment.py @@ -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", @@ -48,6 +54,7 @@ def sv_init(self, context): def draw_buttons(self, context, layout): layout.prop(self, "join") + layout.prop(self, "use_nurbs") layout.prop(self, "rescale") def process(self): @@ -67,7 +74,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) diff --git a/utils/curve/algorithms.py b/utils/curve/algorithms.py index be33362b55..61865f83c2 100644 --- a/utils/curve/algorithms.py +++ b/utils/curve/algorithms.py @@ -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: From 70f80c74e120662b3b1d3fc488ea24f4a30aa84c Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Fri, 4 Nov 2022 18:55:52 +0500 Subject: [PATCH 2/2] Update documentation. --- docs/nodes/curve/curve_segment.rst | 7 ++++++- nodes/curve/curve_segment.py | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/nodes/curve/curve_segment.rst b/docs/nodes/curve/curve_segment.rst index 774cc5ee6e..e0f11611bd 100644 --- a/docs/nodes/curve/curve_segment.rst +++ b/docs/nodes/curve/curve_segment.rst @@ -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 diff --git a/nodes/curve/curve_segment.py b/nodes/curve/curve_segment.py index 8cd66bc3fd..276f1ce26d 100644 --- a/nodes/curve/curve_segment.py +++ b/nodes/curve/curve_segment.py @@ -54,9 +54,12 @@ def sv_init(self, context): def draw_buttons(self, context, layout): layout.prop(self, "join") - layout.prop(self, "use_nurbs") 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