Attributes: support setting the active attribute to "None"
Support setting: `object.data.attributes.active = None` for
ID attributes. Use -1 to represent no active index.
Resolves #127691
Ref !128233
----
Backport e21b424eee
Pull Request: https://projects.blender.org/blender/blender/pulls/129036
This commit is contained in:
committed by
Philipp Oeser
parent
ba847042d5
commit
88a566e719
@@ -92,6 +92,7 @@ int BKE_id_attributes_length(const struct ID *id,
|
||||
|
||||
struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id);
|
||||
void BKE_id_attributes_active_set(struct ID *id, const char *name);
|
||||
void BKE_id_attributes_active_clear(struct ID *id);
|
||||
int *BKE_id_attributes_active_index_p(struct ID *id);
|
||||
|
||||
CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers);
|
||||
@@ -109,6 +110,7 @@ int BKE_id_attribute_to_index(const struct ID *id,
|
||||
const char *BKE_id_attributes_active_color_name(const struct ID *id);
|
||||
const char *BKE_id_attributes_default_color_name(const struct ID *id);
|
||||
void BKE_id_attributes_active_color_set(struct ID *id, const char *name);
|
||||
void BKE_id_attributes_active_color_clear(struct ID *id);
|
||||
void BKE_id_attributes_default_color_set(struct ID *id, const char *name);
|
||||
|
||||
const struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name);
|
||||
|
||||
@@ -710,6 +710,9 @@ bool BKE_id_attribute_required(const ID *id, const char *name)
|
||||
CustomDataLayer *BKE_id_attributes_active_get(ID *id)
|
||||
{
|
||||
int active_index = *BKE_id_attributes_active_index_p(id);
|
||||
if (active_index == -1) {
|
||||
return nullptr;
|
||||
}
|
||||
if (active_index > BKE_id_attributes_length(id, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL)) {
|
||||
active_index = 0;
|
||||
}
|
||||
@@ -750,6 +753,11 @@ void BKE_id_attributes_active_set(ID *id, const char *name)
|
||||
*BKE_id_attributes_active_index_p(id) = index;
|
||||
}
|
||||
|
||||
void BKE_id_attributes_active_clear(ID *id)
|
||||
{
|
||||
*BKE_id_attributes_active_index_p(id) = -1;
|
||||
}
|
||||
|
||||
int *BKE_id_attributes_active_index_p(ID *id)
|
||||
{
|
||||
switch (GS(id->name)) {
|
||||
@@ -897,6 +905,19 @@ void BKE_id_attributes_active_color_set(ID *id, const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_id_attributes_active_color_clear(ID *id)
|
||||
{
|
||||
switch (GS(id->name)) {
|
||||
case ID_ME: {
|
||||
Mesh *mesh = reinterpret_cast<Mesh *>(id);
|
||||
MEM_SAFE_FREE(mesh->active_color_attribute);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_id_attributes_default_color_set(ID *id, const char *name)
|
||||
{
|
||||
switch (GS(id->name)) {
|
||||
|
||||
@@ -169,6 +169,8 @@ typedef struct Curves {
|
||||
CurvesGeometry geometry;
|
||||
|
||||
int flag;
|
||||
|
||||
/** Set to -1 when none is active. */
|
||||
int attributes_active_index;
|
||||
|
||||
/* Materials. */
|
||||
|
||||
@@ -446,6 +446,8 @@ typedef struct GreasePencil {
|
||||
CustomData layers_data;
|
||||
/**
|
||||
* The index of the active attribute in the UI.
|
||||
*
|
||||
* Set to -1 when none is active.
|
||||
*/
|
||||
int attributes_active_index;
|
||||
char _pad2[4];
|
||||
|
||||
@@ -103,6 +103,8 @@ typedef struct Mesh {
|
||||
/**
|
||||
* The index of the active attribute in the UI. The attribute list is a combination of the
|
||||
* generic type attributes from vertex, edge, face, and corner custom data.
|
||||
*
|
||||
* Set to -1 when none is active.
|
||||
*/
|
||||
int attributes_active_index;
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ typedef struct PointCloud {
|
||||
|
||||
/* Custom Data */
|
||||
struct CustomData pdata;
|
||||
/** Set to -1 when none is active. */
|
||||
int attributes_active_index;
|
||||
int _pad4;
|
||||
|
||||
|
||||
@@ -594,18 +594,23 @@ static void rna_AttributeGroup_active_set(PointerRNA *ptr,
|
||||
{
|
||||
ID *id = ptr->owner_id;
|
||||
CustomDataLayer *layer = static_cast<CustomDataLayer *>(attribute_ptr.data);
|
||||
BKE_id_attributes_active_set(id, layer->name);
|
||||
if (layer) {
|
||||
BKE_id_attributes_active_set(id, layer->name);
|
||||
}
|
||||
else {
|
||||
BKE_id_attributes_active_clear(id);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_AttributeGroup_active_index_set(PointerRNA *ptr, int value)
|
||||
{
|
||||
*BKE_id_attributes_active_index_p(ptr->owner_id) = value;
|
||||
*BKE_id_attributes_active_index_p(ptr->owner_id) = std::max(-1, value);
|
||||
}
|
||||
|
||||
static void rna_AttributeGroup_active_index_range(
|
||||
PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
|
||||
{
|
||||
*min = 0;
|
||||
*min = -1;
|
||||
*max = BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL);
|
||||
|
||||
*softmin = *min;
|
||||
@@ -636,7 +641,12 @@ static void rna_AttributeGroup_active_color_set(PointerRNA *ptr,
|
||||
{
|
||||
ID *id = ptr->owner_id;
|
||||
CustomDataLayer *layer = static_cast<CustomDataLayer *>(attribute_ptr.data);
|
||||
BKE_id_attributes_active_color_set(id, layer->name);
|
||||
if (layer) {
|
||||
BKE_id_attributes_active_color_set(id, layer->name);
|
||||
}
|
||||
else {
|
||||
BKE_id_attributes_active_color_clear(ptr->owner_id);
|
||||
}
|
||||
}
|
||||
|
||||
static int rna_AttributeGroup_active_color_index_get(PointerRNA *ptr)
|
||||
@@ -656,18 +666,18 @@ static void rna_AttributeGroup_active_color_index_set(PointerRNA *ptr, int value
|
||||
CustomDataLayer *layer = BKE_id_attribute_from_index(
|
||||
ptr->owner_id, value, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
|
||||
|
||||
if (!layer) {
|
||||
fprintf(stderr, "%s: error setting active color index to %d\n", __func__, value);
|
||||
return;
|
||||
if (layer) {
|
||||
BKE_id_attributes_active_color_set(ptr->owner_id, layer->name);
|
||||
}
|
||||
else {
|
||||
BKE_id_attributes_active_color_clear(ptr->owner_id);
|
||||
}
|
||||
|
||||
BKE_id_attributes_active_color_set(ptr->owner_id, layer->name);
|
||||
}
|
||||
|
||||
static void rna_AttributeGroup_active_color_index_range(
|
||||
PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
|
||||
{
|
||||
*min = 0;
|
||||
*min = -1;
|
||||
*max = BKE_id_attributes_length(ptr->owner_id, ATTR_DOMAIN_MASK_COLOR, CD_MASK_COLOR_ALL);
|
||||
|
||||
*softmin = *min;
|
||||
@@ -1323,7 +1333,9 @@ static void rna_def_attribute_group(BlenderRNA *brna)
|
||||
RNA_def_property_update(prop, 0, "rna_AttributeGroup_update_active");
|
||||
|
||||
prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_ui_text(prop, "Active Attribute Index", "Active attribute index");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Active Attribute Index", "Active attribute index or -1 when none are active");
|
||||
RNA_def_property_range(prop, -1, INT_MAX);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_int_funcs(prop,
|
||||
"rna_AttributeGroup_active_index_get",
|
||||
|
||||
Reference in New Issue
Block a user