Blender V4.3
geometry_component_grease_pencil.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_geometry_set.hh"
7#include "BKE_lib_id.hh"
8
10
12
13namespace blender::bke {
14
15/* -------------------------------------------------------------------- */
20
25
27{
28 GreasePencilComponent *new_component = new GreasePencilComponent();
29 if (grease_pencil_ != nullptr) {
30 new_component->grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
31 new_component->ownership_ = GeometryOwnershipType::Owned;
32 }
33 return GeometryComponentPtr(new_component);
34}
35
37{
38 BLI_assert(this->is_mutable() || this->is_expired());
39 if (grease_pencil_ != nullptr) {
40 if (ownership_ == GeometryOwnershipType::Owned) {
41 BKE_id_free(nullptr, grease_pencil_);
42 }
43 grease_pencil_ = nullptr;
44 }
45}
46
48{
49 return grease_pencil_ != nullptr;
50}
51
53{
54 BLI_assert(this->is_mutable());
55 this->clear();
56 grease_pencil_ = grease_pencil;
57 ownership_ = ownership;
58}
59
61{
62 BLI_assert(this->is_mutable());
63 GreasePencil *grease_pencil = grease_pencil_;
64 grease_pencil_ = nullptr;
65 return grease_pencil;
66}
67
69{
70 return grease_pencil_;
71}
72
74{
75 BLI_assert(this->is_mutable());
76 if (ownership_ == GeometryOwnershipType::ReadOnly) {
77 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
79 }
80 return grease_pencil_;
81}
82
84{
85 return grease_pencil_ == nullptr;
86}
87
89{
90 return ownership_ == GeometryOwnershipType::Owned;
91}
92
94{
95 BLI_assert(this->is_mutable());
96 if (ownership_ != GeometryOwnershipType::Owned) {
97 if (grease_pencil_) {
98 grease_pencil_ = BKE_grease_pencil_copy_for_eval(grease_pencil_);
99 }
100 ownership_ = GeometryOwnershipType::Owned;
101 }
102}
103
105{
106 static CustomDataAccessInfo layers_access = {
107 [](void *owner) -> CustomData * {
108 GreasePencil &grease_pencil = *static_cast<GreasePencil *>(owner);
109 return &grease_pencil.layers_data;
110 },
111 [](const void *owner) -> const CustomData * {
112 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
113 return &grease_pencil.layers_data;
114 },
115 [](const void *owner) -> int {
116 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
117 return grease_pencil.layers().size();
118 }};
119
120 static CustomDataAttributeProvider layer_custom_data(AttrDomain::Layer, layers_access);
121
122 return ComponentAttributeProviders({}, {&layer_custom_data});
123}
124
126 const GVArray &varray,
127 const AttrDomain from,
128 const AttrDomain to)
129{
130 if (from == to) {
131 return varray;
132 }
133 return {};
134}
135
137{
138 static const ComponentAttributeProviders providers =
142 fn.domain_size = [](const void *owner, const AttrDomain domain) {
143 if (owner == nullptr) {
144 return 0;
145 }
146 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
147 switch (domain) {
149 return int(grease_pencil.layers().size());
150 default:
151 return 0;
152 }
153 };
154 fn.domain_supported = [](const void * /*owner*/, const AttrDomain domain) {
155 return domain == AttrDomain::Layer;
156 };
157 fn.adapt_domain = [](const void *owner,
158 const GVArray &varray,
159 const AttrDomain from_domain,
160 const AttrDomain to_domain) -> GVArray {
161 if (owner == nullptr) {
162 return {};
163 }
164 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
165 return adapt_grease_pencil_attribute_domain(grease_pencil, varray, from_domain, to_domain);
166 };
167 return fn;
168}
169
175
176} // namespace blender::bke
177
178blender::bke::AttributeAccessor GreasePencil::attributes() const
179{
182}
183
184blender::bke::MutableAttributeAccessor GreasePencil::attributes_for_write()
185{
188}
189
190namespace blender::bke {
191
192std::optional<AttributeAccessor> GreasePencilComponent::attributes() const
193{
195}
196
197std::optional<MutableAttributeAccessor> GreasePencilComponent::attributes_for_write()
198{
199 GreasePencil *grease_pencil = this->get_for_write();
201}
202
203} // namespace blender::bke
Low-level operations for grease pencil.
GreasePencil * BKE_grease_pencil_copy_for_eval(const GreasePencil *grease_pencil_src)
void BKE_id_free(Main *bmain, void *idv)
#define BLI_assert(a)
Definition BLI_assert.h:50
GeometryComponentPtr copy() const override
void replace(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
AttributeAccessorFunctions accessor_functions_for_providers()
static ComponentAttributeProviders create_attribute_providers_for_grease_pencil()
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
static GVArray adapt_grease_pencil_attribute_domain(const GreasePencil &, const GVArray &varray, const AttrDomain from, const AttrDomain to)
static const AttributeAccessorFunctions & get_grease_pencil_accessor_functions_ref()
static AttributeAccessorFunctions get_grease_pencil_accessor_functions()
GVArray(* adapt_domain)(const void *owner, const GVArray &varray, AttrDomain from_domain, AttrDomain to_domain)
bool(* domain_supported)(const void *owner, AttrDomain domain)
int(* domain_size)(const void *owner, AttrDomain domain)