[Bf-blender-cvs] [b22dc19ce7e] functions: new Dot Production operation in vector math node

Jacques Lucke noreply at git.blender.org
Tue Sep 10 12:20:48 CEST 2019


Commit: b22dc19ce7ef3bf7c9aa7106bb04959e9567c1d2
Author: Jacques Lucke
Date:   Tue Sep 10 12:18:58 2019 +0200
Branches: functions
https://developer.blender.org/rBb22dc19ce7ef3bf7c9aa7106bb04959e9567c1d2

new Dot Production operation in vector math node

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

M	release/scripts/startup/nodes/function_nodes/vector.py
M	source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
M	source/blender/functions/functions/vectors.cpp
M	source/blender/functions/functions/vectors.hpp

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

diff --git a/release/scripts/startup/nodes/function_nodes/vector.py b/release/scripts/startup/nodes/function_nodes/vector.py
index 6581b2f973c..50a4b772849 100644
--- a/release/scripts/startup/nodes/function_nodes/vector.py
+++ b/release/scripts/startup/nodes/function_nodes/vector.py
@@ -16,6 +16,7 @@ class VectorMathNode(bpy.types.Node, FunctionNode):
         ("CROSS", "Cross Product", "", "", 5),
         ("REFLECT", "Reflect", "", "", 6),
         ("PROJECT", "Project", "", "", 7),
+        ("DOT", "Dot", "", "", 8),
     ]
 
     operation: EnumProperty(
@@ -35,9 +36,14 @@ class VectorMathNode(bpy.types.Node, FunctionNode):
             "b", "use_list__b",
             "B", "B", "Vector")
 
-        builder.vectorized_output(
-            "result", ["use_list__a", "use_list__b"],
-            "Result", "Result", "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="")
diff --git a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
index 3d24e32ab47..c76d18fdfb1 100644
--- a/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
@@ -163,6 +163,8 @@ static SharedFunction &get_vector_math_function(int operation)
       return Functions::GET_FN_reflect_vector();
     case 7:
       return Functions::GET_FN_project_vector();
+    case 8:
+      return Functions::GET_FN_dot_product();
     default:
       BLI_assert(false);
       return Functions::GET_FN_none();
diff --git a/source/blender/functions/functions/vectors.cpp b/source/blender/functions/functions/vectors.cpp
index d30929d30cc..8da6cea3060 100644
--- a/source/blender/functions/functions/vectors.cpp
+++ b/source/blender/functions/functions/vectors.cpp
@@ -287,5 +287,28 @@ BLI_LAZY_INIT(SharedFunction, GET_FN_project_vector)
   return fn;
 }
 
+class VectorDotProduct : public TupleCallBody {
+  void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+  {
+    float3 a = fn_in.get<float3>(0);
+    float3 b = fn_in.get<float3>(1);
+
+    float result = float3::dot(a, b);
+    fn_out.set<float>(0, result);
+  }
+};
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_dot_product)
+{
+  FunctionBuilder builder;
+  builder.add_input("A", TYPE_float3);
+  builder.add_input("B", TYPE_float3);
+  builder.add_output("Result", TYPE_float);
+
+  auto fn = builder.build("Dot Product");
+  fn->add_body<VectorDotProduct>();
+  return fn;
+}
+
 }  // namespace Functions
 }  // namespace FN
diff --git a/source/blender/functions/functions/vectors.hpp b/source/blender/functions/functions/vectors.hpp
index 980bfa3d1bb..fe7dae882de 100644
--- a/source/blender/functions/functions/vectors.hpp
+++ b/source/blender/functions/functions/vectors.hpp
@@ -15,6 +15,7 @@ SharedFunction &GET_FN_div_vectors();
 SharedFunction &GET_FN_cross_vectors();
 SharedFunction &GET_FN_reflect_vector();
 SharedFunction &GET_FN_project_vector();
+SharedFunction &GET_FN_dot_product();
 
 }  // namespace Functions
 }  // namespace FN



More information about the Bf-blender-cvs mailing list