Fix #154189: Transfer Mesh Data UVs are not set active

Caused by a958e3d6b7

Above commit introduced `transfer_active/default_uv_map_string` but this
had two issues:
- it only did it for transferring the layout
(`BKE_object_data_transfer_layout`), not for the actual transfer
(`BKE_object_data_transfer_ex`) though
- it had a logical mistake, which would basically do nothing al the time
(it would check if active/default already existed on the **src** and if
so return early...)

Since we are doing similar transfer of strings for colors as well (and
we have to do it in a couple of places), I added
`transfer_attribute_name_strings` which does all this (colors and uvs
atm) in a central place to resolve the first issue.

Logical mistake is also corrected.

Pull Request: https://projects.blender.org/blender/blender/pulls/154190
This commit is contained in:
Philipp Oeser 2026-02-10 15:36:04 +01:00 • committed by Philipp Oeser
parent 58242e5fe7
commit c02e53ff48

View file

@ -316,10 +316,10 @@ static void transfer_default_color_string(Mesh *mesh_dst, const Mesh *mesh_src)
static void transfer_active_uv_map_string(Mesh *mesh_dst, const Mesh *mesh_src)
{
const StringRef name = mesh_src->active_uv_map_attribute;
if (!name.is_empty()) {
if (!mesh_dst->active_uv_map_name().is_empty()) {
return;
}
const StringRef name = mesh_src->active_uv_map_name();
const bke::AttributeAccessor attributes_src = mesh_src->attributes();
const bke::AttributeAccessor attributes_dst = mesh_dst->attributes();
@ -345,10 +345,11 @@ static void transfer_active_uv_map_string(Mesh *mesh_dst, const Mesh *mesh_src)
static void transfer_default_uv_map_string(Mesh *mesh_dst, const Mesh *mesh_src)
{
const StringRef name = mesh_src->default_uv_map_attribute;
if (!name.is_empty()) {
if (!mesh_dst->default_uv_map_name().is_empty()) {
return;
}
const StringRef name = mesh_src->default_uv_map_name();
const bke::AttributeAccessor attributes_src = mesh_src->attributes();
const bke::AttributeAccessor attributes_dst = mesh_dst->attributes();
@ -372,6 +373,25 @@ static void transfer_default_uv_map_string(Mesh *mesh_dst, const Mesh *mesh_src)
}
}
/**
* Make sure we have active/default color/uv layers if none existed before.
* If a match cant be found, use the first color/uv layer that can be found (to ensure a valid
* string is set).
*/
static void transfer_attribute_name_strings(const eCustomDataType cddata_type,
Mesh &mesh_dst,
const Mesh &mesh_src)
{
if (ELEM(cddata_type, CD_PROP_COLOR, CD_PROP_BYTE_COLOR)) {
transfer_active_color_string(&mesh_dst, &mesh_src);
transfer_default_color_string(&mesh_dst, &mesh_src);
}
else if (ELEM(cddata_type, CD_PROP_FLOAT2)) {
transfer_active_uv_map_string(&mesh_dst, &mesh_src);
transfer_default_uv_map_string(&mesh_dst, &mesh_src);
}
}
/* ********** */
static void data_transfer_dtdata_type_postprocess(Mesh *me_dst,
@ -716,6 +736,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(
return false;
}
transfer_attribute_name_strings(cddata_type, mesh_dst, mesh_src);
return true;
}
@ -854,6 +876,8 @@ static bool data_transfer_layersmapping_cdlayers(Vector<CustomDataTransferLayerM
return false;
}
transfer_attribute_name_strings(cddata_type, mesh_dst, mesh_src);
if (r_map) {
data_transfer_layersmapping_add_item_cd(r_map,
cddata_type,
@ -895,6 +919,9 @@ static bool data_transfer_layersmapping_cdlayers(Vector<CustomDataTransferLayerM
if (use_layers_src) {
MEM_delete(use_layers_src);
}
transfer_attribute_name_strings(cddata_type, mesh_dst, mesh_src);
return ret;
}
else {
@ -1311,12 +1338,6 @@ void BKE_object_data_transfer_layout(Depsgraph *depsgraph,
fromlayers,
tolayers,
nullptr);
/* Make sure we have active/default color layers if none existed before.
* Use the active/default from src (if it was transferred), otherwise the first. */
if (ELEM(cddata_type, CD_PROP_COLOR, CD_PROP_BYTE_COLOR)) {
transfer_active_color_string(me_dst, me_src);
transfer_default_color_string(me_dst, me_src);
}
}
if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
data_transfer_layersmapping_generate(nullptr,
@ -1351,16 +1372,6 @@ void BKE_object_data_transfer_layout(Depsgraph *depsgraph,
fromlayers,
tolayers,
nullptr);
/* Make sure we have active/default color layers if none existed before.
* Use the active/default from src (if it was transferred), otherwise the first. */
if (ELEM(cddata_type, CD_PROP_COLOR, CD_PROP_BYTE_COLOR)) {
transfer_active_color_string(me_dst, me_src);
transfer_default_color_string(me_dst, me_src);
}
else if (ELEM(cddata_type, CD_PROP_FLOAT2)) {
transfer_active_uv_map_string(me_dst, me_src);
transfer_default_uv_map_string(me_dst, me_src);
}
}
if (DT_DATATYPE_IS_FACE(dtdata_type)) {
data_transfer_layersmapping_generate(nullptr,
@ -1379,6 +1390,8 @@ void BKE_object_data_transfer_layout(Depsgraph *depsgraph,
tolayers,
nullptr);
}
transfer_attribute_name_strings(eCustomDataType(cddata_type), *me_dst, *me_src);
}
}