Blender V5.3
curves_data.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 "BKE_curves.hh"
10#include "BKE_curves_utils.hh"
11
12#include "DNA_object_types.h"
13
14#include "ED_curves.hh"
15#include "ED_transverts.hh"
16
17namespace blender::ed::curves {
18
20{
21 Vector<MutableSpan<float3>> positions_per_attribute;
22 positions_per_attribute.append(curves.positions_for_write());
23 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
24 positions_per_attribute.append(curves.handle_positions_left_for_write());
25 positions_per_attribute.append(curves.handle_positions_right_for_write());
26 }
27 return positions_per_attribute;
28}
29
31{
32 Vector<Span<float3>> positions_per_attribute;
33 positions_per_attribute.append(curves.positions());
34 const std::optional<Span<float3>> handles_left = curves.handle_positions_left();
35 const std::optional<Span<float3>> handles_right = curves.handle_positions_right();
36 if (handles_left && handles_right) {
37 positions_per_attribute.append(*handles_left);
38 positions_per_attribute.append(*handles_right);
39 }
40 return positions_per_attribute;
41}
42
43static std::array<IndexMask, 3> transverts_curves_selection(const bke::CurvesGeometry &curves,
44 const bool skip_handles,
45 IndexMaskMemory &memory)
46{
47 std::array<IndexMask, 3> selection;
49 if (selection_names.size() == 1) {
50 selection[0] = ed::curves::retrieve_selected_points(curves, memory);
51 }
52 else {
54 curves, CURVE_TYPE_BEZIER, memory);
55
56 for (const int i : selection_names.index_range()) {
58 curves, selection_names[i], bezier_points, memory);
59 }
60 }
61
62 if (skip_handles) {
63 /* When the control point is selected, both handles are ignored. */
64 selection[1] = IndexMask::from_difference(selection[1], selection[0], memory);
65 selection[2] = IndexMask::from_difference(selection[2], selection[0], memory);
66 }
67
68 return selection;
69}
70
72 TransVertStore *tvs,
73 const bool skip_handles)
74{
75 IndexMaskMemory memory;
76 std::array<IndexMask, 3> selection = transverts_curves_selection(curves, skip_handles, memory);
77 const int size = selection[0].size() + selection[1].size() + selection[2].size();
78 if (size == 0) {
79 return;
80 }
81 tvs->transverts = MEM_new_array_zeroed<TransVert>(size, __func__);
82 tvs->transverts_tot = size;
83
84 int offset = 0;
86 for (const int attribute_i : positions.index_range()) {
87 selection[attribute_i].foreach_index(
88 [&](const int64_t i, const int64_t pos) {
89 TransVert &tv = tvs->transverts[pos + offset];
90 tv.loc = positions[attribute_i][i];
91 tv.flag = SELECT;
92 copy_v3_v3(tv.oldloc, tv.loc);
93 },
95
96 offset += selection[attribute_i].size();
97 }
98}
99
101 const TransVertStore *tvs,
102 const bool skip_handles)
103{
104 IndexMaskMemory memory;
105 std::array<IndexMask, 3> selection = transverts_curves_selection(curves, skip_handles, memory);
106 const int size = selection[0].size() + selection[1].size() + selection[2].size();
107 if (size == 0 || size != tvs->transverts_tot) {
108 return;
109 }
110
111 int offset = 0;
113 const Span<TransVert> all_transverts = {tvs->transverts, tvs->transverts_tot};
114 for (const int attribute_i : positions.index_range()) {
115 const Span<TransVert> transverts = all_transverts.slice_safe(offset,
116 selection[attribute_i].size());
117 selection[attribute_i].foreach_index(
118 [&](const int64_t i, const int64_t pos) {
119 const TransVert &tv = transverts[pos];
120 positions[attribute_i][i] += float3(tv.loc) - float3(tv.oldloc);
121 },
123
124 offset += selection[attribute_i].size();
125 }
126
127 curves.tag_positions_changed();
128 curves.calculate_bezier_auto_handles();
129}
130
132{
133 const bke::CurvesGeometry &curves = curves_id->geometry.wrap();
134 const int size = curves.points_num();
137 return reinterpret_cast<float (*)[3]>(data);
138}
139
140} // namespace blender::ed::curves
Low-level operations for curves.
Low-level operations for curves.
#define SELECT
Definition BKE_mask.hh:19
Object is a sort of wrapper for general info.
static IndexMask from_difference(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr Span slice_safe(const int64_t start, const int64_t size) const
Definition BLI_span.hh:158
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
void append(const T &value)
IndexRange index_range() const
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, LinearAllocator<> &memory)
void curves_normals_point_domain_calc(const CurvesGeometry &curves, MutableSpan< float3 > normals)
void transverts_from_curves_positions_create(bke::CurvesGeometry &curves, TransVertStore *tvs, const bool skip_handles)
static std::array< IndexMask, 3 > transverts_curves_selection(const bke::CurvesGeometry &curves, const bool skip_handles, IndexMaskMemory &memory)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
Vector< Span< float3 > > get_curves_positions(const bke::CurvesGeometry &curves)
float(* point_normals_array_create(const Curves *curves_id))[3]
Vector< MutableSpan< float3 > > get_curves_positions_for_write(bke::CurvesGeometry &curves)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
void transverts_update_curves(bke::CurvesGeometry &curves, const TransVertStore *tvs, const bool skip_handles)
constexpr ParallelGrainSize grain_size(int grain_size)
__int64 int64_t
Definition BKE_text.h:90
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
BMesh const char void * data
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
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float