28 const auto &
data = std::get<Attribute::ArrayData>(
attribute.data());
31 data.sharing_info.get()};
34 const auto &
data = std::get<Attribute::SingleData>(
attribute.data());
37 data.sharing_info.get()};
52 auto &
data = std::get<Attribute::ArrayData>(
attribute.data_for_write());
55 std::function<void()> tag_modified_fn;
59 tag_modified_fn = [owner, update_fn]() { update_fn(owner); };
65 std::move(tag_modified_fn)};
70 const auto &
data = std::get<Attribute::SingleData>(
attribute.data());
83 const bool require_array_data)
85 switch (initializer.
type) {
93 if (require_array_data) {
106 if (!require_array_data) {
120 data.data =
const_cast<void *
>(
init.data);
121 data.size = domain_size;
123 data.sharing_info->add_user();
136 const void *default_value)
140 const auto return_default = [&]() {
145 return return_default();
147 if (attr->
domain() != domain) {
148 return return_default();
151 return return_default();
155 const auto &
data = std::get<bke::Attribute::ArrayData>(attr->
data());
160 const auto &
data = std::get<bke::Attribute::SingleData>(attr->
data());
164 return return_default();
177 if (attr->
domain() != domain) {
180 if (
const auto *array_data = std::get_if<bke::Attribute::ArrayData>(&attr->
data())) {
183 return GSpan(cpp_type, array_data->data, array_data->
size);
193 const void *custom_default_value)
195 if (domain_size <= 0) {
200 if (attr->data_type() == type) {
201 if (
const auto *single_data = std::get_if<bke::Attribute::SingleData>(&attr->data())) {
203 const GPointer g_value(cpp_type, single_data->value);
206 auto &array_data = std::get<bke::Attribute::ArrayData>(attr->data_for_write());
207 return GMutableSpan(cpp_type, array_data.data, domain_size);
213 const void *default_value = custom_default_value ? custom_default_value :
220 auto &array_data = std::get<bke::Attribute::ArrayData>(attr.
data_for_write());
222 return GMutableSpan(cpp_type, array_data.data, domain_size);
248 if (group.name == name) {
260 const auto &
data = std::get<Attribute::SingleData>(attr.
data());
272 std::optional<ListBaseT<bDeformGroup> *> vertex_groups,
283 return std::monostate();
288 const bool overwrite,
292 std::optional<ListBaseT<bDeformGroup> *> vertex_groups,
300 for (
const auto &[old_name, new_name] : name_map.
items()) {
301 if (new_name.is_empty()) {
305 const std::variant<std::monostate, Attribute *, bDeformGroup *> old_attr =
find_attr_or_group(
306 storage, vertex_groups, old_name);
307 if (std::holds_alternative<std::monostate>(old_attr)) {
311 const bke::AttrDomain old_domain = std::holds_alternative<Attribute *>(old_attr) ?
312 std::get<Attribute *>(old_attr)->domain() :
314 const bke::AttrType old_type = std::holds_alternative<Attribute *>(old_attr) ?
315 std::get<Attribute *>(old_attr)->data_type() :
319 if (!old_info->deletable) {
325 if (new_info->domain != old_domain || new_info->type != old_type) {
330 if (array_storage_required.
contains(new_name)) {
331 if (std::holds_alternative<Attribute *>(old_attr)) {
341 names_to_remove.
add_new(new_name);
344 const std::variant<std::monostate, Attribute *, bDeformGroup *> new_attr =
346 if (!std::holds_alternative<std::monostate>(new_attr)) {
352 if (std::holds_alternative<Attribute *>(old_attr)) {
353 map.
add_new(std::get<Attribute *>(old_attr), new_name);
356 vertex_group_map.
add_new(std::get<bDeformGroup *>(old_attr), new_name);
361 const int start_attrs_num =
storage.count();
362 storage.remove(names_to_remove);
363 if (vertex_groups && (start_attrs_num -
storage.count()) != names_to_remove.
size()) {
365 for (
bDeformGroup &defgroup : (*vertex_groups)->items_mutable()) {
376 if (vertex_groups && !vertex_group_map.
is_empty()) {
378 if (
const std::optional<StringRef> name = vertex_group_map.
lookup_try(&defgroup)) {
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
const void * default_value() const
CommonVArrayInfo common_info() const
const CPPType & type() const
void materialize_to_uninitialized(void *dst) const
IndexRange index_range() const
static GVArray from_single(const CPPType &type, int64_t size, const void *value)
static GVArray from_span(GSpan span)
static GVArray from_single_ref(const CPPType &type, int64_t size, const void *value)
static GVMutableArray from_span(GMutableSpan span)
friend class ImplicitSharingPtr
const Value * lookup_ptr(const Key &key) const
std::optional< Value > lookup_try(const Key &key) const
Value lookup_default(const Key &key, const Value &default_value) const
void add_new(const Key &key, const Value &value)
ItemIterator items() const &
constexpr bool is_empty() const
bool contains_as(const ForwardKey &key) const
bool contains(const Key &key) const
void add_new(const Key &key)
AttrStorageType storage_type() const
const DataVariant & data() const
std::variant< ArrayData, SingleData > DataVariant
DataVariant & data_for_write()
AttrDomain domain() const
void assign_data(DataVariant &&data)
AttrType data_type() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
#define storage(slot, qualifiers)
GMutableSpan get_mutable_attribute(AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size, const void *custom_default_value)
GAttributeReader attribute_to_reader(const Attribute &attribute, const AttrDomain domain, const int64_t domain_size)
std::optional< GSpan > get_span_attribute(const AttributeStorage &storage, const AttrDomain domain, const CPPType &cpp_type, const StringRef name, const int64_t domain_size)
Set< StringRef > rename_attributes(AttributeStorage &storage, const Map< StringRef, StringRef > &name_map, const bool overwrite, const Map< StringRef, AttrBuiltinInfo > &builtin_attributes, const Set< StringRef > &array_storage_required, const FunctionRef< int(AttrDomain)> domain_size_fn, std::optional< ListBaseT< bDeformGroup > * > vertex_groups, FunctionRef< MutableSpan< MDeformVert >()> get_mutable_dverts)
void remove_defgroup_index(MutableSpan< MDeformVert > dverts, int defgroup_index)
GAttributeWriter attribute_to_writer(void *owner, const Map< StringRef, AttrUpdateOnChange > &changed_tags, const int64_t domain_size, Attribute &attribute)
static std::variant< std::monostate, Attribute *, bDeformGroup * > find_attr_or_group(AttributeStorage &storage, std::optional< ListBaseT< bDeformGroup > * > vertex_groups, const StringRef name)
bool try_delete_vertex_group(ListBaseT< bDeformGroup > &vertex_groups, const StringRef name, FunctionRef< MutableSpan< MDeformVert >()> get_mutable_dverts)
GVArray get_varray_attribute(const AttributeStorage &storage, AttrDomain domain, const CPPType &cpp_type, StringRef name, int64_t domain_size, const void *default_value)
void(*)(void *owner) AttrUpdateOnChange
Attribute::DataVariant attribute_init_to_data(const bke::AttrType data_type, const int64_t domain_size, const AttributeInit &initializer, const bool require_array_data)
static void ensure_array_storage(Attribute &attr, const FunctionRef< int(AttrDomain)> domain_size_fn)
static bDeformGroup * find_vertex_group(ListBaseT< bDeformGroup > &vertex_groups, const StringRef name)
AttrType cpp_type_to_attribute_type(const CPPType &type)
const CPPType & attribute_type_to_cpp_type(AttrType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BKE_defgroup_listbase_name_find(ListBaseT< bDeformGroup > *defbase, StringRef name, int *r_index, bDeformGroup **r_group)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
BMesh const char void * data
static ArrayData from_uninitialized(const CPPType &type, int64_t domain_size)
static ArrayData from_default_value(const CPPType &type, int64_t domain_size)
static ArrayData from_value(const GPointer &value, int64_t domain_size)
static ArrayData from_constructed(const CPPType &type, int64_t domain_size)
static SingleData from_value(const GPointer &value)