43 dst[i] = src[i *
scale + offset];
53 dst_positions[i * 3] = src_handles_l[i];
54 dst_positions[i * 3 + 1] = src_positions[i];
55 dst_positions[i * 3 + 2] = src_handles_r[i];
67 constexpr float handle_scale = 1.0f / 6.0f;
69 if (src_positions.
size() == 1) {
75 const float3 first_offset = cyclic ? src_positions[1] - src_positions.
last() :
76 src_positions[1] - src_positions[0];
77 dst_handles_r.
first() = src_positions.
first() + first_offset * handle_scale;
78 dst_handles_l.
first() = src_positions.
first() - first_offset * handle_scale;
80 const float3 last_offset = cyclic ? src_positions.
first() - src_positions.
last(1) :
81 src_positions.
last() - src_positions.
last(1);
82 dst_handles_l.
last() = src_positions.
last() - last_offset * handle_scale;
83 dst_handles_r.
last() = src_positions.
last() + last_offset * handle_scale;
86 const float3 left_offset = src_positions[i - 1] - src_positions[i + 1];
87 dst_handles_l[i] = src_positions[i] + left_offset * handle_scale;
89 const float3 right_offset = src_positions[i + 1] - src_positions[i - 1];
90 dst_handles_r[i] = src_positions[i] + right_offset * handle_scale;
109 const int nurbs_positions_num = nurbs_positions.
size();
115 handle_positions.
append(nurbs_positions[1] +
116 ((nurbs_positions[0] - nurbs_positions[1]) / 3));
119 handle_positions.
append(2 * nurbs_positions[0] - nurbs_positions[1]);
120 handle_positions.
append(nurbs_positions[1]);
125 const int segments_num = nurbs_positions_num - 1;
126 const bool ignore_interior_segment = segments_num == 3 && is_periodic ==
false;
127 if (ignore_interior_segment ==
false) {
128 const float mid_offset =
float(segments_num - 1) / 2.0f;
129 for (
const int i :
IndexRange(1, segments_num - 2)) {
131 const int divisor = is_periodic ?
133 std::min(3,
int(-std::abs(i - mid_offset) + mid_offset + 1.0f));
134 const float3 &p1 = nurbs_positions[i];
135 const float3 &p2 = nurbs_positions[i + 1];
136 const float3 displacement = (p2 - p1) / divisor;
137 const int num_handles_on_segment = divisor < 3 ? 1 : 2;
138 for (
int j :
IndexRange(1, num_handles_on_segment)) {
139 handle_positions.
append(p1 + (displacement * j));
144 const int last_index = nurbs_positions_num - 1;
147 nurbs_positions[last_index - 1] +
148 ((nurbs_positions[last_index] - nurbs_positions[last_index - 1]) / 3));
151 handle_positions.
append(nurbs_positions[last_index - 1]);
152 handle_positions.
append(2 * nurbs_positions[last_index] - nurbs_positions[last_index - 1]);
156 for (
const int i :
IndexRange(nurbs_positions_num)) {
160 handle_positions.
append(nurbs_positions[i]);
162 if (nurbs_positions_num % 3 == 1) {
165 else if (nurbs_positions_num % 3 == 2) {
166 const int last_index = nurbs_positions_num - 1;
167 handle_positions.
append(2 * nurbs_positions[last_index] - nurbs_positions[last_index - 1]);
171 return handle_positions;
180 for (
const int i : bezier_positions.
index_range()) {
182 handle_positions[i * 2], handle_positions[i * 2 + 1], 0.5f);
199 return cyclic ? src_size : std::max(1, src_size - 2);
201 return (src_size + 1) / 3;
244 src_points_by_curve[i].size());
260 "position",
"handle_type_left",
"handle_type_right",
"handle_right",
"handle_left"};
262 attributes_to_skip.add_new(
"nurbs_weight");
265 auto catmull_rom_to_bezier = [&](
const IndexMask &selection) {
271 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
275 const IndexRange src_points = src_points_by_curve[i];
276 const IndexRange dst_points = dst_points_by_curve[i];
279 dst_handles_l.
slice(dst_points),
280 dst_handles_r.
slice(dst_points));
285 if (attributes_to_skip.contains(
attribute.name)) {
289 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
293 auto poly_to_bezier = [&](
const IndexMask &selection) {
295 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
302 if (attributes_to_skip.contains(
attribute.name)) {
306 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
310 auto bezier_to_bezier = [&](
const IndexMask &selection) {
317 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
319 src_points_by_curve, dst_points_by_curve, selection, src_handles_l, dst_handles_l);
321 src_points_by_curve, dst_points_by_curve, selection, src_handles_r, dst_handles_r);
323 src_points_by_curve, dst_points_by_curve, selection, src_types_l, dst_types_l);
325 src_points_by_curve, dst_points_by_curve, selection, src_types_r, dst_types_r);
330 if (attributes_to_skip.contains(
attribute.name)) {
334 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
338 auto nurbs_to_bezier = [&](
const IndexMask &selection) {
346 const IndexRange src_points = src_points_by_curve[i];
347 const IndexRange dst_points = dst_points_by_curve[i];
349 if (dst_points.
size() == 1) {
363 nurbs_positions_vector.
extend(src_curve_positions);
364 nurbs_positions_vector.
append(src_curve_positions[0]);
365 nurbs_positions_vector.
append(src_curve_positions[1]);
366 nurbs_positions = nurbs_positions_vector;
377 nurbs_positions, handle_positions, knots_mode, dst_positions.
slice(dst_points));
382 dst_points_by_curve, selection, memory);
385 [&](
const int curve) {
386 const IndexRange src_points = src_points_by_curve[curve];
387 const IndexRange dst_points = dst_points_by_curve[curve];
389 switch (
KnotsMode(src_knot_modes[curve])) {
392 dst[i] = src_points[(i + 1) % src_points.
size()];
397 dst[i] = src_points[i + 1];
405 dst[i] = src_points[i * 3 + 1];
413 if (attributes_to_skip.contains(
attribute.name)) {
424 catmull_rom_to_bezier,
431 src_points_by_curve, dst_points_by_curve, unselected,
attribute.src,
attribute.dst.span);
478 auto fill_weights_if_necessary = [&](
const IndexMask &selection) {
479 if (src_attributes.
contains(
"nurbs_weight")) {
485 auto bezier_to_nurbs_copy_attributes = [&](
const IndexMask &selection) {
487 dst_points_by_curve, selection, memory);
490 [&](
const int curve) {
491 const IndexRange src_points = src_points_by_curve[curve];
492 const IndexRange dst_points = dst_points_by_curve[curve];
497 dst[i * 3] = src_points[i];
498 dst[i * 3 + 1] = src_points[i];
499 dst[i * 3 + 2] = src_points[i];
505 if (attributes_to_skip.contains(
attribute.name)) {
513 auto catmull_rom_to_nurbs = [&](
const IndexMask &selection) {
517 fill_weights_if_necessary(selection);
521 for (
const int i : segment) {
522 const IndexRange src_points = src_points_by_curve[i];
523 const IndexRange dst_points = dst_points_by_curve[i];
525 src_positions.
slice(src_points), src_cyclic[i], dst_positions.
slice(dst_points));
530 bezier_to_nurbs_copy_attributes(selection);
533 auto poly_to_nurbs = [&](
const IndexMask &selection) {
536 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
537 fill_weights_if_necessary(selection);
558 if (attributes_to_skip.contains(
attribute.name)) {
562 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
566 auto bezier_to_nurbs = [&](
const IndexMask &selection) {
573 fill_weights_if_necessary(selection);
577 const IndexRange src_points = src_points_by_curve[i];
578 const IndexRange dst_points = dst_points_by_curve[i];
580 src_handles_l.
slice(src_points),
581 src_handles_r.
slice(src_points),
582 dst_positions.
slice(dst_points));
586 bezier_to_nurbs_copy_attributes(selection);
589 auto nurbs_to_nurbs = [&](
const IndexMask &selection) {
591 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
602 if (attributes_to_skip.contains(
attribute.name)) {
606 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
613 catmull_rom_to_nurbs,
620 src_points_by_curve, dst_points_by_curve, unselected,
attribute.src,
attribute.dst.span);
646 options.convert_bezier_handles_to_catmull_rom_points :
647 options.convert_bezier_handles_to_poly_points;
669 const IndexRange src_points = src_points_by_curve[i];
671 int &size = dst_offsets[i];
673 size = src_points.
size() * 3;
676 size = src_points.
size();
695 auto convert_from_catmull_rom_or_poly_or_nurbs = [&](
const IndexMask &selection) {
697 src_points_by_curve, dst_points_by_curve, selection, src_positions, dst_positions);
699 if (attributes_to_skip.contains(
attribute.name)) {
703 src_points_by_curve, dst_points_by_curve, selection,
attribute.src,
attribute.dst.span);
707 auto convert_from_bezier = [&](
const IndexMask &selection) {
713 const IndexRange src_points = src_points_by_curve[curve_i];
714 const IndexRange dst_points = dst_points_by_curve[curve_i];
716 const int src_point_i = src_points[i];
717 const int dst_points_start = dst_points.
start() + 3 * i;
718 dst_positions[dst_points_start + 0] = src_left_handles[src_point_i];
719 dst_positions[dst_points_start + 1] = src_positions[src_point_i];
720 dst_positions[dst_points_start + 2] = src_right_handles[src_point_i];
726 if (attributes_to_skip.contains(
attribute.name)) {
731 const IndexRange src_points = src_points_by_curve[curve_i];
732 const IndexRange dst_points = dst_points_by_curve[curve_i];
734 const int src_point_i = src_points[i];
735 const int dst_points_start = dst_points.
start() + 3 * i;
736 const void *src_value =
attribute.src[src_point_i];
746 convert_from_catmull_rom_or_poly_or_nurbs,
747 convert_from_catmull_rom_or_poly_or_nurbs,
749 convert_from_catmull_rom_or_poly_or_nurbs);
753 src_points_by_curve, dst_points_by_curve, unselected,
attribute.src,
attribute.dst.span);
795 src_curves, selection, dst_type, attribute_filter,
options);
799 if (!
options.keep_bezier_shape_as_nurbs || !
options.keep_catmull_rom_shape_as_nurbs) {
802 src_curves, selection,
options);
Low-level operations for curves.
Low-level operations for curves.
#define BLI_assert_unreachable()
MutableSpan< T > as_mutable_span()
void fill_assign_n(const void *value, void *dst, int64_t n) const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr int64_t first() const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
constexpr IndexRange index_range() const
constexpr IndexRange drop_front(int64_t n) const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr T & first() const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
T get_internal_single() const
void append(const T &value)
void extend(Span< T > array)
Span< T > as_span() const
bool contains(StringRef name) const
MutableSpan< int8_t > handle_types_left_for_write()
VArray< int8_t > curve_types() const
std::optional< Span< float > > nurbs_weights() const
void calculate_bezier_auto_handles()
MutableSpan< int8_t > nurbs_orders_for_write()
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
std::optional< Span< float3 > > handle_positions_right() const
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
MutableSpan< float3 > handle_positions_right_for_write()
void remove_attributes_based_on_types()
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
VArray< int8_t > nurbs_knots_modes() const
MutableSpan< int8_t > nurbs_knots_modes_for_write()
VArray< int8_t > handle_types_left() const
MutableSpan< float3 > handle_positions_left_for_write()
bool has_curve_with_type(CurveType type) const
MutableSpan< int > offsets_for_write()
void fill_curve_types(CurveType type)
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
MutableSpan< float > nurbs_weights_for_write()
VArray< int8_t > handle_types_right() const
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
int64_t min_array_size() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
CCL_NAMESPACE_BEGIN struct Options options
float3x3 scale(float3x3 mat, float2 scale)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void copy_custom_knots(const bke::CurvesGeometry &src_curves, const IndexMask &exclude_curves, bke::CurvesGeometry &dst_curves)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
void fill_points(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, GPointer value, GMutableSpan dst)
IndexMask curve_to_point_selection(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, LinearAllocator<> &memory)
void foreach_curve_by_type(const VArray< int8_t > &types, const std::array< int, CURVE_TYPES_NUM > &type_counts, const IndexMask &selection, FunctionRef< void(IndexMask)> catmull_rom_fn, FunctionRef< void(IndexMask)> poly_fn, FunctionRef< void(IndexMask)> bezier_fn, FunctionRef< void(IndexMask)> nurbs_fn)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
constexpr ParallelGrainSize grain_size(int grain_size)
static bke::CurvesGeometry convert_bezier_or_catmull_rom_to_poly_before_conversion_to_nurbs(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const ConvertCurvesOptions &options)
static bool is_nurbs_to_bezier_one_to_one(const KnotsMode knots_mode)
static void create_nurbs_to_bezier_positions(const Span< float3 > nurbs_positions, const Span< float3 > handle_positions, const KnotsMode knots_mode, MutableSpan< float3 > bezier_positions)
static void bezier_positions_to_nurbs(const Span< float3 > src_positions, const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, MutableSpan< float3 > dst_positions)
static int to_nurbs_size(const CurveType src_type, const int src_size)
static void catmull_rom_to_bezier_handles(const Span< float3 > src_positions, const bool cyclic, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r)
static bke::CurvesGeometry convert_curves_trivial(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const CurveType dst_type)
static void catmull_rom_to_nurbs_positions(const Span< float3 > src_positions, const bool cyclic, MutableSpan< float3 > dst_positions)
static Vector< float3 > create_nurbs_to_bezier_handles(const Span< float3 > nurbs_positions, const KnotsMode knots_mode)
static void scale_input_assign(const Span< T > src, const int scale, const int offset, MutableSpan< T > dst)
static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const bke::AttributeFilter &attribute_filter)
static bke::CurvesGeometry convert_curves_to_catmull_rom_or_poly(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const CurveType dst_type, const bke::AttributeFilter &attribute_filter, const ConvertCurvesOptions &options)
static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const bke::AttributeFilter &attribute_filter)
static int to_bezier_size(const CurveType src_type, const bool cyclic, const KnotsMode knots_mode, const int src_size)
bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, CurveType dst_type, const bke::AttributeFilter &attribute_filter, const ConvertCurvesOptions &options={})
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T interpolate(const T &a, const T &b, const FactorT &t)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
@ NURBS_KNOT_MODE_ENDPOINT
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
VecBase< float, 3 > float3
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< struct bDeformGroup > vertex_group_names