[Bf-blender-cvs] [c4364f34990] functions: initial node tree

Jacques Lucke noreply at git.blender.org
Sun Feb 10 20:26:53 CET 2019


Commit: c4364f34990786ce918e3770f685d07b2c2413ac
Author: Jacques Lucke
Date:   Fri Feb 8 16:46:39 2019 +0100
Branches: functions
https://developer.blender.org/rBc4364f34990786ce918e3770f685d07b2c2413ac

initial node tree

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

A	release/scripts/startup/function_nodes/__init__.py
A	release/scripts/startup/function_nodes/base.py
A	release/scripts/startup/function_nodes/menu.py
A	release/scripts/startup/function_nodes/nodes/__init__.py
A	release/scripts/startup/function_nodes/nodes/add_floats.py
A	release/scripts/startup/function_nodes/nodes/combine_vector.py
A	release/scripts/startup/function_nodes/sockets.py
M	source/blender/functions/CMakeLists.txt
M	source/blender/functions/FN_functions.h
M	source/blender/functions/FN_functions.hpp
M	source/blender/functions/c_wrapper.cpp
M	source/blender/functions/core/core.hpp
M	source/blender/functions/core/data_flow_graph.hpp
A	source/blender/functions/function_nodes/function_nodes.cpp
A	source/blender/functions/function_nodes/function_nodes.hpp
M	source/blender/modifiers/intern/MOD_functiondeform.c

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

diff --git a/release/scripts/startup/function_nodes/__init__.py b/release/scripts/startup/function_nodes/__init__.py
new file mode 100644
index 00000000000..f64bb7d6c88
--- /dev/null
+++ b/release/scripts/startup/function_nodes/__init__.py
@@ -0,0 +1,6 @@
+
+def register():
+    from . import base
+    from . import sockets
+    from . import nodes
+    from . import menu
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/base.py b/release/scripts/startup/function_nodes/base.py
new file mode 100644
index 00000000000..36cde50e660
--- /dev/null
+++ b/release/scripts/startup/function_nodes/base.py
@@ -0,0 +1,33 @@
+import bpy
+
+class FunctionNodeTree(bpy.types.NodeTree):
+    bl_idname = "FunctionNodeTree"
+    bl_icon = "MOD_DATA_TRANSFER"
+    bl_label = "Function Nodes"
+
+bpy.utils.register_class(FunctionNodeTree)
+
+
+class FunctionNode:
+    def init(self, context):
+        inputs, outputs = self.get_sockets()
+        for idname, name in inputs:
+            self.inputs.new(idname, name)
+        for idname, name in outputs:
+            self.outputs.new(idname, name)
+
+    def get_sockets():
+        return [], []
+
+class DataSocket:
+    color = (0, 0, 0, 0)
+
+    def draw_color(self, context, node):
+        return self.color
+
+    def draw(self, context, layout, node, text):
+        if not (self.is_linked or self.is_output) and hasattr(self, "draw_property"):
+            self.draw_property(layout, text, node)
+        else:
+            layout.label(text=text)
+
diff --git a/release/scripts/startup/function_nodes/menu.py b/release/scripts/startup/function_nodes/menu.py
new file mode 100644
index 00000000000..fa504b0d96f
--- /dev/null
+++ b/release/scripts/startup/function_nodes/menu.py
@@ -0,0 +1,25 @@
+import bpy
+from . base import FunctionNodeTree
+
+def draw_menu(self, context):
+    tree = context.space_data.node_tree
+    if not isinstance(tree, FunctionNodeTree):
+        return
+
+    layout = self.layout
+    self.operator_context = "INVOKE_DEFAULT"
+
+    insert_node(layout, "fn_AddFloatsNode", "Add Floats")
+    insert_node(layout, "fn_CombineVectorNode", "Combine Vector")
+
+def insert_node(layout, type, text, settings = {}, icon = "NONE"):
+    operator = layout.operator("node.add_node", text = text, icon = icon)
+    operator.type = type
+    operator.use_transform = True
+    for name, value in settings.items():
+        item = operator.settings.add()
+        item.name = name
+        item.value = value
+    return operator
+
+bpy.types.NODE_MT_add.append(draw_menu)
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/__init__.py b/release/scripts/startup/function_nodes/nodes/__init__.py
new file mode 100644
index 00000000000..4cd5c083146
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/__init__.py
@@ -0,0 +1,4 @@
+from . import (
+    add_floats,
+    combine_vector,
+)
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/add_floats.py b/release/scripts/startup/function_nodes/nodes/add_floats.py
new file mode 100644
index 00000000000..f6b83cbb13b
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/add_floats.py
@@ -0,0 +1,16 @@
+import bpy
+from .. base import FunctionNode
+
+class AddFloatsNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_AddFloatsNode"
+    bl_label = "Add Floats"
+
+    def get_sockets(self):
+        return [
+            ("fn_FloatSocket", "A"),
+            ("fn_FloatSocket", "B"),
+        ], [
+            ("fn_FloatSocket", "Result"),
+        ]
+
+bpy.utils.register_class(AddFloatsNode)
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/combine_vector.py b/release/scripts/startup/function_nodes/nodes/combine_vector.py
new file mode 100644
index 00000000000..cebd9f266f0
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/combine_vector.py
@@ -0,0 +1,17 @@
+import bpy
+from .. base import FunctionNode
+
+class CombineVectorNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_CombineVectorNode"
+    bl_label = "Combine Vector"
+
+    def get_sockets(self):
+        return [
+            ("fn_FloatSocket", "X"),
+            ("fn_FloatSocket", "Y"),
+            ("fn_FloatSocket", "Z"),
+        ], [
+            ("fn_VectorSocket", "Result"),
+        ]
+
+bpy.utils.register_class(CombineVectorNode)
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/sockets.py b/release/scripts/startup/function_nodes/sockets.py
new file mode 100644
index 00000000000..acc8d4b7986
--- /dev/null
+++ b/release/scripts/startup/function_nodes/sockets.py
@@ -0,0 +1,33 @@
+import bpy
+from . base import DataSocket
+from bpy.props import *
+
+class FloatSocket(bpy.types.NodeSocket, DataSocket):
+    bl_idname = "fn_FloatSocket"
+    bl_label = "Float Socket"
+    color = (0, 0, 0, 1)
+
+    value: FloatProperty(
+        name="Value",
+        default=0.0,
+    )
+
+    def draw_property(self, layout, text, node):
+        layout.prop(self, "value", text=text)
+
+class VectorSocket(bpy.types.NodeSocket, DataSocket):
+    bl_idname = "fn_VectorSocket"
+    bl_label = "Vector Socket"
+    color = (0, 0, 0.5, 1)
+
+    value: FloatVectorProperty(
+        name="Value",
+        size=3,
+        default=(0.0, 0.0, 0.0),
+    )
+
+    def draw_property(self, layout, text, node):
+        layout.column().prop(self, "value", text=text)
+
+bpy.utils.register_class(FloatSocket)
+bpy.utils.register_class(VectorSocket)
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 3161e2a98d7..7ef027faec7 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -1,6 +1,9 @@
 set(INC
 	.
 	../blenlib
+	../makesdna
+	../makesrna
+	../blenkernel
 )
 
 set(INC_SYS
@@ -24,6 +27,9 @@ set(SRC
 	types/numeric.cpp
 	types/numeric.hpp
 	types/types.hpp
+
+	function_nodes/function_nodes.hpp
+	function_nodes/function_nodes.cpp
 )
 
 blender_add_lib(bf_functions "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/functions/FN_functions.h b/source/blender/functions/FN_functions.h
index a45a5b0487f..593f7f644e1 100644
--- a/source/blender/functions/FN_functions.h
+++ b/source/blender/functions/FN_functions.h
@@ -2,6 +2,7 @@
 #define __FUNCTIONS_H__
 
 #include "BLI_utildefines.h"
+#include "DNA_node_types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -39,6 +40,8 @@ FnFunction FN_get_deform_function(int type);
 
 FnFunction FN_get_generated_function(void);
 
+void FN_testing(bNodeTree *bnodetree);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index c84b700225a..735c6bca0cb 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -2,6 +2,8 @@
 
 #include "core/core.hpp"
 #include "core/data_flow_graph.hpp"
-#include "./core/graph_to_function.hpp"
+#include "core/graph_to_function.hpp"
 
-#include "core/cpu.hpp"
\ No newline at end of file
+#include "core/cpu.hpp"
+
+#include "types/types.hpp"
\ No newline at end of file
diff --git a/source/blender/functions/c_wrapper.cpp b/source/blender/functions/c_wrapper.cpp
index 4117af07983..20be9d0f0a7 100644
--- a/source/blender/functions/c_wrapper.cpp
+++ b/source/blender/functions/c_wrapper.cpp
@@ -1,7 +1,7 @@
 #include "FN_functions.h"
 #include "FN_functions.hpp"
 
-#include "./types/types.hpp"
+#include "function_nodes/function_nodes.hpp"
 
 #include <iostream>
 
@@ -150,7 +150,7 @@ static FN::SharedFunction get_deform_function(int type)
 	FN::OutputParameters outputs;
 	outputs.append(FN::OutputParameter("Position", FN::Types::get_fvec3_type()));
 
-	auto fn = FN::SharedFunction::New(FN::Signature(inputs, outputs), "Deform");
+	auto fn = FN::SharedFunction::New("Deform", FN::Signature(inputs, outputs));
 	if (type == 0) {
 		fn->add_body(new Deform1());
 	}
@@ -164,7 +164,7 @@ static FN::SharedFunction get_pass_through_float_function()
 {
 	FN::InputParameters inputs = {FN::InputParameter("In", FN::Types::get_float_type())};
 	FN::OutputParameters outputs = {FN::OutputParameter("Out", FN::Types::get_float_type())};
-	auto fn = FN::SharedFunction::New(FN::Signature(inputs, outputs), "Pass Through");
+	auto fn = FN::SharedFunction::New("Pass Through", FN::Signature(inputs, outputs));
 	fn->add_body(new PassThroughFloat());
 	return fn;
 }
@@ -205,4 +205,11 @@ FnFunction FN_get_generated_function()
 	BLI::RefCounted<FN::Function> *fn_ref = fn.refcounter();
 	fn_ref->incref();
 	return wrap(fn_ref);
+}
+
+void FN_testing(bNodeTree *bnodetree)
+{
+	FN::FunctionNodes::FunctionNodeTree tree(bnodetree);
+	auto graph = tree.to_data_flow_graph();
+	std::cout << graph->to_dot() << std::endl;
 }
\ No newline at end of file
diff --git a/source/blender/functions/core/core.hpp b/source/blender/functions/core/core.hpp
index 9e37dba9fb2..2cf503f630f 100644
--- a/source/blender/functions/core/core.hpp
+++ b/source/blender/functions/core/core.hpp
@@ -129,8 +129,11 @@ namespace FN {
 
 	class Function final {
 	public:
-		Function(const Signature &signature, const std::string &name = "Function")
-			: m_signature(signature), m_name(name) {}
+		Function(const std::string &name, const Signature &signature)
+			:m_signature(signature), m_name(name) {}
+
+		Function(const Signature &signature)
+			: Function("Function", signature) {}
 
 		~Function() = default;
 
diff --git a/source/blender/functions/core/data_flow_graph.hpp b/source/blender/functions/core/data_flow_graph.hpp
index a742799b961..00705044dc9 100644
--- a/source/blender/functions/core/data_flow_graph.hpp
+++ b/source/blender/functions/core/data_flow_graph.hpp
@@ -30,6 +30,7 @@ namespace FN {
 		friend bool operator==(const Socket &a, const Socket &b);
 
 		inline Socket origin() const;
+		inline bool is_linked() const;
 
 	private:
 		Socket(const Node *node, bool is_output, uint index)
@@ -136,7 +137,9 @@ namespace FN {
 
 		SmallSet<Socket> get_linked(Socket socket) const
 		{
-			return m_links.lookup(socket);
+			SmallSet<Socket> *linked = m_links.lookup_ptr(socket);
+			if (linked == nullptr) retu

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list