Blender V4.3
geometry_component_edit_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"
7#include "BKE_geometry_set.hh"
9
10namespace blender::bke {
11
13
15{
18 new_component->gizmo_edit_hints_ = std::make_unique<GizmoEditHints>(*gizmo_edit_hints_);
19 }
21 new_component->curves_edit_hints_ = std::make_unique<CurvesEditHints>(*curves_edit_hints_);
22 }
24 new_component->grease_pencil_edit_hints_ = std::make_unique<GreasePencilEditHints>(
26 }
27 return GeometryComponentPtr(new_component);
28}
29
31{
32 return true;
33}
34
36{
37 /* Nothing to do. */
38}
39
47
49{
50 if (attribute.sharing_info && attribute.varray.is_span()) {
51 const void *data = attribute.varray.get_internal_span().data();
52 attribute.sharing_info->add_user();
53 return {ImplicitSharingPtr(attribute.sharing_info), data};
54 }
55 auto *data = new ImplicitSharedValue<GArray<>>(attribute.varray.type(), attribute.varray.size());
56 attribute.varray.materialize(data->data.data());
57 return {ImplicitSharingPtr<>(data), data->data.data()};
58}
59
61 const Curves *curves_id, GeometryComponentEditData &edit_component)
62{
63 if (!edit_component.curves_edit_hints_) {
64 return;
65 }
66 if (curves_id == nullptr) {
67 return;
68 }
69 CurvesEditHints &edit_hints = *edit_component.curves_edit_hints_;
70 if (edit_hints.positions().has_value()) {
71 return;
72 }
73 const CurvesGeometry &curves = curves_id->geometry.wrap();
74 const int points_num = curves.points_num();
75 if (points_num != edit_hints.curves_id_orig.geometry.point_num) {
76 return;
77 }
78 edit_hints.positions_data = save_shared_attribute(curves.attributes().lookup("position"));
79}
80
82 GeometryComponentEditData &edit_component)
83{
84 if (!edit_component.grease_pencil_edit_hints_) {
85 return;
86 }
87 if (edit_component.grease_pencil_edit_hints_->drawing_hints.has_value()) {
88 return;
89 }
90 if (grease_pencil == nullptr) {
91 return;
92 }
93 const GreasePencil &orig_grease_pencil =
94 edit_component.grease_pencil_edit_hints_->grease_pencil_id_orig;
95 const Span<const greasepencil::Layer *> layers = grease_pencil->layers();
96 const Span<const greasepencil::Layer *> orig_layers = orig_grease_pencil.layers();
97 const int layers_num = layers.size();
98 if (layers_num != orig_layers.size()) {
99 return;
100 }
101 edit_component.grease_pencil_edit_hints_->drawing_hints.emplace(layers_num);
103 *edit_component.grease_pencil_edit_hints_->drawing_hints;
104 for (const int layer_index : layers.index_range()) {
105 const greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
106 grease_pencil->layer(layer_index));
107 const greasepencil::Layer &orig_layer = *orig_layers[layer_index];
108 const greasepencil::Drawing *orig_drawing = orig_grease_pencil.get_drawing_at(
109 orig_layer, grease_pencil->runtime->eval_frame);
110 GreasePencilDrawingEditHints &drawing_hints = all_hints[layer_index];
111 if (!drawing || !orig_drawing) {
112 continue;
113 }
114 drawing_hints.drawing_orig = orig_drawing;
115 const CurvesGeometry &curves = drawing->strokes();
116 if (curves.points_num() != orig_drawing->strokes().points_num()) {
117 continue;
118 }
119 drawing_hints.positions_data = save_shared_attribute(curves.attributes().lookup("position"));
120 }
121}
122
124{
125 /* This component should be created at the start of object evaluation if it's necessary. */
126 if (!geometry.has<GeometryComponentEditData>()) {
127 return;
128 }
129 GeometryComponentEditData &edit_component =
130 geometry.get_component_for_write<GeometryComponentEditData>();
131 remember_deformed_curve_positions_if_necessary(geometry.get_curves(), edit_component);
132 remember_deformed_grease_pencil_if_necessary(geometry.get_grease_pencil(), edit_component);
133}
134
135} // namespace blender::bke
Low-level operations for curves.
Low-level operations for grease pencil.
#define BLI_assert(a)
Definition BLI_assert.h:50
constexpr int64_t size() const
Definition BLI_span.hh:253
ImplicitSharingPtrAndData positions_data
std::optional< Span< float3 > > positions() const
std::unique_ptr< GreasePencilEditHints > grease_pencil_edit_hints_
std::unique_ptr< GizmoEditHints > gizmo_edit_hints_
std::unique_ptr< CurvesEditHints > curves_edit_hints_
static void remember_deformed_positions_if_necessary(GeometrySet &geometry)
const bke::CurvesGeometry & strokes() const
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
static void remember_deformed_grease_pencil_if_necessary(const GreasePencil *grease_pencil, GeometryComponentEditData &edit_component)
static void remember_deformed_curve_positions_if_necessary(const Curves *curves_id, GeometryComponentEditData &edit_component)
static ImplicitSharingPtrAndData save_shared_attribute(const GAttributeReader &attribute)
CurvesGeometry geometry
GreasePencilRuntimeHandle * runtime