[Bf-blender-cvs] [366a427f04b] functions-experimental-refactor: more vector math

Jacques Lucke noreply at git.blender.org
Fri Nov 8 18:31:13 CET 2019


Commit: 366a427f04b696d15efb5e048aa31bc864ef77ff
Author: Jacques Lucke
Date:   Fri Nov 8 16:56:06 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB366a427f04b696d15efb5e048aa31bc864ef77ff

more vector math

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

R087	release/scripts/startup/nodes/function_nodes/float_math.py	release/scripts/startup/nodes/function_nodes/math.py
M	release/scripts/startup/nodes/function_nodes/vector.py
M	source/blender/functions/FN_multi_function.h
M	source/blender/functions/intern/multi_functions/mixed.h
M	source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc

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

diff --git a/release/scripts/startup/nodes/function_nodes/float_math.py b/release/scripts/startup/nodes/function_nodes/math.py
similarity index 87%
rename from release/scripts/startup/nodes/function_nodes/float_math.py
rename to release/scripts/startup/nodes/function_nodes/math.py
index 3906e9b2371..d345a7f4306 100644
--- a/release/scripts/startup/nodes/function_nodes/float_math.py
+++ b/release/scripts/startup/nodes/function_nodes/math.py
@@ -22,32 +22,35 @@ def create_variadic_math_node(data_type, idname, label):
     return MathNode
 
 def create_two_inputs_math_node(data_type, idname, label):
+    return create_two_inputs_other_output_math_node(data_type, data_type, idname, label)
+
+def create_single_input_math_node(data_type, idname, label):
 
     class MathNode(bpy.types.Node, FunctionNode):
         bl_idname = idname
         bl_label = label
 
-        use_list__a: NodeBuilder.VectorizedProperty()
-        use_list__b: NodeBuilder.VectorizedProperty()
+        use_list: NodeBuilder.VectorizedProperty()
 
         def declaration(self, builder: NodeBuilder):
-            builder.vectorized_input("a", "use_list__a", "A", "A", data_type)
-            builder.vectorized_input("b", "use_list__b", "B", "B", data_type)
-            builder.vectorized_output("result", ["use_list__a", "use_list__b"], "Result", "Result", data_type)
+            builder.vectorized_input("input", "use_list", "Value", "Values", data_type)
+            builder.vectorized_output("output", ["use_list"], "Result", "Result", data_type)
 
     return MathNode
 
-def create_single_input_math_node(data_type, idname, label):
+def create_two_inputs_other_output_math_node(input_type, output_type, idname, label):
 
     class MathNode(bpy.types.Node, FunctionNode):
         bl_idname = idname
         bl_label = label
 
-        use_list: NodeBuilder.VectorizedProperty()
+        use_list__a: NodeBuilder.VectorizedProperty()
+        use_list__b: NodeBuilder.VectorizedProperty()
 
         def declaration(self, builder: NodeBuilder):
-            builder.vectorized_input("input", "use_list", "Value", "Values", data_type)
-            builder.vectorized_output("output", ["use_list"], "Result", "Result", data_type)
+            builder.vectorized_input("a", "use_list__a", "A", "A", input_type)
+            builder.vectorized_input("b", "use_list__b", "B", "B", input_type)
+            builder.vectorized_output("result", ["use_list__a", "use_list__b"], "Result", "Result", output_type)
 
     return MathNode
 
@@ -73,3 +76,5 @@ DivideVectorsNode = create_two_inputs_math_node("Vector", "fn_DivideVectorsNode"
 VectorCrossProductNode = create_two_inputs_math_node("Vector", "fn_VectorCrossProductNode", "Cross Product")
 VectorReflectNode = create_two_inputs_math_node("Vector", "fn_ReflectVectorNode", "Reflect Vector")
 VectorProjectNode = create_two_inputs_math_node("Vector", "fn_ProjectVectorNode", "Project Vector")
+VectorDotProductNode = create_two_inputs_other_output_math_node("Vector", "Float", "fn_VectorDotProductNode", "Dot Product") 
+VectorDistanceNode = create_two_inputs_other_output_math_node("Vector", "Float", "fn_VectorDistanceNode", "Vector Distance")
diff --git a/release/scripts/startup/nodes/function_nodes/vector.py b/release/scripts/startup/nodes/function_nodes/vector.py
index c9824f7128f..ced712a6b86 100644
--- a/release/scripts/startup/nodes/function_nodes/vector.py
+++ b/release/scripts/startup/nodes/function_nodes/vector.py
@@ -3,61 +3,6 @@ from bpy.props import *
 from .. base import FunctionNode
 from .. node_builder import NodeBuilder
 
-'''
-class VectorMathNode(bpy.types.Node, FunctionNode):
-    bl_idname = "fn_VectorMathNode"
-    bl_label = "Vector Math"
-
-    operation_items = [
-        ("ADD", "Add", "", "", 1),
-        ("SUB", "Subtract", "", "", 2),
-        ("MUL", "Multiply", "", "", 3),
-        ("DIV", "Divide", "", "", 4),
-        ("CROSS", "Cross Product", "", "", 5),
-        ("REFLECT", "Reflect", "", "", 6),
-        ("PROJECT", "Project", "", "", 7),
-        ("DOT", "Dot", "", "", 8),
-    ]
-
-    operation: EnumProperty(
-        name="Operation",
-        items=operation_items,
-        update=FunctionNode.sync_tree,
-    )
-
-    use_list__a: NodeBuilder.VectorizedProperty()
-    use_list__b: NodeBuilder.VectorizedProperty()
-
-    def declaration(self, builder: NodeBuilder):
-        builder.vectorized_input(
-            "a", "use_list__a",
-            "A", "A", "Vector")
-        builder.vectorized_input(
-            "b", "use_list__b",
-            "B", "B", "Vector")
-
-        if self.operation == "DOT":
-            builder.vectorized_output(
-                "result", ["use_list__a", "use_list__b"],
-                "Result", "Result", "Float")
-        else:
-            builder.vectorized_output(
-                "result", ["use_list__a", "use_list__b"],
-                "Result", "Result", "Vector")
-
-    def draw(self, layout):
-        layout.prop(self, "operation", text="")
-'''
-
-class VectorDistanceNode(bpy.types.Node, FunctionNode):
-    bl_idname = "fn_VectorDistanceNode"
-    bl_label = "Vector Distance"
-
-    def declaration(self, builder: NodeBuilder):
-        builder.fixed_input("a", "A", "Vector")
-        builder.fixed_input("b", "B", "Vector")
-        builder.fixed_output("distance", "Distance", "Float")
-
 
 class CombineVectorNode(bpy.types.Node, FunctionNode):
     bl_idname = "fn_CombineVectorNode"
diff --git a/source/blender/functions/FN_multi_function.h b/source/blender/functions/FN_multi_function.h
index 49906173da2..4b31ae57f0b 100644
--- a/source/blender/functions/FN_multi_function.h
+++ b/source/blender/functions/FN_multi_function.h
@@ -137,7 +137,9 @@ class MFSignature {
 
   bool is_valid_param(uint index, StringRef name, MFParamType::Category category) const
   {
-    return m_param_names[index] == name && m_param_types[index].category() == category;
+    /* Empty name means that it should not be checked for. */
+    return (m_param_names[index] == name || name == "") &&
+           m_param_types[index].category() == category;
   }
 };
 
@@ -222,12 +224,13 @@ class MFParams {
   {
   }
 
-  template<typename T> VirtualListRef<T> readonly_single_input(uint index, StringRef name)
+  template<typename T> VirtualListRef<T> readonly_single_input(uint index, StringRef name = "")
   {
     BLI_assert(m_signature->is_readonly_single_input<T>(index, name));
     return this->readonly_single_input(index, name).as_typed_ref<T>();
   }
-  GenericVirtualListRef readonly_single_input(uint index, StringRef name)
+
+  GenericVirtualListRef readonly_single_input(uint index, StringRef name = "")
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_readonly_single_input(index, name));
@@ -235,12 +238,12 @@ class MFParams {
     return m_virtual_list_refs[corrected_index];
   }
 
-  template<typename T> MutableArrayRef<T> single_output(uint index, StringRef name)
+  template<typename T> MutableArrayRef<T> single_output(uint index, StringRef name = "")
   {
     BLI_assert(m_signature->is_single_output<T>(index, name));
     return this->single_output(index, name).as_typed_ref<T>();
   }
-  GenericMutableArrayRef single_output(uint index, StringRef name)
+  GenericMutableArrayRef single_output(uint index, StringRef name = "")
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_single_output(index, name));
@@ -249,12 +252,12 @@ class MFParams {
   }
 
   template<typename T>
