29 const int *src = intervals.
data();
33 int *dst = intervals.
data() + intervals_by_curve[0].
size() - 1;
36 const IndexRange range = intervals_by_curve[curve];
38 const int width = range.
size() - 2;
39 std::copy_n(src + range.
first() + 1, width, dst);
42 (*dst) = src[intervals_by_curve[intervals_by_curve.
size() - 1].last()];
43 return {intervals.
data(), dst - intervals.
data() + 1};
52 int current_endpoint_index = 0;
53 curves_intervals_offsets.
first() = 0;
62 is_first_selected[curve] = first_range.
first() == curve_points.
start() &&
63 first_range.
size() == 1 &&
66 curve_points.
size() != 1;
67 current_endpoint_index += !is_first_selected[curve];
68 copy_intervals[curves_intervals_offsets[curve]] = curve_points.
start();
70 for (
const IndexRange range : selected_point_ranges) {
71 copy_intervals[current_endpoint_index++] = range.
first();
72 copy_intervals[current_endpoint_index++] = range.
last();
75 const int last_interval_index = current_endpoint_index - 1;
76 if (copy_intervals[last_interval_index] != curve_points.
last() ||
77 copy_intervals[last_interval_index - 1] != copy_intervals[last_interval_index])
81 copy_intervals[current_endpoint_index++] = curve_points.
last();
84 curves_intervals_offsets[curve + 1] = current_endpoint_index;
87 for (
const int curve :
curves) {
88 const IndexRange curve_points = points_by_curve[curve];
90 is_first_selected[curve] =
false;
91 copy_intervals[current_endpoint_index++] = curve_points.
first();
92 copy_intervals[current_endpoint_index++] = curve_points.
last();
93 curves_intervals_offsets[curve + 1] = current_endpoint_index;
102 new_offsets.
first() = 0;
105 for (
const int i : index_range) {
110 new_offsets[i] = old_offsets[i] + curves_intervals_offsets[i] - 2 * i;
125 return math::abs(value) < 0.00001 ? 0.0 : value;
135 const IndexMask custom_knot_curves =
curves.nurbs_custom_knot_curves(memory);
145 const int order = orders[curve];
146 const bool is_first_interval_selected = is_first_selected[curve];
153 curve_span_data[span] =
clamp_to_zero(src_curve_knots[1] - src_curve_knots[0]);
154 span_multiplicity[span] = 1;
157 const float span_value =
clamp_to_zero(src_curve_knots[i + 1] - src_curve_knots[i]);
158 const bool is_new =
abs(curve_span_data[span] - span_value) >= 0.00001;
160 curve_span_data[span] = span_value;
161 span_multiplicity[span]++;
166 const IndexRange curve_intervals = intervals_by_curve[curve];
168 copy_intervals.
data().slice(curve_intervals).drop_front(1).drop_back(1);
169 const int first_curve_point = copy_intervals.
data()[curve_intervals.
first()];
171 increase_span_multiplicity.
reserve(duplicated_points.
size());
172 int first_span_knot = 0;
175 for (
const int i : duplicated_points.
index_range()) {
176 const bool is_selected = bool(i % 2) != is_first_interval_selected;
177 const int point = duplicated_points[i] - first_curve_point;
178 while (first_span_knot + span_multiplicity[span] <= point) {
179 first_span_knot += span_multiplicity[span];
183 int multiplicity = point - first_span_knot;
184 int point_span = span;
185 std::array<int, 2> side_spans{point_span, point_span};
187 for ([[maybe_unused]]
const int i :
IndexRange(order)) {
189 if (multiplicity > span_multiplicity[point_span]) {
193 if (curve_spans[point_span] == 0.0) {
196 side_spans[side] = point_span;
198 side_spans[side] = point_span;
200 increase_span_multiplicity.
append(side_spans[is_selected]);
202 for (
const int span : increase_span_multiplicity) {
203 span_multiplicity[span]++;
209 float knot_value = src_curve_knots[knot];
210 dst_curve_knots[knot++] = knot_value;
212 for ([[maybe_unused]]
const int k :
IndexRange(span_multiplicity[span])) {
213 knot_value += curve_spans[span];
214 dst_curve_knots[knot++] = knot_value;
227 const int curves_num =
curves.curves_num();
234 Array<int> copy_interval_offsets(extruded_points.
size() * 2 + curves_num * 2);
239 Array<int> curves_intervals_offsets(curves_num + 1);
248 copy_interval_offsets,
249 curves_intervals_offsets,
258 std::array<GVArraySpan, 3> src_selection;
259 std::array<bke::GSpanAttributeWriter, 3> dst_selections;
262 for (
const int selection_i : selection_attr_names.
index_range()) {
263 const StringRef selection_name = selection_attr_names[selection_i];
266 if (!src_selection_array) {
270 src_selection[selection_i] = src_selection_array;
280 0, curves_intervals_offsets.
last());
283 for (const int curve : curves_range) {
284 const int first_index = intervals_by_curve[curve].start();
285 const int first_value = copy_intervals[first_index].start();
286 const bool first_selected = is_first_selected[curve];
288 for (const int i : intervals_by_curve[curve].drop_back(1)) {
289 const bool is_selected = bool((i - first_index) % 2) != first_selected;
290 const IndexRange src = shift_end_by(copy_intervals[i], 1);
291 const IndexRange dst = src.shift(new_offsets[curve] - first_value + i - first_index);
293 for (const int selection_i : selection_attr_names.index_range()) {
294 GMutableSpan dst_span = dst_selections[selection_i].span.slice(dst);
296 GSpan src_span = src_selection[selection_i].slice(src);
297 src_selection[selection_i].type().copy_assign_n(
298 src_span.data(), dst_span.data(), src.size());
301 fill_selection(dst_span, false);
308 for (
const int selection_i : selection_attr_names.index_range()) {
309 dst_selections[selection_i].finish();
312 if (
curves.nurbs_has_custom_knots()) {
317 copy_interval_offsets);
319 bke::MutableAttributeAccessor dst_attributes = new_curves.attributes_for_write();
327 const CPPType &type =
attribute.src.type();
329 for (const int i : range) {
330 const IndexRange src = shift_end_by(compact_intervals[i], 1);
331 const IndexRange dst = src.shift(i);
333 attribute.src.slice(src).data(), attribute.dst.span.slice(dst).data(), src.size());
343 bool extruded =
false;
366 ot->
name =
"Extrude";
367 ot->
description =
"Extrude selected control point(s)";
368 ot->
idname =
"CURVES_OT_extrude";
Low-level operations for curves.
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
const T & last(const int64_t n=0) const
const CPPType & type() const
constexpr int64_t first() const
constexpr IndexRange shift(int64_t n) 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
static constexpr IndexRange from_begin_size(const int64_t begin, const int64_t size)
constexpr int64_t start() const
constexpr IndexRange drop_front(int64_t n) const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr T * data() 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 IndexRange index_range() const
static VArray from_single(T value, const int64_t size)
void append(const T &value)
void reserve(const int64_t min_capacity)
GAttributeReader lookup(const StringRef name) const
void resize(int points_num, int curves_num)
OffsetIndices< int > nurbs_custom_knots_by_curve() const
MutableSpan< float > nurbs_custom_knots_for_write()
MutableSpan< int > offsets_for_write()
void nurbs_custom_knots_update_size()
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() const
void foreach_selected_point_ranges_per_curve(const IndexMask &mask, OffsetIndices< int > points_by_curve, SelectedCallback selected_fn)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
static bke::CurvesGeometry extrude_curves(const bke::CurvesGeometry &curves, const IndexMask &extruded_points)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
static void calc_new_offsets(const Span< int > old_offsets, const Span< int > curves_intervals_offsets, MutableSpan< int > new_offsets)
VectorSet< Curves * > get_unique_editable_curves(const bContext &C)
static void calc_curves_extrusion(const IndexMask &selection, const OffsetIndices< int > points_by_curve, MutableSpan< int > copy_intervals, MutableSpan< int > curves_intervals_offsets, MutableSpan< bool > is_first_selected)
static float clamp_to_zero(const float value)
bool editable_curves_in_edit_mode_poll(bContext *C)
static void extrude_knots(const bke::CurvesGeometry &curves, const OffsetIndices< int > intervals_by_curve, const OffsetIndices< int > copy_intervals, const Span< bool > is_first_selected, bke::CurvesGeometry &dst_curves)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
static Span< int > compress_intervals(const OffsetIndices< int > intervals_by_curve, MutableSpan< int > intervals)
static wmOperatorStatus curves_extrude_exec(bContext *C, wmOperator *)
static IndexRange shift_end_by(const IndexRange &range, const int n)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
void CURVES_OT_extrude(wmOperatorType *ot)
constexpr ParallelGrainSize grain_size(int grain_size)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void DEG_id_tag_update(ID *id, unsigned int flags)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT