From 33a558bf21579b57f94329bc98d87f28e178c17a Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 14 Jan 2021 18:11:44 +0100 Subject: [PATCH] Geometry Nodes: support accessing UV layers with attribute system Note that uv layers still can't be accessed with nodes, because those only access attributes on the point domain currently, while uv data is stored per corner. Implicit domain conversion hasn't been implemented yet. --- .../blenkernel/intern/attribute_access.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 6739294a2c4..b9ccee0dd4a 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -526,6 +526,10 @@ static ReadAttributePtr read_attribute_from_custom_data(const CustomData &custom case CD_PROP_BOOL: return std::make_unique>( domain, Span(static_cast(layer.data), size)); + case CD_MLOOPUV: + auto get_uv = [](const MLoopUV &uv) { return float2(uv.uv); }; + return std::make_unique>( + domain, Span(static_cast(layer.data), size), get_uv); } } } @@ -570,6 +574,12 @@ static WriteAttributePtr write_attribute_from_custom_data( case CD_PROP_BOOL: return std::make_unique>( domain, MutableSpan(static_cast(layer.data), size)); + case CD_MLOOPUV: + auto get_uv = [](const MLoopUV &uv) { return float2(uv.uv); }; + auto set_uv = [](MLoopUV &uv, const float2 value) { copy_v2_v2(uv.uv, value); }; + return std::make_unique< + DerivedArrayWriteAttribute>( + domain, MutableSpan(static_cast(layer.data), size), get_uv, set_uv); } } } @@ -597,8 +607,9 @@ static void get_custom_data_layer_attribute_names(const CustomData &custom_data, Set &r_names) { for (const CustomDataLayer &layer : blender::Span(custom_data.layers, custom_data.totlayer)) { - if (component.attribute_domain_with_type_supported(domain, - static_cast(layer.type))) { + const CustomDataType data_type = static_cast(layer.type); + if (component.attribute_domain_with_type_supported(domain, data_type) || + ELEM(data_type, CD_MLOOPUV)) { r_names.add(layer.name); } } @@ -1307,7 +1318,7 @@ Set MeshComponent::attribute_names() const for (StringRef name : vertex_group_names_.keys()) { names.add(name); } - get_custom_data_layer_attribute_names(mesh_->pdata, *this, ATTR_DOMAIN_CORNER, names); + get_custom_data_layer_attribute_names(mesh_->ldata, *this, ATTR_DOMAIN_CORNER, names); get_custom_data_layer_attribute_names(mesh_->vdata, *this, ATTR_DOMAIN_POINT, names); get_custom_data_layer_attribute_names(mesh_->edata, *this, ATTR_DOMAIN_EDGE, names); get_custom_data_layer_attribute_names(mesh_->pdata, *this, ATTR_DOMAIN_POLYGON, names);