[Bf-blender-cvs] [5a631ad295a] temp-geometry-nodes-mix-attributes: initial conversion of input a

Jacques Lucke noreply at git.blender.org
Wed Dec 9 15:03:30 CET 2020


Commit: 5a631ad295aafa292e1feac422fe2d20573c3350
Author: Jacques Lucke
Date:   Wed Dec 9 13:46:55 2020 +0100
Branches: temp-geometry-nodes-mix-attributes
https://developer.blender.org/rB5a631ad295aafa292e1feac422fe2d20573c3350

initial conversion of input a

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index ef3ae3c381c..a3dfe127217 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -157,6 +157,12 @@ class GeometryComponent {
                                                                  const CustomDataType data_type,
                                                                  const void *value) const;
 
+  blender::bke::ReadAttributePtr attribute_get_constant_for_read_converted(
+      const AttributeDomain domain,
+      const CustomDataType in_data_type,
+      const CustomDataType out_data_type,
+      const void *value);
+
   /* Get a read-only dummy attribute that always returns the same value. */
   template<typename T>
   blender::bke::TypedReadAttribute<T> attribute_get_constant_for_read(const AttributeDomain domain,
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 9f5795291f0..d2878d59420 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -668,6 +668,37 @@ blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_rea
       domain, domain_size, *cpp_type, value);
 }
 
+blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_read_converted(
+    const AttributeDomain domain,
+    const CustomDataType in_data_type,
+    const CustomDataType out_data_type,
+    const void *value)
+{
+  BLI_assert(this->attribute_domain_supported(domain));
+  if (value == nullptr || in_data_type == out_data_type) {
+    return this->attribute_get_constant_for_read(domain, out_data_type, value);
+  }
+
+  const blender::fn::CPPType *in_cpp_type = blender::bke::custom_data_type_to_cpp_type(
+      in_data_type);
+  const blender::fn::CPPType *out_cpp_type = blender::bke::custom_data_type_to_cpp_type(
+      out_data_type);
+  BLI_assert(in_cpp_type != nullptr);
+  BLI_assert(out_cpp_type != nullptr);
+
+  const blender::nodes::DataTypeConversions &conversions =
+      blender::nodes::get_implicit_type_conversions();
+  void *out_value = alloca(out_cpp_type->size());
+  conversions.convert(*in_cpp_type, *out_cpp_type, value, out_value);
+
+  const int domain_size = this->attribute_domain_size(domain);
+  blender::bke::ReadAttributePtr attribute = std::make_unique<blender::bke::ConstantReadAttribute>(
+      domain, domain_size, *out_cpp_type, out_value);
+
+  out_cpp_type->destruct(out_value);
+  return attribute;
+}
+
 WriteAttributePtr GeometryComponent::attribute_try_ensure_for_write(const StringRef attribute_name,
                                                                     const AttributeDomain domain,
                                                                     const CustomDataType data_type)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
index d4817b45873..f3316dfdbb9 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
@@ -95,7 +95,6 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
   const bNode &node = params.node();
   const NodeAttributeMix *node_storage = (const NodeAttributeMix *)node.storage;
 
-  const std::string attribute_a_name = params.get_input<std::string>("Attribute A");
   const std::string attribute_b_name = params.get_input<std::string>("Attribute B");
   const std::string result_name = params.get_input<std::string>("Result");
 
@@ -117,15 +116,39 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa
 
   FloatReadAttribute attribute_factor = [&]() {
     if (node_storage->input_type_factor == GEO_NODE_ATTRIBUTE_INPUT__ATTRIBUTE) {
-      const std::string factor_name = params.get_input<std::string>("Factor");
-      return component.attribute_get_for_read<float>(factor_name, result_domain, 0.5f);
+      const std::string name = params.get_input<std::string>("Factor");
+      return component.attribute_get_for_read<float>(name, result_domain, 0.5f);
     }
     const float factor = params.get_input<float>("Factor_001");
     return component.attribute_get_constant_for_read(result_domain, factor);
   }();
 
-  ReadAttributePtr attribute_a = component.attribute_get_for_read(
-      attribute_a_name, result_domain, result_type, nullptr);
+  ReadAttributePtr attribute_a = [&]() {
+    if (node_storage->input_type_a == GEO_NODE_ATTRIBUTE_INPUT__ATTRIBUTE) {
+      const std::string name = params.get_input<std::string>("Attribute A");
+      return component.attribute_get_for_read(name, result_domain, result_type, nullptr);
+    }
+    else if (node_storage->input_type_a == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_FLOAT) {
+      const float value = params.get_input<float>("Attribute A_001");
+      return component.attribute_get_constant_for_read_converted(
+          result_domain, CD_PROP_FLOAT, result_type, &value);
+    }
+    else if (node_storage->input_type_a == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_VECTOR) {
+      const float3 value = params.get_input<float3>("Attribute A_002");
+      return component.attribute_get_constant_for_read_converted(
+          result_domain, CD_PROP_FLOAT3, result_type, &value);
+    }
+    else if (node_storage->input_type_a == GEO_NODE_ATTRIBUTE_INPUT__CONSTANT_COLOR) {
+      const Color4f value = params.get_input<Color4f>("Attribute A_003");
+      return component.attribute_get_constant_for_read_converted(
+          result_domain, CD_PROP_COLOR, result_type, &value);
+    }
+    BLI_assert(false);
+    return component.attribute_get_constant_for_read(result_domain, result_type, nullptr);
+  }();
+
+  // ReadAttributePtr attribute_a = component.attribute_get_for_read(
+  //     attribute_a_name, result_domain, result_type, nullptr);
   ReadAttributePtr attribute_b = component.attribute_get_for_read(
       attribute_b_name, result_domain, result_type, nullptr);



More information about the Bf-blender-cvs mailing list