[Bf-blender-cvs] [3ce30fa159f] virtual-array-attributes: progress

Jacques Lucke noreply at git.blender.org
Mon Apr 12 18:27:57 CEST 2021


Commit: 3ce30fa159f68b8b601af72967f32f33a0b18a49
Author: Jacques Lucke
Date:   Mon Apr 12 18:04:29 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB3ce30fa159f68b8b601af72967f32f33a0b18a49

progress

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/nodes/intern/node_geometry_exec.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 9e0f0d68cce..dbd27434ad5 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -90,7 +90,7 @@ class MaybeUnsavedWriteAttribute {
 
   GVMutableArray *operator->()
   {
-    return varray_;
+    return varray_.get();
   }
 
   GVMutableArray &varray()
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index a4fb99a988e..aee3df9723e 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -53,22 +53,24 @@ const bNodeSocket *GeoNodeExecParams::find_available_socket(const StringRef name
   return nullptr;
 }
 
-ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
-                                                        const GeometryComponent &component,
-                                                        const AttributeDomain domain,
-                                                        const CustomDataType type,
-                                                        const void *default_value) const
+std::unique_ptr<GVArray> GeoNodeExecParams::get_input_attribute(const StringRef name,
+                                                                const GeometryComponent &component,
+                                                                const AttributeDomain domain,
+                                                                const CustomDataType type,
+                                                                const void *default_value) const
 {
   const bNodeSocket *found_socket = this->find_available_socket(name);
   BLI_assert(found_socket != nullptr); /* There should always be available socket for the name. */
+  const CPPType *cpp_type = bke::custom_data_type_to_cpp_type(type);
+  const int64_t domain_size = component.attribute_domain_size(domain);
   if (found_socket == nullptr) {
-    return component.attribute_get_constant_for_read(domain, type, default_value);
+    return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, default_value);
   }
 
   if (found_socket->type == SOCK_STRING) {
     const std::string name = this->get_input<std::string>(found_socket->identifier);
     /* Try getting the attribute without the default value. */
-    ReadAttributePtr attribute = component.attribute_try_get_for_read(name, domain, type);
+    std::unique_ptr<GVArray> attribute = component.attribute_try_get_for_read(name, domain, type);
     if (attribute) {
       return attribute;
     }
@@ -80,25 +82,26 @@ ReadAttributePtr GeoNodeExecParams::get_input_attribute(const StringRef name,
       this->error_message_add(NodeWarningType::Error,
                               TIP_("No attribute with name \"") + name + "\"");
     }
-    return component.attribute_get_constant_for_read(domain, type, default_value);
-  }
-  if (found_socket->type == SOCK_FLOAT) {
-    const float value = this->get_input<float>(found_socket->identifier);
-    return component.attribute_get_constant_for_read_converted(
-        domain, CD_PROP_FLOAT, type, &value);
-  }
-  if (found_socket->type == SOCK_VECTOR) {
-    const float3 value = this->get_input<float3>(found_socket->identifier);
-    return component.attribute_get_constant_for_read_converted(
-        domain, CD_PROP_FLOAT3, type, &value);
-  }
-  if (found_socket->type == SOCK_RGBA) {
-    const Color4f value = this->get_input<Color4f>(found_socket->identifier);
-    return component.attribute_get_constant_for_read_converted(
-        domain, CD_PROP_COLOR, type, &value);
+    return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, default_value);
   }
+  /* TODO */
+  // if (found_socket->type == SOCK_FLOAT) {
+  //   const float value = this->get_input<float>(found_socket->identifier);
+  //   return component.attribute_get_constant_for_read_converted(
+  //       domain, CD_PROP_FLOAT, type, &value);
+  // }
+  // if (found_socket->type == SOCK_VECTOR) {
+  //   const float3 value = this->get_input<float3>(found_socket->identifier);
+  //   return component.attribute_get_constant_for_read_converted(
+  //       domain, CD_PROP_FLOAT3, type, &value);
+  // }
+  // if (found_socket->type == SOCK_RGBA) {
+  //   const Color4f value = this->get_input<Color4f>(found_socket->identifier);
+  //   return component.attribute_get_constant_for_read_converted(
+  //       domain, CD_PROP_COLOR, type, &value);
+  // }
   BLI_assert(false);
-  return component.attribute_get_constant_for_read(domain, type, default_value);
+  return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, default_value);
 }
 
 CustomDataType GeoNodeExecParams::get_input_attribute_data_type(
@@ -114,11 +117,11 @@ CustomDataType GeoNodeExecParams::get_input_attribute_data_type(
 
   if (found_socket->type == SOCK_STRING) {
     const std::string name = this->get_input<std::string>(found_socket->identifier);
-    ReadAttributePtr attribute = component.attribute_try_get_for_read(name);
+    ReadAttributeLookup attribute = component.attribute_try_get_for_read(name);
     if (!attribute) {
       return default_type;
     }
-    return attribute->custom_data_type();
+    return bke::cpp_type_to_custom_data_type(attribute.varray->type());
   }
   if (found_socket->type == SOCK_FLOAT) {
     return CD_PROP_FLOAT;
@@ -157,9 +160,9 @@ AttributeDomain GeoNodeExecParams::get_highest_priority_input_domain(
 
     if (found_socket->type == SOCK_STRING) {
       const std::string name = this->get_input<std::string>(found_socket->identifier);
-      ReadAttributePtr attribute = component.attribute_try_get_for_read(name);
+      ReadAttributeLookup attribute = component.attribute_try_get_for_read(name);
       if (attribute) {
-        input_domains.append(attribute->domain());
+        input_domains.append(attribute.domain);
       }
     }
   }



More information about the Bf-blender-cvs mailing list