-  const VirtualListListRef<T> readonly_vector_input(uint index, StringRef name)
+  const VirtualListListRef<T> readonly_vector_input(uint index, StringRef name = "")
   {
     BLI_assert(m_signature->is_readonly_vector_input<T>(index, name));
     return this->readonly_vector_input(index, name).as_typed_ref<T>();
   }
-  GenericVirtualListListRef readonly_vector_input(uint index, StringRef name)
+  GenericVirtualListListRef readonly_vector_input(uint index, StringRef name = "")
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_readonly_vector_input(index, name));
@@ -263,12 +266,12 @@ class MFParams {
   }
 
   template<typename T>
-  GenericVectorArray::MutableTypedRef<T> vector_output(uint index, StringRef name)
+  GenericVectorArray::MutableTypedRef<T> vector_output(uint index, StringRef name = "")
   {
     BLI_assert(m_signature->is_vector_output<T>(index, name));
     return this->vector_output(index, name).as_mutable_typed_ref<T>();
   }
-  GenericVectorArray &vector_output(uint index, StringRef name)
+  GenericVectorArray &vector_output(uint index, StringRef name = "")
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_vector_output(index, name));
@@ -276,7 +279,7 @@ class MFParams {
     return *m_vector_arrays[corrected_index];
   }
 
-  GenericVectorArray &mutable_vector(uint index, StringRef name)
+  GenericVectorArray &mutable_vector(uint index, StringRef name = "")
   {
     UNUSED_VARS_NDEBUG(name);
     BLI_assert(m_signature->is_mutable_vector(index, name));
diff --git a/source/blender/functions/intern/multi_functions/mixed.h b/source/blender/functions/intern/multi_functions/mixed.h
index f28f51ced10..cb1bc3eceb6 100644
--- a/source/blender/functions/intern/multi_functions/mixed.h
+++ b/source/blender/functions/intern/multi_functions/mixed.h
@@ -148,6 +148,28 @@ class MF_Mappping final : public MultiFunction {
   }
 };
 
+template<typename In1, typename In2, typename Out, Out (*Func)(In1, In2)>
+class MF_2In_1Out final : public MultiFunction {
+ public:
+  MF_2In_1Out(StringRef function_name, StringRef in1_name, StringRef in2_name, StringRef out_name)
+  {
+    MFSignatureBuilder signature(function_name);
+    signature.readonly_single_input<In1>(in1_name);
+    signature.readonly_single_input<In2>(in2_name);
+    signature.single_output<Out>(out_name);
+    this->set_signature(signature);
+  }
+
+  void call(const MFMask &mask, MFParams &params, MFContext &UNUSED(context)) const override
+  {
+    VirtualListRef<In1> in1 = params.readonly_single_input<In1>(0);
+    VirtualListRef<In2> in2 = params.readonly_single_input<In2>(1);
+    MutableArrayRef<Out> out = params.single_output<Out>(2);
+
+    mask.foreach_index([&](uint i) { out[i] = Func(in1[i], in2[i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list