Blender V4.5
grease_pencil_attributes.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8
10
12
13static GeometryAttributeProviders create_attribute_providers_for_grease_pencil()
14{
15 static CustomDataAccessInfo layers_access = {
16 [](void *owner) -> CustomData * {
17 GreasePencil &grease_pencil = *static_cast<GreasePencil *>(owner);
18 return &grease_pencil.layers_data;
19 },
20 [](const void *owner) -> const CustomData * {
21 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
22 return &grease_pencil.layers_data;
23 },
24 [](const void *owner) -> int {
25 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
26 return grease_pencil.layers().size();
27 }};
28
29 static CustomDataAttributeProvider layer_custom_data(AttrDomain::Layer, layers_access);
30
31 return GeometryAttributeProviders({}, {&layer_custom_data});
32}
33
34static GVArray adapt_grease_pencil_attribute_domain(const GreasePencil & /*grease_pencil*/,
35 const GVArray &varray,
36 const AttrDomain from,
37 const AttrDomain to)
38{
39 if (from == to) {
40 return varray;
41 }
42 return {};
43}
44
45static AttributeAccessorFunctions get_grease_pencil_accessor_functions()
46{
47 static const GeometryAttributeProviders providers =
49 AttributeAccessorFunctions fn =
50 attribute_accessor_functions::accessor_functions_for_providers<providers>();
51 fn.domain_size = [](const void *owner, const AttrDomain domain) {
52 if (owner == nullptr) {
53 return 0;
54 }
55 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
56 switch (domain) {
57 case AttrDomain::Layer:
58 return int(grease_pencil.layers().size());
59 default:
60 return 0;
61 }
62 };
63 fn.domain_supported = [](const void * /*owner*/, const AttrDomain domain) {
64 return domain == AttrDomain::Layer;
65 };
66 fn.adapt_domain = [](const void *owner,
67 const GVArray &varray,
68 const AttrDomain from_domain,
69 const AttrDomain to_domain) -> GVArray {
70 if (owner == nullptr) {
71 return {};
72 }
73 const GreasePencil &grease_pencil = *static_cast<const GreasePencil *>(owner);
74 return adapt_grease_pencil_attribute_domain(grease_pencil, varray, from_domain, to_domain);
75 };
76 return fn;
77}
78
79const AttributeAccessorFunctions &get_attribute_accessor_functions()
80{
81 static const AttributeAccessorFunctions fn = get_grease_pencil_accessor_functions();
82 return fn;
83}
84
85} // namespace blender::bke::greasepencil
Low-level operations for grease pencil.
AttrDomain
const AttributeAccessorFunctions & get_attribute_accessor_functions()
static AttributeAccessorFunctions get_grease_pencil_accessor_functions()
static GeometryAttributeProviders create_attribute_providers_for_grease_pencil()
static GVArray adapt_grease_pencil_attribute_domain(const GreasePencil &, const GVArray &varray, const AttrDomain from, const AttrDomain to)