Adds a new operator in Grease Pencil edit mode to convert between curve
types. This acts as a replacment for the `Set Curve Type` operator as
the new operator better aligns with previous workflows and artist
expectations. Specifically using a threshold to adjust how well the
resulting curves fit to the original.
It can be found in the `Stroke` > `Convert Type` menu.
This operator aims at keeping visual fidelity between the curves. When
converting to a non-poly curve type, there's a `threshold` parameter
that dictates how closley the shapes will match (a value of zero meaning
an almost perfect match, and higher values will result in less accuracy
but lower control point count).
The conversion to `Catmull-Rom` does not do an actual curve fitting.
For now, this will resample the curves and then do an adaptive
simplification of the line (using the threshold parameter)
to simulate a curve fitting.
The `Set Curve Type` operator is no longer exposed in the
`Stroke` menu.
This also adds a new `geometry::fit_curves` function.
The function will fit a selection of curves to bézier curves. The
selected curves are treated as if they were poly curves.
The `thresholds` virtual array is the error threshold distance
for each curve that the fit should be within. The size of the virtual
array is assumed to have the same size as the total number of
input curves.
The `corners` virtual array allows specific input points to be treated
as sharp corners. The resulting bezier curve will have this point and
the handles will be set to "free".
There are two fitting methods:
* **Split**: Uses a least squares solver to find the control
points (faster, but less accurate).
* **Refit**: Iteratively removes knots with the least error starting
with a dense curve (slower, more accurate fit).
Co-authored-by: Casey Bianco-Davis <caseycasey739@gmail.com>
Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/137808
43 lines
1.6 KiB
C++
43 lines
1.6 KiB
C++
/* SPDX-FileCopyrightText: 2025 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BKE_curves.hh"
|
|
|
|
namespace blender::geometry {
|
|
|
|
enum class FitMethod {
|
|
/**
|
|
* Iteratively removes knots/control points with the least error starting with a dense curve.
|
|
*/
|
|
Refit,
|
|
/**
|
|
* Uses a least squares solver to recursively find the control points.
|
|
*/
|
|
Split
|
|
};
|
|
|
|
/**
|
|
* Fit the selected curves to Bézier curves.
|
|
*
|
|
* \param src_curves: The input curves.
|
|
* \param curve_selection: A selection of curves to fit. The selected curves will be replaced by
|
|
* the fitted bézier curves and the unselected curves are copied to the output geometry.
|
|
* \param thresholds: A error threshold (fit distance) for each input curve. The fitted curve
|
|
* should be within this distance.
|
|
* \param corners: Boolean value for each input point. When this is true, the point is treated as a
|
|
* corner in the curve fitting. The resulting bézier curve will include this point and the handles
|
|
* will be "free", resulting in a sharp corner.
|
|
* \param method: The fitting algorithm to use. See #FitMethod.
|
|
*/
|
|
bke::CurvesGeometry fit_poly_to_bezier_curves(const bke::CurvesGeometry &src_curves,
|
|
const IndexMask &curve_selection,
|
|
const VArray<float> &thresholds,
|
|
const VArray<bool> &corners,
|
|
FitMethod method,
|
|
const bke::AttributeFilter &attribute_filter);
|
|
|
|
} // namespace blender::geometry
|