From 037121c2614826c6ba379fd447c54ed6d58d7d06 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 12 Jun 2025 14:54:32 +0200 Subject: [PATCH] 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 --- source/blender/blenkernel/intern/mesh.cc | 25 ++++++++++++++++++++++++ source/blender/makesdna/DNA_mesh_types.h | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 8f23e88fe95..2ce1d38f4b7 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -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( + 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( + 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); diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index ba0c52ed3ca..8b8ce9ca69b 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -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;