[Bf-blender-cvs] [3c5681c2129] temp-geometry-nodes-fields--fields-jacques: support field conversion

Jacques Lucke noreply at git.blender.org
Tue Aug 31 13:22:57 CEST 2021


Commit: 3c5681c2129b0bef2362cb32dc38dc93e1a20dff
Author: Jacques Lucke
Date:   Tue Aug 31 12:40:53 2021 +0200
Branches: temp-geometry-nodes-fields--fields-jacques
https://developer.blender.org/rB3c5681c2129b0bef2362cb32dc38dc93e1a20dff

support field conversion

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

M	source/blender/functions/FN_field.hh
M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc

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

diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index 77c1dedb721..4b0dee88491 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -107,26 +107,13 @@ class GField {
   }
 };
 
-template<typename T> class Field {
- private:
-  GField field_;
-
+template<typename T> class Field : public GField {
  public:
   Field() = default;
 
-  Field(GField field) : field_(std::move(field))
-  {
-    BLI_assert(field_.cpp_type().is<T>());
-  }
-
-  const GField *operator->() const
-  {
-    return &field_;
-  }
-
-  const GField &operator*() const
+  Field(GField field) : GField(std::move(field))
   {
-    return field_;
+    BLI_assert(this->cpp_type().template is<T>());
   }
 };
 
@@ -222,7 +209,7 @@ template<typename T> T evaluate_constant_field(const Field<T> &field)
 {
   T value;
   value.~T();
-  evaluate_constant_field(*field, &value);
+  evaluate_constant_field(field, &value);
   return value;
 }
 
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 98006d1eaee..0251163d9a7 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -36,6 +36,7 @@ namespace blender::modifiers::geometry_nodes {
 
 using fn::CPPType;
 using fn::Field;
+using fn::FieldCPPType;
 using fn::GField;
 using fn::GValueMap;
 using nodes::GeoNodeExecParams;
@@ -1381,6 +1382,21 @@ class GeometryNodesEvaluator {
       return;
     }
 
+    const FieldCPPType *from_field_type = dynamic_cast<const FieldCPPType *>(&from_type);
+    const FieldCPPType *to_field_type = dynamic_cast<const FieldCPPType *>(&to_type);
+
+    if (from_field_type != nullptr && to_field_type != nullptr) {
+      const CPPType &from_base_type = from_field_type->field_type();
+      const CPPType &to_base_type = to_field_type->field_type();
+      if (conversions_.is_convertible(from_base_type, to_base_type)) {
+        const MultiFunction &fn = *conversions_.get_conversion_multi_function(
+            MFDataType::ForSingle(from_base_type), MFDataType::ForSingle(to_base_type));
+        const GField &from_field = *(const GField *)from_value;
+        auto field_fn = std::make_shared<fn::FieldFunction>(fn, Vector<GField>{from_field});
+        new (to_value) GField(std::move(field_fn), 0);
+        return;
+      }
+    }
     if (conversions_.is_convertible(from_type, to_type)) {
       /* Do the conversion if possible. */
       conversions_.convert_to_uninitialized(from_type, to_type, from_value, to_value);
@@ -1393,7 +1409,7 @@ class GeometryNodesEvaluator {
 
   void construct_default_value(const CPPType &type, void *r_value)
   {
-    if (const fn::FieldCPPType *field_cpp_type = dynamic_cast<const fn::FieldCPPType *>(&type)) {
+    if (const FieldCPPType *field_cpp_type = dynamic_cast<const FieldCPPType *>(&type)) {
       const CPPType &base_type = field_cpp_type->field_type();
       auto constant_fn = std::make_unique<fn::CustomMF_GenericConstant>(base_type,
                                                                         base_type.default_value());



More information about the Bf-blender-cvs mailing list