Cleanup: Use StringRef instead of C strings in CustomData API

This simplifies some code. It may improve performance slightly too,
because of faster string comparisons with a known length.

Pull Request: https://projects.blender.org/blender/blender/pulls/117996
This commit is contained in:
Hans Goudey
2024-02-08 16:56:42 +01:00
committed by Hans Goudey
parent 74b8f99b43
commit a39e8a4ab9
13 changed files with 103 additions and 109 deletions

View File

@@ -261,14 +261,17 @@ const void *CustomData_add_layer_with_data(CustomData *data,
/**
* Same as above but accepts a name.
*/
void *CustomData_add_layer_named(
CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem, const char *name);
void *CustomData_add_layer_named(CustomData *data,
eCustomDataType type,
eCDAllocType alloctype,
int totelem,
blender::StringRef name);
const void *CustomData_add_layer_named_with_data(CustomData *data,
eCustomDataType type,
void *layer_data,
int totelem,
const char *name,
blender::StringRef name,
const ImplicitSharingInfoHandle *sharing_info);
void *CustomData_add_layer_anonymous(CustomData *data,
@@ -291,7 +294,7 @@ const void *CustomData_add_layer_anonymous_with_data(
* In edit-mode, use #EDBM_data_layer_free instead of this function.
*/
bool CustomData_free_layer(CustomData *data, eCustomDataType type, int totelem, int index);
bool CustomData_free_layer_named(CustomData *data, const char *name, const int totelem);
bool CustomData_free_layer_named(CustomData *data, blender::StringRef name, const int totelem);
/**
* Frees the layer index with the give type.
@@ -310,7 +313,9 @@ void CustomData_free_layers(CustomData *data, eCustomDataType type, int totelem)
* Returns true if a layer with the specified type exists.
*/
bool CustomData_has_layer(const CustomData *data, eCustomDataType type);
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, const char *name);
bool CustomData_has_layer_named(const CustomData *data,
eCustomDataType type,
blender::StringRef name);
/**
* Returns the number of layers with this type.
@@ -490,7 +495,10 @@ void *CustomData_bmesh_get_n(const CustomData *data, void *block, eCustomDataTyp
*/
void *CustomData_bmesh_get_layer_n(const CustomData *data, void *block, int n);
bool CustomData_set_layer_name(CustomData *data, eCustomDataType type, int n, const char *name);
bool CustomData_set_layer_name(CustomData *data,
eCustomDataType type,
int n,
blender::StringRef name);
const char *CustomData_get_layer_name(const CustomData *data, eCustomDataType type, int n);
/**
@@ -513,27 +521,31 @@ void *CustomData_get_layer_n_for_write(CustomData *data, eCustomDataType type, i
*/
const void *CustomData_get_layer_named(const CustomData *data,
eCustomDataType type,
const char *name);
blender::StringRef name);
void *CustomData_get_layer_named_for_write(CustomData *data,
eCustomDataType type,
const char *name,
blender::StringRef name,
int totelem);
int CustomData_get_offset(const CustomData *data, eCustomDataType type);
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, const char *name);
int CustomData_get_offset_named(const CustomData *data,
eCustomDataType type,
blender::StringRef name);
int CustomData_get_n_offset(const CustomData *data, eCustomDataType type, int n);
int CustomData_get_layer_index(const CustomData *data, eCustomDataType type);
int CustomData_get_layer_index_n(const CustomData *data, eCustomDataType type, int n);
int CustomData_get_named_layer_index(const CustomData *data,
eCustomDataType type,
const char *name);
int CustomData_get_named_layer_index_notype(const CustomData *data, const char *name);
blender::StringRef name);
int CustomData_get_named_layer_index_notype(const CustomData *data, blender::StringRef name);
int CustomData_get_active_layer_index(const CustomData *data, eCustomDataType type);
int CustomData_get_render_layer_index(const CustomData *data, eCustomDataType type);
int CustomData_get_clone_layer_index(const CustomData *data, eCustomDataType type);
int CustomData_get_stencil_layer_index(const CustomData *data, eCustomDataType type);
int CustomData_get_named_layer(const CustomData *data, eCustomDataType type, const char *name);
int CustomData_get_named_layer(const CustomData *data,
eCustomDataType type,
blender::StringRef name);
int CustomData_get_active_layer(const CustomData *data, eCustomDataType type);
int CustomData_get_render_layer(const CustomData *data, eCustomDataType type);
int CustomData_get_clone_layer(const CustomData *data, eCustomDataType type);
@@ -631,7 +643,7 @@ void CustomData_set_layer_unique_name(CustomData *data, int index);
void CustomData_validate_layer_name(const CustomData *data,
eCustomDataType type,
const char *name,
blender::StringRef name,
char *outname);
/**

View File

@@ -287,7 +287,7 @@ CustomDataLayer *BKE_id_attribute_new(ID *id,
Mesh *mesh = reinterpret_cast<Mesh *>(id);
if (BMEditMesh *em = mesh->edit_mesh) {
BM_data_layer_add_named(em->bm, customdata, type, uniquename.c_str());
const int index = CustomData_get_named_layer_index(customdata, type, uniquename.c_str());
const int index = CustomData_get_named_layer_index(customdata, type, uniquename);
return (index == -1) ? nullptr : &(customdata->layers[index]);
}
}
@@ -299,7 +299,7 @@ CustomDataLayer *BKE_id_attribute_new(ID *id,
attributes->add(uniquename, domain, eCustomDataType(type), AttributeInitDefaultValue());
const int index = CustomData_get_named_layer_index(customdata, type, uniquename.c_str());
const int index = CustomData_get_named_layer_index(customdata, type, uniquename);
if (index == -1) {
BKE_reportf(reports, RPT_WARNING, "Layer '%s' could not be created", uniquename.c_str());
}
@@ -417,7 +417,7 @@ bool BKE_id_attribute_remove(ID *id, const char *name, ReportList *reports)
for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
if (CustomData *data = info[domain].customdata) {
const std::string name_copy = name;
const int layer_index = CustomData_get_named_layer_index_notype(data, name_copy.c_str());
const int layer_index = CustomData_get_named_layer_index_notype(data, name_copy);
if (layer_index == -1) {
continue;
}

View File

@@ -321,10 +321,8 @@ static const void *add_generic_custom_data_layer_with_existing_data(
return CustomData_add_layer_anonymous_with_data(
&custom_data, data_type, &anonymous_id, domain_size, layer_data, sharing_info);
}
char attribute_name_c[MAX_CUSTOMDATA_LAYER_NAME];
attribute_id.name().copy(attribute_name_c);
return CustomData_add_layer_named_with_data(
&custom_data, data_type, layer_data, domain_size, attribute_name_c, sharing_info);
&custom_data, data_type, layer_data, domain_size, attribute_id.name(), sharing_info);
}
static bool add_custom_data_layer_from_attribute_init(const AttributeIDRef &attribute_id,
@@ -386,7 +384,7 @@ static bool custom_data_layer_matches_attribute_id(const CustomDataLayer &layer,
bool BuiltinCustomDataLayerProvider::layer_exists(const CustomData &custom_data) const
{
if (stored_as_named_attribute_) {
return CustomData_get_named_layer_index(&custom_data, stored_type_, name_.c_str()) != -1;
return CustomData_get_named_layer_index(&custom_data, stored_type_, name_) != -1;
}
return CustomData_has_layer(&custom_data, stored_type_);
}
@@ -410,7 +408,7 @@ GAttributeReader BuiltinCustomDataLayerProvider::try_get_for_read(const void *ow
int index;
if (stored_as_named_attribute_) {
index = CustomData_get_named_layer_index(custom_data, stored_type_, name_.c_str());
index = CustomData_get_named_layer_index(custom_data, stored_type_, name_);
}
else {
index = CustomData_get_layer_index(custom_data, stored_type_);
@@ -446,8 +444,7 @@ GAttributeWriter BuiltinCustomDataLayerProvider::try_get_for_write(void *owner)
void *data = nullptr;
if (stored_as_named_attribute_) {
data = CustomData_get_layer_named_for_write(
custom_data, stored_type_, name_.c_str(), element_num);
data = CustomData_get_layer_named_for_write(custom_data, stored_type_, name_, element_num);
}
else {
data = CustomData_get_layer_for_write(custom_data, stored_type_, element_num);
@@ -476,7 +473,7 @@ bool BuiltinCustomDataLayerProvider::try_delete(void *owner) const
const int element_num = custom_data_access_.get_element_num(owner);
if (stored_as_named_attribute_) {
if (CustomData_free_layer_named(custom_data, name_.c_str(), element_num)) {
if (CustomData_free_layer_named(custom_data, name_, element_num)) {
update();
return true;
}
@@ -505,7 +502,7 @@ bool BuiltinCustomDataLayerProvider::try_create(void *owner,
const int element_num = custom_data_access_.get_element_num(owner);
if (stored_as_named_attribute_) {
if (CustomData_has_layer_named(custom_data, data_type_, name_.c_str())) {
if (CustomData_has_layer_named(custom_data, data_type_, name_)) {
/* Exists already. */
return false;
}
@@ -528,7 +525,7 @@ bool BuiltinCustomDataLayerProvider::exists(const void *owner) const
return false;
}
if (stored_as_named_attribute_) {
return CustomData_has_layer_named(custom_data, stored_type_, name_.c_str());
return CustomData_has_layer_named(custom_data, stored_type_, name_);
}
return CustomData_get_layer(custom_data, stored_type_) != nullptr;
}

View File

@@ -207,14 +207,14 @@ static const CustomData &domain_custom_data(const CurvesGeometry &curves, const
template<typename T>
static VArray<T> get_varray_attribute(const CurvesGeometry &curves,
const AttrDomain domain,
const StringRefNull name,
const StringRef name,
const T default_value)
{
const int num = domain_num(curves, domain);
const eCustomDataType type = cpp_type_to_custom_data_type(CPPType::get<T>());
const CustomData &custom_data = domain_custom_data(curves, domain);
const T *data = (const T *)CustomData_get_layer_named(&custom_data, type, name.c_str());
const T *data = (const T *)CustomData_get_layer_named(&custom_data, type, name);
if (data != nullptr) {
return VArray<T>::ForSpan(Span<T>(data, num));
}
@@ -224,13 +224,13 @@ static VArray<T> get_varray_attribute(const CurvesGeometry &curves,
template<typename T>
static Span<T> get_span_attribute(const CurvesGeometry &curves,
const AttrDomain domain,
const StringRefNull name)
const StringRef name)
{
const int num = domain_num(curves, domain);
const CustomData &custom_data = domain_custom_data(curves, domain);
const eCustomDataType type = cpp_type_to_custom_data_type(CPPType::get<T>());
T *data = (T *)CustomData_get_layer_named(&custom_data, type, name.c_str());
T *data = (T *)CustomData_get_layer_named(&custom_data, type, name);
if (data == nullptr) {
return {};
}
@@ -240,18 +240,18 @@ static Span<T> get_span_attribute(const CurvesGeometry &curves,
template<typename T>
static MutableSpan<T> get_mutable_attribute(CurvesGeometry &curves,
const AttrDomain domain,
const StringRefNull name,
const StringRef name,
const T default_value = T())
{
const int num = domain_num(curves, domain);
const eCustomDataType type = cpp_type_to_custom_data_type(CPPType::get<T>());
CustomData &custom_data = domain_custom_data(curves, domain);
T *data = (T *)CustomData_get_layer_named_for_write(&custom_data, type, name.c_str(), num);
T *data = (T *)CustomData_get_layer_named_for_write(&custom_data, type, name, num);
if (data != nullptr) {
return {data, num};
}
data = (T *)CustomData_add_layer_named(&custom_data, type, CD_SET_DEFAULT, num, name.c_str());
data = (T *)CustomData_add_layer_named(&custom_data, type, CD_SET_DEFAULT, num, name);
MutableSpan<T> span = {data, num};
if (num > 0 && span.first() != default_value) {
span.fill(default_value);

View File

@@ -2102,7 +2102,7 @@ static CustomDataLayer *customData_add_layer__internal(
void *layer_data_to_assign,
const ImplicitSharingInfo *sharing_info_to_assign,
int totelem,
const char *name);
const StringRef name);
void CustomData_update_typemap(CustomData *data)
{
@@ -2580,11 +2580,11 @@ int CustomData_get_layer_index_n(const CustomData *data, const eCustomDataType t
int CustomData_get_named_layer_index(const CustomData *data,
const eCustomDataType type,
const char *name)
const StringRef name)
{
for (int i = 0; i < data->totlayer; i++) {
if (data->layers[i].type == type) {
if (STREQ(data->layers[i].name, name)) {
if (data->layers[i].name == name) {
return i;
}
}
@@ -2593,10 +2593,10 @@ int CustomData_get_named_layer_index(const CustomData *data,
return -1;
}
int CustomData_get_named_layer_index_notype(const CustomData *data, const char *name)
int CustomData_get_named_layer_index_notype(const CustomData *data, const StringRef name)
{
for (int i = 0; i < data->totlayer; i++) {
if (STREQ(data->layers[i].name, name)) {
if (data->layers[i].name == name) {
return i;
}
}
@@ -2637,7 +2637,7 @@ int CustomData_get_stencil_layer_index(const CustomData *data, const eCustomData
int CustomData_get_named_layer(const CustomData *data,
const eCustomDataType type,
const char *name)
const StringRef name)
{
const int named_index = CustomData_get_named_layer_index(data, type, name);
const int layer_index = data->typemap[type];
@@ -2845,7 +2845,7 @@ static CustomDataLayer *customData_add_layer__internal(
void *layer_data_to_assign,
const ImplicitSharingInfo *sharing_info_to_assign,
const int totelem,
const char *name)
StringRef name)
{
const LayerTypeInfo &type_info = *layerType_getInfo(type);
int flag = 0;
@@ -2926,12 +2926,12 @@ static CustomDataLayer *customData_add_layer__internal(
/* Set default name if none exists. Note we only call DATA_() once
* we know there is a default name, to avoid overhead of locale lookups
* in the depsgraph. */
if (!name && type_info.defaultname) {
if (name.is_empty() && type_info.defaultname) {
name = DATA_(type_info.defaultname);
}
if (name) {
STRNCPY(new_layer.name, name);
if (!name.is_empty()) {
name.copy(new_layer.name);
CustomData_set_layer_unique_name(data, index);
}
else {
@@ -2997,7 +2997,7 @@ void *CustomData_add_layer_named(CustomData *data,
const eCustomDataType type,
const eCDAllocType alloctype,
const int totelem,
const char *name)
const StringRef name)
{
CustomDataLayer *layer = customData_add_layer__internal(
data, type, alloctype, nullptr, nullptr, totelem, name);
@@ -3013,7 +3013,7 @@ const void *CustomData_add_layer_named_with_data(CustomData *data,
eCustomDataType type,
void *layer_data,
int totelem,
const char *name,
const StringRef name,
const ImplicitSharingInfo *sharing_info)
{
CustomDataLayer *layer = customData_add_layer__internal(
@@ -3032,7 +3032,7 @@ void *CustomData_add_layer_anonymous(CustomData *data,
const int totelem,
const AnonymousAttributeIDHandle *anonymous_id)
{
const char *name = anonymous_id->name().c_str();
const StringRef name = anonymous_id->name().c_str();
CustomDataLayer *layer = customData_add_layer__internal(
data, type, alloctype, nullptr, nullptr, totelem, name);
CustomData_update_typemap(data);
@@ -3054,7 +3054,7 @@ const void *CustomData_add_layer_anonymous_with_data(
void *layer_data,
const ImplicitSharingInfo *sharing_info)
{
const char *name = anonymous_id->name().c_str();
const StringRef name = anonymous_id->name().c_str();
CustomDataLayer *layer = customData_add_layer__internal(
data, type, std::nullopt, layer_data, sharing_info, totelem, name);
CustomData_update_typemap(data);
@@ -3122,7 +3122,7 @@ bool CustomData_free_layer(CustomData *data,
return true;
}
bool CustomData_free_layer_named(CustomData *data, const char *name, const int totelem)
bool CustomData_free_layer_named(CustomData *data, const StringRef name, const int totelem)
{
for (const int i : IndexRange(data->totlayer)) {
const CustomDataLayer &layer = data->layers[i];
@@ -3153,7 +3153,7 @@ void CustomData_free_layers(CustomData *data, const eCustomDataType type, const
bool CustomData_has_layer_named(const CustomData *data,
const eCustomDataType type,
const char *name)
const StringRef name)
{
return CustomData_get_named_layer_index(data, type, name) != -1;
}
@@ -3531,7 +3531,7 @@ void *CustomData_get_layer_n_for_write(CustomData *data,
const void *CustomData_get_layer_named(const CustomData *data,
const eCustomDataType type,
const char *name)
const StringRef name)
{
int layer_index = CustomData_get_named_layer_index(data, type, name);
if (layer_index == -1) {
@@ -3542,7 +3542,7 @@ const void *CustomData_get_layer_named(const CustomData *data,
void *CustomData_get_layer_named_for_write(CustomData *data,
const eCustomDataType type,
const char *name,
const StringRef name,
const int totelem)
{
const int layer_index = CustomData_get_named_layer_index(data, type, name);
@@ -3575,7 +3575,7 @@ int CustomData_get_n_offset(const CustomData *data, const eCustomDataType type,
int CustomData_get_offset_named(const CustomData *data,
const eCustomDataType type,
const char *name)
const StringRef name)
{
int layer_index = CustomData_get_named_layer_index(data, type, name);
if (layer_index == -1) {
@@ -3588,15 +3588,14 @@ int CustomData_get_offset_named(const CustomData *data,
bool CustomData_set_layer_name(CustomData *data,
const eCustomDataType type,
const int n,
const char *name)
const StringRef name)
{
const int layer_index = CustomData_get_layer_index_n(data, type, n);
if ((layer_index == -1) || !name) {
if (layer_index == -1) {
return false;
}
STRNCPY(data->layers[layer_index].name, name);
name.copy(data->layers[layer_index].name);
return true;
}
@@ -4281,7 +4280,7 @@ int CustomData_layertype_layers_max(const eCustomDataType type)
}
static bool cd_layer_find_dupe(CustomData *data,
const char *name,
const StringRef name,
const eCustomDataType type,
const int index)
{
@@ -4291,12 +4290,12 @@ static bool cd_layer_find_dupe(CustomData *data,
CustomDataLayer *layer = &data->layers[i];
if (CD_TYPE_AS_MASK(type) & CD_MASK_PROP_ALL) {
if ((CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) && STREQ(layer->name, name)) {
if ((CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) && layer->name == name) {
return true;
}
}
else {
if (i != index && layer->type == type && STREQ(layer->name, name)) {
if (i != index && layer->type == type && layer->name == name) {
return true;
}
}
@@ -4358,7 +4357,7 @@ void CustomData_set_layer_unique_name(CustomData *data, const int index)
void CustomData_validate_layer_name(const CustomData *data,
const eCustomDataType type,
const char *name,
const StringRef name,
char *outname)
{
int index = -1;
@@ -4376,7 +4375,9 @@ void CustomData_validate_layer_name(const CustomData *data,
BLI_strncpy_utf8(outname, data->layers[index].name, MAX_CUSTOMDATA_LAYER_NAME);
}
else {
BLI_strncpy_utf8(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
char name_c_str[MAX_CUSTOMDATA_LAYER_NAME];
name.copy(name_c_str);
BLI_strncpy_utf8(outname, name_c_str, MAX_CUSTOMDATA_LAYER_NAME);
}
}
@@ -5264,7 +5265,7 @@ void CustomData_debug_info_from_layers(const CustomData *data, const char *inden
{
if (CustomData_has_layer(data, type)) {
/* NOTE: doesn't account for multiple layers. */
const char *name = CustomData_layertype_name(type);
const StringRef name = CustomData_layertype_name(type);
const int size = CustomData_sizeof(type);
const void *pt = CustomData_get_layer(data, type);
const int pt_size = pt ? int(MEM_allocN_len(pt) / size) : 0;

View File

@@ -259,18 +259,18 @@ static CustomData &domain_custom_data(CurvesGeometry &curves, const AttrDomain d
template<typename T>
static MutableSpan<T> get_mutable_attribute(CurvesGeometry &curves,
const AttrDomain domain,
const StringRefNull name,
const StringRef name,
const T default_value = T())
{
const int num = domain_num(curves, domain);
const eCustomDataType type = cpp_type_to_custom_data_type(CPPType::get<T>());
CustomData &custom_data = domain_custom_data(curves, domain);
T *data = (T *)CustomData_get_layer_named_for_write(&custom_data, type, name.c_str(), num);
T *data = (T *)CustomData_get_layer_named_for_write(&custom_data, type, name, num);
if (data != nullptr) {
return {data, num};
}
data = (T *)CustomData_add_layer_named(&custom_data, type, CD_SET_DEFAULT, num, name.c_str());
data = (T *)CustomData_add_layer_named(&custom_data, type, CD_SET_DEFAULT, num, name);
MutableSpan<T> span = {data, num};
if (num > 0 && span.first() != default_value) {
span.fill(default_value);

View File

@@ -1712,7 +1712,7 @@ void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh)
for (const int i : uv_names.index_range()) {
const MLoopUV *mloopuv = static_cast<const MLoopUV *>(
CustomData_get_layer_named(&mesh->corner_data, CD_MLOOPUV, uv_names[i].c_str()));
CustomData_get_layer_named(&mesh->corner_data, CD_MLOOPUV, uv_names[i]));
const uint32_t needed_boolean_attributes = threading::parallel_reduce(
IndexRange(mesh->corners_num),
4096,
@@ -1763,13 +1763,13 @@ void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh)
}
});
CustomData_free_layer_named(&mesh->corner_data, uv_names[i].c_str(), mesh->corners_num);
CustomData_free_layer_named(&mesh->corner_data, uv_names[i], mesh->corners_num);
const std::string new_name = BKE_id_attribute_calc_unique_name(mesh->id, uv_names[i].c_str());
uv_names[i] = new_name;
CustomData_add_layer_named_with_data(
&mesh->corner_data, CD_PROP_FLOAT2, coords, mesh->corners_num, new_name.c_str(), nullptr);
&mesh->corner_data, CD_PROP_FLOAT2, coords, mesh->corners_num, new_name, nullptr);
char buffer[MAX_CUSTOMDATA_LAYER_NAME];
if (vert_selection) {
CustomData_add_layer_named_with_data(
@@ -1800,18 +1800,18 @@ void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh)
}
if (active_name_i != -1) {
CustomData_set_layer_active_index(
&mesh->corner_data,
CD_PROP_FLOAT2,
CustomData_get_named_layer_index(
&mesh->corner_data, CD_PROP_FLOAT2, uv_names[active_name_i].c_str()));
CustomData_set_layer_active_index(&mesh->corner_data,
CD_PROP_FLOAT2,
CustomData_get_named_layer_index(&mesh->corner_data,
CD_PROP_FLOAT2,
uv_names[active_name_i]));
}
if (default_name_i != -1) {
CustomData_set_layer_render_index(
&mesh->corner_data,
CD_PROP_FLOAT2,
CustomData_get_named_layer_index(
&mesh->corner_data, CD_PROP_FLOAT2, uv_names[default_name_i].c_str()));
CustomData_set_layer_render_index(&mesh->corner_data,
CD_PROP_FLOAT2,
CustomData_get_named_layer_index(&mesh->corner_data,
CD_PROP_FLOAT2,
uv_names[default_name_i]));
}
}

View File

@@ -265,7 +265,7 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *
BLI_SCOPED_DEFER([&]() {
for (const std::string &name : temporary_layers_to_delete) {
CustomData_free_layer_named(&mesh_ldata, name.c_str(), mesh->corners_num);
CustomData_free_layer_named(&mesh_ldata, name, mesh->corners_num);
}
MEM_SAFE_FREE(mesh_vdata.layers);

View File

@@ -914,11 +914,10 @@ struct PBVHBatches {
}
else {
const GenericRequest &request = std::get<GenericRequest>(vbo.request);
const StringRefNull name = request.name;
const bke::AttrDomain domain = request.domain;
const eCustomDataType data_type = request.type;
const CustomData &custom_data = *get_cdata(domain, args);
const int cd_offset = CustomData_get_offset_named(&custom_data, data_type, name.c_str());
const int cd_offset = CustomData_get_offset_named(&custom_data, data_type, request.name);
bke::attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
using T = decltype(dummy);
switch (domain) {

View File

@@ -274,17 +274,14 @@ int ED_mesh_uv_add(
CD_PROP_FLOAT2,
MEM_dupallocN(CustomData_get_layer(&mesh->corner_data, CD_PROP_FLOAT2)),
mesh->corners_num,
unique_name.c_str(),
unique_name,
nullptr);
is_init = true;
}
else {
CustomData_add_layer_named(&mesh->corner_data,
CD_PROP_FLOAT2,
CD_SET_DEFAULT,
mesh->corners_num,
unique_name.c_str());
CustomData_add_layer_named(
&mesh->corner_data, CD_PROP_FLOAT2, CD_SET_DEFAULT, mesh->corners_num, unique_name);
}
if (active_set || layernum_dst == 0) {
@@ -341,10 +338,10 @@ const bool *ED_mesh_uv_map_pin_layer_get(const Mesh *mesh, const int uv_index)
static bool *ensure_corner_boolean_attribute(Mesh &mesh, const blender::StringRefNull name)
{
bool *data = static_cast<bool *>(CustomData_get_layer_named_for_write(
&mesh.corner_data, CD_PROP_BOOL, name.c_str(), mesh.corners_num));
&mesh.corner_data, CD_PROP_BOOL, name, mesh.corners_num));
if (!data) {
data = static_cast<bool *>(CustomData_add_layer_named(
&mesh.corner_data, CD_PROP_BOOL, CD_SET_DEFAULT, mesh.faces_num, name.c_str()));
&mesh.corner_data, CD_PROP_BOOL, CD_SET_DEFAULT, mesh.faces_num, name));
}
return data;
}

View File

@@ -742,8 +742,8 @@ static void add_shapekey_layers(Mesh &mesh_dest, const Mesh &mesh_src)
memcpy(array, kb->data, sizeof(float[3]) * size_t(mesh_src.verts_num));
}
CustomData_add_layer_named_with_data(
&mesh_dest.vert_data, CD_SHAPEKEY, array, mesh_dest.verts_num, kb->name, nullptr);
CustomData_add_layer_with_data(
&mesh_dest.vert_data, CD_SHAPEKEY, array, mesh_dest.verts_num, nullptr);
const int ci = CustomData_get_layer_index_n(&mesh_dest.vert_data, CD_SHAPEKEY, i);
mesh_dest.vert_data.layers[ci].uid = kb->uid;

View File

@@ -155,13 +155,6 @@ int CustomData_get_offset(const struct CustomData * /*data*/, eCustomDataType /*
return 0;
}
int CustomData_get_named_layer_index(const struct CustomData * /*data*/,
eCustomDataType /*type*/,
const char * /*name*/)
{
return -1;
}
int CustomData_get_active_layer_index(const struct CustomData * /*data*/, eCustomDataType /*type*/)
{
return -1;

View File

@@ -476,7 +476,7 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh)
COLLADAFW::String &uvname = info->mName;
/* Allocate space for UV_data */
CustomData_add_layer_named(
&mesh->corner_data, CD_PROP_FLOAT2, CD_SET_DEFAULT, mesh->corners_num, uvname.c_str());
&mesh->corner_data, CD_PROP_FLOAT2, CD_SET_DEFAULT, mesh->corners_num, uvname);
}
/* activate the first uv map */
CustomData_set_layer_active(&mesh->corner_data, CD_PROP_FLOAT2, 0);
@@ -488,11 +488,8 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh)
COLLADAFW::MeshVertexData::InputInfos *info =
collada_mesh->getColors().getInputInfosArray()[i];
COLLADAFW::String colname = extract_vcolname(info->mName);
CustomData_add_layer_named(&mesh->corner_data,
CD_PROP_BYTE_COLOR,
CD_SET_DEFAULT,
mesh->corners_num,
colname.c_str());
CustomData_add_layer_named(
&mesh->corner_data, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, mesh->corners_num, colname);
}
BKE_id_attributes_active_color_set(
&mesh->id, CustomData_get_layer_name(&mesh->corner_data, CD_PROP_BYTE_COLOR, 0));
@@ -726,10 +723,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
{
COLLADAFW::IndexList &index_list = *index_list_array_uvcoord[uvset_index];
blender::float2 *mloopuv = static_cast<blender::float2 *>(
CustomData_get_layer_named_for_write(&mesh->corner_data,
CD_PROP_FLOAT2,
index_list.getName().c_str(),
mesh->corners_num));
CustomData_get_layer_named_for_write(
&mesh->corner_data, CD_PROP_FLOAT2, index_list.getName(), mesh->corners_num));
if (mloopuv == nullptr) {
fprintf(stderr,
"Collada import: Mesh [%s] : Unknown reference to TEXCOORD [#%s].\n",
@@ -770,7 +765,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
COLLADAFW::IndexList &color_index_list = *mp->getColorIndices(vcolor_index);
COLLADAFW::String colname = extract_vcolname(color_index_list.getName());
MLoopCol *mloopcol = (MLoopCol *)CustomData_get_layer_named_for_write(
&mesh->corner_data, CD_PROP_BYTE_COLOR, colname.c_str(), mesh->corners_num);
&mesh->corner_data, CD_PROP_BYTE_COLOR, colname, mesh->corners_num);
if (mloopcol == nullptr) {
fprintf(stderr,
"Collada import: Mesh [%s] : Unknown reference to VCOLOR [#%s].\n",