37#include <fmt/format.h>
69 return ptr_ !=
nullptr;
76 return reinterpret_cast<Mesh *
>(ptr_);
90 return reinterpret_cast<Curves *
>(ptr_);
114 std::array<DomainInfo, ATTR_DOMAIN_NUM>
info;
116 switch (owner.
type()) {
119 info[int(AttrDomain::Point)].customdata = &pointcloud->
pdata;
120 info[int(AttrDomain::Point)].length = pointcloud->
totpoint;
127 info[int(AttrDomain::Point)].customdata = &
bm->
vdata;
129 info[int(AttrDomain::Edge)].customdata = &
bm->
edata;
131 info[int(AttrDomain::Corner)].customdata = &
bm->
ldata;
133 info[int(AttrDomain::Face)].customdata = &
bm->
pdata;
159 info[int(AttrDomain::Layer)].length = grease_pencil->layers().size();
180 switch (owner.
type()) {
185 return mesh.attributes_for_write();
189 return pointcloud.attributes_for_write();
198 return grease_pencil.attributes_for_write();
217 if (layer ==
nullptr) {
226 const AttrDomain domain,
231 if (domain != metadata->domain) {
234 "Domain unsupported for \"%s\" attribute",
235 std::string(
name).c_str());
238 if (data_type != metadata->data_type) {
240 reports,
RPT_ERROR,
"Type unsupported for \"%s\" attribute", std::string(
name).c_str());
249 const AttrDomain domain,
290 if (old_name == new_name_clamped) {
297 if (layer ==
nullptr) {
363 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
366 if (!
info[domain].customdata) {
371 for (
int i = 0; i < cdata->
totlayer; i++) {
394 const AttrDomain domain,
398 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
401 if (customdata ==
nullptr) {
416 return (index == -1) ?
nullptr : &(customdata->
layers[index]);
420 std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(owner);
432 return (index == -1) ?
nullptr : &(customdata->
layers[index]);
441 std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(owner);
470 std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(owner);
520 return layer ? layer->
name :
"";
527 if (
name.is_empty()) {
536 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
543 const std::string name_copy =
name;
545 if (layer_index == -1) {
550 const bool is_active_color_attribute = name_copy.c_str() ==
552 const bool is_default_color_attribute = name_copy.c_str() ==
562 if (is_active_color_attribute) {
567 if (is_default_color_attribute) {
573 if (type ==
CD_PROP_FLOAT2 && domain ==
int(AttrDomain::Corner)) {
588 std::optional<MutableAttributeAccessor> attributes = get_attribute_accessor_for_write(owner);
594 const std::string name_copy =
name;
595 std::optional<blender::bke::AttributeMetaData> metadata = attributes->lookup_meta_data(
607 if (!attributes->remove(name_copy)) {
611 if (is_active_color_attribute) {
615 if (is_default_color_attribute) {
620 if (metadata->data_type ==
CD_PROP_FLOAT2 && metadata->domain == AttrDomain::Corner) {
629 return attributes->remove(
name);
635 const AttrDomain domain)
637 if (
name.is_empty()) {
640 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
643 if (customdata ==
nullptr) {
647 for (
int i = 0; i < customdata->
totlayer; i++) {
659 const eCustomDataMask type_mask,
662 if (
name.is_empty()) {
665 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
667 for (AttrDomain domain = AttrDomain::Point; int(domain) <
ATTR_DOMAIN_NUM;
668 domain = AttrDomain(
int(domain) + 1))
675 if (customdata ==
nullptr) {
679 for (
int i = 0; i < customdata->
totlayer; i++) {
692 const eCustomDataMask type_mask,
703 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
713 eCustomDataMask
mask)
715 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
721 if (customdata ==
nullptr) {
725 if ((1 <<
int(domain)) & domain_mask) {
735 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
739 if (customdata ==
nullptr) {
743 return AttrDomain(domain);
748 return AttrDomain(AttrDomain::Point);
753 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
754 return info[domain].length;
769 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
773 if (customdata ==
nullptr) {
777 return info[domain].length;
787 switch (owner.
type()) {
805 if (active_index == -1) {
812 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
818 if (customdata ==
nullptr) {
821 for (
int i = 0; i < customdata->
totlayer; i++) {
824 if (index == active_index) {
855 switch (owner.
type()) {
877 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
879 bool use_next = (layers ==
nullptr);
883 if (customdata ==
nullptr) {
887 if (customdata->
layers == layers) {
902 eCustomDataMask layer_mask)
904 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
910 if (!customdata || !((1 <<
int(domain)) & domain_mask)) {
914 for (
int i = 0; i < customdata->
totlayer; i++) {
921 if (index == lookup_index) {
922 return customdata->
layers + i;
935 eCustomDataMask layer_mask)
941 const std::array<DomainInfo, ATTR_DOMAIN_NUM>
info =
get_domains(owner);
947 if (!customdata || !((1 <<
int(domain)) & domain_mask)) {
951 for (
int i = 0; i < customdata->
totlayer; i++) {
959 if (layer == layer_iter) {
973 return reinterpret_cast<const Mesh *
>(id)->active_color_attribute;
981 return reinterpret_cast<const Mesh *
>(id)->default_color_attribute;
1039 std::optional<blender::bke::AttributeMetaData> meta_data =
mesh.
attributes().lookup_meta_data(
1057 const auto result = fmt::format_to_n(
1066 const auto result = fmt::format_to_n(
1075 const auto result = fmt::format_to_n(
#define ATTR_DOMAIN_MASK_COLOR
#define ATTR_DOMAIN_AS_MASK(domain)
bool BKE_curves_attribute_required(const struct Curves *curves, blender::StringRef name)
Low-level operations for curves.
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_named_layer_index_notype(const CustomData *data, blender::StringRef name)
int CustomData_number_of_layers_typemask(const CustomData *data, eCustomDataMask mask)
int CustomData_get_named_layer_index(const CustomData *data, eCustomDataType type, blender::StringRef name)
int CustomData_name_maxncpy_calc(blender::StringRef name)
void CustomData_ensure_data_is_mutable(CustomDataLayer *layer, int totelem)
#define CD_TYPE_AS_MASK(_type)
Low-level operations for grease pencil.
bool BKE_grease_pencil_drawing_attribute_required(const GreasePencilDrawing *, blender::StringRef name)
bool BKE_mesh_attribute_required(blender::StringRef name)
General operations for point clouds.
bool BKE_pointcloud_attribute_required(const PointCloud *pointcloud, blender::StringRef name)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t void BLI_uniquename_cb(blender::FunctionRef< bool(blender::StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
ID and Library types, which are fundamental for SDNA.
#define MAX_CUSTOMDATA_LAYER_NAME
#define CD_MASK_COLOR_ALL
Read Guarded memory(de)allocation.
static bool mesh_attribute_valid(const Mesh &mesh, const StringRef name, const AttrDomain domain, const eCustomDataType data_type, ReportList *reports)
bool BKE_color_attribute_supported(const Mesh &mesh, const StringRef name)
StringRef BKE_uv_map_edge_select_name_get(const StringRef uv_map_name, char *buffer)
static int color_name_to_index(AttributeOwner &owner, const StringRef name)
std::optional< StringRef > BKE_id_attributes_active_color_name(const ID *id)
bool BKE_attribute_rename(AttributeOwner &owner, const StringRef old_name, const StringRef new_name, ReportList *reports)
std::optional< blender::StringRefNull > BKE_attributes_active_name_get(AttributeOwner &owner)
CustomData * BKE_attributes_iterator_next_domain(AttributeOwner &owner, CustomDataLayer *layers)
static int color_clamp_index(AttributeOwner &owner, int index)
int BKE_attribute_to_index(const AttributeOwner &owner, const CustomDataLayer *layer, AttrDomainMask domain_mask, eCustomDataMask layer_mask)
CustomDataLayer * BKE_attribute_new(AttributeOwner &owner, const StringRef name, const eCustomDataType type, const AttrDomain domain, ReportList *reports)
AttrDomain BKE_attribute_domain(const AttributeOwner &owner, const CustomDataLayer *layer)
StringRef BKE_uv_map_pin_name_get(const StringRef uv_map_name, char *buffer)
CustomDataLayer * BKE_attribute_search_for_write(AttributeOwner &owner, const StringRef name, const eCustomDataMask type_mask, const AttrDomainMask domain_mask)
static void bke_attribute_copy_if_exists(AttributeOwner &owner, const StringRef srcname, const StringRef dstname)
const CustomDataLayer * BKE_attribute_search(const AttributeOwner &owner, const StringRef name, const eCustomDataMask type_mask, const AttrDomainMask domain_mask)
void BKE_id_attributes_default_color_set(ID *id, const std::optional< StringRef > name)
CustomDataLayer * BKE_attribute_from_index(AttributeOwner &owner, int lookup_index, AttrDomainMask domain_mask, eCustomDataMask layer_mask)
void BKE_attributes_active_set(AttributeOwner &owner, const StringRef name)
static bool attribute_name_exists(const AttributeOwner &owner, const StringRef name)
int * BKE_attributes_active_index_p(AttributeOwner &owner)
bool BKE_attribute_remove(AttributeOwner &owner, const StringRef name, ReportList *reports)
std::string BKE_attribute_calc_unique_name(const AttributeOwner &owner, const StringRef name)
CustomDataLayer * BKE_attribute_duplicate(AttributeOwner &owner, const StringRef name, ReportList *reports)
void BKE_id_attributes_active_color_set(ID *id, const std::optional< StringRef > name)
const CustomDataLayer * BKE_id_attributes_color_find(const ID *id, const StringRef name)
void BKE_id_attributes_active_color_clear(ID *id)
StringRef BKE_uv_map_vert_select_name_get(const StringRef uv_map_name, char *buffer)
static StringRef color_name_from_index(AttributeOwner &owner, int index)
static bool bke_attribute_rename_if_exists(AttributeOwner &owner, const StringRef old_name, const StringRef new_name, ReportList *reports)
CustomDataLayer * BKE_attribute_find(const AttributeOwner &owner, const StringRef name, const eCustomDataType type, const AttrDomain domain)
std::optional< StringRef > BKE_id_attributes_default_color_name(const ID *id)
static std::array< DomainInfo, ATTR_DOMAIN_NUM > get_domains(const AttributeOwner &owner)
bool BKE_attribute_required(const AttributeOwner &owner, const StringRef name)
int BKE_attribute_data_length(AttributeOwner &owner, CustomDataLayer *layer)
int BKE_attributes_length(const AttributeOwner &owner, AttrDomainMask domain_mask, eCustomDataMask mask)
static bool name_valid_for_builtin_domain_and_type(const blender::bke::AttributeAccessor attributes, const StringRef name, const AttrDomain domain, const eCustomDataType data_type, ReportList *reports)
int BKE_attribute_domain_size(const AttributeOwner &owner, const int domain)
void BKE_attributes_active_clear(AttributeOwner &owner)
bool BM_data_layer_free_named(BMesh *bm, CustomData *data, StringRef name)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
bool BM_attribute_stored_in_bmesh_builtin(const StringRef name)
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
AttributeOwnerType type() const
static AttributeOwner from_id(ID *id)
GreasePencil * get_grease_pencil() const
PointCloud * get_pointcloud() const
Curves * get_curves() const
GreasePencilDrawing * get_grease_pencil_drawing() const
const CPPType & type() const
constexpr bool contains_ptr(const T *ptr) const
constexpr bool is_empty() const
constexpr int64_t size() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
std::optional< AttributeDomainAndType > get_builtin_domain_and_type(const StringRef name) const
MutableAttributeAccessor attributes_for_write()
bke::CurvesGeometry & strokes_for_write()
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bool allow_procedural_attribute_access(StringRef attribute_name)
static std::optional< blender::bke::MutableAttributeAccessor > get_attribute_accessor_for_write(AttributeOwner &owner)
int attributes_active_index
int attributes_active_index
MeshRuntimeHandle * runtime
char * default_color_attribute
int attributes_active_index
char * active_color_attribute
int attributes_active_index