41 const int curve_index,
44 if (points_to_transform_per_attr.
size() == 1) {
54 const IndexMask &selected_points = points_to_transform_per_attr[0];
56 points_to_transform_per_attr[1], selected_points, memory);
59 const IndexMask selected_right_handles = evaluate_expression(
60 builder.
subtract({&points_to_transform_per_attr[2]},
61 {&selected_left_handles, &selected_points}),
65 selected_left_handles, selected_right_handles, memory);
74 aligned_handles_to_selection(handle_types_left),
75 aligned_handles_to_selection(handle_types_right),
79 selected_left_handles, both_aligned, transform_data.
memory);
81 selected_right_handles, both_aligned, transform_data.
memory);
96 visited[
index] =
true;
98 const int left_i =
index - 1;
99 if (left_i >= 0 && !visited[left_i]) {
100 const float left_dist = r_distances[
index] +
102 if (left_dist < r_distances[left_i]) {
103 r_distances[left_i] = left_dist;
108 const int right_i =
index + 1;
109 if (right_i < positions.
size() && !visited[right_i]) {
110 const float right_dist = r_distances[
index] +
112 if (right_dist < r_distances[right_i]) {
113 r_distances[right_i] = right_dist;
129 if (visited[
index]) {
132 visited[
index] =
true;
135 const float left_dist = r_distances[
index] +
137 if (left_dist < r_distances[left_i] && !visited[left_i]) {
138 r_distances[left_i] = left_dist;
143 const float right_dist = r_distances[
index] +
145 if (right_dist < r_distances[right_i] && !visited[right_i]) {
146 r_distances[right_i] = right_dist;
157 if (
const std::optional<int8_t> single_type = types.
get_if_single()) {
162 handles, memory, [&](
const int64_t i) {
return types_span[i] == type; });
169 const IndexMask &selected_handles_opposite,
174 const IndexMask convert_to_align = evaluate_expression(
177 &builder.intersect({&selected_handles, &auto_handles}),
180 &builder.
intersect({&selected_handles_opposite, &auto_handles_opposite, &auto_handles}),
183 if (convert_to_align.is_empty()) {
218 const std::array<IndexMask, 3> &selection_per_attribute,
225 selection_per_attribute[1], selection_per_attribute[0], memory);
227 selection_per_attribute[2], selection_per_attribute[0], memory);
234 bool changed =
false;
239 const int64_t selected_point = selection_per_attribute[0].first();
240 if (auto_left.
contains(selected_point)) {
244 if (auto_right.
contains(selected_point)) {
251 curves, auto_left, auto_right, selected_left, selected_right,
"handle_type_left", memory);
253 curves, auto_right, auto_left, selected_right, selected_left,
"handle_type_right", memory);
260 curves.tag_topology_changed();
282 .slice(data_offset, selection.
size())
301 for (
const int i : trans_data_contrainers.
index_range()) {
309 std::array<IndexMask, 3> selection_per_attribute;
312 curves.curve_type_counts(),
315 curves_transform_data->
memory);
318 curves.points_by_curve(), bezier_curves[i], curves_transform_data->
memory);
320 for (
const int attribute_i : selection_attribute_names.
index_range()) {
321 const StringRef &selection_name = selection_attribute_names[attribute_i];
323 curves, selection_name, bezier_points, curves_transform_data->
memory);
332 {&bezier_points, selection_per_attribute.data()});
336 selection_per_attribute[1] = evaluate_expression(
337 builder.
merge({&selection_per_attribute[1], &selected_bezier_points}),
338 curves_transform_data->
memory);
339 selection_per_attribute[2] = evaluate_expression(
340 builder.
merge({&selection_per_attribute[2], &selected_bezier_points}),
341 curves_transform_data->
memory);
344 if (use_proportional_edit) {
346 points_to_transform_per_attribute[i].append(
curves.points_range());
348 if (selection_attribute_names.
size() > 1) {
349 points_to_transform_per_attribute[i].append(bezier_points);
350 points_to_transform_per_attribute[i].append(bezier_points);
355 for (
const int selection_i : selection_attribute_names.
index_range()) {
356 points_to_transform_per_attribute[i].append(selection_per_attribute[selection_i]);
357 tc.
data_len += points_to_transform_per_attribute[i][selection_i].
size();
371 for (
const int i : trans_data_contrainers.
index_range()) {
382 std::optional<MutableSpan<float>> value_attribute;
390 value_attribute = attribute_writer.
span;
396 value_attribute = attribute_writer.
span;
406 object->object_to_world(),
409 points_to_transform_per_attribute[i],
416 attribute_writer.
finish();
422 const int curve_index)
437 handle_positions_left,
438 handle_positions_right);
442 handle_positions_right,
443 handle_positions_left);
454 Curves *curves_id = id_cast<Curves *>(tc.obedit->data);
457 curves.tag_radii_changed();
460 curves.tag_normals_changed();
465 for (
const int i : positions_per_selection_attr.
index_range()) {
467 tc.custom.type, i, positions_per_selection_attr[i]);
469 curves.tag_positions_changed();
470 curves.calculate_bezier_auto_handles();
495 const int handles_offset,
498 const int position_index = curve_points.
start() + position_offsets_in_td[0].start();
500 const int left_handle_index = handles_offset + position_offsets_in_td[1].start();
501 const int right_handle_index = handles_offset + position_offsets_in_td[2].start();
502 std::array<int, 3> first_per_attr = {left_handle_index, position_index, right_handle_index};
504 for (const int i : range) {
505 for (const int attr : IndexRange(3)) {
506 map[i * 3 + attr] = first_per_attr[attr] + i;
520 custom_data.
data = transform_data;
524 custom_data->
data =
nullptr;
526 return transform_data;
550 bool use_connected_only,
554 const std::array<std::optional<Span<float3>>, 3> src_positions_per_selection_attr = {
567 std::array<MutableSpan<float3>, 3> positions_per_selection_attr;
568 for (
const int selection_i : points_to_transform_per_attr.
index_range()) {
570 points_to_transform_per_attr[selection_i],
571 src_positions_per_selection_attr[selection_i],
582 for (
const StringRef selection_name : selection_attribute_names) {
585 selection_attrs.
append(selection_attr);
593 if (use_individual_origin) {
596 const IndexRange points = points_by_curve[curve_i];
608 [&](
const int64_t point_i) { center += point_positions[point_i]; });
609 center /= selection.
size();
610 mean_center_point_per_curve[curve_i] = center;
616 for (
const int selection_i : position_offsets_in_td.
index_range()) {
617 if (position_offsets_in_td[selection_i].is_empty()) {
622 const IndexMask points_to_transform = points_to_transform_per_attr[selection_i];
623 const VArray<bool> selection = selection_attrs[selection_i];
627 const int curve_i = point_to_curve_map[domain_i];
630 float3 *elem = &positions[transform_i];
633 const bool use_local_center = hide_handles || use_individual_origin ||
634 point_selection[domain_i];
635 const bool use_mean_center = use_individual_origin &&
637 if (use_mean_center) {
638 center = mean_center_point_per_curve[curve_i];
640 else if (use_local_center) {
641 center = point_positions[domain_i];
652 if (selection[domain_i]) {
658 if (value_attribute) {
659 float *value = &((*value_attribute)[domain_i]);
680 if (points_to_transform_per_attr.
size() > 1 && points_to_transform_per_attr.
first().is_empty()) {
681 auto update_handle_center = [&](
const int handle_selection_attr,
682 const int opposite_handle_selection_attr) {
683 const IndexMask &handles_to_transform = points_to_transform_per_attr[handle_selection_attr];
684 const IndexMask &opposite_handles_to_transform =
685 points_to_transform_per_attr[opposite_handle_selection_attr];
687 if (handles_to_transform.
size() == 1 && opposite_handles_to_transform.
size() <= 1) {
689 position_offsets_in_td[handle_selection_attr]);
690 copy_v3_v3(tc_data[0].center, point_positions[handles_to_transform.
first()]);
693 update_handle_center(1, 2);
694 update_handle_center(2, 1);
697 if (use_connected_only) {
701 curves_offsets_in_td_buffer[curve] =
702 points_to_transform_per_attr[0].slice_content(points_by_curve[curve]).
size();
718 for (
const int curve_i : segment) {
719 const int selection_attrs_num = curve_types[curve_i] ==
CURVE_TYPE_BEZIER ? 3 : 1;
720 const IndexRange curve_points = points_by_curve[curve_i];
721 const IndexRange editable_curve_points = curves_offsets_in_td[curve_i];
722 const int total_curve_points = selection_attrs_num * editable_curve_points.
size();
725 closest_distances.
fill(std::numeric_limits<float>::max());
726 mapped_curve_positions.
reinitialize(total_curve_points);
729 editable_curve_points,
730 position_offsets_in_td,
731 bezier_offsets_in_td[curve_i],
734 bool has_any_selected =
false;
735 for (
const int selection_attr_i :
IndexRange(selection_attrs_num)) {
736 has_any_selected = has_any_selected ||
738 selection_attrs[selection_attr_i], curve_points);
740 if (!has_any_selected) {
741 for (
const int i : map) {
748 for (
const int i : closest_distances.
index_range()) {
750 mapped_curve_positions[i] = td.
loc;
752 closest_distances[i] = 0.0f;
756 if (cyclic[curve_i]) {
765 for (
const int i : closest_distances.
index_range()) {
767 td.
dist = closest_distances[i];
Low-level operations for curves.
Low-level operations for curves.
Read Blender memory allocation and freeing.
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
IndexRange index_range() const
void fill(const T &value) const
void reinitialize(const int64_t new_size)
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
static IndexMask from_difference(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
static IndexMask from_union(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
static IndexMask from_intersection(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr int64_t size() const
constexpr int64_t start() const
constexpr IndexRange index_range() const
void priority_increased(const int64_t index)
constexpr int64_t size() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr IndexRange index_range() const
constexpr const T & first() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
std::optional< T > get_if_single() const
static VArray from_single(T value, const int64_t size)
void append(const T &value)
const T & last(const int64_t n=0) const
IndexRange index_range() const
Span< T > as_span() const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
const IntersectionExpr & intersect(const Span< Term > terms)
const UnionExpr & merge(const Span< Term > terms)
const DifferenceExpr & subtract(const Term &main_term, const Span< Term > subtract_terms)
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask slice_content(IndexRange range) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
bool contains(int64_t query_index) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexRange index_range() const
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void scatter(const Span< T > src, const Span< IndexT > indices, MutableSpan< T > dst, const Mode mode={})
void fill_index_range(MutableSpan< T > span, const T start=0)
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
void calculate_single_aligned_handles(const IndexMask &selection, Span< float3 > positions, Span< float3 > align_with, MutableSpan< float3 > align_handles)
IndexMask indices_for_type(const VArray< int8_t > &types, const std::array< int, CURVE_TYPES_NUM > &type_counts, const CurveType type, const IndexMask &selection, LinearAllocator<> &memory)
IndexMask curve_to_point_selection(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, LinearAllocator<> &memory)
bool has_anything_selected(const VArray< bool > &varray, const IndexRange range_to_check)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
Vector< MutableSpan< float3 > > get_curves_positions_for_write(bke::CurvesGeometry &curves)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
constexpr ParallelGrainSize grain_size(int grain_size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T distance(const T &a, const T &b)
MatBase< T, Size, Size > pseudo_invert(const MatBase< T, Size, Size > &mat, T epsilon=1e-8)
T mod_periodic(const T &a, const T &b)
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))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
@ V3D_AROUND_LOCAL_ORIGINS
MatBase< float, 4, 4 > float4x4
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
ATTR_WARN_UNUSED_RESULT const size_t num
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
const c_style_mat & ptr() const
eHandleDisplay handle_display
MutableVArraySpan< T > span