[Bf-blender-cvs] [6fa863f6d99] functions: Sin operation in Float Math node

Jacques Lucke noreply at git.blender.org
Fri Apr 5 12:45:35 CEST 2019


Commit: 6fa863f6d99e875a9e04f8eab67fc80a9f7f8670
Author: Jacques Lucke
Date:   Fri Apr 5 12:45:11 2019 +0200
Branches: functions
https://developer.blender.org/rB6fa863f6d99e875a9e04f8eab67fc80a9f7f8670

Sin operation in Float Math node

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

M	release/scripts/startup/function_nodes/nodes/float_math.py
M	source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
M	source/blender/functions/functions/scalar_math.cpp
M	source/blender/functions/functions/scalar_math.hpp

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

diff --git a/release/scripts/startup/function_nodes/nodes/float_math.py b/release/scripts/startup/function_nodes/nodes/float_math.py
index 66c7fb97959..2f9b60bbf7e 100644
--- a/release/scripts/startup/function_nodes/nodes/float_math.py
+++ b/release/scripts/startup/function_nodes/nodes/float_math.py
@@ -7,8 +7,13 @@ operation_items = [
     ("MULTIPLY", "Multiply", "", "", 2),
     ("MIN", "Minimum", "", "", 3),
     ("MAX", "Maximum", "", "", 4),
+    ("SIN", "Sin", "", "", 5),
 ]
 
+single_value_operations = {
+    "SIN",
+}
+
 class FloatMathNode(bpy.types.Node, FunctionNode):
     bl_idname = "fn_FloatMathNode"
     bl_label = "Float Math"
@@ -21,11 +26,13 @@ class FloatMathNode(bpy.types.Node, FunctionNode):
     operation: EnumProperty(
         name="Operation",
         items=operation_items,
+        update=FunctionNode.refresh,
     )
 
     def declaration(self, builder):
         builder.fixed_input("a", "A", "Float")
-        builder.fixed_input("b", "B", "Float")
+        if self.operation not in single_value_operations:
+            builder.fixed_input("b", "B", "Float")
         builder.fixed_output("result", "Result", "Float")
 
     def draw(self, layout):
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index d18e0824839..8acbbda499e 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -34,6 +34,7 @@ namespace FN { namespace DataFlowNodes {
 			case 2: return Functions::multiply_floats();
 			case 3: return Functions::min_floats();
 			case 4: return Functions::max_floats();
+			case 5: return Functions::sin_float();
 			default:
 				BLI_assert(false);
 				return *(SharedFunction *)nullptr;
diff --git a/source/blender/functions/functions/scalar_math.cpp b/source/blender/functions/functions/scalar_math.cpp
index ccfbb5760de..cb0bc76b92d 100644
--- a/source/blender/functions/functions/scalar_math.cpp
+++ b/source/blender/functions/functions/scalar_math.cpp
@@ -1,3 +1,5 @@
+#include <cmath>
+
 #include "scalar_math.hpp"
 #include "FN_types.hpp"
 #include "FN_tuple_call.hpp"
@@ -9,7 +11,17 @@ namespace FN { namespace Functions {
 
 	using namespace Types;
 
-	static SharedFunction get_simple_math_function(std::string name)
+	static SharedFunction get_math_function__one_input(std::string name)
+	{
+		auto fn = SharedFunction::New(name, Signature({
+			InputParameter("Value", get_float_type()),
+		}, {
+			OutputParameter("Result", get_float_type()),
+		}));
+		return fn;
+	}
+
+	static SharedFunction get_math_function__two_inputs(std::string name)
 	{
 		auto fn = SharedFunction::New(name, Signature({
 			InputParameter("A", get_float_type()),
@@ -45,7 +57,7 @@ namespace FN { namespace Functions {
 
 	LAZY_INIT_REF__NO_ARG(SharedFunction, add_floats)
 	{
-		auto fn = get_simple_math_function("Add Floats");
+		auto fn = get_math_function__two_inputs("Add Floats");
 		//fn->add_body(new AddFloats());
 		fn->add_body(new GenAddFloats());
 		return fn;
@@ -63,7 +75,7 @@ namespace FN { namespace Functions {
 
 	LAZY_INIT_REF__NO_ARG(SharedFunction, multiply_floats)
 	{
-		auto fn = get_simple_math_function("Multiply Floats");
+		auto fn = get_math_function__two_inputs("Multiply Floats");
 		fn->add_body(new MultiplyFloats());
 		return fn;
 	}
@@ -80,7 +92,7 @@ namespace FN { namespace Functions {
 
 	LAZY_INIT_REF__NO_ARG(SharedFunction, min_floats)
 	{
-		auto fn = get_simple_math_function("Minimum");
+		auto fn = get_math_function__two_inputs("Minimum");
 		fn->add_body(new MinFloats());
 		return fn;
 	}
@@ -97,7 +109,7 @@ namespace FN { namespace Functions {
 
 	LAZY_INIT_REF__NO_ARG(SharedFunction, max_floats)
 	{
-		auto fn = get_simple_math_function("Maximum");
+		auto fn = get_math_function__two_inputs("Maximum");
 		fn->add_body(new MaxFloats());
 		return fn;
 	}
@@ -144,4 +156,20 @@ namespace FN { namespace Functions {
 		return fn;
 	}
 
+
+	class SinFloat : public TupleCallBody {
+		void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+		{
+			float a = fn_in.get<float>(0);
+			fn_out.set<float>(0, std::sin(a));
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, sin_float)
+	{
+		auto fn = get_math_function__one_input("Sin");
+		fn->add_body(new SinFloat());
+		return fn;
+	}
+
 } } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/scalar_math.hpp b/source/blender/functions/functions/scalar_math.hpp
index 7a4d54c9d4c..6db1880ed0f 100644
--- a/source/blender/functions/functions/scalar_math.hpp
+++ b/source/blender/functions/functions/scalar_math.hpp
@@ -9,5 +9,6 @@ namespace FN { namespace Functions {
 	SharedFunction &min_floats();
 	SharedFunction &max_floats();
 	SharedFunction &map_range();
+	SharedFunction &sin_float();
 
 } } /* namespace FN::Functions */
\ No newline at end of file



More information about the Bf-blender-cvs mailing list