[Bf-blender-cvs] [33a558bf215] master: Geometry Nodes: support accessing UV layers with attribute system

Jacques Lucke noreply at git.blender.org
Thu Jan 14 18:11:58 CET 2021


Commit: 33a558bf21579b57f94329bc98d87f28e178c17a
Author: Jacques Lucke
Date:   Thu Jan 14 18:11:44 2021 +0100
Branches: master
https://developer.blender.org/rB33a558bf21579b57f94329bc98d87f28e178c17a

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.

===================================================================

M	source/blender/blenkernel/intern/attribute_access.cc

===================================================================

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<ArrayReadAttribute<bool>>(
               domain, Span(static_cast<bool *>(layer.data), size));
+        case CD_MLOOPUV:
+          auto get_uv = [](const MLoopUV &uv) { return float2(uv.uv); };
+          return std::make_unique<DerivedArrayReadAttribute<MLoopUV, float2, decltype(get_uv)>>(
+              domain, Span(static_cast<MLoopUV *>(layer.data), size), get_uv);
       }
     }
   }
@@ -570,6 +574,12 @@ static WriteAttributePtr write_attribute_from_custom_data(
         case CD_PROP_BOOL:
           return std::make_unique<ArrayWriteAttribute<bool>>(
               domain, MutableSpan(static_cast<bool *>(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<MLoopUV, float2, decltype(get_uv), decltype(set_uv)>>(
+              domain, MutableSpan(static_cast<MLoopUV *>(layer.data), size), get_uv, set_uv);
       }
     }
   }
@@ -597,8 +607,9 @@ static void get_custom_data_layer_attribute_names(const CustomData &custom_data,
                                                   Set<std::string> &r_names)
 {
   for (const CustomDataLayer &layer : blender::Span(custom_data.layers, custom_data.totlayer)) {
-    if (component.attribute_domain_with_type_supported(domain,
-                                                       static_cast<CustomDataType>(layer.type))) {
+    const CustomDataType data_type = static_cast<CustomDataType>(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<std::string> 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);



More information about the Bf-blender-cvs mailing list