Blender V5.0
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
5#include "BKE_curves.hh"
6#include "BKE_curves_utils.hh"
7
8#include "DNA_object_types.h"
9
10#include "ED_curves.hh"
11#include "ED_transverts.hh"
12
13namespace blender::ed::curves {
14
16{
17 Vector<MutableSpan<float3>> positions_per_attribute;
18 positions_per_attribute.append(curves.positions_for_write());
19 if (curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
20 positions_per_attribute.append(curves.handle_positions_left_for_write());
21 positions_per_attribute.append(curves.handle_positions_right_for_write());
22 }
23 return positions_per_attribute;
24}
25
27{
28 Vector<Span<float3>> positions_per_attribute;
29 positions_per_attribute.append(curves.positions());
30 const std::optional<Span<float3>> handles_left = curves.handle_positions_left();
31 const std::optional<Span<float3>> handles_right = curves.handle_positions_right();
32 if (handles_left && handles_right) {
33 positions_per_attribute.append(*handles_left);
34 positions_per_attribute.append(*handles_right);
35 }
36 return positions_per_attribute;
37}
38
40 TransVertStore *tvs,
41 const bool skip_handles)
42{
44
45 IndexMaskMemory memory;
46 std::array<IndexMask, 3> selection;
47 if (selection_names.size() == 1) {
48 selection[0] = ed::curves::retrieve_selected_points(curves, memory);
49 }
50 else {
52 curves, CURVE_TYPE_BEZIER, memory);
53
54 for (const int i : selection_names.index_range()) {
56 curves, selection_names[i], bezier_points, memory);
57 }
58 }
59
60 if (skip_handles) {
61 /* When the control point is selected, both handles are ignored. */
62 selection[1] = IndexMask::from_difference(selection[1], selection[0], memory);
63 selection[2] = IndexMask::from_difference(selection[2], selection[0], memory);
64 }
65
66 const int size = selection[0].size() + selection[1].size() + selection[2].size();
67 if (size == 0) {
68 return;
69 }
70
72 tvs->transverts_tot = size;
73
74 int offset = 0;
76 for (const int attribute_i : positions.index_range()) {
77 selection[attribute_i].foreach_index(GrainSize(1024), [&](const int64_t i, const int64_t pos) {
78 TransVert &tv = tvs->transverts[pos + offset];
79 tv.loc = positions[attribute_i][i];
80 tv.flag = SELECT;
81 copy_v3_v3(tv.oldloc, tv.loc);
82 });
83
84 offset += selection[attribute_i].size();
85 }
86}
87
89{
90 using namespace blender;
91 const bke::CurvesGeometry &curves = curves_id->geometry.wrap();
92 const int size = curves.points_num();
95 return reinterpret_cast<float (*)[3]>(data);
96}
97
98} // namespace blender::ed::curves
Low-level operations for curves.
Low-level operations for curves.
MINLINE void copy_v3_v3(float r[3], const float a[3])
Object is a sort of wrapper for general info.
BMesh const char void * data
long long int int64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static IndexMask from_difference(const IndexMask &mask_a, const IndexMask &mask_b, IndexMaskMemory &memory)
constexpr int64_t size() const
Definition BLI_span.hh:252
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
void append(const T &value)
IndexRange index_range() const
nullptr float
#define SELECT
uint pos
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, IndexMaskMemory &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)
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)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, IndexMaskMemory &memory)
VecBase< float, 3 > float3
TransVert * transverts
float * loc
float oldloc[3]
i
Definition text_draw.cc:230