Mesh: Use names to store active/default UV status

Required for the transition to `AttributeStorage`, because this
information was previously stored in `CustomDataLayer` flags.
This is already the way we store the active/default color attribute status.
Migrating runtime usage to use the names isn't done here, just like
we still use `CustomData` everywhere at runtime for `Mesh`.

Pull Request: https://projects.blender.org/blender/blender/pulls/140137
This commit is contained in:
Hans Goudey
2025-06-12 14:54:32 +02:00
committed by Hans Goudey
parent 8b67050575
commit 037121c261
2 changed files with 27 additions and 2 deletions

View File

@@ -308,6 +308,29 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
mesh->totface_legacy = 0;
mesh->fdata_legacy = CustomData{};
if (U.experimental.use_attribute_storage_write) {
/* Convert from the format still used at runtime (flags on #CustomDataLayer) to the format
* reserved for future runtime use (names stored on #Mesh). */
if (const char *name = CustomData_get_active_layer_name(&mesh->corner_data, CD_PROP_FLOAT2)) {
mesh->active_uv_map_attribute = const_cast<char *>(
scope.allocator().copy_string(name).c_str());
}
else {
mesh->active_uv_map_attribute = nullptr;
}
if (const char *name = CustomData_get_render_layer_name(&mesh->corner_data, CD_PROP_FLOAT2)) {
mesh->default_uv_map_attribute = const_cast<char *>(
scope.allocator().copy_string(name).c_str());
}
else {
mesh->default_uv_map_attribute = nullptr;
}
}
else {
mesh->active_uv_map_attribute = nullptr;
mesh->default_uv_map_attribute = nullptr;
}
/* Do not store actual geometry data in case this is a library override ID. */
if (ID_IS_OVERRIDE_LIBRARY(mesh) && !is_undo) {
mesh->verts_num = 0;
@@ -351,6 +374,8 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
BKE_defbase_blend_write(writer, &mesh->vertex_group_names);
BLO_write_string(writer, mesh->active_color_attribute);
BLO_write_string(writer, mesh->default_color_attribute);
BLO_write_string(writer, mesh->active_uv_map_attribute);
BLO_write_string(writer, mesh->default_uv_map_attribute);
BLO_write_pointer_array(writer, mesh->totcol, mesh->mat);
BLO_write_struct_array(writer, MSelect, mesh->totselect, mesh->mselect);

View File

@@ -180,12 +180,12 @@ typedef struct Mesh {
/**
* The UV map currently selected in the list and edited by a user.
* Currently only used for file forward compatibility (see #AttributeStorage).
* Currently only used for file reading/writing (see #AttributeStorage).
*/
char *active_uv_map_attribute;
/**
* The UV map used by default (i.e. for rendering) if no name is given explicitly.
* Currently only used for file forward compatibility (see #AttributeStorage).
* Currently only used for file reading/writing (see #AttributeStorage).
*/
char *default_uv_map_attribute;