[Bf-blender-cvs] [451884d2ea6] functions: better separation between functions and nodes

Jacques Lucke noreply at git.blender.org
Thu Feb 28 12:41:34 CET 2019


Commit: 451884d2ea65e5519ead68b619a22f1598910cc7
Author: Jacques Lucke
Date:   Thu Feb 28 12:25:57 2019 +0100
Branches: functions
https://developer.blender.org/rB451884d2ea65e5519ead68b619a22f1598910cc7

better separation between functions and nodes

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

M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/FN_functions.hpp
A	source/blender/functions/FN_functions_core.hpp
A	source/blender/functions/FN_functions_types.hpp
A	source/blender/functions/functions/object_input.cpp
A	source/blender/functions/functions/object_input.hpp
A	source/blender/functions/functions/random.cpp
A	source/blender/functions/functions/random.hpp
A	source/blender/functions/functions/scalar_math.cpp
A	source/blender/functions/functions/scalar_math.hpp
A	source/blender/functions/functions/vectors.cpp
A	source/blender/functions/functions/vectors.hpp
M	source/blender/functions/nodes/test_nodes.cpp
M	source/blender/functions/types/numeric.hpp
D	source/blender/functions/types/types.hpp

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

diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 706e2cf2113..d3228a4bd39 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -31,11 +31,21 @@ set(SRC
 	core/type_relations.cpp
 
 	FN_functions.hpp
+	FN_functions_core.hpp
+	FN_functions_types.hpp
 
-	types/types.hpp
 	types/numeric.cpp
 	types/numeric.hpp
 
+	functions/object_input.hpp
+	functions/object_input.cpp
+	functions/random.hpp
+	functions/random.cpp
+	functions/scalar_math.hpp
+	functions/scalar_math.cpp
+	functions/vectors.hpp
+	functions/vectors.cpp
+
 	nodes/nodes.hpp
 	nodes/nodes.cpp
 	nodes/graph_generation.hpp
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 96c6fd46b57..f7e51bd5114 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -1,11 +1,4 @@
 #pragma once
 
-#include "core/core.hpp"
-#include "core/data_flow_graph.hpp"
-#include "core/graph_to_function.hpp"
-#include "core/type_relations.hpp"
-#include "core/type_inferencing.hpp"
-
-#include "core/cpu.hpp"
-
-#include "types/types.hpp"
\ No newline at end of file
+#include "FN_functions_core.hpp"
+#include "FN_functions_types.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions_core.hpp
similarity index 78%
copy from source/blender/functions/FN_functions.hpp
copy to source/blender/functions/FN_functions_core.hpp
index 96c6fd46b57..c3e17fedc63 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions_core.hpp
@@ -5,7 +5,4 @@
 #include "core/graph_to_function.hpp"
 #include "core/type_relations.hpp"
 #include "core/type_inferencing.hpp"
-
-#include "core/cpu.hpp"
-
-#include "types/types.hpp"
\ No newline at end of file
+#include "core/cpu.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/FN_functions_types.hpp b/source/blender/functions/FN_functions_types.hpp
new file mode 100644
index 00000000000..a6e12ad5f52
--- /dev/null
+++ b/source/blender/functions/FN_functions_types.hpp
@@ -0,0 +1,3 @@
+#pragma once
+
+#include "types/numeric.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/functions/object_input.cpp b/source/blender/functions/functions/object_input.cpp
new file mode 100644
index 00000000000..8c35f5d809e
--- /dev/null
+++ b/source/blender/functions/functions/object_input.cpp
@@ -0,0 +1,45 @@
+#include "object_input.hpp"
+#include "FN_functions_types.hpp"
+
+#include "BLI_lazy_init.hpp"
+#include "DNA_object_types.h"
+
+namespace FN { namespace Functions {
+
+	using namespace Types;
+
+	class ObjectTransforms : public TupleCallBody {
+	private:
+		Object *m_object;
+
+	public:
+		ObjectTransforms(Object *object)
+			: m_object(object) {}
+
+		void call(const Tuple &UNUSED(fn_in), Tuple &fn_out) const override
+		{
+			if (m_object) {
+				Vector position = *(Vector *)m_object->loc;
+				fn_out.set<Vector>(0, position);
+			}
+			else {
+				fn_out.set<Vector>(0, Vector());
+			}
+		}
+
+		void dependencies(Dependencies &deps) const override
+		{
+			deps.add_object_transform_dependency(m_object);
+		}
+	};
+
+	SharedFunction object_location(Object *object)
+	{
+		auto fn = SharedFunction::New("Object Transforms", Signature({}, {
+			OutputParameter("Location", get_fvec3_type()),
+		}));
+		fn->add_body(new ObjectTransforms(object));
+		return fn;
+	}
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/object_input.hpp b/source/blender/functions/functions/object_input.hpp
new file mode 100644
index 00000000000..3df19de52c7
--- /dev/null
+++ b/source/blender/functions/functions/object_input.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "FN_functions_core.hpp"
+
+struct Object;
+
+namespace FN { namespace Functions {
+
+	SharedFunction object_location(struct Object *object);
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/random.cpp b/source/blender/functions/functions/random.cpp
new file mode 100644
index 00000000000..b223975530e
--- /dev/null
+++ b/source/blender/functions/functions/random.cpp
@@ -0,0 +1,47 @@
+#include "random.hpp"
+#include "FN_functions_types.hpp"
+
+#include "BLI_lazy_init.hpp"
+
+namespace FN { namespace Functions {
+
+	using namespace Types;
+
+	static uint32_t random_int(uint32_t x)
+	{
+		x = (x<<13) ^ x;
+		return x * (x * x * 15731 + 789221) + 1376312589;
+	}
+
+	static float random_float(uint32_t x)
+	{
+		x = random_int(x);
+		return (float)x / 4294967296.0f;
+	}
+
+
+	class RandomNumber : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			uint32_t seed = fn_in.get<int32_t>(0);
+			float min = fn_in.get<float>(1);
+			float max = fn_in.get<float>(2);
+			float result = random_float(seed) * (max - min) + min;
+			fn_out.set<float>(0, result);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, random_number)
+	{
+		auto fn = SharedFunction::New("Random Number", Signature({
+			InputParameter("Seed", get_int32_type()),
+			InputParameter("Min", get_float_type()),
+			InputParameter("Max", get_float_type()),
+		}, {
+			OutputParameter("Value", get_float_type()),
+		}));
+		fn->add_body(new RandomNumber());
+		return fn;
+	}
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/random.hpp b/source/blender/functions/functions/random.hpp
new file mode 100644
index 00000000000..dff671f80fa
--- /dev/null
+++ b/source/blender/functions/functions/random.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "FN_functions_core.hpp"
+
+namespace FN { namespace Functions {
+
+	SharedFunction &random_number();
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/scalar_math.cpp b/source/blender/functions/functions/scalar_math.cpp
new file mode 100644
index 00000000000..f510ba6bb32
--- /dev/null
+++ b/source/blender/functions/functions/scalar_math.cpp
@@ -0,0 +1,131 @@
+#include "scalar_math.hpp"
+#include "FN_functions_types.hpp"
+
+#include "BLI_lazy_init.hpp"
+
+namespace FN { namespace Functions {
+
+	using namespace Types;
+
+	static SharedFunction get_simple_math_function(std::string name)
+	{
+		auto fn = SharedFunction::New(name, Signature({
+			InputParameter("A", get_float_type()),
+			InputParameter("B", get_float_type()),
+		}, {
+			OutputParameter("Result", get_float_type()),
+		}));
+		return fn;
+	}
+
+
+	class AddFloats : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			float a = fn_in.get<float>(0);
+			float b = fn_in.get<float>(1);
+			fn_out.set<float>(0, a + b);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, add_floats)
+	{
+		auto fn = get_simple_math_function("Add Floats");
+		fn->add_body(new AddFloats());
+		return fn;
+	}
+
+
+	class MultiplyFloats : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			float a = fn_in.get<float>(0);
+			float b = fn_in.get<float>(1);
+			fn_out.set<float>(0, a * b);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, multiply_floats)
+	{
+		auto fn = get_simple_math_function("Multiply Floats");
+		fn->add_body(new MultiplyFloats());
+		return fn;
+	}
+
+
+	class MinFloats : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			float a = fn_in.get<float>(0);
+			float b = fn_in.get<float>(1);
+			fn_out.set<float>(0, (a < b) ? a : b);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, min_floats)
+	{
+		auto fn = get_simple_math_function("Minimum");
+		fn->add_body(new MinFloats());
+		return fn;
+	}
+
+
+	class MaxFloats : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			float a = fn_in.get<float>(0);
+			float b = fn_in.get<float>(1);
+			fn_out.set<float>(0, (a < b) ? b : a);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, max_floats)
+	{
+		auto fn = get_simple_math_function("Maximum");
+		fn->add_body(new MaxFloats());
+		return fn;
+	}
+
+
+	class MapRange : public TupleCallBody {
+		void call(const Tuple &fn_in, Tuple &fn_out) const override
+		{
+			float value = fn_in.get<float>(0);
+			float from_min = fn_in.get<float>(1);
+			float from_max = fn_in.get<float>(2);
+			float to_min = fn_in.get<float>(3);
+			float to_max = fn_in.get<float>(4);
+
+			float from_range = from_max - from_min;
+			float to_range = to_max - to_min;
+
+			float result;
+			if (from_range == 0) {
+				result = to_min;
+			}
+			else {
+				float t = (value - from_min) / from_range;
+				CLAMP(t, 0.0f, 1.0f);
+				result = t * to_range + to_min;
+			}
+
+			fn_out.set<float>(0, result);
+		}
+	};
+
+	LAZY_INIT_REF__NO_ARG(SharedFunction, map_range)
+	{
+		auto fn = SharedFunction::New("Map Range", Signature({
+			InputParameter("Value", get_float_type()),
+			InputParameter("From Min", get_float_type()),
+			InputParameter("From Max", get_float_type()),
+			InputParameter("To Min", get_float_type()),
+			InputParameter("To Max", get_float_type()),
+		}, {
+			OutputParameter("Value", get_float_type()),
+		}));
+		fn->add_body(new MapRange());
+		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
new file mode 100644
index 00000000000..85947b88fc6
--- /dev/null
+++ b/source/blender/functions/functions/scalar_math.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "FN_functions_core.hpp"
+
+namespace FN { namespace Functions {
+
+	SharedFunction &add_floats();
+	SharedFunction &multiply_floats();
+	SharedFunction &min_floats();
+	SharedFunction &max_floats();
+	SharedFunction &map_range();
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/vectors.cpp b/source/blender/functions/functions/vectors.cpp
new file mode 100644
index 00000000000..97d3cef7ca8
--- /dev/null
+++ b/source/blender/functions/functions/vectors.cpp
@@ -0,0 +1,82 @@
+#include

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list