[Bf-blender-cvs] [ca5b24ce8e7] builtin-simulation-nodes: add Float Compare node

Jacques Lucke noreply at git.blender.org
Mon Mar 30 13:39:04 CEST 2020


Commit: ca5b24ce8e79de53d6a26f80422f2b2de8624ddc
Author: Jacques Lucke
Date:   Mon Mar 30 13:19:18 2020 +0200
Branches: builtin-simulation-nodes
https://developer.blender.org/rBca5b24ce8e79de53d6a26f80422f2b2de8624ddc

add Float Compare node

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

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/makesdna/DNA_node_types.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_nodetree.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_compare.cc
M	source/blender/nodes/intern/node_util.c
M	source/blender/nodes/intern/node_util.h

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index eaa2da8611f..29ee1d8322f 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -526,6 +526,7 @@ simulation_node_categories = [
         NodeItem("FunctionNodeFloatMath"),
         NodeItem("FunctionNodeVectorMath"),
         NodeItem("FunctionNodeBooleanMath"),
+        NodeItem("FunctionNodeFloatCompare"),
     ]),
     FunctionNodeCategory("SURFACE", "Surface", items=[
         NodeItem("FunctionNodeClosestSurface"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 52f57d4f899..62605b7abc9 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1027,6 +1027,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree,
 #define FN_NODE_SURFACE_WEIGHT 1111
 #define FN_NODE_CLOSEST_SURFACE 1112
 #define FN_NODE_BOOLEAN_MATH 1113
+#define FN_NODE_FLOAT_COMPARE 1114
 
 /* 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 a47461fe143..715b3c0493d 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4239,6 +4239,7 @@ static void registerFunctionNodes(void)
   register_node_type_fn_surface_position();
   register_node_type_fn_surface_weight();
   register_node_type_fn_boolean_math();
+  register_node_type_fn_float_compare();
 }
 
 void init_nodesystem(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 99afeac20f6..f4b9d352141 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3174,6 +3174,13 @@ static void node_function_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C
   uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
 }
 
+static void node_function_buts_float_compare(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) {
@@ -3186,6 +3193,9 @@ static void node_function_set_butfunc(bNodeType *ntype)
     case FN_NODE_BOOLEAN_MATH:
       ntype->draw_buttons = node_function_buts_boolean_math;
       break;
+    case FN_NODE_FLOAT_COMPARE:
+      ntype->draw_buttons = node_function_buts_float_compare;
+      break;
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 5dece86f8c9..0fc239ffc33 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1309,12 +1309,23 @@ enum {
   NODE_VECTOR_MATH_TANGENT = 23,
 };
 
+/* Boolean math node operations. */
 enum {
   NODE_BOOLEAN_MATH_AND = 0,
   NODE_BOOLEAN_MATH_OR = 1,
   NODE_BOOLEAN_MATH_NOT = 2,
 };
 
+/* Float compare node operations. */
+enum {
+  NODE_FLOAT_COMPARE_LESS_THAN = 0,
+  NODE_FLOAT_COMPARE_LESS_EQUAL = 1,
+  NODE_FLOAT_COMPARE_GREATER_THAN = 2,
+  NODE_FLOAT_COMPARE_GREATER_EQUAL = 3,
+  NODE_FLOAT_COMPARE_EQUAL = 4,
+  NODE_FLOAT_COMPARE_NOT_EQUAL = 5,
+};
+
 /* Clamp node types. */
 enum {
   NODE_CLAMP_MINMAX = 0,
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index b9f28731723..b2f9c90b7f5 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -192,6 +192,7 @@ extern const EnumPropertyItem rna_enum_node_math_items[];
 extern const EnumPropertyItem rna_enum_mapping_type_items[];
 extern const EnumPropertyItem rna_enum_node_vec_math_items[];
 extern const EnumPropertyItem rna_enum_node_boolean_math_items[];
+extern const EnumPropertyItem rna_enum_node_float_compare_items[];
 extern const EnumPropertyItem rna_enum_node_filter_items[];
 extern const EnumPropertyItem rna_enum_node_map_range_items[];
 extern const EnumPropertyItem rna_enum_node_clamp_items[];
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index f6758c171af..fed3c7aecfa 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -270,6 +270,40 @@ const EnumPropertyItem rna_enum_node_boolean_math_items[] = {
     {0, NULL, 0, NULL, NULL},
 };
 
+const EnumPropertyItem rna_enum_node_float_compare_items[] = {
+    {NODE_FLOAT_COMPARE_LESS_THAN,
+     "LESS_THAN",
+     0,
+     "A < B",
+     "True when the first input is smaller than second input"},
+    {NODE_FLOAT_COMPARE_LESS_EQUAL,
+     "LESS_EQUAL",
+     0,
+     "A <= B",
+     "True when the first input is smaller than the second input or equal"},
+    {NODE_FLOAT_COMPARE_GREATER_THAN,
+     "GREATER_THAN",
+     0,
+     "A > B",
+     "True when the first input is greater than the second input"},
+    {NODE_FLOAT_COMPARE_GREATER_EQUAL,
+     "GREATER_EQUAL",
+     0,
+     "A >= B",
+     "True when the first input is greater than the second input or equal"},
+    {NODE_FLOAT_COMPARE_EQUAL,
+     "EQUAL",
+     0,
+     "A = B",
+     "True when both inputs are approximately equal"},
+    {NODE_FLOAT_COMPARE_NOT_EQUAL,
+     "NOT_EQUAL",
+     0,
+     "A != B",
+     "True when both inputs are not approximately equal"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 const EnumPropertyItem rna_enum_node_map_range_items[] = {
     {NODE_MAP_RANGE_LINEAR,
      "LINEAR",
@@ -4158,6 +4192,17 @@ static void def_boolean_math(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_FunctionNode_socket_update");
 }
 
+static void def_float_compare(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "custom1");
+  RNA_def_property_enum_items(prop, rna_enum_node_float_compare_items);
+  RNA_def_property_ui_text(prop, "Operation", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_FunctionNode_socket_update");
+}
+
 static void def_rgb_curve(StructRNA *srna)
 {
   PropertyRNA *prop;
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 36a0a0d7fc2..e9613fd93cc 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -134,15 +134,16 @@ set(SRC
   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_compare.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/nodes/node_fn_surface_color.cc
   function/nodes/node_fn_surface_normal.cc
   function/nodes/node_fn_surface_position.cc
   function/nodes/node_fn_surface_weight.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 3b49b6afac1..d29c9f73612 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -19,6 +19,7 @@ void register_node_type_fn_surface_normal(void);
 void register_node_type_fn_surface_position(void);
 void register_node_type_fn_surface_weight(void);
 void register_node_type_fn_boolean_math(void);
+void register_node_type_fn_float_compare(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 099b900eed5..8052b1ee12d 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -285,6 +285,7 @@ DefNode(FunctionNode, FN_NODE_SURFACE_NORMAL, 0, "SURFACE_NORMAL", SurfaceNormal
 DefNode(FunctionNode, FN_NODE_SURFACE_POSITION, 0, "SURFACE_POSITION", SurfacePosition, "Surface Position", "")
 DefNode(FunctionNode, FN_NODE_SURFACE_WEIGHT, 0, "SURFACE_WEIGHT", SurfaceWeight, "Surface Weight", "")
 DefNode(FunctionNode, FN_NODE_BOOLEAN_MATH, def_boolean_math, "BOOLEAN_MATH", BooleanMath, "Boolean Math", "");
+DefNode(FunctionNode, FN_NODE_FLOAT_COMPARE, def_float_compare, "FLOAT_COMPARE", FloatCompare, "Float Compare", "");
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/function/nodes/node_fn_float_compare.cc b/source/blender/nodes/function/nodes/node_fn_float_compare.cc
new file mode 100644
index 00000000000..260979bf27b
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_float_compare.cc
@@ -0,0 +1,24 @@
+#include "node_fn_util.h"
+
+static bNodeSocketTemplate fn_node_float_compare_in[] = {
+    {SOCK_FLOAT, N_("A"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
+    {SOCK_FLOAT, N_("B"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
+    {SOCK_FLOAT, N_("Epsilon"), 0.001f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate fn_node_float_compare_out[] = {
+    {SOCK_BOOLEAN, N_("Result")},
+    {-1, ""},
+};
+
+void register_node_type_fn_float_compare()
+{
+  static bNodeType ntype;
+
+  fn_node_type_base(&ntype, FN_NODE_FLOAT_COMPARE, "Boolean Math", 0, 0);
+  node_type_socket_templates(&ntype, fn_node_float_compare_in, fn_node_float_compare_out);
+  node_type_label(&ntype, node_float_compare_label);
+  node_type_update(&ntype, node_float_compare_update);
+  nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index c66d61f8df6..61c29589dd7 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -233,6 +233,14 @@ void node_boolean_math_update(bNodeTree *UNUSED(ntree), bNode *node)
                             ELEM(node->custom1, NODE_BOOLEAN_MATH_AND, NODE_BOOLEAN_MATH_OR));
 }
 
+void node_float_compare_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  bNodeSocket *sockEpsilon = BLI_findlink(&node->inputs, 2);
+
+  nodeSetSocketAvailability(
+   

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list