Geometry Nodes: new Material input node
authorJacques Lucke <jacques@blender.org>
Thu, 20 May 2021 10:29:06 +0000 (12:29 +0200)
committerJacques Lucke <jacques@blender.org>
Thu, 20 May 2021 10:29:06 +0000 (12:29 +0200)
This node is similar to the Value and Vector node.
It just provides a way to use the same material in multiple nodes
without exposing it outside of a node group.

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

release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.cc
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_geometry.h
source/blender/nodes/NOD_static_types.h
source/blender/nodes/geometry/nodes/node_geo_input_material.cc [new file with mode: 0644]

index 7faed2d4bceac3d040c4ac627f65e122542e5506..6006161debf730106476c7b26e9ddec77245f57c 100644 (file)
@@ -523,6 +523,7 @@ geometry_node_categories = [
         NodeItem("ShaderNodeValue"),
         NodeItem("FunctionNodeInputString"),
         NodeItem("FunctionNodeInputVector"),
+        NodeItem("GeometryNodeInputMaterial"),
         NodeItem("GeometryNodeIsViewport"),
     ]),
     GeometryNodeCategory("GEO_MATERIAL", "Material", items=[
index 5ee4f5f5a993c4ee3a174e40c2bc27fb869c5b6d..a08a2edd5f6e96fd3f7cd4184186c98c35402e51 100644 (file)
@@ -1424,6 +1424,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_CURVE_RESAMPLE 1047
 #define GEO_NODE_ATTRIBUTE_VECTOR_ROTATE 1048
 #define GEO_NODE_MATERIAL_ASSIGN 1049
+#define GEO_NODE_INPUT_MATERIAL 1050
 
 /** \} */
 
index 6f961657d162e57558b7af2fea88d77d69fe3783..6405888d5bea9223d463cd2044e27be7fdbe232e 100644 (file)
@@ -5053,6 +5053,7 @@ static void registerGeometryNodes()
   register_node_type_geo_curve_to_mesh();
   register_node_type_geo_curve_resample();
   register_node_type_geo_edge_split();
+  register_node_type_geo_input_material();
   register_node_type_geo_is_viewport();
   register_node_type_geo_join_geometry();
   register_node_type_geo_material_assign();
index 6cb893d165782ab4fd81da18a4991246cecaa2a2..49abb892acc5ad50b3e18140418f48d06e0d4f53 100644 (file)
@@ -9858,6 +9858,19 @@ static void def_geo_attribute_transfer(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_geo_input_material(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
+  RNA_def_property_pointer_sdna(prop, NULL, "id");
+  RNA_def_property_struct_type(prop, "Material");
+  RNA_def_property_flag(prop, PROP_EDITABLE);
+  RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
+  RNA_def_property_ui_text(prop, "Material", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static void rna_def_shader_node(BlenderRNA *brna)
index ed2a6a24569d8c30a006a876d0c3face85642659..1096f2c9eb49b6ba87ebb8ab78c01bdfc0e33c5c 100644 (file)
@@ -165,6 +165,7 @@ set(SRC
   geometry/nodes/node_geo_curve_to_mesh.cc
   geometry/nodes/node_geo_curve_resample.cc
   geometry/nodes/node_geo_edge_split.cc
+  geometry/nodes/node_geo_input_material.cc
   geometry/nodes/node_geo_is_viewport.cc
   geometry/nodes/node_geo_join_geometry.cc
   geometry/nodes/node_geo_material_assign.cc
index 879092f1476afb14315850b79d1732e927c2c3b3..d43cd5044eef24d102ecbd64f4db483daecc2a63 100644 (file)
@@ -53,6 +53,7 @@ void register_node_type_geo_collection_info(void);
 void register_node_type_geo_curve_to_mesh(void);
 void register_node_type_geo_curve_resample(void);
 void register_node_type_geo_edge_split(void);
+void register_node_type_geo_input_material(void);
 void register_node_type_geo_is_viewport(void);
 void register_node_type_geo_join_geometry(void);
 void register_node_type_geo_material_assign(void);
index 3b2c7feb00ec5267c7f5c2d8a6fb9391d505f7b4..b49eb1b1d991e3b8b33544ecad2bd04ce20f4ae2 100644 (file)
@@ -292,6 +292,7 @@ DefNode(GeometryNode, GEO_NODE_COLLECTION_INFO, def_geo_collection_info, "COLLEC
 DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
 DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
+DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
 DefNode(GeometryNode, GEO_NODE_IS_VIEWPORT, 0, "IS_VIEWPORT", IsViewport, "Is Viewport", "")
 DefNode(GeometryNode, GEO_NODE_JOIN_GEOMETRY, 0, "JOIN_GEOMETRY", JoinGeometry, "Join Geometry", "")
 DefNode(GeometryNode, GEO_NODE_MATERIAL_ASSIGN, 0, "MATERIAL_ASSIGN", MaterialAssign, "Material Assign", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_material.cc b/source/blender/nodes/geometry/nodes/node_geo_input_material.cc
new file mode 100644 (file)
index 0000000..6bad71a
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_input_material_out[] = {
+    {SOCK_MATERIAL, N_("Material")},
+    {-1, ""},
+};
+
+static void geo_node_input_material_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "material", 0, "", ICON_NONE);
+}
+
+namespace blender::nodes {
+
+static void geo_node_input_material_exec(GeoNodeExecParams params)
+{
+  Material *material = (Material *)params.node().id;
+  params.set_output("Material", material);
+}
+
+}  // namespace blender::nodes
+
+void register_node_type_geo_input_material()
+{
+  static bNodeType ntype;
+
+  geo_node_type_base(&ntype, GEO_NODE_INPUT_MATERIAL, "Material", NODE_CLASS_INPUT, 0);
+  node_type_socket_templates(&ntype, nullptr, geo_node_input_material_out);
+  ntype.draw_buttons = geo_node_input_material_layout;
+  ntype.geometry_node_execute = blender::nodes::geo_node_input_material_exec;
+  nodeRegisterType(&ntype);
+}