[Bf-blender-cvs] [26c7be27b76] geometry-nodes: Geometry Nodes: Add boilerplate code for attribute math node
Hans Goudey
noreply at git.blender.org
Mon Nov 23 04:29:41 CET 2020
Commit: 26c7be27b76d66c9c96b0b353d883852d267a5d4
Author: Hans Goudey
Date: Sun Nov 22 22:17:08 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB26c7be27b76d66c9c96b0b353d883852d267a5d4
Geometry Nodes: Add boilerplate code for attribute math node
This code doesn't actually do anything, but it provides a base for an
implementation and exposes the the necessary interface to the UI.
===================================================================
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/makesrna/intern/rna_nodetree.c
M source/blender/nodes/CMakeLists.txt
M source/blender/nodes/NOD_geometry.h
M source/blender/nodes/NOD_static_types.h
A source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
===================================================================
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 66b452b3293..8ab872b83c7 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -487,6 +487,7 @@ geometry_node_categories = [
# Geometry Nodes
GeometryNodeCategory("GEO_ATTRIBUTE", "Attribute", items=[
NodeItem("GeometryNodeRandomAttribute"),
+ NodeItem("GeometryNodeAttributeMath"),
]),
GeometryNodeCategory("GEO_COLOR", "Color", items=[
NodeItem("ShaderNodeValToRGB"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 975500d164d..1cee60fe87d 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1346,6 +1346,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
#define GEO_NODE_SUBDIVISION_SURFACE 1006
#define GEO_NODE_OBJECT_INFO 1007
#define GEO_NODE_RANDOM_ATTRIBUTE 1008
+#define GEO_NODE_ATTRIBUTE_MATH 1009
/** \} */
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index fa3ee0979f1..ebdfb3c6cc0 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4691,6 +4691,7 @@ static void registerGeometryNodes(void)
register_node_type_geo_point_instance();
register_node_type_geo_object_info();
register_node_type_geo_random_attribute();
+ register_node_type_geo_attribute_math();
}
static void registerFunctionNodes(void)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 6e9da7982f2..56bbe8c8988 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -3171,6 +3171,13 @@ static void node_geometry_buts_random_attribute(uiLayout *layout,
uiItemR(layout, ptr, "domain", DEFAULT_FLAGS, "", ICON_NONE);
}
+static void node_geometry_buts_attribute_math(uiLayout *layout,
+ bContext *UNUSED(C),
+ PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "operation", DEFAULT_FLAGS, "", ICON_NONE);
+}
+
static void node_geometry_set_butfunc(bNodeType *ntype)
{
switch (ntype->type) {
@@ -3186,6 +3193,9 @@ static void node_geometry_set_butfunc(bNodeType *ntype)
case GEO_NODE_RANDOM_ATTRIBUTE:
ntype->draw_buttons = node_geometry_buts_random_attribute;
break;
+ case GEO_NODE_ATTRIBUTE_MATH:
+ ntype->draw_buttons = node_geometry_buts_attribute_math;
+ break;
}
}
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 7552ffdda85..ea0fc4b5567 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -1858,15 +1858,16 @@ static StructRNA *rna_Node_register(Main *bmain,
return nt->rna_ext.srna;
}
-static const EnumPropertyItem *generic_attribute_supported_list(
- const EnumPropertyItem *original_item_array, bool (*value_supported)(int value))
+static const EnumPropertyItem *itemf_function_check(
+ const EnumPropertyItem *original_item_array,
+ bool (*value_supported)(const EnumPropertyItem *item))
{
EnumPropertyItem *item_array = NULL;
int items_len = 0;
for (const EnumPropertyItem *item = original_item_array; item->identifier != NULL; item++) {
- if (value_supported(item->value)) {
- RNA_enum_items_add_value(&item_array, &items_len, original_item_array, item->value);
+ if (value_supported(item)) {
+ RNA_enum_item_add(&item_array, &items_len, item);
}
}
@@ -1874,28 +1875,42 @@ static const EnumPropertyItem *generic_attribute_supported_list(
return item_array;
}
-static bool attribute_random_type_supported(int value)
+static bool attribute_random_type_supported(const EnumPropertyItem *item)
{
- return ELEM(value, CD_PROP_FLOAT, CD_PROP_FLOAT3);
+ return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3);
}
static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_type_itemf(
bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
{
*r_free = true;
- return generic_attribute_supported_list(rna_enum_attribute_type_items,
- attribute_random_type_supported);
+ return itemf_function_check(rna_enum_attribute_type_items, attribute_random_type_supported);
}
-static bool attribute_random_domain_supported(int value)
+static bool attribute_random_domain_supported(const EnumPropertyItem *item)
{
- return value == ATTR_DOMAIN_POINT;
+ return item->value == ATTR_DOMAIN_POINT;
}
static const EnumPropertyItem *rna_GeometryNodeAttributeRandom_domain_itemf(
bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
{
*r_free = true;
- return generic_attribute_supported_list(rna_enum_attribute_domain_items,
- attribute_random_domain_supported);
+ return itemf_function_check(rna_enum_attribute_domain_items, attribute_random_domain_supported);
+}
+
+static bool attribute_math_operation_supported(const EnumPropertyItem *item)
+{
+ return ELEM(item->value,
+ NODE_MATH_ADD,
+ NODE_MATH_SUBTRACT,
+ NODE_MATH_MULTIPLY,
+ NODE_MATH_DIVIDE) &&
+ (item->identifier[0] != '\0');
+}
+static const EnumPropertyItem *rna_GeometryNodeAttributeMath_operation_itemf(
+ bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ *r_free = true;
+ return itemf_function_check(rna_enum_node_math_items, attribute_math_operation_supported);
}
static StructRNA *rna_ShaderNode_register(Main *bmain,
@@ -8346,6 +8361,19 @@ static void def_geo_random_attribute(StructRNA *srna)
"rna_GeometryNodeAttributeRandom_domain_itemf");
}
+static void def_geo_attribute_math(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_math_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_GeometryNodeAttributeMath_operation_itemf");
+ RNA_def_property_enum_default(prop, NODE_MATH_ADD);
+ RNA_def_property_ui_text(prop, "Operation", "");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
/* -------------------------------------------------------------------------- */
static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 570fc5e8bd2..3585703fb7d 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -138,6 +138,7 @@ set(SRC
function/nodes/node_fn_switch.cc
function/node_function_util.cc
+ geometry/nodes/node_geo_attribute_math.cc
geometry/nodes/node_geo_common.cc
geometry/nodes/node_geo_boolean.cc
geometry/nodes/node_geo_edge_split.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 9c86b02a3b1..102e370e132 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -35,6 +35,7 @@ void register_node_type_geo_point_distribute(void);
void register_node_type_geo_point_instance(void);
void register_node_type_geo_object_info(void);
void register_node_type_geo_random_attribute(void);
+void register_node_type_geo_attribute_math(void);
#ifdef __cplusplus
}
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index e332dc358da..170fecb256d 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -275,6 +275,7 @@ DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, 0, "POINT_DISTRIBUTE", PointDis
DefNode(GeometryNode, GEO_NODE_POINT_INSTANCE, 0, "POINT_INSTANCE", PointInstance, "Point Instance", "")
DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "")
DefNode(GeometryNode, GEO_NODE_RANDOM_ATTRIBUTE, def_geo_random_attribute, "RANDOM_ATTRIBUTE", RandomAttribute, "Random Attribute", "")
+DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MATH, def_geo_attribute_math, "ATTRIBUTE_MATH", AttributeMath, "Attribute Math", "")
/* undefine macros */
#undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
new file mode 100644
index 00000000000..e6ccb0efdce
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
@@ -0,0 +1,70 @@
+/*
+ * 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_geometry_util.hh"
+
+#include "BKE_attribute.h"
+
+#include "BLI_rand.hh"
+
+#include "DNA_mesh_types.h"
+#include "DNA_pointcloud_types.h"
+
+static bNodeSocketTemplate geo_node_attribute_math_in[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {SOCK_STRING, N_("Attribute A")},
+ {SOCK_STRING, N_("Attribute B")},
+ {SOCK_STRING, N_("Result")},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_attribute_math_out[] = {
+ {SOCK_GEOMETRY, N_("Geometry")},
+ {-1, ""},
+};
+
+namespace blender::nodes {
+
+static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecParams ¶ms)
+{
+ UNUSED_VARS(component, params);
+}
+
+static void geo_attribute_math_exec(GeoNo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list