Blender V5.3
curves_geometry.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <utility>
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_array_utils.hh"
14#include "BLI_bounds.hh"
15#include "BLI_index_mask.hh"
17#include "BLI_listbase.hh"
18#include "BLI_math_matrix.hh"
20#include "BLI_memory_counter.hh"
21#include "BLI_resource_scope.hh"
22#include "BLI_task.hh"
23
24#include "BLO_read_write.hh"
25
26#include "BLT_translation.hh"
27
28#include "DNA_curves_types.h"
29#include "DNA_material_types.h"
30#include "DNA_object_types.h"
31
32#include "BKE_attribute.hh"
34#include "BKE_attribute_math.hh"
38#include "BKE_curves.hh"
39#include "BKE_curves_utils.hh"
40#include "BKE_customdata.hh"
41#include "BKE_deform.hh"
42#include "BKE_report.hh"
43
45
46namespace blender::bke {
47
48constexpr StringRef ATTR_POSITION = "position";
49constexpr StringRef ATTR_RADIUS = "radius";
50constexpr StringRef ATTR_TILT = "tilt";
51constexpr StringRef ATTR_CURVE_TYPE = "curve_type";
52constexpr StringRef ATTR_CYCLIC = "cyclic";
53constexpr StringRef ATTR_RESOLUTION = "resolution";
54constexpr StringRef ATTR_NORMAL_MODE = "normal_mode";
55constexpr StringRef ATTR_HANDLE_TYPE_LEFT = "handle_type_left";
56constexpr StringRef ATTR_HANDLE_TYPE_RIGHT = "handle_type_right";
57constexpr StringRef ATTR_HANDLE_POSITION_LEFT = "handle_left";
58constexpr StringRef ATTR_HANDLE_POSITION_RIGHT = "handle_right";
59constexpr StringRef ATTR_NURBS_ORDER = "nurbs_order";
60constexpr StringRef ATTR_NURBS_WEIGHT = "nurbs_weight";
61constexpr StringRef ATTR_NURBS_KNOTS_MODE = "knots_mode";
62constexpr StringRef ATTR_SURFACE_UV_COORDINATE = "surface_uv_coordinate";
63
64/* -------------------------------------------------------------------- */
67
69
71{
72 this->runtime = MEM_new<CurvesGeometryRuntime>(__func__);
73
74 this->point_num = point_num;
75 this->curve_num = curve_num;
78 new (&this->attribute_storage.wrap()) bke::AttributeStorage();
79 this->vertex_group_names.clear_no_delete();
80
83
84 this->custom_knots = nullptr;
85 this->custom_knot_num = 0;
86
87 if (curve_num > 0) {
88 this->curve_offsets = MEM_new_array_uninitialized<int>(size_t(this->curve_num) + 1, __func__);
90 this->curve_offsets);
91#ifndef NDEBUG
92 this->offsets_for_write().fill(-1);
93#endif
94 /* Set common values for convenience. */
95 this->curve_offsets[0] = 0;
96 this->curve_offsets[this->curve_num] = this->point_num;
97 }
98 else {
99 this->curve_offsets = nullptr;
100 }
101
102 /* Fill the type counts with the default so they're in a valid state. */
104}
105
107{
108 this->curve_offsets = other.curve_offsets;
111 }
112
113 this->custom_knots = other.custom_knots;
114 this->custom_knot_num = other.custom_knot_num;
117 }
118
119 CustomData_init_from(&other.point_data, &this->point_data, CD_MASK_MDEFORMVERT, other.point_num);
120
121 new (&this->attribute_storage.wrap()) AttributeStorage(other.attribute_storage.wrap());
122
123 this->point_num = other.point_num;
124 this->curve_num = other.curve_num;
125
128
130
131 this->runtime = MEM_new<CurvesGeometryRuntime>(
132 __func__,
135 other.runtime->type_counts,
140 other.runtime->bounds_cache,
147 {},
148 true});
149
150 if (other.runtime->bake_materials) {
151 this->runtime->bake_materials = std::make_unique<bake::BakeMaterialsList>(
152 *other.runtime->bake_materials);
153 }
154}
155
157{
158 if (this == &other) {
159 return *this;
160 }
161 std::destroy_at(this);
162 new (this) CurvesGeometry(other);
163 return *this;
164}
165
167{
168 this->curve_offsets = other.curve_offsets;
169 other.curve_offsets = nullptr;
170
171 this->custom_knots = other.custom_knots;
172 other.custom_knots = nullptr;
173
174 this->custom_knot_num = other.custom_knot_num;
175 other.custom_knot_num = 0;
176
177 this->point_data = other.point_data;
178 CustomData_reset(&other.point_data);
179
180 new (&this->attribute_storage.wrap())
181 AttributeStorage(std::move(other.attribute_storage.wrap()));
182
183 this->point_num = other.point_num;
184 other.point_num = 0;
185
186 this->curve_num = other.curve_num;
187 other.curve_num = 0;
188
189 this->vertex_group_names = other.vertex_group_names;
190 other.vertex_group_names.clear_no_delete();
191
192 this->vertex_group_active_index = other.vertex_group_active_index;
193 other.vertex_group_active_index = 0;
194
195 this->attributes_active_index = other.attributes_active_index;
196 other.attributes_active_index = -1;
197
198 this->runtime = other.runtime;
199 other.runtime = nullptr;
200}
201
203{
204 if (this == &other) {
205 return *this;
206 }
207 std::destroy_at(this);
208 new (this) CurvesGeometry(std::move(other));
209 return *this;
210}
211
225
227
228/* -------------------------------------------------------------------- */
231
240
246
248{
249 if (type == CURVE_TYPE_CATMULL_ROM) {
250 /* Avoid creating the attribute for Catmull Rom which is the default when the attribute doesn't
251 * exist anyway. */
252 this->attributes_for_write().remove("curve_type");
253 }
254 else {
255 const GPointer value(CPPType::get<int8_t>(), &type);
257 if (Attribute *attr = this->attribute_storage.wrap().lookup("curve_type")) {
258 attr->assign_data(std::move(data));
259 }
260 else {
261 this->attribute_storage.wrap().add(
262 "curve_type", AttrDomain::Curve, AttrType::Int8, std::move(data));
263 }
264 }
265 this->runtime->type_counts.fill(0);
266 this->runtime->type_counts[type] = this->curves_num();
267 this->tag_topology_changed();
268}
269
270void CurvesGeometry::fill_curve_types(const IndexMask &selection, const CurveType type)
271{
272 if (selection.size() == this->curves_num()) {
273 this->fill_curve_types(type);
274 return;
275 }
276 if (std::optional<int8_t> single_type = this->curve_types().get_if_single()) {
277 if (single_type == type) {
278 this->fill_curve_types(type);
279 return;
280 }
281 }
282 /* A potential performance optimization is only counting the changed indices. */
284 this->update_curve_types();
285 this->tag_topology_changed();
286}
287
288static bool is_valid_curve_type(const int8_t type)
289{
290 return type >= 0 && type < CURVE_TYPES_NUM;
291}
292
294static bool curve_types_are_valid(const VArray<int8_t> &types)
295{
296 if (const std::optional<int8_t> single = types.get_if_single()) {
297 return is_valid_curve_type(*single);
298 }
299 const Span<int8_t> types_span = types.get_internal_span();
301 types_span.index_range(),
302 2048,
303 true,
304 [&](const IndexRange curves_range, const bool &init) {
305 if (!init) {
306 return false;
307 }
308 for (const int64_t curve_index : curves_range) {
309 if (!is_valid_curve_type(types_span[curve_index])) {
310 return false;
311 }
312 }
313 return true;
314 },
315 [](const bool &a, const bool &b) { return a && b; });
316}
317
320{
321 for (int8_t &type : types) {
322 if (!is_valid_curve_type(type)) {
323 type = CURVE_TYPE_POLY;
324 }
325 }
326}
327
328std::array<int, CURVE_TYPES_NUM> calculate_type_counts(const VArray<int8_t> &types)
329{
331 using CountsType = std::array<int, CURVE_TYPES_NUM>;
332 CountsType counts;
333 counts.fill(0);
334
335 if (const std::optional<int8_t> single = types.get_if_single()) {
336 counts[*single] = types.size();
337 return counts;
338 }
339
340 Span<int8_t> types_span = types.get_internal_span();
342 types.index_range(),
343 2048,
344 counts,
345 [&](const IndexRange curves_range, const CountsType &init) {
346 CountsType result = init;
347 for (const int curve_index : curves_range) {
348 result[types_span[curve_index]]++;
349 }
350 return result;
351 },
352 [](const CountsType &a, const CountsType &b) {
353 CountsType result = a;
354 for (const int i : IndexRange(CURVE_TYPES_NUM)) {
355 result[i] += b[i];
356 }
357 return result;
358 });
359}
360
365
367{
369 this->attribute_storage.wrap(), AttrDomain::Point, ATTR_POSITION, this->points_num());
370}
376
378{
380 this->attribute_storage.wrap(), AttrDomain::Point, ATTR_RADIUS, this->points_num(), 0.01f);
381}
387
389{
390 if (this->curve_num == 0) {
391 return {};
392 }
393 return {this->curve_offsets, this->curve_num + 1};
394}
396{
397 if (this->curve_num == 0) {
398 return {};
399 }
401 &this->curve_offsets, &this->runtime->curve_offsets_sharing_info, this->curve_num + 1);
402 return {this->curve_offsets, this->curve_num + 1};
403}
404
406{
408 this->attribute_storage.wrap(), AttrDomain::Curve, ATTR_CYCLIC, this->curves_num(), false);
409}
415
417{
419 this->attribute_storage.wrap(), AttrDomain::Curve, ATTR_RESOLUTION, this->curves_num(), 12);
420}
426
437
439{
441 this->attribute_storage.wrap(), AttrDomain::Point, ATTR_TILT, this->points_num(), 0.0f);
442}
448
450{
454 this->points_num(),
455 0);
456}
465
467{
471 this->points_num(),
472 0);
473}
482
483std::optional<Span<float3>> CurvesGeometry::handle_positions_left() const
484{
488 this->points_num());
489}
497
498std::optional<Span<float3>> CurvesGeometry::handle_positions_right() const
499{
503 this->points_num());
504}
512
523
524std::optional<Span<float>> CurvesGeometry::nurbs_weights() const
525{
527 this->attribute_storage.wrap(), AttrDomain::Point, ATTR_NURBS_WEIGHT, this->points_num());
528}
537
539{
543 this->curves_num(),
544 0);
545}
554
555std::optional<Span<float2>> CurvesGeometry::surface_uv_coords() const
556{
560 this->curves_num());
561}
562
570
572{
573 if (this->custom_knot_num == 0) {
574 return {};
575 }
576 return {this->custom_knots, this->custom_knot_num};
577}
578
580{
581 if (this->custom_knot_num == 0) {
582 return {};
583 }
585 &this->custom_knots, &this->runtime->custom_knots_sharing_info, this->custom_knot_num);
586 return {this->custom_knots, this->custom_knot_num};
587}
588
590{
591 const VArray<int8_t> curve_types = this->curve_types();
592 const VArray<int8_t> knot_modes = this->nurbs_knots_modes();
593 return IndexMask::from_predicate(this->curves_range(), memory, [&](const int64_t curve) {
594 return curve_types[curve] == CURVE_TYPE_NURBS && knot_modes[curve] == NURBS_KNOT_MODE_CUSTOM;
595 });
596}
597
599{
600 const CurvesGeometryRuntime &runtime = *this->runtime;
602 return {};
603 }
604 runtime.custom_knot_offsets_cache.ensure([&](Vector<int> &r_data) {
605 r_data.resize(this->curve_num + 1);
606
607 const OffsetIndices<int> points_by_curve = this->points_by_curve();
608 const VArray<int8_t> curve_types = this->curve_types();
609 const VArray<int8_t> knot_modes = this->nurbs_knots_modes();
610 const VArray<int8_t> orders = this->nurbs_orders();
611
612 threading::parallel_for(this->curves_range(), 1024, [&](const IndexRange range) {
613 for (const int curve : range) {
614 if (curve_types[curve] != CURVE_TYPE_NURBS) {
615 r_data[curve] = 0;
616 continue;
617 }
618 if (knot_modes[curve] != NURBS_KNOT_MODE_CUSTOM) {
619 r_data[curve] = 0;
620 continue;
621 }
622 r_data[curve] = points_by_curve[curve].size() + orders[curve];
623 }
624 });
626 });
628}
629
631{
632 this->runtime->custom_knot_offsets_cache.tag_dirty();
633 const OffsetIndices<int> knots_by_curve = this->nurbs_custom_knots_by_curve();
634 const int knots_num = knots_by_curve.total_size();
635 if (this->custom_knot_num != knots_num) {
638 this->custom_knot_num,
639 knots_num);
640 this->custom_knot_num = knots_num;
641 }
642}
643
645{
648 this->custom_knot_num,
649 knots_num);
650 this->custom_knot_num = knots_num;
651 this->runtime->custom_knot_offsets_cache.tag_dirty();
652}
653
655{
656 const MDeformVert *dverts = static_cast<const MDeformVert *>(
658 if (dverts == nullptr) {
659 return {};
660 }
661 return {dverts, this->point_num};
662}
663
665{
666 MDeformVert *dvert = static_cast<MDeformVert *>(
668 if (dvert != nullptr) {
669 return {dvert, this->point_num};
670 }
671 return {static_cast<MDeformVert *>(CustomData_add_layer(
673 this->point_num};
674}
675
677
678/* -------------------------------------------------------------------- */
681
682template<typename CountFn> void build_offsets(MutableSpan<int> offsets, const CountFn &count_fn)
683{
684 int offset = 0;
685 for (const int i : offsets.drop_back(1).index_range()) {
686 offsets[i] = offset;
687 offset += count_fn(i);
688 }
689 offsets.last() = offset;
690}
691
693 MutableSpan<int> offsets,
694 MutableSpan<int> all_bezier_offsets)
695{
697 const OffsetIndices points_by_curve = curves.points_by_curve();
698 const VArray<int8_t> types = curves.curve_types();
699 const VArray<int> resolution = curves.resolution();
700 const VArray<bool> cyclic = curves.cyclic();
701
702 VArraySpan<int8_t> handle_types_left;
703 VArraySpan<int8_t> handle_types_right;
704 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
705 handle_types_left = curves.handle_types_left();
706 handle_types_right = curves.handle_types_right();
707 }
708
709 const VArray<int8_t> nurbs_orders = curves.nurbs_orders();
710 const VArray<int8_t> nurbs_knots_modes = curves.nurbs_knots_modes();
711 const OffsetIndices<int> custom_knots_by_curve = curves.nurbs_custom_knots_by_curve();
712 const Span<float> all_custom_knots = curves.nurbs_custom_knots();
713
714 build_offsets(offsets, [&](const int curve_index) -> int {
715 const IndexRange points = points_by_curve[curve_index];
716 switch (types[curve_index]) {
719 points.size(), cyclic[curve_index], resolution[curve_index]);
720 case CURVE_TYPE_POLY:
721 return points.size();
722 case CURVE_TYPE_BEZIER: {
723 const IndexRange offsets = curves::per_curve_point_offsets_range(points, curve_index);
724 curves::bezier::calculate_evaluated_offsets(handle_types_left.slice(points),
725 handle_types_right.slice(points),
726 cyclic[curve_index],
727 resolution[curve_index],
728 all_bezier_offsets.slice(offsets));
729 return all_bezier_offsets[offsets.last()];
730 }
731 case CURVE_TYPE_NURBS:
732 const bool is_cyclic = cyclic[curve_index];
733 const int8_t order = nurbs_orders[curve_index];
734 const KnotsMode knots_mode = KnotsMode(nurbs_knots_modes[curve_index]);
735 const IndexRange custom_knots_range = custom_knots_by_curve[curve_index];
736 const Span<float> custom_knots = knots_mode == NURBS_KNOT_MODE_CUSTOM &&
737 !all_custom_knots.is_empty() &&
738 !custom_knots_range.is_empty() ?
739 all_custom_knots.slice(custom_knots_range) :
740 Span<float>();
742 points.size(), order, is_cyclic, resolution[curve_index], knots_mode, custom_knots);
743 }
745 return 0;
746 });
747}
748
750{
751 const CurvesGeometryRuntime &runtime = *this->runtime;
752 if (this->is_single_type(CURVE_TYPE_POLY)) {
753 /* When all the curves are poly curves, the evaluated offsets are the same as the control
754 * point offsets, so it's possible to completely avoid building a new offsets array. */
758 });
759 return this->points_by_curve();
760 }
761
763 r_data.evaluated_offsets.resize(this->curves_num() + 1);
764
766 r_data.all_bezier_offsets.resize(this->points_num() + this->curves_num());
767 }
768 else {
770 }
771
773 });
774
775 return OffsetIndices<int>(runtime.evaluated_offsets_cache.data().evaluated_offsets);
776}
777
779{
780 this->runtime->has_cyclic_curve_cache.ensure([&](bool &r_data) {
781 r_data = array_utils::contains(this->cyclic(), this->curves_range(), true);
782 });
783 return this->runtime->has_cyclic_curve_cache.data();
784}
785
787 IndexMaskMemory &memory) const
788{
789 return this->indices_for_curve_type(type, this->curves_range(), memory);
790}
791
793 const IndexMask &selection,
794 IndexMaskMemory &memory) const
795{
797 this->curve_types(), this->curve_type_counts(), type, selection, memory);
798}
799
806
807void CurvesGeometry::ensure_nurbs_basis_cache() const
808{
809 const CurvesGeometryRuntime &runtime = *this->runtime;
811 PRF_scope_with_name("CurvesGeometry::ensure_nurbs_basis_cache", ProfileCategory::Default);
812 IndexMaskMemory memory;
813 const IndexMask nurbs_mask = this->indices_for_curve_type(CURVE_TYPE_NURBS, memory);
814 if (nurbs_mask.is_empty()) {
815 r_data.clear_and_shrink();
816 return;
817 }
818
819 r_data.resize(this->curves_num());
820
821 const OffsetIndices<int> points_by_curve = this->points_by_curve();
822 const OffsetIndices<int> evaluated_points_by_curve = this->evaluated_points_by_curve();
823 const OffsetIndices<int> custom_knots_by_curve = this->nurbs_custom_knots_by_curve();
824 const VArray<bool> cyclic = this->cyclic();
825 const VArray<int8_t> orders = this->nurbs_orders();
826 const VArray<int> resolutions = this->resolution();
827 const VArray<int8_t> knots_modes = this->nurbs_knots_modes();
829
830 nurbs_mask.foreach_segment(
831 [&](const IndexMaskSegment segment) {
832 Vector<float, 32> knots;
833 for (const int curve_index : segment) {
834 const IndexRange points = points_by_curve[curve_index];
835 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
836
837 const int8_t order = orders[curve_index];
838 const int resolution = resolutions[curve_index];
839 const bool is_cyclic = cyclic[curve_index];
840 const KnotsMode mode = KnotsMode(knots_modes[curve_index]);
841
843 points.size(), order, is_cyclic, mode, resolution))
844 {
845 r_data[curve_index].invalid = true;
846 continue;
847 }
848 const int knots_num = curves::nurbs::knots_num(points.size(), order, is_cyclic);
849 knots.reinitialize(knots_num);
851 points.size(),
852 order,
853 is_cyclic,
854 custom_knots_by_curve[curve_index],
856 knots);
857
859 evaluated_points.size(),
860 order,
862 is_cyclic,
863 mode,
864 knots,
865 r_data[curve_index]);
866 }
867 },
869 });
870}
871
873{
874 const CurvesGeometryRuntime &runtime = *this->runtime;
875 if (this->is_single_type(CURVE_TYPE_POLY)) {
877 [&](Vector<float3> &r_data) { r_data.clear_and_shrink(); });
878 return this->positions();
879 }
880 this->ensure_nurbs_basis_cache();
882 PRF_scope_with_name("CurvesGeometry::evaluated_positions", ProfileCategory::Default);
883 r_data.resize(this->evaluated_points_num());
885
886 const OffsetIndices<int> points_by_curve = this->points_by_curve();
887 const OffsetIndices<int> evaluated_points_by_curve = this->evaluated_points_by_curve();
888 const Span<float3> positions = this->positions();
889
890 auto evaluate_catmull = [&](const IndexMask &selection) {
891 const VArray<bool> cyclic = this->cyclic();
892 const VArray<int> resolution = this->resolution();
893 selection.foreach_index(
894 [&](const int curve_index) {
895 const IndexRange points = points_by_curve[curve_index];
896 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
898 positions.slice(points),
899 cyclic[curve_index],
900 resolution[curve_index],
901 evaluated_positions.slice(evaluated_points));
902 },
904 };
905 auto evaluate_poly = [&](const IndexMask &selection) {
908 };
909 auto evaluate_bezier = [&](const IndexMask &selection) {
910 const std::optional<Span<float3>> handle_positions_left = this->handle_positions_left();
911 const std::optional<Span<float3>> handle_positions_right = this->handle_positions_right();
914 return;
915 }
916 const Span<int> all_bezier_offsets =
917 runtime.evaluated_offsets_cache.data().all_bezier_offsets;
918 selection.foreach_index(
919 [&](const int curve_index) {
920 const IndexRange points = points_by_curve[curve_index];
921 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
922 const IndexRange offsets = curves::per_curve_point_offsets_range(points, curve_index);
924 positions.slice(points),
927 all_bezier_offsets.slice(offsets),
928 evaluated_positions.slice(evaluated_points));
929 },
931 };
932 auto evaluate_nurbs = [&](const IndexMask &selection) {
933 this->ensure_nurbs_basis_cache();
934 const VArray<int8_t> nurbs_orders = this->nurbs_orders();
935 const std::optional<Span<float>> nurbs_weights = this->nurbs_weights();
936 const Span<curves::nurbs::BasisCache> nurbs_basis_cache = runtime.nurbs_basis_cache.data();
937 selection.foreach_index(
938 [&](const int curve_index) {
939 const IndexRange points = points_by_curve[curve_index];
940 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
941 curves::nurbs::interpolate_to_evaluated(nurbs_basis_cache[curve_index],
942 nurbs_orders[curve_index],
943 nurbs_weights ? nurbs_weights->slice(points) :
944 Span<float>(),
945 positions.slice(points),
946 evaluated_positions.slice(evaluated_points));
947 },
949 };
951 this->curve_type_counts(),
952 this->curves_range(),
953 evaluate_catmull,
954 evaluate_poly,
955 evaluate_bezier,
956 evaluate_nurbs);
957 });
958 return runtime.evaluated_position_cache.data();
959}
960
962{
963 const CurvesGeometryRuntime &runtime = *this->runtime;
965 PRF_scope_with_name("CurvesGeometry::evaluated_tangents", ProfileCategory::Default);
966 const OffsetIndices<int> evaluated_points_by_curve = this->evaluated_points_by_curve();
967 const Span<float3> evaluated_positions = this->evaluated_positions();
968 const VArray<bool> cyclic = this->cyclic();
969
970 r_data.resize(this->evaluated_points_num());
971 MutableSpan<float3> tangents = r_data;
972
974 for (const int curve_index : curves_range) {
975 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
977 cyclic[curve_index],
978 tangents.slice(evaluated_points));
979 }
980 });
981
982 /* Correct the first and last tangents of non-cyclic Bezier curves so that they align with
983 * the inner handles. This is a separate loop to avoid the cost when Bezier type curves are
984 * not used. */
985 IndexMaskMemory memory;
986 const IndexMask bezier_mask = this->indices_for_curve_type(CURVE_TYPE_BEZIER, memory);
987 if (!bezier_mask.is_empty()) {
988 const OffsetIndices<int> points_by_curve = this->points_by_curve();
989 const Span<float3> positions = this->positions();
990 const Span<float3> handles_left = *this->handle_positions_left();
991 const Span<float3> handles_right = *this->handle_positions_right();
992
993 bezier_mask.foreach_index(
994 [&](const int curve_index) {
995 if (cyclic[curve_index]) {
996 return;
997 }
998 const IndexRange points = points_by_curve[curve_index];
999 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
1000
1001 const float epsilon = 1e-6f;
1003 handles_right[points.first()], positions[points.first()], epsilon))
1004 {
1005 tangents[evaluated_points.first()] = math::normalize(handles_right[points.first()] -
1006 positions[points.first()]);
1007 }
1009 handles_left[points.last()], positions[points.last()], epsilon))
1010 {
1011 tangents[evaluated_points.last()] = math::normalize(positions[points.last()] -
1012 handles_left[points.last()]);
1013 }
1014 },
1015 exec_mode::grain_size(1024));
1016 }
1017 });
1018 return runtime.evaluated_tangent_cache.data();
1019}
1020
1022 const Span<float3> axes,
1023 const Span<float> angles)
1024{
1025 for (const int i : directions.index_range()) {
1026 const float3 axis = axes[i];
1027 if (math::is_zero(axis)) [[unlikely]] {
1028 continue;
1029 }
1030 directions[i] = math::rotate_direction_around_axis(directions[i], axis, angles[i]);
1031 }
1032}
1033
1035{
1036 for (const int i : data.index_range()) {
1037 data[i] = math::normalize(data[i]);
1038 }
1039}
1040
1052
1053static void evaluate_generic_data_for_curve(const EvalData &eval_data,
1054 const int curve_index,
1055 const GSpan src,
1056 GMutableSpan dst)
1057{
1058 const IndexRange points = eval_data.points_by_curve[curve_index];
1059 switch (eval_data.types[curve_index]) {
1062 src, eval_data.cyclic[curve_index], eval_data.resolution[curve_index], dst);
1063 break;
1064 case CURVE_TYPE_POLY:
1065 dst.copy_from(src);
1066 break;
1067 case CURVE_TYPE_BEZIER: {
1068 const IndexRange offsets = curves::per_curve_point_offsets_range(points, curve_index);
1070 src, eval_data.all_bezier_evaluated_offsets.slice(offsets), dst);
1071 break;
1072 }
1073 case CURVE_TYPE_NURBS:
1075 eval_data.nurbs_basis_cache[curve_index],
1076 eval_data.nurbs_orders[curve_index],
1077 eval_data.nurbs_weights ? eval_data.nurbs_weights->slice(points) : Span<float>(),
1078 src,
1079 dst);
1080 break;
1081 }
1082}
1083
1085{
1086 const CurvesGeometryRuntime &runtime = *this->runtime;
1087 this->ensure_nurbs_basis_cache();
1088 runtime.evaluated_normal_cache.ensure([&](Vector<float3> &r_data) {
1089 const OffsetIndices<int> points_by_curve = this->points_by_curve();
1090 const OffsetIndices<int> evaluated_points_by_curve = this->evaluated_points_by_curve();
1091 const VArray<int8_t> types = this->curve_types();
1092 const VArray<bool> cyclic = this->cyclic();
1093 const VArray<int8_t> normal_mode = this->normal_mode();
1094 const Span<float3> evaluated_tangents = this->evaluated_tangents();
1095 const AttributeAccessor attributes = this->attributes();
1096 const EvalData eval_data{
1098 types,
1099 cyclic,
1100 this->resolution(),
1101 runtime.evaluated_offsets_cache.data().all_bezier_offsets,
1103 this->nurbs_orders(),
1104 this->nurbs_weights(),
1105 };
1106 const VArray<float> tilt = this->tilt();
1107 VArraySpan<float> tilt_span;
1108 const bool use_tilt = !(tilt.is_single() && tilt.get_internal_single() == 0.0f);
1109 if (use_tilt) {
1110 tilt_span = tilt;
1111 }
1112 VArraySpan<float3> custom_normal_span;
1113 if (const VArray<float3> custom_normal = *attributes.lookup<float3>("custom_normal",
1115 {
1116 custom_normal_span = custom_normal;
1117 }
1118
1119 r_data.resize(this->evaluated_points_num());
1121
1123 /* Reuse a buffer for the evaluated tilts. */
1124 Vector<float> evaluated_tilts;
1125
1126 for (const int curve_index : curves_range) {
1127 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
1128 switch (NormalMode(normal_mode[curve_index])) {
1129 case NORMAL_MODE_Z_UP:
1131 evaluated_normals.slice(evaluated_points));
1132 break;
1135 cyclic[curve_index],
1136 evaluated_normals.slice(evaluated_points));
1137 break;
1138 case NORMAL_MODE_FREE:
1139 if (custom_normal_span.is_empty()) {
1141 evaluated_normals.slice(evaluated_points));
1142 }
1143 else {
1144 const Span<float3> src = custom_normal_span.slice(points_by_curve[curve_index]);
1146 evaluated_points_by_curve[curve_index]);
1147 evaluate_generic_data_for_curve(eval_data, curve_index, src, dst);
1148 normalize_span(dst);
1149 }
1150 break;
1151 }
1152
1153 /* If the "tilt" attribute exists, rotate the normals around the tangents by the
1154 * evaluated angles. We can avoid copying the tilts to evaluate them for poly curves. */
1155 if (use_tilt) {
1156 const IndexRange points = points_by_curve[curve_index];
1157 if (types[curve_index] == CURVE_TYPE_POLY) {
1159 evaluated_tangents.slice(evaluated_points),
1160 tilt_span.slice(points));
1161 }
1162 else {
1163 evaluated_tilts.reinitialize(evaluated_points.size());
1165 curve_index,
1166 tilt_span.slice(points),
1167 evaluated_tilts.as_mutable_span());
1169 evaluated_tangents.slice(evaluated_points),
1170 evaluated_tilts.as_span());
1171 }
1172 }
1173 }
1174 });
1175 });
1176 return this->runtime->evaluated_normal_cache.data();
1177}
1178
1180 const GSpan src,
1181 GMutableSpan dst) const
1182{
1183 const CurvesGeometryRuntime &runtime = *this->runtime;
1184 const EvalData eval_data{
1185 this->points_by_curve(),
1186 this->curve_types(),
1187 this->cyclic(),
1188 this->resolution(),
1189 runtime.evaluated_offsets_cache.data().all_bezier_offsets,
1191 this->nurbs_orders(),
1192 this->nurbs_weights(),
1193 };
1194 BLI_assert(src.size() == this->points_by_curve()[curve_index].size());
1195 BLI_assert(dst.size() == this->evaluated_points_by_curve()[curve_index].size());
1196 evaluate_generic_data_for_curve(eval_data, curve_index, src, dst);
1197}
1198
1200{
1201 const CurvesGeometryRuntime &runtime = *this->runtime;
1202 const OffsetIndices points_by_curve = this->points_by_curve();
1203 const EvalData eval_data{
1205 this->curve_types(),
1206 this->cyclic(),
1207 this->resolution(),
1208 runtime.evaluated_offsets_cache.data().all_bezier_offsets,
1210 this->nurbs_orders(),
1211 this->nurbs_weights(),
1212 };
1213 const OffsetIndices evaluated_points_by_curve = this->evaluated_points_by_curve();
1214 PRF_scope_with_name("CurvesGeometry::interpolate_to_evaluated", ProfileCategory::Default);
1215
1217 for (const int curve_index : curves_range) {
1218 const IndexRange points = points_by_curve[curve_index];
1219 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
1221 eval_data, curve_index, src.slice(points), dst.slice(evaluated_points));
1222 }
1223 });
1224}
1225
1227{
1228 const CurvesGeometryRuntime &runtime = *this->runtime;
1229 runtime.evaluated_length_cache.ensure([&](Vector<float> &r_data) {
1230 PRF_scope_with_name("CurvesGeometry::ensure_evaluated_lengths", ProfileCategory::Default);
1231 /* Use an extra length value for the final cyclic segment for a consistent size
1232 * (see comment on #evaluated_length_cache). */
1233 const int total_num = this->evaluated_points_num() + this->curves_num();
1234 r_data.resize(total_num);
1235 MutableSpan<float> evaluated_lengths = r_data;
1236
1237 const OffsetIndices<int> evaluated_points_by_curve = this->evaluated_points_by_curve();
1238 const Span<float3> evaluated_positions = this->evaluated_positions();
1239 const VArray<bool> curves_cyclic = this->cyclic();
1240
1242 for (const int curve_index : curves_range) {
1243 const bool cyclic = curves_cyclic[curve_index];
1244 const IndexRange evaluated_points = evaluated_points_by_curve[curve_index];
1245 const IndexRange lengths_range = this->lengths_range_for_curve(curve_index, cyclic);
1247 cyclic,
1248 evaluated_lengths.slice(lengths_range));
1249 }
1250 });
1251 });
1252}
1253
1255{
1256 this->evaluated_points_by_curve();
1257 this->ensure_nurbs_basis_cache();
1258}
1259
1261
1262/* -------------------------------------------------------------------- */
1265
1267{
1268 BLI_assert(curves_num >= 0 && points_num >= 0);
1269 if (points_num != this->point_num) {
1271 CustomData_realloc(&this->point_data, this->points_num(), points_num);
1272 this->point_num = points_num;
1273 }
1274 if (curves_num != this->curve_num) {
1277 &this->runtime->curve_offsets_sharing_info,
1278 this->curve_num == 0 ? 0 : (this->curve_num + 1),
1279 curves_num == 0 ? 0 : (curves_num + 1));
1280 if (curves_num > 0) {
1281 /* Set common values for convenience. */
1282 this->curve_offsets[0] = 0;
1283 this->curve_offsets[curves_num] = this->point_num;
1284 }
1285 this->curve_num = curves_num;
1286 }
1287 this->tag_topology_changed();
1288}
1289
1291{
1292 this->runtime->evaluated_position_cache.tag_dirty();
1293 this->runtime->evaluated_tangent_cache.tag_dirty();
1294 this->runtime->evaluated_normal_cache.tag_dirty();
1295 this->runtime->evaluated_length_cache.tag_dirty();
1296 this->runtime->bounds_cache.tag_dirty();
1297 this->runtime->bounds_with_radius_cache.tag_dirty();
1298}
1300{
1301 this->runtime->custom_knot_offsets_cache.tag_dirty();
1302 this->tag_positions_changed();
1303 this->runtime->evaluated_offsets_cache.tag_dirty();
1304 this->runtime->has_cyclic_curve_cache.tag_dirty();
1305 this->runtime->nurbs_basis_cache.tag_dirty();
1306 this->runtime->max_material_index_cache.tag_dirty();
1307 this->runtime->check_type_counts = true;
1308}
1310{
1311 this->runtime->evaluated_normal_cache.tag_dirty();
1312}
1314{
1315 this->runtime->bounds_with_radius_cache.tag_dirty();
1316}
1321
1322static void translate_positions(MutableSpan<float3> positions, const float3 &translation)
1323{
1324 threading::parallel_for(positions.index_range(), 2048, [&](const IndexRange range) {
1325 for (float3 &position : positions.slice(range)) {
1326 position += translation;
1327 }
1328 });
1329}
1330
1332{
1334 return;
1335 }
1336 if (!this->handle_positions_left() || !this->handle_positions_right()) {
1337 return;
1338 }
1339 const OffsetIndices points_by_curve = this->points_by_curve();
1340 const VArray<int8_t> types = this->curve_types();
1341 const VArray<bool> cyclic = this->cyclic();
1342 const VArraySpan<int8_t> types_left{this->handle_types_left()};
1343 const VArraySpan<int8_t> types_right{this->handle_types_right()};
1344 const Span<float3> positions = this->positions();
1346 MutableSpan<float3> positions_right = this->handle_positions_right_for_write();
1347
1348 threading::parallel_for(this->curves_range(), 128, [&](IndexRange range) {
1349 for (const int i_curve : range) {
1350 if (types[i_curve] == CURVE_TYPE_BEZIER) {
1351 const IndexRange points = points_by_curve[i_curve];
1353 types_left.slice(points),
1354 types_right.slice(points),
1355 positions.slice(points),
1356 positions_left.slice(points),
1357 positions_right.slice(points));
1358 }
1359 }
1360 });
1361}
1362
1364{
1366 return;
1367 }
1368 if (!this->handle_positions_left() || !this->handle_positions_right()) {
1369 return;
1370 }
1371 const VArraySpan<int8_t> types_left = this->handle_types_left();
1372 const VArraySpan<int8_t> types_right = this->handle_types_right();
1373 const Span<float3> positions = this->positions();
1375 MutableSpan<float3> positions_right = this->handle_positions_right_for_write();
1376
1377 IndexMaskMemory memory;
1379 *this, CURVE_TYPE_BEZIER, memory);
1380 const IndexMask selection = IndexMask::from_predicate(
1381 bezier_points, memory, [&](const int64_t i) {
1382 return types_left[i] == BEZIER_HANDLE_ALIGN && types_right[i] == BEZIER_HANDLE_ALIGN;
1383 });
1384
1386 selection, positions, positions_left, positions_right, positions_left, positions_right);
1387}
1388
1389void CurvesGeometry::translate(const float3 &translation)
1390{
1391 if (math::is_zero(translation)) {
1392 return;
1393 }
1394
1395 std::optional<Bounds<float3>> bounds;
1396 if (this->runtime->bounds_cache.is_cached()) {
1397 bounds = this->runtime->bounds_cache.data();
1398 }
1399
1400 translate_positions(this->positions_for_write(), translation);
1401 if (this->handle_positions_left()) {
1403 }
1404 if (this->handle_positions_right()) {
1406 }
1407 this->tag_positions_changed();
1408
1409 if (bounds) {
1410 bounds->min += translation;
1411 bounds->max += translation;
1412 this->runtime->bounds_cache.ensure([&](Bounds<float3> &r_data) { r_data = *bounds; });
1413 }
1414}
1415
1429
1430std::optional<Bounds<float3>> CurvesGeometry::bounds_min_max(const bool use_radius) const
1431{
1432 if (this->is_empty()) {
1433 return std::nullopt;
1434 }
1435 if (use_radius) {
1436 this->runtime->bounds_with_radius_cache.ensure([&](Bounds<float3> &r_bounds) {
1437 const VArray<float> radius = this->radius();
1438 if (const std::optional radius_single = radius.get_if_single()) {
1439 r_bounds = *this->bounds_min_max(false);
1440 r_bounds.pad(*radius_single);
1441 return;
1442 }
1443 const Span radius_span = radius.get_internal_span();
1444 if (this->is_single_type(CURVE_TYPE_POLY)) {
1445 r_bounds = *bounds::min_max_with_radii(this->positions(), radius_span);
1446 return;
1447 }
1448 Array<float> radii_eval(this->evaluated_points_num());
1450 this->interpolate_to_evaluated(radius_span, radii_eval.as_mutable_span());
1451 r_bounds = *bounds::min_max_with_radii(this->evaluated_positions(), radii_eval.as_span());
1452 });
1453 }
1454 else {
1455 this->runtime->bounds_cache.ensure([&](Bounds<float3> &r_bounds) {
1456 r_bounds = *bounds::min_max(this->evaluated_positions());
1457 });
1458 }
1459 return use_radius ? this->runtime->bounds_with_radius_cache.data() :
1460 this->runtime->bounds_cache.data();
1461}
1462
1463std::optional<int> CurvesGeometry::material_index_max() const
1464{
1465 this->runtime->max_material_index_cache.ensure([&](std::optional<int> &r_max_material_index) {
1466 r_max_material_index = bounds::max<int>(
1467 this->attributes()
1468 .lookup_or_default<int>("material_index", bke::AttrDomain::Curve, 0)
1469 .varray);
1470 if (r_max_material_index.has_value()) {
1471 r_max_material_index = std::clamp(*r_max_material_index, 0, MAXMAT);
1472 }
1473 });
1474 return this->runtime->max_material_index_cache.data();
1475}
1476
1478{
1479 memory.add_shared(this->runtime->curve_offsets_sharing_info, this->offsets().size_in_bytes());
1480 memory.add_shared(this->runtime->custom_knots_sharing_info,
1481 this->nurbs_custom_knots().size_in_bytes());
1482 this->attribute_storage.wrap().count_memory(memory);
1483 CustomData_count_memory(this->point_data, this->point_num, memory);
1484}
1485
1487 const IndexMask &points_to_copy,
1488 const Span<int> curve_point_counts,
1489 CurvesGeometry &dst_curves)
1490{
1491 const OffsetIndices points_by_curve = curves.points_by_curve();
1492 const VArray<int8_t> orders = curves.nurbs_orders();
1493 const VArray<bool> cyclic = curves.cyclic();
1494
1495 IndexMaskMemory memory;
1496 const IndexMask custom_knot_curves = curves.nurbs_custom_knot_curves(memory);
1497 const IndexMask custom_knot_points = bke::curves::curve_to_point_selection(
1498 points_by_curve, custom_knot_curves, memory);
1499 const IndexMask custom_knot_points_to_copy = IndexMask::from_intersection(
1500 points_to_copy, custom_knot_points, memory);
1501
1502 int dst_knot_count = 0;
1503 custom_knot_curves.foreach_index([&](const int64_t curve) {
1504 dst_knot_count += curves::nurbs::knots_num(
1505 curve_point_counts[curve], orders[curve], cyclic[curve]);
1506 });
1507 const OffsetIndices<int> src_knots_by_curve = curves.nurbs_custom_knots_by_curve();
1508 const Span<float> src_knots = curves.nurbs_custom_knots();
1509
1510 Vector<float> new_knots;
1511 new_knots.reserve(dst_knot_count);
1512
1514 custom_knot_points_to_copy,
1515 points_by_curve,
1516 [&](int curve, IndexRange points, Span<IndexRange> ranges_to_copy) {
1517 const IndexRange src_range = src_knots_by_curve[curve];
1518 const int order = orders[curve];
1519 const int leading_spans = order / 2;
1520 const int point_to_knot = -points.start() + src_range.start();
1521 const int point_to_span = point_to_knot + leading_spans;
1522
1523 const int first_knot = ranges_to_copy.first().start() + point_to_knot;
1524 new_knots.extend(
1525 src_knots.slice(IndexRange::from_begin_size(first_knot, leading_spans + 1)));
1526 float last_knot = new_knots.last();
1527 for (IndexRange range : ranges_to_copy) {
1528 for (const int spans_left_knot : range.shift(point_to_span)) {
1529 last_knot += src_knots[spans_left_knot + 1] - src_knots[spans_left_knot];
1530 new_knots.append(last_knot);
1531 }
1532 }
1533 const int last_spans_left_knot = ranges_to_copy.last().last() + point_to_span + 1;
1534 last_knot += src_knots[last_spans_left_knot + 1] - src_knots[last_spans_left_knot];
1535 new_knots.append(last_knot);
1536 });
1537 dst_curves.nurbs_custom_knots_update_size();
1538 dst_curves.nurbs_custom_knots_for_write().copy_from(new_knots);
1539}
1540
1542 const IndexMask &points_to_copy,
1543 const AttributeFilter &attribute_filter)
1544{
1546 const Array<int> point_to_curve_map = curves.point_to_curve_map();
1547 Array<int> curve_point_counts(curves.curves_num(), 0);
1548 points_to_copy.foreach_index_optimized<int64_t>(
1549 [&](const int64_t point_i) { curve_point_counts[point_to_curve_map[point_i]]++; });
1550
1551 IndexMaskMemory memory;
1552 const IndexMask curves_to_copy = IndexMask::from_predicate(
1553 curves.curves_range(), memory, [&](const int64_t i) { return curve_point_counts[i] > 0; });
1554
1555 CurvesGeometry dst_curves(points_to_copy.size(), curves_to_copy.size());
1556
1557 BKE_defgroup_copy_list(&dst_curves.vertex_group_names, &curves.vertex_group_names);
1558
1560 dst_curves.curves_num() > 1024,
1561 [&]() {
1562 if (curves_to_copy.is_empty()) {
1563 return;
1564 }
1565 MutableSpan<int> new_curve_offsets = dst_curves.offsets_for_write();
1567 curve_point_counts.as_span(), curves_to_copy, new_curve_offsets.drop_back(1));
1569 },
1570 [&]() {
1571 gather_attributes(curves.attributes(),
1574 attribute_filter,
1575 points_to_copy,
1576 dst_curves.attributes_for_write());
1577 gather_attributes(curves.attributes(),
1580 attribute_filter,
1581 curves_to_copy,
1582 dst_curves.attributes_for_write());
1583 });
1584
1585 if (curves.nurbs_has_custom_knots()) {
1586 copy_point_selection_custom_knots(curves, points_to_copy, curve_point_counts, dst_curves);
1587 }
1588
1589 if (dst_curves.curves_num() == curves.curves_num()) {
1590 dst_curves.runtime->type_counts = curves.runtime->type_counts;
1591 }
1592 else {
1593 dst_curves.remove_attributes_based_on_types();
1594 }
1595
1596 return dst_curves;
1597}
1598
1599void CurvesGeometry::remove_points(const IndexMask &points_to_delete,
1600 const AttributeFilter &attribute_filter)
1601{
1602 if (points_to_delete.is_empty()) {
1603 return;
1604 }
1605 if (points_to_delete.size() == this->points_num()) {
1606 this->resize(0, 0);
1607 this->update_curve_types();
1608 return;
1609 }
1610 IndexMaskMemory memory;
1611 const IndexMask points_to_copy = points_to_delete.complement(this->points_range(), memory);
1612 *this = curves_copy_point_selection(*this, points_to_copy, attribute_filter);
1613}
1614
1616 const IndexMask &curves_to_copy,
1617 CurvesGeometry &dst_curves)
1618{
1619 IndexMaskMemory memory;
1620 const IndexMask custom_knot_curves = curves.nurbs_custom_knot_curves(memory);
1621 const IndexMask custom_knot_curves_to_copy = IndexMask::from_intersection(
1622 curves_to_copy, custom_knot_curves, memory);
1623
1624 Array<int> dst_knot_offsets_data(custom_knot_curves_to_copy.size() + 1, 0);
1625
1626 const OffsetIndices<int> src_knots_by_curve = curves.nurbs_custom_knots_by_curve();
1628 src_knots_by_curve, custom_knot_curves_to_copy, dst_knot_offsets_data);
1629
1630 dst_curves.nurbs_custom_knots_update_size();
1631 array_utils::gather_group_to_group(src_knots_by_curve,
1632 dst_knots_by_curve,
1633 custom_knot_curves_to_copy,
1634 curves.nurbs_custom_knots(),
1635 dst_curves.nurbs_custom_knots_for_write());
1636}
1637
1639 const IndexMask &curves_to_copy,
1640 const AttributeFilter &attribute_filter)
1641{
1643 const OffsetIndices points_by_curve = curves.points_by_curve();
1644 CurvesGeometry dst_curves(0, curves_to_copy.size());
1645 const OffsetIndices dst_points_by_curve = offset_indices::gather_selected_offsets(
1646 points_by_curve, curves_to_copy, dst_curves.offsets_for_write());
1647 dst_curves.resize(dst_points_by_curve.total_size(), dst_curves.curves_num());
1648
1649 BKE_defgroup_copy_list(&dst_curves.vertex_group_names, &curves.vertex_group_names);
1650
1651 const AttributeAccessor src_attributes = curves.attributes();
1652 MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
1653
1654 gather_attributes_group_to_group(src_attributes,
1657 attribute_filter,
1658 points_by_curve,
1659 dst_points_by_curve,
1660 curves_to_copy,
1661 dst_attributes);
1662
1663 gather_attributes(src_attributes,
1666 attribute_filter,
1667 curves_to_copy,
1668 dst_attributes);
1669
1670 if (curves.nurbs_has_custom_knots()) {
1671 copy_curve_selection_custom_knots(curves, curves_to_copy, dst_curves);
1672 }
1673
1675
1676 return dst_curves;
1677}
1678
1679void CurvesGeometry::remove_curves(const IndexMask &curves_to_delete,
1680 const AttributeFilter &attribute_filter)
1681{
1682 if (curves_to_delete.is_empty()) {
1683 return;
1684 }
1685 if (curves_to_delete.size() == this->curves_num()) {
1686 this->resize(0, 0);
1687 this->update_curve_types();
1688 return;
1689 }
1690 IndexMaskMemory memory;
1691 const IndexMask curves_to_copy = curves_to_delete.complement(this->curves_range(), memory);
1692 *this = curves_copy_curve_selection(*this, curves_to_copy, attribute_filter);
1693}
1694
1696{
1697 const float last = custom_knots.last();
1698 custom_knots.reverse();
1699 for (float &knot_value : custom_knots) {
1700 knot_value = last - knot_value;
1701 }
1702}
1703
1704template<typename T>
1706 const IndexMask &curve_selection,
1708{
1709 const OffsetIndices points_by_curve = curves.points_by_curve();
1710 curve_selection.foreach_index(
1711 [&](const int curve_i) { data.slice(points_by_curve[curve_i]).reverse(); },
1713}
1714
1715template<typename T>
1717 const IndexMask &curve_selection,
1718 MutableSpan<T> data_a,
1719 MutableSpan<T> data_b)
1720{
1721 const OffsetIndices points_by_curve = curves.points_by_curve();
1722 curve_selection.foreach_index(
1723 [&](const int curve_i) {
1724 const IndexRange points = points_by_curve[curve_i];
1725 MutableSpan<T> a = data_a.slice(points);
1726 MutableSpan<T> b = data_b.slice(points);
1727 for (const int i : IndexRange(points.size() / 2)) {
1728 const int end_index = points.size() - 1 - i;
1729 std::swap(a[end_index], b[i]);
1730 std::swap(b[end_index], a[i]);
1731 }
1732 if (points.size() % 2) {
1733 const int64_t middle_index = points.size() / 2;
1734 std::swap(a[middle_index], b[middle_index]);
1735 }
1736 },
1738}
1739
1740void CurvesGeometry::reverse_curves(const IndexMask &curves_to_reverse)
1741{
1742 Set<StringRef> bezier_handle_names{{ATTR_HANDLE_POSITION_LEFT,
1746
1748
1749 attributes.foreach_attribute([&](const AttributeIter &iter) {
1750 if (iter.domain != AttrDomain::Point) {
1751 return;
1752 }
1753 if (iter.data_type == bke::AttrType::String) {
1754 return;
1755 }
1757 return;
1758 }
1759 if (bezier_handle_names.contains(iter.name)) {
1760 return;
1761 }
1762
1764 attribute_math::to_static_type(attribute.span.type(), [&]<typename T>() {
1765 reverse_curve_point_data<T>(*this, curves_to_reverse, attribute.span.typed<T>());
1766 });
1767 attribute.finish();
1768 return;
1769 });
1770
1771 if (this->nurbs_has_custom_knots()) {
1772 const OffsetIndices custom_knots_by_curve = this->nurbs_custom_knots_by_curve();
1774 curves_to_reverse.foreach_index(
1775 [&](const int64_t curve) {
1776 const IndexRange curve_knots = custom_knots_by_curve[curve];
1777 if (!custom_knots.is_empty()) {
1779 }
1780 },
1782 }
1783
1784 /* In order to maintain the shape of Bezier curves, handle attributes must reverse, but also the
1785 * values for the left and right must swap. Use a utility to swap and reverse at the same time,
1786 * to avoid loading the attribute twice. Generally we can expect the right layer to exist when
1787 * the left does, but there's no need to count on it, so check for both attributes. */
1788
1791 {
1793 curves_to_reverse,
1796 }
1799 curves_to_reverse,
1802 }
1803
1804 this->tag_topology_changed();
1805}
1806
1825
1826CurvesGeometry curves_new_no_attributes(int point_num, int curve_num)
1827{
1828 CurvesGeometry curves(0, curve_num);
1829 curves.point_num = point_num;
1830 curves.attribute_storage.wrap().remove("position");
1831 return curves;
1832}
1833
1835
1836/* -------------------------------------------------------------------- */
1839
1847template<typename T>
1849 const VArray<T> &old_values,
1850 MutableSpan<T> r_values)
1851{
1852 attribute_math::DefaultMixer<T> mixer(r_values);
1853
1854 const OffsetIndices points_by_curve = curves.points_by_curve();
1855 threading::parallel_for(curves.curves_range(), 128, [&](const IndexRange range) {
1856 for (const int i_curve : range) {
1857 for (const int i_point : points_by_curve[i_curve]) {
1858 mixer.mix_in(i_curve, old_values[i_point]);
1859 }
1860 }
1861 mixer.finalize(range);
1862 });
1863}
1864
1872template<>
1874 const VArray<bool> &old_values,
1875 MutableSpan<bool> r_values)
1876{
1877 const OffsetIndices points_by_curve = curves.points_by_curve();
1878 r_values.fill(true);
1879 for (const int i_curve : IndexRange(curves.curves_num())) {
1880 for (const int i_point : points_by_curve[i_curve]) {
1881 if (!old_values[i_point]) {
1882 r_values[i_curve] = false;
1883 break;
1884 }
1885 }
1886 }
1887}
1888
1890 const GVArray &varray)
1891{
1893 GVArray new_varray;
1894 attribute_math::to_static_type(varray.type(), [&]<typename T>() {
1895 if constexpr (!std::is_void_v<attribute_math::DefaultMixer<T>>) {
1896 Array<T> values(curves.curves_num());
1897 adapt_curve_domain_point_to_curve_impl<T>(curves, varray.typed<T>(), values);
1898 new_varray = VArray<T>::from_container(std::move(values));
1899 }
1900 });
1901 return new_varray;
1902}
1903
1912 const GVArray &varray)
1913{
1915 GArray<> values(varray.type(), curves.points_num());
1917 curves.points_by_curve(), curves.curves_range(), GVArraySpan(varray), values);
1918 return GVArray::from_garray(std::move(values));
1919}
1920
1922 const AttrDomain from,
1923 const AttrDomain to) const
1924{
1925 if (!varray) {
1926 return {};
1927 }
1928 if (varray.is_empty()) {
1929 return {};
1930 }
1931 if (from == to) {
1932 return varray;
1933 }
1934 if (varray.is_single()) {
1935 BUFFER_FOR_CPP_TYPE_VALUE(varray.type(), value);
1936 varray.get_internal_single(value);
1937 return GVArray::from_single(varray.type(), this->attributes().domain_size(to), value);
1938 }
1939
1940 if (from == AttrDomain::Point && to == AttrDomain::Curve) {
1941 return adapt_curve_domain_point_to_curve(*this, varray);
1942 }
1943 if (from == AttrDomain::Curve && to == AttrDomain::Point) {
1944 return adapt_curve_domain_curve_to_point(*this, varray);
1945 }
1946
1948 return {};
1949}
1950
1955
1960
1962
1963/* -------------------------------------------------------------------- */
1966
1968{
1969 this->runtime = MEM_new<bke::CurvesGeometryRuntime>(__func__);
1970
1971 CustomData_blend_read(&reader, &this->point_data, this->point_num);
1972 CustomData_blend_read(&reader, &this->curve_data_legacy, this->curve_num);
1973 this->attribute_storage.wrap().blend_read(reader);
1974
1975 if (this->curve_offsets) {
1977 &reader, &this->curve_offsets, [&]() {
1978 if (!BLO_read_array(&reader, &this->curve_offsets, int64_t(this->curve_num) + 1)) {
1979 this->curve_num = 0;
1980 }
1982 nullptr;
1983 });
1984 }
1985
1987
1988 if (this->custom_knot_num) {
1990 &reader, &this->custom_knots, [&]() {
1991 BLO_read_array_and_validate_size(&reader, &this->custom_knots, &this->custom_knot_num);
1992 return this->custom_knots ? implicit_sharing::info_for_mem_free(this->custom_knots) :
1993 nullptr;
1994 });
1995 }
1996
1997 /* Curve types are used as array indices when counting them below. There is always one value per
1998 * curve when writing, so a different size means the file is corrupt. */
1999 const VArray<int8_t> types = this->curve_types();
2000 if (types.size() != this->curve_num) {
2001 BLO_read_data_invalidate(&reader, "Invalid curve types");
2002 return;
2003 }
2004
2005 /* Out of range values can be written, since the attribute validator used to allow
2006 * #CURVE_TYPES_NUM. Replace them so such files can still be loaded. */
2007 bool any_invalid = false;
2008 if (!curve_types_are_valid(types)) {
2009 any_invalid = true;
2010 if (this->curve_num > 0) {
2012 }
2013 else {
2015 }
2016 }
2017
2018 /* Older files store curve types in legacy custom data, converted during versioning. */
2019 if (const void *legacy_types = CustomData_get_layer_named(
2021 {
2022 const Span<int8_t> legacy_span(static_cast<const int8_t *>(legacy_types), this->curve_num);
2024 any_invalid = true;
2025 void *legacy_types_for_write = CustomData_get_layer_named_for_write(
2027 sanitize_curve_types({static_cast<int8_t *>(legacy_types_for_write), this->curve_num});
2028 }
2029 }
2030
2031 if (any_invalid) {
2033 BLO_read_data_reports(&reader), RPT_ERROR, "%s", RPT_("Invalid curve type identifiers"));
2034 }
2035
2036 /* Recalculate curve type count cache that isn't saved in files. */
2037 this->update_curve_types();
2038}
2039
2047
2049 const bool use_5_0_compatibility)
2050{
2053 this->attribute_storage.wrap(),
2054 use_5_0_compatibility,
2055 [&](const AttrDomain domain) { return this->attributes().domain_size(domain); },
2056 write_data.attribute_data);
2058 if (write_data.attribute_data.attributes.is_empty()) {
2059 this->attribute_storage.dna_attributes = nullptr;
2061 }
2062 else {
2065 }
2066
2068}
2069
2071 ID &id,
2072 const CurvesGeometry::BlendWriteData &write_data)
2073{
2075 &writer, &this->point_data, write_data.point_layers, this->point_num, CD_MASK_ALL, &id);
2076 this->attribute_storage.wrap().blend_write(writer, write_data.attribute_data);
2077
2078 if (this->curve_offsets) {
2079 writer.write_shared(
2080 this->curve_offsets,
2081 sizeof(int) * (this->curve_num + 1),
2082 this->runtime->curve_offsets_sharing_info,
2083 [&]() { writer.write_int32_array(this->curve_num + 1, this->curve_offsets); });
2084 }
2085
2087
2088 if (this->custom_knot_num) {
2089 writer.write_shared(
2090 this->custom_knots,
2091 sizeof(float) * this->custom_knot_num,
2092 this->runtime->custom_knots_sharing_info,
2093 [&]() { writer.write_float_array(this->custom_knot_num, this->custom_knots); });
2094 }
2095}
2096
2098
2099} // namespace blender::bke
Low-level operations for curves.
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
#define BLO_read_struct_list(reader, struct_name, list)
#define RPT_(msgid)
#define CURVE_TYPES_NUM
#define MAXMAT
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define PRF_scope_with_name(ui_name, category)
#define PRF_scope(category)
#define BLI_assert_unreachable()
#define CD_MASK_MDEFORMVERT
#define CD_MASK_ALL
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
static const CPPType & get()
void copy_from(GSpan values)
GMutableSpan slice(const int64_t start, int64_t size) const
GSpan slice(const int64_t start, int64_t size) const
int64_t size() const
void get_internal_single(void *r_value) const
static GVArray from_garray(GArray<> array)
static GVArray from_single(const CPPType &type, int64_t size, const void *value)
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_intersection(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr IndexRange()=default
static constexpr IndexRange from_begin_size(const int64_t begin, const int64_t size)
constexpr int64_t start() const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr bool is_empty() const
Definition BLI_span.hh:515
constexpr MutableSpan drop_back(const int64_t n) const
Definition BLI_span.hh:624
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
constexpr void reverse() const
Definition BLI_span.hh:656
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:695
bool contains(const Key &key) const
Definition BLI_set.hh:310
void ensure(FunctionRef< void(T &data)> compute_cache)
const T & data() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
std::optional< T > get_if_single() const
IndexRange index_range() const
Span< T > get_internal_span() const
static VArray from_span(Span< T > values)
void append(const T &value)
const T & last(const int64_t n=0) const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void reserve(const int64_t min_capacity)
void extend(Span< T > array)
void reinitialize(const int64_t new_size)
Span< T > as_span() const
void clear_and_shrink()
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
AttributeAccessor(const void *owner, const AttributeAccessorFunctions &fn)
std::optional< AttrStorageType > storage_type
void blend_read(BlendDataReader &reader)
void resize(AttrDomain domain, int64_t new_size)
Attribute * lookup(StringRef name)
void blend_write(BlendWriter &writer, const BlendWriteData &write_data)
void count_memory(MemoryCounter &memory) const
Attribute & add(std::string name, bke::AttrDomain domain, bke::AttrType data_type, Attribute::DataVariant data)
SharedCache< Vector< curves::nurbs::BasisCache > > nurbs_basis_cache
SharedCache< Vector< float > > evaluated_length_cache
SharedCache< Bounds< float3 > > bounds_with_radius_cache
SharedCache< Vector< int > > custom_knot_offsets_cache
SharedCache< Vector< float3 > > evaluated_tangent_cache
SharedCache< EvaluatedOffsets > evaluated_offsets_cache
Definition BKE_curves.hh:97
SharedCache< Vector< float3 > > evaluated_normal_cache
std::unique_ptr< bake::BakeMaterialsList > bake_materials
const ImplicitSharingInfo * custom_knots_sharing_info
Definition BKE_curves.hh:81
SharedCache< std::optional< int > > max_material_index_cache
SharedCache< Bounds< float3 > > bounds_cache
SharedCache< Vector< float3 > > evaluated_position_cache
const ImplicitSharingInfo * curve_offsets_sharing_info
Definition BKE_curves.hh:78
SharedCache< bool > has_cyclic_curve_cache
Definition BKE_curves.hh:99
std::array< int, CURVE_TYPES_NUM > type_counts
Definition BKE_curves.hh:87
Span< float3 > evaluated_tangents() const
MutableSpan< MDeformVert > deform_verts_for_write()
MutableSpan< int8_t > handle_types_left_for_write()
VArray< int8_t > curve_types() const
void ensure_can_interpolate_to_evaluated() const
VArray< int8_t > nurbs_orders() const
std::optional< Span< float > > nurbs_weights() const
MutableSpan< int8_t > nurbs_orders_for_write()
void blend_write(BlendWriter &writer, ID &id, const BlendWriteData &write_data)
Span< float > nurbs_custom_knots() const
std::optional< int > material_index_max() const
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
std::optional< Bounds< float3 > > bounds_min_max(bool use_radius=true) const
void blend_read(BlendDataReader &reader)
void remove_points(const IndexMask &points_to_delete, const AttributeFilter &attribute_filter)
void transform(const float4x4 &matrix)
std::optional< Span< float3 > > handle_positions_right() const
MutableSpan< int8_t > normal_mode_for_write()
void resize(int points_num, int curves_num)
MutableSpan< float > tilt_for_write()
VArray< bool > cyclic() const
OffsetIndices< int > nurbs_custom_knots_by_curve() const
AttributeAccessor attributes() const
MutableSpan< float > nurbs_custom_knots_for_write()
Span< float3 > positions() const
bool is_single_type(CurveType type) const
void interpolate_to_evaluated(int curve_index, GSpan src, GMutableSpan dst) const
MutableSpan< float3 > handle_positions_right_for_write()
MutableSpan< float2 > surface_uv_coords_for_write()
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
std::optional< Span< float2 > > surface_uv_coords() const
Span< MDeformVert > deform_verts() const
MutableSpan< int > resolution_for_write()
void blend_write_prepare(BlendWriteData &write_data, bool use_5_0_compatibility)
VArray< int8_t > normal_mode() const
IndexMask nurbs_custom_knot_curves(IndexMaskMemory &memory) const
VArray< int8_t > nurbs_knots_modes() const
MutableSpan< int8_t > curve_types_for_write()
IndexMask indices_for_curve_type(CurveType type, IndexMaskMemory &memory) const
CurvesGeometry & operator=(const CurvesGeometry &other)
MutableSpan< int8_t > nurbs_knots_modes_for_write()
VArray< int8_t > handle_types_left() const
OffsetIndices< int > evaluated_points_by_curve() const
MutableSpan< float3 > handle_positions_left_for_write()
bool has_curve_with_type(CurveType type) const
MutableSpan< int > offsets_for_write()
IndexRange points_range() const
void fill_curve_types(CurveType type)
const std::array< int, CURVE_TYPES_NUM > & curve_type_counts() const
Span< float3 > evaluated_positions() const
VArray< int > resolution() const
MutableSpan< float > radius_for_write()
MutableSpan< float > nurbs_weights_for_write()
VArray< int8_t > handle_types_right() const
VArray< float > tilt() const
VArray< float > radius() const
GVArray adapt_domain(const GVArray &varray, AttrDomain from, AttrDomain to) const
MutableSpan< bool > cyclic_for_write()
void count_memory(MemoryCounter &memory) const
void nurbs_custom_knots_resize(int knots_num)
void remove_curves(const IndexMask &curves_to_delete, const AttributeFilter &attribute_filter)
OffsetIndices< int > points_by_curve() const
Span< float3 > evaluated_normals() const
Array< int > point_to_curve_map() const
MutableAttributeAccessor attributes_for_write()
void reverse_curves(const IndexMask &curves_to_reverse)
void translate(const float3 &translation)
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
MutableAttributeAccessor(void *owner, const AttributeAccessorFunctions &fn)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
constexpr bool is_empty() const
constexpr Span slice(int64_t start, int64_t size) const
void foreach_index_optimized(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
#define attribute(slot)
#define T
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void gather_group_to_group(const OffsetIndices< int > src_offsets, const OffsetIndices< int > dst_offsets, const IndexMask &selection, const Span< T > src, MutableSpan< T > dst)
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
void gather_to_groups(OffsetIndices< int > dst_offsets, const IndexMask &src_selection, GSpan src, GMutableSpan dst)
typename DefaultMixerStruct< T >::type DefaultMixer
void to_static_type(const CPPType &cpp_type, Fn &&fn)
void calculate_aligned_handles(const IndexMask &selection, Span< float3 > positions, Span< float3 > handles_left, Span< float3 > handles_right, MutableSpan< float3 > align_handles_left, MutableSpan< float3 > align_handles_right)
void calculate_auto_handles(bool cyclic, Span< int8_t > types_left, Span< int8_t > types_right, Span< float3 > positions, MutableSpan< float3 > positions_left, MutableSpan< float3 > positions_right)
void calculate_evaluated_offsets(Span< int8_t > handle_types_left, Span< int8_t > handle_types_right, bool cyclic, int resolution, MutableSpan< int > evaluated_offsets)
void calculate_evaluated_positions(Span< float3 > positions, Span< float3 > handles_left, Span< float3 > handles_right, OffsetIndices< int > evaluated_offsets, MutableSpan< float3 > evaluated_positions)
void interpolate_to_evaluated(GSpan src, OffsetIndices< int > evaluated_offsets, GMutableSpan dst)
int calculate_evaluated_num(int points_num, bool cyclic, int resolution)
void interpolate_to_evaluated(GSpan src, bool cyclic, int resolution, GMutableSpan dst)
int calculate_evaluated_num(int points_num, int8_t order, bool cyclic, int resolution, KnotsMode knots_mode, Span< float > knots)
void calculate_basis_cache(int points_num, int evaluated_num, int8_t order, int resolution, bool cyclic, KnotsMode knots_mode, Span< float > knots, BasisCache &basis_cache)
bool check_valid_eval_params(int points_num, int8_t order, bool cyclic, KnotsMode knots_mode, int resolution)
int knots_num(int points_num, int8_t order, bool cyclic)
void load_curve_knots(KnotsMode mode, int points_num, int8_t order, bool cyclic, IndexRange curve_knots, Span< float > custom_knots, MutableSpan< float > knots)
void interpolate_to_evaluated(const BasisCache &basis_cache, int8_t order, Span< float > control_weights, GSpan src, GMutableSpan dst)
void calculate_normals_z_up(Span< float3 > tangents, MutableSpan< float3 > normals)
void calculate_normals_minimum(Span< float3 > tangents, bool cyclic, MutableSpan< float3 > normals)
void calculate_tangents(Span< float3 > positions, bool is_cyclic, MutableSpan< float3 > tangents)
Definition curve_poly.cc:74
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, LinearAllocator<> &memory)
void foreach_selected_point_ranges_per_curve(const IndexMask &mask, OffsetIndices< int > points_by_curve, SelectedCallback selected_fn)
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)
IndexRange per_curve_point_offsets_range(const IndexRange points, const int curve_index)
const AttributeAccessorFunctions & get_attribute_accessor_functions()
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)
static void normalize_span(MutableSpan< float3 > data)
static void translate_positions(MutableSpan< float3 > positions, const float3 &translation)
CurvesGeometry curves_copy_curve_selection(const CurvesGeometry &curves, const IndexMask &curves_to_copy, const AttributeFilter &attribute_filter)
CurvesGeometry curves_copy_point_selection(const CurvesGeometry &curves, const IndexMask &points_to_copy, const AttributeFilter &attribute_filter)
constexpr StringRef ATTR_RADIUS
constexpr StringRef ATTR_RESOLUTION
GMutableSpan get_mutable_attribute(AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size, const void *custom_default_value)
static void copy_point_selection_custom_knots(const CurvesGeometry &curves, const IndexMask &points_to_copy, const Span< int > curve_point_counts, CurvesGeometry &dst_curves)
std::optional< GSpan > get_span_attribute(const AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size)
constexpr StringRef ATTR_CURVE_TYPE
static bool is_valid_curve_type(const int8_t type)
static GVArray adapt_curve_domain_point_to_curve(const CurvesGeometry &curves, const GVArray &varray)
constexpr StringRef ATTR_CYCLIC
void gather_attributes(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
CurvesGeometry curves_new_no_attributes(int point_num, int curve_num)
constexpr StringRef ATTR_SURFACE_UV_COORDINATE
constexpr StringRef ATTR_HANDLE_POSITION_RIGHT
std::array< int, CURVE_TYPES_NUM > calculate_type_counts(const VArray< int8_t > &types)
static void evaluate_generic_data_for_curve(const EvalData &eval_data, const int curve_index, const GSpan src, GMutableSpan dst)
GVArray get_varray_attribute(const AttributeStorage &storage, AttrDomain domain, const CPPType &cpp_type, StringRef name, int64_t domain_size, const void *default_value)
static void reverse_custom_knots(MutableSpan< float > custom_knots)
constexpr StringRef ATTR_NORMAL_MODE
constexpr StringRef ATTR_TILT
constexpr StringRef ATTR_HANDLE_POSITION_LEFT
void transform_custom_normal_attribute(const float4x4 &transform, MutableAttributeAccessor &attributes)
void attribute_storage_blend_write_prepare(AttributeStorage &data, bool use_5_0_compatibility, FunctionRef< int(AttrDomain)> get_domain_size, AttributeStorage::BlendWriteData &write_data)
void build_offsets(MutableSpan< int > offsets, const CountFn &count_fn)
static void reverse_curve_point_data(const CurvesGeometry &curves, const IndexMask &curve_selection, MutableSpan< T > data)
constexpr StringRef ATTR_HANDLE_TYPE_LEFT
void gather_attributes_group_to_group(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
static void reverse_swap_curve_point_data(const CurvesGeometry &curves, const IndexMask &curve_selection, MutableSpan< T > data_a, MutableSpan< T > data_b)
constexpr StringRef ATTR_NURBS_KNOTS_MODE
static bool curve_types_are_valid(const VArray< int8_t > &types)
constexpr StringRef ATTR_POSITION
static GVArray adapt_curve_domain_curve_to_point(const CurvesGeometry &curves, const GVArray &varray)
constexpr StringRef ATTR_NURBS_ORDER
static void sanitize_curve_types(MutableSpan< int8_t > types)
constexpr StringRef ATTR_NURBS_WEIGHT
constexpr StringRef ATTR_HANDLE_TYPE_RIGHT
static void rotate_directions_around_axes(MutableSpan< float3 > directions, const Span< float3 > axes, const Span< float > angles)
static void copy_curve_selection_custom_knots(const CurvesGeometry &curves, const IndexMask &curves_to_copy, CurvesGeometry &dst_curves)
static void calculate_evaluated_offsets(const CurvesGeometry &curves, MutableSpan< int > offsets, MutableSpan< int > all_bezier_offsets)
static void adapt_curve_domain_point_to_curve_impl(const CurvesGeometry &curves, const VArray< T > &old_values, MutableSpan< T > r_values)
std::optional< Bounds< T > > min_max_with_radii(const Span< T > values, const Span< RadiusT > radii)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
Definition BLI_bounds.hh:56
std::optional< T > max(const VArray< T > &values)
constexpr ParallelGrainSize grain_size(int grain_size)
void resize_trivial_array(T **data, const ImplicitSharingInfo **sharing_info, int64_t old_size, int64_t new_size)
void free_shared_data(T **data, const ImplicitSharingInfo **sharing_info)
const ImplicitSharingInfo * info_for_mem_free(T *data)
void make_trivial_data_mutable(T **data, const ImplicitSharingInfo **sharing_info, const int64_t size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
void accumulate_lengths(const Span< T > values, const bool cyclic, MutableSpan< float > lengths)
bool is_zero(const T &a)
float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, float angle)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
bool almost_equal_relative(const VecBase< T, Size > &a, const VecBase< T, Size > &b, const T &epsilon_factor)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
void build_reverse_map(OffsetIndices< int > offsets, MutableSpan< int > r_map)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
void parallel_invoke(Functions &&...functions)
Definition BLI_task.hh:197
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
const ImplicitSharingInfo * BLO_read_shared(BlendDataReader *reader, T **data_ptr, FunctionRef< const ImplicitSharingInfo *()> read_fn)
void BKE_defbase_blend_write(BlendWriter *writer, const ListBaseT< bDeformGroup > *defbase)
Definition deform.cc:1597
BlendFileReadReport * BLO_read_data_reports(BlendDataReader *reader)
Definition readfile.cc:6834
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void CustomData_realloc(CustomData *data, int old_size, int new_size, eCDAllocType alloctype=CD_CONSTRUCT)
void BLO_read_data_invalidate(BlendDataReader *reader, const char *message)
Definition readfile.cc:6839
MatBase< float, 4, 4 > float4x4
@ NURBS_KNOT_MODE_CUSTOM
const void * CustomData_get_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
void CustomData_reset(CustomData *data)
void CustomData_blend_write(BlendWriter *writer, CustomData *data, Span< CustomDataLayer > layers_to_write, int count, eCustomDataMask cddata_mask, ID *id)
BMesh const char void * data
void CustomData_blend_write_prepare(CustomData &data, Vector< CustomDataLayer, 16 > &layers_to_write)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void BLO_reportf_wrap(BlendFileReadReport *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition readfile.cc:237
bool BLO_read_array(BlendDataReader *reader, T **ptr_p, const SizeT array_size, const int elems=1)
void BLO_read_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size, const int elems=1)
void CustomData_count_memory(const CustomData &data, int totelem, MemoryCounter &memory)
void CustomData_free(CustomData *data)
@ CURVE_TYPE_CATMULL_ROM
void * CustomData_get_layer_named_for_write(CustomData *data, eCustomDataType type, StringRef name, int totelem)
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
VecBase< float, 3 > float3
@ NORMAL_MODE_MINIMUM_TWIST
void CustomData_init_from(const CustomData *source, CustomData *dest, eCustomDataMask mask, int totelem)
signed char int8_t
Definition BKE_text.h:76
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
void CustomData_blend_read(BlendDataReader *reader, CustomData *data, int count)
struct Attribute * dna_attributes
void write_shared(const void *data, size_t approximate_size_in_bytes, const ImplicitSharingInfo *sharing_info, FunctionRef< void()> write_fn)
void generated_pointer_tag(const void *data)
void pad(const PaddingT &padding)
bke::CurvesGeometryRuntime * runtime
struct AttributeStorage attribute_storage
ListBaseT< struct bDeformGroup > vertex_group_names
static SingleData from_value(const GPointer &value)
Vector< CustomDataLayer, 16 > & curve_layers
BlendWriteData(BlendWriter *writer, ResourceScope &scope)
Vector< CustomDataLayer, 16 > & point_layers
AttributeStorage::BlendWriteData attribute_data
const VArray< bool > & cyclic
const Span< int > all_bezier_evaluated_offsets
const VArray< int > & resolution
const Span< curves::nurbs::BasisCache > nurbs_basis_cache
const VArray< int8_t > & nurbs_orders
const VArray< int8_t > & types
const OffsetIndices< int > points_by_curve
const std::optional< Span< float > > nurbs_weights