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 00c07fcad3..276f1ce26d 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", @@ -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 @@ -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) 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: