Fix: Skip anonymous CustomData layers for the python API #104783
|
@ -282,6 +282,7 @@ bool CustomData_has_layer(const struct CustomData *data, int type);
|
||||||
* Returns the number of layers with this type.
|
* Returns the number of layers with this type.
|
||||||
*/
|
*/
|
||||||
int CustomData_number_of_layers(const struct CustomData *data, int type);
|
int CustomData_number_of_layers(const struct CustomData *data, int type);
|
||||||
|
int CustomData_number_of_anonymous_layers(const struct CustomData *data, int type);
|
||||||
int CustomData_number_of_layers_typemask(const struct CustomData *data, eCustomDataMask mask);
|
int CustomData_number_of_layers_typemask(const struct CustomData *data, eCustomDataMask mask);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2991,6 +2991,20 @@ int CustomData_number_of_layers(const CustomData *data, const int type)
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CustomData_number_of_anonymous_layers(const CustomData *data, const int type)
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < data->totlayer; i++) {
|
||||||
|
|||||||
|
if (data->layers[i].type == type && data->layers[i].anonymous_id != nullptr) {
|
||||||
|
number++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int CustomData_number_of_layers_typemask(const CustomData *data, const eCustomDataMask mask)
|
int CustomData_number_of_layers_typemask(const CustomData *data, const eCustomDataMask mask)
|
||||||
{
|
{
|
||||||
int number = 0;
|
int number = 0;
|
||||||
|
|
|
@ -8,13 +8,14 @@
|
||||||
|
|
||||||
/* Macros to help reduce code clutter in rna_mesh.c */
|
/* Macros to help reduce code clutter in rna_mesh.c */
|
||||||
|
|
||||||
/* Define the accessors for a basic CustomDataLayer collection */
|
|
||||||
|
/* Define the accessors for a basic CustomDataLayer collection, skipping anonymous layers */
|
||||||
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION(collection_name, customdata_type, layer_type) \
|
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION(collection_name, customdata_type, layer_type) \
|
||||||
/* check */ \
|
/* check */ \
|
||||||
static int rna_##collection_name##_check(CollectionPropertyIterator *UNUSED(iter), void *data) \
|
static int rna_##collection_name##_check(CollectionPropertyIterator *UNUSED(iter), void *data) \
|
||||||
{ \
|
{ \
|
||||||
CustomDataLayer *layer = (CustomDataLayer *)data; \
|
CustomDataLayer *layer = (CustomDataLayer *)data; \
|
||||||
return (layer->type != layer_type); \
|
return (layer->anonymous_id != NULL || layer->type != layer_type); \
|
||||||
} \
|
} \
|
||||||
/* begin */ \
|
/* begin */ \
|
||||||
static void rna_Mesh_##collection_name##s_begin(CollectionPropertyIterator *iter, \
|
static void rna_Mesh_##collection_name##s_begin(CollectionPropertyIterator *iter, \
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
static int rna_Mesh_##collection_name##s_length(PointerRNA *ptr) \
|
static int rna_Mesh_##collection_name##s_length(PointerRNA *ptr) \
|
||||||
{ \
|
{ \
|
||||||
CustomData *data = rna_mesh_##customdata_type(ptr); \
|
CustomData *data = rna_mesh_##customdata_type(ptr); \
|
||||||
return data ? CustomData_number_of_layers(data, layer_type) : 0; \
|
return data ? CustomData_number_of_layers(data, layer_type) - CustomData_number_of_anonymous_layers(data, layer_type) : 0; \
|
||||||
} \
|
} \
|
||||||
/* index range */ \
|
/* index range */ \
|
||||||
static void rna_Mesh_##collection_name##_index_range( \
|
static void rna_Mesh_##collection_name##_index_range( \
|
||||||
|
@ -45,10 +46,11 @@
|
||||||
{ \
|
{ \
|
||||||
CustomData *data = rna_mesh_##customdata_type(ptr); \
|
CustomData *data = rna_mesh_##customdata_type(ptr); \
|
||||||
*min = 0; \
|
*min = 0; \
|
||||||
*max = data ? CustomData_number_of_layers(data, layer_type) - 1 : 0; \
|
*max = data ? CustomData_number_of_layers(data, layer_type) - CustomData_number_of_anonymous_layers(data, layer_type) - 1 : 0; \
|
||||||
*max = MAX2(0, *max); \
|
*max = MAX2(0, *max); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Define the accessors for special CustomDataLayers in the collection
|
/* Define the accessors for special CustomDataLayers in the collection
|
||||||
* (active, render, clone, stencil, etc) */
|
* (active, render, clone, stencil, etc) */
|
||||||
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM( \
|
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM( \
|
||||||
|
|
Loading…
Reference in New Issue
How about
for (const CustomDataLayer &layer : Span(data->layers, data->totlayer)) {
?Can do, but then maybe change CustomData_get_number_of_layers() as well?
Mainly I just think new code should be "clean", even if slightly inconsistent with the surrounding area. Cleaning up existing code is another task.