Commit: 0f42dd82ac8bee12a7b5c87e3899e003e28eb15f Author: Jacques Lucke Date: Fri Apr 5 18:57:31 2019 +0200 Branches: functions https://developer.blender.org/rB0f42dd82ac8bee12a7b5c87e3899e003e28eb15f
new Vector Math node =================================================================== A release/scripts/startup/function_nodes/nodes/vector_math.py M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp M source/blender/functions/functions/vectors.cpp M source/blender/functions/functions/vectors.hpp =================================================================== diff --git a/release/scripts/startup/function_nodes/nodes/vector_math.py b/release/scripts/startup/function_nodes/nodes/vector_math.py new file mode 100644 index 00000000000..ede35101eb3 --- /dev/null +++ b/release/scripts/startup/function_nodes/nodes/vector_math.py @@ -0,0 +1,25 @@ +import bpy +from bpy.props import * +from .. base import FunctionNode + +operation_items = [ + ("ADD", "Add", "", "", 1), +] + +class VectorMathNode(bpy.types.Node, FunctionNode): + bl_idname = "fn_VectorMathNode" + bl_label = "Vector Math" + + operation: EnumProperty( + name="Operation", + items=operation_items, + update=FunctionNode.refresh, + ) + + def declaration(self, builder): + builder.fixed_input("a", "A", "Vector") + builder.fixed_input("b", "B", "Vector") + builder.fixed_output("result", "Result", "Vector") + + def draw(self, layout): + layout.prop(self, "operation", text="") \ No newline at end of file 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 8acbbda499e..ac9973c8c2a 100644 --- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp +++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp @@ -55,6 +55,31 @@ namespace FN { namespace DataFlowNodes { builder.map_sockets(node, bnode); } + static SharedFunction &get_vector_math_function(int operation) + { + switch (operation) + { + case 1: return Functions::add_vectors(); + default: + BLI_assert(false); + return *(SharedFunction *)nullptr; + } + } + + static void insert_vector_math_node( + Builder &builder, + const BuilderContext &ctx, + bNode *bnode) + { + PointerRNA ptr; + ctx.get_rna(bnode, &ptr); + int operation = RNA_enum_get(&ptr, "operation"); + + SharedFunction &fn = get_vector_math_function(operation); + Node *node = builder.insert_function(fn, ctx.btree(), bnode); + builder.map_sockets(node, bnode); + } + static void insert_clamp_node( Builder &builder, const BuilderContext &ctx, @@ -185,6 +210,7 @@ namespace FN { namespace DataFlowNodes { inserters.reg_node_inserter("fn_ObjectTransformsNode", insert_object_transforms_node); inserters.reg_node_inserter("fn_FloatMathNode", insert_float_math_node); + inserters.reg_node_inserter("fn_VectorMathNode", insert_vector_math_node); inserters.reg_node_inserter("fn_ClampNode", insert_clamp_node); inserters.reg_node_inserter("fn_GetListElementNode", insert_get_list_element_node); inserters.reg_node_inserter("fn_PackListNode", insert_pack_list_node); diff --git a/source/blender/functions/functions/vectors.cpp b/source/blender/functions/functions/vectors.cpp index 96f84a0aec6..d3a224dadfd 100644 --- a/source/blender/functions/functions/vectors.cpp +++ b/source/blender/functions/functions/vectors.cpp @@ -89,4 +89,34 @@ namespace FN { namespace Functions { return fn; } + + static SharedFunction get_math_function__two_inputs(std::string name) + { + auto fn = SharedFunction::New(name, Signature({ + InputParameter("A", get_fvec3_type()), + InputParameter("B", get_fvec3_type()), + }, { + OutputParameter("Result", get_fvec3_type()), + })); + return fn; + } + + + class AddVectors : public TupleCallBody { + void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override + { + Vector a = fn_in.get<Vector>(0); + Vector b = fn_in.get<Vector>(1); + Vector result(a.x + b.x, a.y + b.y, a.z + b.z); + fn_out.set<Vector>(0, result); + } + }; + + LAZY_INIT_REF__NO_ARG(SharedFunction, add_vectors) + { + auto fn = get_math_function__two_inputs("Add Vectors"); + fn->add_body(new AddVectors()); + return fn; + } + } } /* namespace FN::Functions */ \ No newline at end of file diff --git a/source/blender/functions/functions/vectors.hpp b/source/blender/functions/functions/vectors.hpp index ae31cb9885e..638f49cc144 100644 --- a/source/blender/functions/functions/vectors.hpp +++ b/source/blender/functions/functions/vectors.hpp @@ -7,5 +7,6 @@ namespace FN { namespace Functions { SharedFunction &combine_vector(); SharedFunction &separate_vector(); SharedFunction &vector_distance(); + SharedFunction &add_vectors(); } } /* namespace FN::Functions */ \ No newline at end of file _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs