[Bf-blender-cvs] [3c4869bf486] temp-geometry-nodes-expandable-geometry-socket-prototype: support implicit conversion for arrays

Jacques Lucke noreply at git.blender.org
Mon Aug 2 15:50:48 CEST 2021


Commit: 3c4869bf486ab7b49bb5f14caa88afba0b8cfcfb
Author: Jacques Lucke
Date:   Mon Aug 2 15:39:15 2021 +0200
Branches: temp-geometry-nodes-expandable-geometry-socket-prototype
https://developer.blender.org/rB3c4869bf486ab7b49bb5f14caa88afba0b8cfcfb

support implicit conversion for arrays

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

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

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

diff --git a/source/blender/functions/FN_array_cpp_type.hh b/source/blender/functions/FN_array_cpp_type.hh
index 9c1af038814..cc2ba214e0f 100644
--- a/source/blender/functions/FN_array_cpp_type.hh
+++ b/source/blender/functions/FN_array_cpp_type.hh
@@ -51,6 +51,11 @@ class ArrayCPPType : public CPPType {
     };
   }
 
+  const CPPType &element_type() const
+  {
+    return element_type_;
+  }
+
   int64_t array_size(const void *value) const
   {
     return get_span_(value).size();
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 98c3943cc33..8754aaed814 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -861,7 +861,7 @@ class GeometryNodesEvaluator {
                                    NodeState &node_state)
   {
     /* Compute output array length. */
-    int output_size = 0;
+    int output_size = -1;
     for (const int i : node->inputs().index_range()) {
       const InputSocketRef &socket_ref = node->input(i);
       if (!socket_ref.is_available()) {
@@ -877,6 +877,10 @@ class GeometryNodesEvaluator {
       const int input_size = array_cpp_type->array_size(single_value.value);
       output_size = std::max(output_size, input_size);
     }
+    /* If there is no input, output a single value. */
+    if (output_size == -1) {
+      output_size = 1;
+    }
 
     MFContextBuilder fn_context;
     MFParamsBuilder fn_params{fn, output_size};
@@ -1272,7 +1276,26 @@ class GeometryNodesEvaluator {
     void *buffer = allocator.allocate(to_type.size(), to_type.alignment());
     GMutablePointer value{to_type, buffer};
 
-    if (conversions_.is_convertible(from_type, to_type)) {
+    const ArrayCPPType *from_array_type = dynamic_cast<const ArrayCPPType *>(&from_type);
+    const ArrayCPPType *to_array_type = dynamic_cast<const ArrayCPPType *>(&to_type);
+
+    if (from_array_type != nullptr && to_array_type != nullptr &&
+        conversions_.is_convertible(from_array_type->element_type(),
+                                    to_array_type->element_type())) {
+      const MultiFunction &fn = *conversions_.get_conversion_multi_function(
+          MFDataType::ForSingle(from_array_type->element_type()),
+          MFDataType::ForSingle(to_array_type->element_type()));
+      GSpan from_span = from_array_type->array_span(value_to_forward.get());
+      const int array_size = from_span.size();
+      GMutableSpan to_span = to_array_type->array_construct_uninitialized(buffer, array_size);
+
+      MFParamsBuilder params{fn, array_size};
+      params.add_readonly_single_input(from_span);
+      params.add_uninitialized_single_output(to_span);
+      MFContextBuilder context;
+      fn.call(IndexRange(array_size), params, context);
+    }
+    else if (conversions_.is_convertible(from_type, to_type)) {
       /* Do the conversion if possible. */
       conversions_.convert_to_uninitialized(from_type, to_type, value_to_forward.get(), buffer);
     }



More information about the Bf-blender-cvs mailing list