Cleanup: Move anonymous attribute removal to geometry component
Implementing removal of anonymous attributes with `GeometryComponent` instead of `Mesh` makes it more reusable for other types like curves.
This commit is contained in:
parent
b7458f909c
commit
db45292d8e
|
@ -235,11 +235,6 @@ 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.
|
||||
*/
|
||||
|
|
|
@ -148,6 +148,12 @@ class GeometryComponent {
|
|||
/** Returns true when the attribute has been deleted. */
|
||||
bool attribute_try_delete(const blender::bke::AttributeIDRef &attribute_id);
|
||||
|
||||
/**
|
||||
* Remove any anonymous attributes on the geometry (they generally shouldn't exist on original
|
||||
* geometry).
|
||||
*/
|
||||
void attributes_remove_anonymous();
|
||||
|
||||
/** Returns true when the attribute has been created. */
|
||||
bool attribute_try_create(const blender::bke::AttributeIDRef &attribute_id,
|
||||
AttributeDomain domain,
|
||||
|
|
|
@ -318,8 +318,6 @@ void BKE_mesh_vert_coords_apply_with_mat4(struct Mesh *mesh,
|
|||
const float mat[4][4]);
|
||||
void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float (*vert_coords)[3]);
|
||||
|
||||
void BKE_mesh_anonymous_attributes_remove(struct Mesh *mesh);
|
||||
|
||||
/* *** mesh_tessellate.c *** */
|
||||
|
||||
/**
|
||||
|
|
|
@ -926,6 +926,21 @@ bool GeometryComponent::attribute_try_delete(const AttributeIDRef &attribute_id)
|
|||
return success;
|
||||
}
|
||||
|
||||
void GeometryComponent::attributes_remove_anonymous()
|
||||
{
|
||||
using namespace blender;
|
||||
Vector<const AnonymousAttributeID *> anonymous_ids;
|
||||
for (const AttributeIDRef &id : this->attribute_ids()) {
|
||||
if (id.is_anonymous()) {
|
||||
anonymous_ids.append(&id.anonymous_id());
|
||||
}
|
||||
}
|
||||
|
||||
while (!anonymous_ids.is_empty()) {
|
||||
this->attribute_try_delete(anonymous_ids.pop_last());
|
||||
}
|
||||
}
|
||||
|
||||
bool GeometryComponent::attribute_try_create(const AttributeIDRef &attribute_id,
|
||||
const AttributeDomain domain,
|
||||
const CustomDataType data_type,
|
||||
|
|
|
@ -2883,24 +2883,6 @@ 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 != nullptr) {
|
||||
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);
|
||||
|
|
|
@ -1930,14 +1930,6 @@ void BKE_mesh_vert_coords_apply_with_mat4(Mesh *mesh,
|
|||
BKE_mesh_normals_tag_dirty(mesh);
|
||||
}
|
||||
|
||||
void BKE_mesh_anonymous_attributes_remove(Mesh *mesh)
|
||||
{
|
||||
CustomData_free_layers_anonymous(&mesh->vdata, mesh->totvert);
|
||||
CustomData_free_layers_anonymous(&mesh->edata, mesh->totedge);
|
||||
CustomData_free_layers_anonymous(&mesh->pdata, mesh->totpoly);
|
||||
CustomData_free_layers_anonymous(&mesh->ldata, mesh->totloop);
|
||||
}
|
||||
|
||||
void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr)
|
||||
{
|
||||
float(*r_loopnors)[3];
|
||||
|
|
|
@ -1219,7 +1219,9 @@ Mesh *BKE_mesh_new_from_object_to_bmain(Main *bmain,
|
|||
BKE_mesh_nomain_to_mesh(mesh, mesh_in_bmain, nullptr, &CD_MASK_MESH, true);
|
||||
|
||||
/* Anonymous attributes shouldn't exist on original data. */
|
||||
BKE_mesh_anonymous_attributes_remove(mesh_in_bmain);
|
||||
MeshComponent component;
|
||||
component.replace(mesh_in_bmain, GeometryOwnershipType::Editable);
|
||||
component.attributes_remove_anonymous();
|
||||
|
||||
/* User-count is required because so far mesh was in a limbo, where library management does
|
||||
* not perform any user management (i.e. copy of a mesh will not increase users of materials). */
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "BKE_duplilist.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_geometry_set.h"
|
||||
#include "BKE_geometry_set.hh"
|
||||
#include "BKE_gpencil_curve.h"
|
||||
#include "BKE_gpencil_geom.h"
|
||||
#include "BKE_gpencil_modifier.h"
|
||||
|
@ -3120,8 +3121,12 @@ static int object_convert_exec(bContext *C, wmOperator *op)
|
|||
BKE_object_material_from_eval_data(bmain, newob, &me_eval->id);
|
||||
Mesh *new_mesh = (Mesh *)newob->data;
|
||||
BKE_mesh_nomain_to_mesh(me_eval, new_mesh, newob, &CD_MASK_MESH, true);
|
||||
|
||||
/* Anonymous attributes shouldn't be available on the applied geometry. */
|
||||
BKE_mesh_anonymous_attributes_remove(new_mesh);
|
||||
MeshComponent component;
|
||||
component.replace(new_mesh, GeometryOwnershipType::Editable);
|
||||
component.attributes_remove_anonymous();
|
||||
|
||||
BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
|
||||
}
|
||||
else if (ob->type == OB_FONT) {
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "BKE_displist.h"
|
||||
#include "BKE_editmesh.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_geometry_set.hh"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_gpencil_modifier.h"
|
||||
#include "BKE_key.h"
|
||||
|
@ -750,7 +751,9 @@ static bool modifier_apply_obdata(
|
|||
BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true);
|
||||
|
||||
/* Anonymous attributes shouldn't be available on the applied geometry. */
|
||||
BKE_mesh_anonymous_attributes_remove(me);
|
||||
MeshComponent component;
|
||||
component.replace(me, GeometryOwnershipType::Editable);
|
||||
component.attributes_remove_anonymous();
|
||||
|
||||
if (md_eval->type == eModifierType_Multires) {
|
||||
multires_customdata_delete(me);
|
||||
|
|
Loading…
Reference in New Issue