[Bf-blender-cvs] [3ad939f82d7] builtin-simulation-nodes: add Float Math/Vector Math function nodes
Jacques Lucke
noreply at git.blender.org
Mon Mar 16 14:37:08 CET 2020
Commit: 3ad939f82d7580af2508467ae613543ed0a4e317
Author: Jacques Lucke
Date: Mon Mar 16 14:36:59 2020 +0100
Branches: builtin-simulation-nodes
https://developer.blender.org/rB3ad939f82d7580af2508467ae613543ed0a4e317
add Float Math/Vector Math function nodes
===================================================================
M release/scripts/startup/nodeitems_builtins.py
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/node.c
M source/blender/editors/space_node/drawnode.c
M source/blender/nodes/CMakeLists.txt
M source/blender/nodes/NOD_function.h
M source/blender/nodes/NOD_static_types.h
A source/blender/nodes/function/nodes/node_fn_float_math.cc
A source/blender/nodes/function/nodes/node_fn_vector_math.cc
M source/blender/nodes/intern/node_util.c
M source/blender/nodes/intern/node_util.h
M source/blender/nodes/shader/nodes/node_shader_vector_math.c
===================================================================
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 2fbc93a942c..f03f7f44034 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -512,6 +512,8 @@ simulation_node_categories = [
NodeItem("FunctionNodeSeparateRGB"),
NodeItem("FunctionNodeCombineHSV"),
NodeItem("FunctionNodeSeparateHSV"),
+ NodeItem("FunctionNodeFloatMath"),
+ NodeItem("FunctionNodeVectorMath"),
]),
SimulationNodeCategory("LAYOUT", "Layout", items=[
NodeItem("NodeFrame"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index cf30d829507..b4c9d3a46ca 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1019,6 +1019,8 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree,
#define FN_NODE_SEPARATE_RGB 1103
#define FN_NODE_COMBINE_HSV 1104
#define FN_NODE_SEPARATE_HSV 1105
+#define FN_NODE_FLOAT_MATH 1106
+#define FN_NODE_VECTOR_MATH 1107
/* custom defines options for Material node */
// #define SH_NODE_MAT_DIFF 1
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 56cda21e994..298370fa0c9 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4231,6 +4231,8 @@ static void registerFunctionNodes(void)
register_node_type_fn_separate_rgb();
register_node_type_fn_combine_hsv();
register_node_type_fn_separate_hsv();
+ register_node_type_fn_float_math();
+ register_node_type_fn_vector_math();
}
void init_nodesystem(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index f1257769e66..5d903d50b26 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3161,6 +3161,25 @@ static void node_simulation_set_butfunc(bNodeType *ntype)
}
}
+/* ****************** BUTTON CALLBACKS FOR FUNCTION NODES ***************** */
+
+static void node_function_buts_vector_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
+}
+
+static void node_function_set_butfunc(bNodeType *ntype)
+{
+ switch (ntype->type) {
+ case FN_NODE_FLOAT_MATH:
+ ntype->draw_buttons = node_buts_math;
+ break;
+ case FN_NODE_VECTOR_MATH:
+ ntype->draw_buttons = node_function_buts_vector_math;
+ break;
+ }
+}
+
/* ****** init draw callbacks for all tree types, only called in usiblender.c, once ************ */
static void node_property_update_default(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
@@ -3270,6 +3289,7 @@ void ED_node_init_butfuncs(void)
node_shader_set_butfunc(ntype);
node_texture_set_butfunc(ntype);
node_simulation_set_butfunc(ntype);
+ node_function_set_butfunc(ntype);
/* define update callbacks for socket properties */
node_template_properties_update(ntype);
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 8aac15dde24..1b396969c8e 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -129,12 +129,14 @@ set(SRC
composite/node_composite_tree.c
composite/node_composite_util.c
- function/nodes/node_fn_combine_xyz.cc
- function/nodes/node_fn_separate_xyz.cc
- function/nodes/node_fn_combine_rgb.cc
- function/nodes/node_fn_separate_rgb.cc
function/nodes/node_fn_combine_hsv.cc
+ function/nodes/node_fn_combine_rgb.cc
+ function/nodes/node_fn_combine_xyz.cc
+ function/nodes/node_fn_float_math.cc
function/nodes/node_fn_separate_hsv.cc
+ function/nodes/node_fn_separate_rgb.cc
+ function/nodes/node_fn_separate_xyz.cc
+ function/nodes/node_fn_vector_math.cc
function/node_fn_util.cc
shader/nodes/node_shader_add_shader.c
diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h
index 4847fb61799..86f232ef52f 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -11,6 +11,8 @@ void register_node_type_fn_combine_rgb(void);
void register_node_type_fn_separate_rgb(void);
void register_node_type_fn_combine_hsv(void);
void register_node_type_fn_separate_hsv(void);
+void register_node_type_fn_float_math(void);
+void register_node_type_fn_vector_math(void);
#ifdef __cplusplus
}
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index bb36c197823..98ecd259a43 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -277,8 +277,10 @@ DefNode(FunctionNode, FN_NODE_COMBINE_RGB, 0, "COMBINE_RGB", CombineRGB, "Combin
DefNode(FunctionNode, FN_NODE_SEPARATE_RGB, 0, "SEPARATE_RGB", SeparateRGB, "Separate RGB", "")
DefNode(FunctionNode, FN_NODE_COMBINE_HSV, 0, "COMBINE_HSV", CombineHSV, "Combine HSV", "")
DefNode(FunctionNode, FN_NODE_SEPARATE_HSV, 0, "SEPARATE_HSV", SeparateHSV, "Separate HSV", "")
+DefNode(FunctionNode, FN_NODE_FLOAT_MATH, def_math, "FLOAT_MATH", FloatMath, "Float Math", "");
+DefNode(FunctionNode, FN_NODE_VECTOR_MATH, def_vector_math, "VECTOR_MATH", VectorMath, "Vector Math", "");
/* undefine macros */
#undef DefNode
- /* clang-format on */
+/* clang-format on */
diff --git a/source/blender/nodes/function/nodes/node_fn_float_math.cc b/source/blender/nodes/function/nodes/node_fn_float_math.cc
new file mode 100644
index 00000000000..0769b560c2a
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_float_math.cc
@@ -0,0 +1,24 @@
+#include "node_fn_util.h"
+
+static bNodeSocketTemplate fn_node_float_math_in[] = {
+ {SOCK_FLOAT, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_FLOAT, N_("Value"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_FLOAT, N_("Value"), 0.0f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate fn_node_float_math_out[] = {
+ {SOCK_FLOAT, N_("Value")},
+ {-1, ""},
+};
+
+void register_node_type_fn_float_math()
+{
+ static bNodeType ntype;
+
+ fn_node_type_base(&ntype, FN_NODE_FLOAT_MATH, "Float Math", 0, 0);
+ node_type_socket_templates(&ntype, fn_node_float_math_in, fn_node_float_math_out);
+ node_type_label(&ntype, node_math_label);
+ node_type_update(&ntype, node_math_update);
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/function/nodes/node_fn_vector_math.cc b/source/blender/nodes/function/nodes/node_fn_vector_math.cc
new file mode 100644
index 00000000000..a773a3ce788
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_vector_math.cc
@@ -0,0 +1,26 @@
+#include "node_fn_util.h"
+
+static bNodeSocketTemplate fn_node_vector_math_in[] = {
+ {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_FLOAT, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate fn_node_vector_math_out[] = {
+ {SOCK_VECTOR, N_("Vector")},
+ {SOCK_FLOAT, N_("Value")},
+ {-1, ""},
+};
+
+void register_node_type_fn_vector_math()
+{
+ static bNodeType ntype;
+
+ fn_node_type_base(&ntype, FN_NODE_VECTOR_MATH, "Vector Math", 0, 0);
+ node_type_socket_templates(&ntype, fn_node_vector_math_in, fn_node_vector_math_out);
+ node_type_label(&ntype, node_vector_math_label);
+ node_type_update(&ntype, node_vector_math_update);
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index 9efbdc079e6..2fbe1cd3b5d 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -173,6 +173,58 @@ void node_math_update(bNodeTree *UNUSED(ntree), bNode *node)
}
}
+void node_vector_math_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ bNodeSocket *sockB = BLI_findlink(&node->inputs, 1);
+ bNodeSocket *sockC = BLI_findlink(&node->inputs, 2);
+ bNodeSocket *sockScale = nodeFindSocket(node, SOCK_IN, "Scale");
+
+ bNodeSocket *sockVector = nodeFindSocket(node, SOCK_OUT, "Vector");
+ bNodeSocket *sockValue = nodeFindSocket(node, SOCK_OUT, "Value");
+
+ nodeSetSocketAvailability(sockB,
+ !ELEM(node->custom1,
+ NODE_VECTOR_MATH_SINE,
+ NODE_VECTOR_MATH_COSINE,
+ NODE_VECTOR_MATH_TANGENT,
+ NODE_VECTOR_MATH_CEIL,
+ NODE_VECTOR_MATH_SCALE,
+ NODE_VECTOR_MATH_FLOOR,
+ NODE_VECTOR_MATH_LENGTH,
+ NODE_VECTOR_MATH_ABSOLUTE,
+ NODE_VECTOR_MATH_FRACTION,
+ NODE_VECTOR_MATH_NORMALIZE));
+ nodeSetSocketAvailability(sockC, ELEM(node->custom1, NODE_VECTOR_MATH_WRAP));
+ nodeSetSocketAvailability(sockScale, node->custom1 == NODE_VECTOR_MATH_SCALE);
+ nodeSetSocketAvailability(sockVector,
+ !ELEM(node->custom1,
+ NODE_VECTOR_MATH_LENGTH,
+ NODE_VECTOR_MATH_DISTANCE,
+ NODE_VECTOR_MATH_DOT_PRODUCT));
+ nodeSetSocketAvailability(sockValue,
+ ELEM(node->custom1,
+ NODE_VECTOR_MATH_LENGTH,
+ NODE_VECTOR_MATH_DISTANCE,
+ NODE_VECTOR_MATH_DOT_PRODUCT));
+
+ /* Labels */
+ if (sockB->label[0] != '\0') {
+ sockB->label[0] = '\0';
+ }
+ if (sockC->label[0] != '\0') {
+ sockC->label[0] = '\0';
+ }
+ switch (node->custom1) {
+ case NODE_VECTOR_MATH_WRAP:
+ node_sock_label(sockB, "Max");
+ node_sock_label(sockC, "Min");
+ break;
+ case NODE_VECTOR_MATH_SNAP:
+ nod
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list