[Bf-blender-cvs] [f43561eae68] master: Function Nodes: Input Vector

Dalai Felinto noreply at git.blender.org
Fri Dec 18 13:09:36 CET 2020


Commit: f43561eae6826eead2e5e78bc8792b3c15dda6ae
Author: Dalai Felinto
Date:   Thu Dec 17 18:37:04 2020 +0100
Branches: master
https://developer.blender.org/rBf43561eae6826eead2e5e78bc8792b3c15dda6ae

Function Nodes: Input Vector

Ref: T82651

Normally people use "Combine XYZ" to input a vector, but it is more
interesting to have an explicit vector input.

So this is basically "Combine XYZ" without any input sockets, the values
are stored in the node itself.

Differential Revision: https://developer.blender.org/D9885

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

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/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_input_vector.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 09c01ade4f1..85a5cb02677 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -502,6 +502,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeObjectInfo"),
         NodeItem("FunctionNodeRandomFloat"),
         NodeItem("ShaderNodeValue"),
+        NodeItem("FunctionNodeInputVector"),
     ]),
     GeometryNodeCategory("GEO_MESH", "Mesh", items=[
         NodeItem("GeometryNodeTriangulate"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 5e360bcb074..bc254b81afb 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1369,6 +1369,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define FN_NODE_COMBINE_STRINGS 1204
 #define FN_NODE_OBJECT_TRANSFORMS 1205
 #define FN_NODE_RANDOM_FLOAT 1206
+#define FN_NODE_INPUT_VECTOR 1207
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index d5cea8b6d63..5af49802868 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4755,6 +4755,7 @@ static void registerFunctionNodes(void)
   register_node_type_fn_combine_strings();
   register_node_type_fn_object_transforms();
   register_node_type_fn_random_float();
+  register_node_type_fn_input_vector();
 }
 
 void BKE_node_system_init(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index c2951a9d7a8..b6744719cad 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3289,6 +3289,12 @@ static void node_function_buts_switch(uiLayout *layout, bContext *UNUSED(C), Poi
   uiItemR(layout, ptr, "data_type", DEFAULT_FLAGS, "", ICON_NONE);
 }
 
+static void node_function_buts_input_vector(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+  uiLayout *col = uiLayoutColumn(layout, true);
+  uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
+}
+
 static void node_function_set_butfunc(bNodeType *ntype)
 {
   switch (ntype->type) {
@@ -3301,6 +3307,9 @@ static void node_function_set_butfunc(bNodeType *ntype)
     case FN_NODE_SWITCH:
       ntype->draw_buttons = node_function_buts_switch;
       break;
+    case FN_NODE_INPUT_VECTOR:
+      ntype->draw_buttons = node_function_buts_input_vector;
+      break;
   }
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index af91ab4f257..d6b5e3ed493 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1110,6 +1110,10 @@ typedef struct NodeAttributeColorRamp {
   ColorBand color_ramp;
 } NodeAttributeColorRamp;
 
+typedef struct NodeInputVector {
+  float vector[3];
+} NodeInputVector;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index d624154ddc7..25bfc70ef8f 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -4480,6 +4480,19 @@ static void def_texture(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_fn_input_vector(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  RNA_def_struct_sdna_from(srna, "NodeInputVector", "storage");
+
+  prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_XYZ);
+  RNA_def_property_array(prop, 3);
+  RNA_def_property_float_sdna(prop, NULL, "vector");
+  RNA_def_property_ui_text(prop, "Vector", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 /* -- Shader Nodes ---------------------------------------------------------- */
 
 static void def_sh_output(StructRNA *srna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index e152c50179e..866cf74d35b 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -133,6 +133,7 @@ set(SRC
   function/nodes/node_fn_combine_strings.cc
   function/nodes/node_fn_float_compare.cc
   function/nodes/node_fn_group_instance_id.cc
+  function/nodes/node_fn_input_vector.cc
   function/nodes/node_fn_object_transforms.cc
   function/nodes/node_fn_random_float.cc
   function/nodes/node_fn_switch.cc
diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h
index 58a968151ac..75dd8f89bc8 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -27,6 +27,7 @@ void register_node_type_fn_group_instance_id(void);
 void register_node_type_fn_combine_strings(void);
 void register_node_type_fn_object_transforms(void);
 void register_node_type_fn_random_float(void);
+void register_node_type_fn_input_vector(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 1e323d23a53..5b61594cca1 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -265,6 +265,7 @@ DefNode(FunctionNode, FN_NODE_GROUP_INSTANCE_ID, 0,             "GROUP_INSTANCE_
 DefNode(FunctionNode, FN_NODE_COMBINE_STRINGS, 0,               "COMBINE_STRINGS", CombineStrings, "Combine Strings", "")
 DefNode(FunctionNode, FN_NODE_OBJECT_TRANSFORMS, 0,             "OBJECT_TRANSFORMS", ObjectTransforms, "Object Transforms", "")
 DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0,                  "RANDOM_FLOAT", RandomFloat, "Random Float", "")
+DefNode(FunctionNode, FN_NODE_INPUT_VECTOR, def_fn_input_vector, "INPUT_VECTOR", InputVector, "Vector", "")
 
 DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE", Triangulate, "Triangulate", "")
 DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
diff --git a/source/blender/nodes/function/nodes/node_fn_input_vector.cc b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
new file mode 100644
index 00000000000..c2707f6307a
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_input_vector.cc
@@ -0,0 +1,55 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_function_util.hh"
+
+#include "BLI_hash.h"
+
+static bNodeSocketTemplate fn_node_input_vector_out[] = {
+    {SOCK_VECTOR, N_("Vector")},
+    {-1, ""},
+};
+
+static void fn_node_vector_input_expand_in_mf_network(
+    blender::nodes::NodeMFNetworkBuilder &builder)
+{
+  bNode &bnode = builder.bnode();
+  NodeInputVector *node_storage = static_cast<NodeInputVector *>(bnode.storage);
+  blender::float3 vector(node_storage->vector);
+
+  builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<blender::float3>>(vector);
+}
+
+static void fn_node_input_vector_init(bNodeTree *UNUSED(ntree), bNode *node)
+{
+  NodeInputVector *data = (NodeInputVector *)MEM_callocN(sizeof(NodeInputVector),
+                                                         "input vector node");
+  node->storage = data;
+}
+
+void register_node_type_fn_input_vector()
+{
+  static bNodeType ntype;
+
+  fn_node_type_base(&ntype, FN_NODE_INPUT_VECTOR, "Vector", 0, 0);
+  node_type_socket_templates(&ntype, nullptr, fn_node_input_vector_out);
+  node_type_init(&ntype, fn_node_input_vector_init);
+  node_type_storage(
+      &ntype, "NodeInputVector", node_free_standard_storage, node_copy_standard_storage);
+  ntype.expand_in_mf_network = fn_node_vector_input_expand_in_mf_network;
+
+  nodeRegisterType(&ntype);
+}



More information about the Bf-blender-cvs mailing list