Fix T94435: remove anonymous attributes when applying modifier

Differential Revision: https://developer.blender.org/D13994
This commit is contained in:
Jacques Lucke 2022-02-03 16:52:16 +01:00
parent 946c70e6a7
commit 4be87e97f4
Notes: blender-bot 2023-02-14 09:03:55 +01:00
Referenced by issue #94435, Applying GN modifier with Capture Attribute node clutters resulting mesh with anonymous attributes
3 changed files with 29 additions and 0 deletions

View File

@ -253,6 +253,11 @@ bool CustomData_free_layer_active(struct CustomData *data, int type, int totelem
*/
void CustomData_free_layers(struct CustomData *data, int type, int totelem);
/**
* Free all anonymous attributes.
*/
void CustomData_free_layers_anonymous(struct CustomData *data, int totelem);
/**
* Returns true if a layer with the specified type exists.
*/

View File

@ -2780,6 +2780,24 @@ void CustomData_free_layers(CustomData *data, int type, int totelem)
}
}
void CustomData_free_layers_anonymous(struct CustomData *data, int totelem)
{
while (true) {
bool found_anonymous_layer = false;
for (int i = 0; i < data->totlayer; i++) {
const CustomDataLayer *layer = &data->layers[i];
if (layer->anonymous_id != NULL) {
CustomData_free_layer(data, layer->type, totelem, i);
found_anonymous_layer = true;
break;
}
}
if (!found_anonymous_layer) {
break;
}
}
}
bool CustomData_has_layer(const CustomData *data, int type)
{
return (CustomData_get_layer_index(data, type) != -1);

View File

@ -763,6 +763,12 @@ static bool modifier_apply_obdata(
BKE_object_material_from_eval_data(bmain, ob, &mesh_applied->id);
BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true);
/* Anonymous attributes shouldn't by available on the applied geometry. */
CustomData_free_layers_anonymous(&me->vdata, me->totvert);
CustomData_free_layers_anonymous(&me->edata, me->totedge);
CustomData_free_layers_anonymous(&me->pdata, me->totpoly);
CustomData_free_layers_anonymous(&me->ldata, me->totloop);
if (md_eval->type == eModifierType_Multires) {
multires_customdata_delete(me);
}