From 2e69a2b9afc70d40bf5586c6a7c3624ed3204709 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 14 Feb 2023 13:10:52 +0100 Subject: [PATCH 1/5] Fix #104730: Make first visible CustomData layer active When creating a CustomData layer with a name not starting with a dot while all existing layers of the same type have names which do start with a dot make the new layer the active/render/mask/clone layer. It can be confusing if the render layers is a hidden/anonymous layer. --- .../blender/blenkernel/intern/customdata.cc | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 75a8c865170..1d03ffe09a6 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2706,6 +2706,24 @@ static bool customData_resize(CustomData *data, const int amount) return true; } +static bool customData_has_visible_layer(const CustomData *data, const int type) +{ + int layer = data->typemap[type]; + + if (layer <= 0) { + return false; + } + + while (data->layers[layer].type == type) { + if (data->layers[layer].name[0] && data->layers[layer].name[0] != '.') { + return true; + } + layer++; + } + + return false; +} + static CustomDataLayer *customData_add_layer__internal(CustomData *data, const int type, const eCDAllocType alloctype, @@ -2716,6 +2734,11 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, const LayerTypeInfo *typeInfo = layerType_getInfo(type); int flag = 0; + bool isfirstvisible = false; + if (name && name[0] != '.') { + isfirstvisible = !customData_has_visible_layer(data, type); + } + /* Some layer types only support a single layer. */ if (!typeInfo->defaultname && CustomData_has_layer(data, type)) { /* This function doesn't support dealing with existing layer data for these layer types when @@ -2834,6 +2857,13 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, customData_update_offsets(data); + if (isfirstvisible) { + CustomData_set_layer_active_index(data, type, index); + CustomData_set_layer_render_index(data, type, index); + CustomData_set_layer_clone_index(data, type, index); + CustomData_set_layer_stencil_index(data, type, index); + } + return &data->layers[index]; } -- 2.30.2 From 6ecfa73d6a3878f3e89e17742733ecdeffdeae73 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Tue, 14 Feb 2023 14:51:58 +0100 Subject: [PATCH 2/5] Change for existence of 'nonanonymous' layers instead of layernames starting wwith a . --- .../blender/blenkernel/intern/customdata.cc | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 1d03ffe09a6..984f8007148 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2166,7 +2166,8 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, eCDAllocType alloctype, void *layerdata, int totelem, - const char *name); + const char *name, + bool isanonymous); void CustomData_update_typemap(CustomData *data) { @@ -2254,10 +2255,10 @@ bool CustomData_merge(const CustomData *source, if ((alloctype == CD_ASSIGN) && (flag & CD_FLAG_NOFREE)) { newlayer = customData_add_layer__internal( - dest, type, CD_REFERENCE, data, totelem, layer->name); + dest, type, CD_REFERENCE, data, totelem, layer->name, layer->anonymous_id != nullptr); } else { - newlayer = customData_add_layer__internal(dest, type, alloctype, data, totelem, layer->name); + newlayer = customData_add_layer__internal(dest, type, alloctype, data, totelem, layer->name, layer->anonymous_id != nullptr); } if (newlayer) { @@ -2706,7 +2707,7 @@ static bool customData_resize(CustomData *data, const int amount) return true; } -static bool customData_has_visible_layer(const CustomData *data, const int type) +static bool customData_has_nonanonymous_layer(const CustomData *data, const int type) { int layer = data->typemap[type]; @@ -2715,7 +2716,7 @@ static bool customData_has_visible_layer(const CustomData *data, const int type) } while (data->layers[layer].type == type) { - if (data->layers[layer].name[0] && data->layers[layer].name[0] != '.') { + if (data->layers[layer].name[0] && data->layers[layer].anonymous_id == nullptr) { return true; } layer++; @@ -2729,14 +2730,15 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, const eCDAllocType alloctype, void *layerdata, const int totelem, - const char *name) + const char *name, + bool isanonymous) { const LayerTypeInfo *typeInfo = layerType_getInfo(type); int flag = 0; bool isfirstvisible = false; - if (name && name[0] != '.') { - isfirstvisible = !customData_has_visible_layer(data, type); + if (!isanonymous) { + isfirstvisible = !customData_has_nonanonymous_layer(data, type); } /* Some layer types only support a single layer. */ @@ -2873,7 +2875,7 @@ void *CustomData_add_layer( const LayerTypeInfo *typeInfo = layerType_getInfo(type); CustomDataLayer *layer = customData_add_layer__internal( - data, type, alloctype, layerdata, totelem, typeInfo->defaultname); + data, type, alloctype, layerdata, totelem, typeInfo->defaultname, false); CustomData_update_typemap(data); if (layer) { @@ -2891,7 +2893,7 @@ void *CustomData_add_layer_named(CustomData *data, const char *name) { CustomDataLayer *layer = customData_add_layer__internal( - data, type, alloctype, layerdata, totelem, name); + data, type, alloctype, layerdata, totelem, name, false); CustomData_update_typemap(data); if (layer) { @@ -2910,7 +2912,7 @@ void *CustomData_add_layer_anonymous(CustomData *data, { const char *name = anonymous_id->name().c_str(); CustomDataLayer *layer = customData_add_layer__internal( - data, type, alloctype, layerdata, totelem, name); + data, type, alloctype, layerdata, totelem, name, true); CustomData_update_typemap(data); if (layer == nullptr) { -- 2.30.2 From 965a936118b8bc619f41df3bfe6adfe76d488f03 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Thu, 16 Feb 2023 11:31:00 +0100 Subject: [PATCH 3/5] Never let anonymous layers be the active/render/mask/clone lauyer --- source/blender/blenkernel/intern/customdata.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 70f788efb42..91826226efe 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2851,10 +2851,10 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, new_layer.active_mask = data->layers[index - 1].active_mask; } else { - new_layer.active = 0; - new_layer.active_rnd = 0; - new_layer.active_clone = 0; - new_layer.active_mask = 0; + new_layer.active = isanonymous ? -1 : 0; + new_layer.active_rnd = isanonymous ? -1 : 0; + new_layer.active_clone = isanonymous ? -1 : 0; + new_layer.active_mask = isanonymous ? -1 : 0; } customData_update_offsets(data); -- 2.30.2 From 7dc47e8bdffadf1139f1a9687b5c21d99a7d69c1 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Thu, 16 Feb 2023 14:41:24 +0100 Subject: [PATCH 4/5] Fix customdata_has_nonanonymous --- source/blender/blenkernel/intern/customdata.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 91826226efe..0f1ab62fcc5 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2716,7 +2716,7 @@ static bool customData_has_nonanonymous_layer(const CustomData *data, const int } while (data->layers[layer].type == type) { - if (data->layers[layer].name[0] && data->layers[layer].anonymous_id == nullptr) { + if (data->layers[layer].anonymous_id != nullptr) { return true; } layer++; -- 2.30.2 From 0de0f96bd4ae1fb2718ee8d90fd9ff7d796a3b25 Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Thu, 16 Feb 2023 14:41:53 +0100 Subject: [PATCH 5/5] Revert "Never let anonymous layers be the active/render/mask/clone lauyer" This reverts commit 965a936118b8bc619f41df3bfe6adfe76d488f03. --- source/blender/blenkernel/intern/customdata.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 0f1ab62fcc5..56b79b68011 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2851,10 +2851,10 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, new_layer.active_mask = data->layers[index - 1].active_mask; } else { - new_layer.active = isanonymous ? -1 : 0; - new_layer.active_rnd = isanonymous ? -1 : 0; - new_layer.active_clone = isanonymous ? -1 : 0; - new_layer.active_mask = isanonymous ? -1 : 0; + new_layer.active = 0; + new_layer.active_rnd = 0; + new_layer.active_clone = 0; + new_layer.active_mask = 0; } customData_update_offsets(data); -- 2.30.2