29 const IndexRange src_points = src_points_by_curve[curve_i];
36 if (src_points.
size() == 1) {
37 point_counts.
first() = 1;
41 for (
int &
count : point_counts) {
45 if (!cyclic[curve_i]) {
47 point_counts.last() = 1;
52 dst_curve_offsets[curve_i] = point_offsets.
last();
61 const float step = 1.0f / dst.
size();
76 const IndexRange src_points = src_points_by_curve[curve_i];
80 const IndexRange dst_points = dst_points_by_curve[curve_i];
85 for (const int i : range) {
86 const IndexRange segment_points = curve_offsets[i];
87 linear_interpolation(curve_src[i], curve_src[i + 1], curve_dst.slice(segment_points));
91 const IndexRange dst_last_segment = dst_points.
slice(curve_offsets[src_points.size() - 1]);
104 using T = decltype(dummy);
105 subdivide_attribute_linear(src_points_by_curve,
123 const IndexRange src_points = src_points_by_curve[curve_i];
126 const IndexRange dst_points = dst_points_by_curve[curve_i];
129 all_point_offsets.
slice(src_segments),
130 dst.
slice(dst_points));
151 const float3 &handle_prev,
152 const float3 &handle_next,
153 const float3 &position_next,
157 const int dst_next_segment_start,
174 dst_positions[segment_points.
first()] = position_prev;
179 float3 segment_start = position_prev;
180 float3 segment_handle_prev = handle_prev;
181 float3 segment_handle_next = handle_next;
182 const float3 segment_end = position_next;
185 const float parameter = 1.0f / (segment_points.
size() -
i);
186 const int point_i = segment_points[
i];
188 segment_start, segment_handle_prev, segment_handle_next, segment_end, parameter);
191 dst_handles_r[point_i] =
insert.handle_prev;
192 dst_handles_l[point_i + 1] =
insert.left_handle;
193 dst_positions[point_i + 1] =
insert.position;
196 segment_start =
insert.position;
197 segment_handle_prev =
insert.right_handle;
198 segment_handle_next =
insert.handle_next;
202 dst_handles_r[segment_points.
last()] = segment_handle_prev;
203 dst_handles_l[dst_next_segment_start] = segment_handle_next;
229 for (const int segment_i : range) {
230 const IndexRange segment = evaluated_offsets[segment_i];
231 subdivide_bezier_segment(src_positions[segment_i],
232 src_handles_r[segment_i],
233 src_handles_l[segment_i + 1],
234 src_positions[segment_i + 1],
235 HandleType(src_types_r[segment_i]),
236 HandleType(src_types_l[segment_i + 1]),
238 segment.one_after_last(),
248 const int last_index = src_positions.index_range().last();
249 const IndexRange segment = evaluated_offsets[last_index];
250 subdivide_bezier_segment(src_positions.last(),
251 src_handles_r.last(),
252 src_handles_l.first(),
253 src_positions.first(),
265 dst_positions.last() = src_positions.last();
266 dst_types_l.first() = src_types_l.first();
267 dst_types_r.last() = src_types_r.last();
268 dst_handles_l.first() = src_handles_l.first();
269 dst_handles_r.last() = src_handles_r.last();
273 bke::curves::bezier::calculate_auto_handles(
274 cyclic, dst_types_l, dst_types_r, dst_positions, dst_handles_l, dst_handles_r);
310 all_point_offset_data.
fill(-1);
318 all_point_offset_data);
321 const Span<int> all_point_offsets(all_point_offset_data);
332 auto subdivide_catmull_rom = [&](
const IndexMask &selection) {
333 for (
auto &attribute : attributes_to_transfer) {
344 auto subdivide_poly = [&](
const IndexMask &selection) {
345 for (
auto &attribute : attributes_to_transfer) {
355 auto subdivide_bezier = [&](
const IndexMask &selection) {
370 const IndexRange src_points = src_points_by_curve[curve_i];
373 const IndexRange dst_points = dst_points_by_curve[curve_i];
375 src_types_l.
slice(src_points),
376 src_types_r.
slice(src_points),
377 src_handles_l.
slice(src_points),
378 src_handles_r.
slice(src_points),
379 all_point_offsets.
slice(src_segments),
381 dst_positions.
slice(dst_points),
382 dst_types_l.
slice(dst_points),
383 dst_types_r.
slice(dst_points),
384 dst_handles_l.
slice(dst_points),
385 dst_handles_r.
slice(dst_points));
390 "position",
"handle_type_left",
"handle_type_right",
"handle_right",
"handle_left"};
391 for (
auto &attribute : attributes_to_transfer) {
392 if (attributes_to_skip.
contains(attribute.name)) {
406 auto subdivide_nurbs = subdivide_poly;
411 subdivide_catmull_rom,
416 for (
auto &attribute : attributes_to_transfer) {
418 src_points_by_curve, dst_points_by_curve, unselected, attribute.src, attribute.dst.span);
419 attribute.dst.finish();
Low-level operations for curves.
Low-level operations for curves.
#define BLI_assert_unreachable()
void BLI_kdtree_nd_ insert(KDTree *tree, int index, const float co[KD_DIMS]) ATTR_NONNULL(1
constexpr const T & last(const int64_t n=0) const
void fill(const T &value) const
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
GSpan slice(const int64_t start, int64_t size) const
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 slice(int64_t start, int64_t size) const
constexpr IndexRange drop_front(int64_t n) const
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr MutableSpan drop_back(const int64_t n) const
constexpr void fill(const T &value) const
constexpr T & first() const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
bool contains(const Key &key) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr IndexRange index_range() const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
VArray< int8_t > handle_types_left() const
MutableSpan< float3 > positions_for_write()
OffsetIndices< int > points_by_curve() const
MutableSpan< int8_t > handle_types_right_for_write()
VArray< int8_t > handle_types_right() const
IndexRange curves_range() const
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
MutableSpan< float3 > handle_positions_left_for_write()
MutableAttributeAccessor attributes_for_write()
MutableSpan< float3 > handle_positions_right_for_write()
Span< int > offsets() const
std::optional< Span< float3 > > handle_positions_left() const
Span< float3 > positions() const
std::optional< Span< float3 > > handle_positions_right() const
void resize(int points_num, int curves_num)
AttributeAccessor attributes() const
MutableSpan< int > offsets_for_write()
VArray< int8_t > curve_types() const
VArray< bool > cyclic() const
MutableSpan< int8_t > handle_types_left_for_write()
IndexMask complement(const IndexMask &universe, IndexMaskMemory &memory) const
void foreach_index(Fn &&fn) const
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
T mix2(float factor, const T &a, const T &b)
Insertion insert(const float3 &point_prev, const float3 &handle_prev, const float3 &handle_next, const float3 &point_next, float parameter)
bool segment_is_vector(const HandleType left, const HandleType right)
void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, 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)
IndexRange per_curve_point_offsets_range(const IndexRange points, const int curve_index)
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, AttrDomainMask domain_mask, const AttributeFilter &attribute_filter={})
static HandleType aligned_or_free_handle_type(const HandleType type)
static void calculate_result_offsets(const OffsetIndices< int > src_points_by_curve, const IndexMask &selection, const IndexMask &unselected, const VArray< float > &radii, const VArray< int > &counts, const Span< bool > cyclic, MutableSpan< int > dst_curve_offsets, MutableSpan< int > dst_point_offsets)
static void subdivide_bezier_positions(const Span< float3 > src_positions, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const OffsetIndices< int > evaluated_offsets, const bool cyclic, MutableSpan< float3 > dst_positions, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r)
static void linear_interpolation(const T &a, const T &b, MutableSpan< T > dst)
bke::CurvesGeometry subdivide_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, const VArray< int > &cuts, const bke::AttributeFilter &attribute_filter={})
static void subdivide_attribute_catmull_rom(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &selection, const Span< int > all_point_offsets, const Span< bool > cyclic, const GSpan src, GMutableSpan dst)
static void subdivide_bezier_segment(const float3 &position_prev, const float3 &handle_prev, const float3 &handle_next, const float3 &position_next, const HandleType type_prev, const HandleType type_next, const IndexRange segment_points, const int dst_next_segment_start, MutableSpan< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
static void subdivide_attribute_linear(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &selection, const Span< int > all_point_offsets, const Span< T > src, MutableSpan< T > dst)
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)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< float, 3 > float3
ListBase vertex_group_names