[Bf-blender-cvs] [10395fd00d8] functions: separate vector node
Jacques Lucke
noreply at git.blender.org
Mon Feb 11 18:30:32 CET 2019
Commit: 10395fd00d8e6a7ee228e809829f193a3ecfc797
Author: Jacques Lucke
Date: Mon Feb 11 17:33:34 2019 +0100
Branches: functions
https://developer.blender.org/rB10395fd00d8e6a7ee228e809829f193a3ecfc797
separate vector node
===================================================================
M release/scripts/startup/function_nodes/menu.py
M release/scripts/startup/function_nodes/nodes/__init__.py
A release/scripts/startup/function_nodes/nodes/separate_vector.py
M source/blender/functions/function_nodes/function_nodes.cpp
M source/blender/modifiers/intern/MOD_functiondeform.c
===================================================================
diff --git a/release/scripts/startup/function_nodes/menu.py b/release/scripts/startup/function_nodes/menu.py
index 446d53ff437..c8b32175db0 100644
--- a/release/scripts/startup/function_nodes/menu.py
+++ b/release/scripts/startup/function_nodes/menu.py
@@ -14,6 +14,7 @@ def draw_menu(self, context):
layout.separator()
insert_node(layout, "fn_AddFloatsNode", "Add Floats")
insert_node(layout, "fn_CombineVectorNode", "Combine Vector")
+ insert_node(layout, "fn_SeparateVectorNode", "Separate Vector")
def insert_node(layout, type, text, settings = {}, icon = "NONE"):
operator = layout.operator("node.add_node", text = text, icon = icon)
diff --git a/release/scripts/startup/function_nodes/nodes/__init__.py b/release/scripts/startup/function_nodes/nodes/__init__.py
index e3567f28c29..ce73c7da5b3 100644
--- a/release/scripts/startup/function_nodes/nodes/__init__.py
+++ b/release/scripts/startup/function_nodes/nodes/__init__.py
@@ -4,4 +4,5 @@ from . import (
add_floats,
combine_vector,
+ separate_vector,
)
\ No newline at end of file
diff --git a/release/scripts/startup/function_nodes/nodes/separate_vector.py b/release/scripts/startup/function_nodes/nodes/separate_vector.py
new file mode 100644
index 00000000000..b96441fc145
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/separate_vector.py
@@ -0,0 +1,17 @@
+import bpy
+from .. base import FunctionNode
+
+class SeparateVectorNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_SeparateVectorNode"
+ bl_label = "Separate Vector"
+
+ def get_sockets(self):
+ return [
+ ("fn_VectorSocket", "Vector"),
+ ], [
+ ("fn_FloatSocket", "X"),
+ ("fn_FloatSocket", "Y"),
+ ("fn_FloatSocket", "Z"),
+ ]
+
+bpy.utils.register_class(SeparateVectorNode)
\ No newline at end of file
diff --git a/source/blender/functions/function_nodes/function_nodes.cpp b/source/blender/functions/function_nodes/function_nodes.cpp
index eb2dd2f6763..eac43169258 100644
--- a/source/blender/functions/function_nodes/function_nodes.cpp
+++ b/source/blender/functions/function_nodes/function_nodes.cpp
@@ -16,35 +16,47 @@ namespace FN::FunctionNodes {
SocketMap &map,
bNode *bnode);
- class AddFloats : public FN::TupleCallBody {
- void call(const FN::Tuple &fn_in, FN::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);
+
+ static SharedType &get_type_of_socket(bNodeSocket *bsocket)
+ {
+ if (STREQ(bsocket->idname, "fn_FloatSocket")) {
+ return Types::get_float_type();
}
- };
+ else if (STREQ(bsocket->idname, "fn_VectorSocket")) {
+ return Types::get_fvec3_type();
+ }
+ else {
+ BLI_assert(false);
+ return *(SharedType *)nullptr;
+ }
+ }
- static void insert_add_floats_node(
- const FunctionNodeTree &UNUSED(tree),
- SharedDataFlowGraph &graph,
- SocketMap &socket_map,
- bNode *bnode)
+ static Signature signature_from_node(bNode *bnode)
{
- SharedType &float_ty = Types::get_float_type();
-
- auto fn = SharedFunction::New("Add Floats", Signature({
- InputParameter("A", float_ty),
- InputParameter("B", float_ty),
- }, {
- OutputParameter("Result", float_ty),
- }));
- fn->add_body(new AddFloats());
- const Node *node = graph->insert(fn);
+ InputParameters inputs;
+ for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
+ inputs.append(InputParameter(bsocket->name, get_type_of_socket(bsocket)));
+ }
+ OutputParameters outputs;
+ for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
+ outputs.append(OutputParameter(bsocket->name, get_type_of_socket(bsocket)));
+ }
+ return Signature(inputs, outputs);
+ }
+
+ static void map_node_sockets(SocketMap &socket_map, bNode *bnode, const Node *node)
+ {
+ uint input_index = 0;
+ for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
+ socket_map.add(bsocket, node->input(input_index));
+ input_index++;
+ }
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->inputs, 0), node->input(0));
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->inputs, 1), node->input(1));
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->outputs, 0), node->output(0));
+ uint output_index = 0;
+ for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
+ socket_map.add(bsocket, node->output(output_index));
+ output_index++;
+ }
}
@@ -63,29 +75,60 @@ namespace FN::FunctionNodes {
}
};
+ class SeparateVector : public FN::TupleCallBody {
+ void call(const FN::Tuple &fn_in, FN::Tuple &fn_out) const override
+ {
+ Vector v = fn_in.get<Vector>(0);
+ fn_out.set<float>(0, v.x);
+ fn_out.set<float>(1, v.y);
+ fn_out.set<float>(2, v.z);
+ }
+ };
+
+ class AddFloats : public FN::TupleCallBody {
+ void call(const FN::Tuple &fn_in, FN::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);
+ }
+ };
+
+
+ static void insert_add_floats_node(
+ const FunctionNodeTree &UNUSED(tree),
+ SharedDataFlowGraph &graph,
+ SocketMap &socket_map,
+ bNode *bnode)
+ {
+ auto fn = SharedFunction::New("Add Floats", signature_from_node(bnode));
+ fn->add_body(new AddFloats());
+ const Node *node = graph->insert(fn);
+ map_node_sockets(socket_map, bnode, node);
+ }
+
static void insert_combine_vector_node(
const FunctionNodeTree &UNUSED(tree),
SharedDataFlowGraph &graph,
SocketMap &socket_map,
bNode *bnode)
{
- SharedType &float_ty = Types::get_float_type();
- SharedType &fvec3_ty = Types::get_fvec3_type();
-
- auto fn = SharedFunction::New("Combine Vector", Signature({
- InputParameter("X", float_ty),
- InputParameter("Y", float_ty),
- InputParameter("Z", float_ty),
- }, {
- OutputParameter("Result", fvec3_ty),
- }));
+ auto fn = SharedFunction::New("Combine Vector", signature_from_node(bnode));
fn->add_body(new CombineVector());
const Node *node = graph->insert(fn);
+ map_node_sockets(socket_map, bnode, node);
+ }
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->inputs, 0), node->input(0));
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->inputs, 1), node->input(1));
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->inputs, 2), node->input(2));
- socket_map.add((bNodeSocket *)BLI_findlink(&bnode->outputs, 0), node->output(0));
+ static void insert_separate_vector_node(
+ const FunctionNodeTree &UNUSED(tree),
+ SharedDataFlowGraph &graph,
+ SocketMap &socket_map,
+ bNode *bnode)
+ {
+ auto fn = SharedFunction::New("Separate Vector", signature_from_node(bnode));
+ fn->add_body(new SeparateVector());
+ const Node *node = graph->insert(fn);
+ map_node_sockets(socket_map, bnode, node);
}
@@ -121,20 +164,6 @@ namespace FN::FunctionNodes {
}
};
- static SharedType &get_type_of_socket(bNodeSocket *bsocket)
- {
- if (STREQ(bsocket->idname, "fn_FloatSocket")) {
- return Types::get_float_type();
- }
- else if (STREQ(bsocket->idname, "fn_VectorSocket")) {
- return Types::get_fvec3_type();
- }
- else {
- BLI_assert(false);
- return *(SharedType *)nullptr;
- }
- }
-
static const Node *get_input_node_for_socket(
const FunctionNodeTree &tree,
SharedDataFlowGraph &graph,
@@ -187,16 +216,9 @@ namespace FN::FunctionNodes {
{
SmallTypeVector types;
for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
- if (STREQ(bsocket->idname, "fn_VectorSocket")) {
- types.append(Types::get_fvec3_type());
- }
- else if (STREQ(bsocket->idname, "fn_FloatSocket")) {
- types.append(Types::get_float_type());
- }
- else {
- BLI_assert(false);
- }
+ types.append(get_type_of_socket(bsocket));
}
+
SharedFunction fn = get_output_function(types);
const Node *node = graph->insert(fn);
@@ -240,6 +262,7 @@ namespace FN::FunctionNodes {
SmallMap<std::string, InsertInGraphFunction> inserters;
inserters.add("fn_AddFloatsNode", insert_add_floats_node);
inserters.add("fn_CombineVectorNode", insert_combine_vector_node);
+ inserters.add("fn_SeparateVectorNode", insert_separate_vector_node);
inserters.add("fn_FunctionOutputNode", insert_output_node);
inserters.add("fn_FunctionInputNode", insert_input_node);
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c b/source/blender/modifiers/intern/MOD_functiondeform.c
index fee920e3d5c..c8ba88a46af 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -51,7 +51,7 @@
#include "FN_functions.h"
-bNodeTree *get_node_tree()
+bNodeTree *get_node_tree(void)
{
return (bNodeTree *)G.main->nodetree.first;
}
@@ -117,9 +117,9 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
+static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *UNUSED(ctx))
{
- FunctionDeformModifierData *bmd = (FunctionDeformModifierData *)md;
+ FunctionDeformModifierData *UNUSED(fdmd) = (FunctionDeformModifierData *)md;
}
More information about the Bf-blender-cvs
mailing list