[Bf-blender-cvs] [648fa6d89e6] temp-geometry-nodes-fields-prototype: Support fields in the curve subdivide node

Hans Goudey noreply at git.blender.org
Tue Aug 3 05:58:41 CEST 2021


Commit: 648fa6d89e63bf1cd6583648c85acbc2744c2bf5
Author: Hans Goudey
Date:   Mon Aug 2 23:58:33 2021 -0400
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB648fa6d89e63bf1cd6583648c85acbc2744c2bf5

Support fields in the curve subdivide node

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

M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc

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

diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 041fd0f443e..75613de6d16 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1387,11 +1387,6 @@ typedef struct NodeGeometryCurveResample {
   uint8_t mode;
 } NodeGeometryCurveResample;
 
-typedef struct NodeGeometryCurveSubdivide {
-  /* GeometryNodeAttributeInputMode (integer or attribute). */
-  uint8_t cuts_type;
-} NodeGeometryCurveSubdivide;
-
 typedef struct NodeGeometryCurveTrim {
   /* GeometryNodeCurveInterpolateMode. */
   uint8_t mode;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index d5bde2c0173..59523a42159 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10065,18 +10065,6 @@ static void def_geo_curve_resample(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
 }
 
-static void def_geo_curve_subdivide(StructRNA *srna)
-{
-  PropertyRNA *prop;
-
-  RNA_def_struct_sdna_from(srna, "NodeGeometryCurveSubdivide", "storage");
-
-  prop = RNA_def_property(srna, "cuts_type", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_int);
-  RNA_def_property_ui_text(prop, "Cuts Type", "");
-  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
-}
-
 static void def_geo_curve_to_points(StructRNA *srna)
 {
   PropertyRNA *prop;
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 5a9f6f6af4b..0d94fd5625a 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -304,7 +304,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_PRIMITIVE_STAR, 0, "CURVE_PRIMITIVE_STAR",
 DefNode(GeometryNode, GEO_NODE_CURVE_RESAMPLE, def_geo_curve_resample, "CURVE_RESAMPLE", CurveResample, "Resample Curve", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_REVERSE, 0, "CURVE_REVERSE", CurveReverse, "Curve Reverse", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_SET_HANDLES, def_geo_curve_set_handles, "CURVE_SET_HANDLES", CurveSetHandles, "Set Handle Type", "")
-DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_SUBDIVIDE", CurveSubdivide, "Curve Subdivide", "")
+DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, 0, "CURVE_SUBDIVIDE", CurveSubdivide, "Curve Subdivide", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_MESH, 0, "CURVE_TO_MESH", CurveToMesh, "Curve to Mesh", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TO_POINTS, def_geo_curve_to_points, "CURVE_TO_POINTS", CurveToPoints, "Curve to Points", "")
 DefNode(GeometryNode, GEO_NODE_CURVE_TRIM, def_geo_curve_trim, "CURVE_TRIM", CurveTrim, "Curve Trim", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
index 7908c26e2dc..d3846cd587e 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
@@ -31,7 +31,6 @@ using blender::fn::GVArray_Typed;
 
 static bNodeSocketTemplate geo_node_curve_subdivide_in[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
-    {SOCK_STRING, N_("Cuts")},
     {SOCK_INT, N_("Cuts"), 1, 0, 0, 0, 0, 1000},
     {-1, ""},
 };
@@ -41,32 +40,8 @@ static bNodeSocketTemplate geo_node_curve_subdivide_out[] = {
     {-1, ""},
 };
 
-static void geo_node_curve_subdivide_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
-  uiLayoutSetPropSep(layout, true);
-  uiLayoutSetPropDecorate(layout, false);
-  uiItemR(layout, ptr, "cuts_type", 0, IFACE_("Cuts"), ICON_NONE);
-}
-
-static void geo_node_curve_subdivide_init(bNodeTree *UNUSED(tree), bNode *node)
-{
-  NodeGeometryCurveSubdivide *data = (NodeGeometryCurveSubdivide *)MEM_callocN(
-      sizeof(NodeGeometryCurveSubdivide), __func__);
-
-  data->cuts_type = GEO_NODE_ATTRIBUTE_INPUT_INTEGER;
-  node->storage = data;
-}
-
 namespace blender::nodes {
 
-static void geo_node_curve_subdivide_update(bNodeTree *UNUSED(ntree), bNode *node)
-{
-  NodeGeometryPointTranslate &node_storage = *(NodeGeometryPointTranslate *)node->storage;
-
-  update_attribute_input_socket_availabilities(
-      *node, "Cuts", (GeometryNodeAttributeInputMode)node_storage.input_type);
-}
-
 static Array<int> get_subdivided_offsets(const Spline &spline,
                                          const VArray<int> &cuts,
                                          const int spline_offset)
@@ -363,10 +338,18 @@ static void geo_node_subdivide_exec(GeoNodeExecParams params)
   }
 
   const CurveComponent &component = *geometry_set.get_component_for_read<CurveComponent>();
-  GVArray_Typed<int> cuts = params.get_input_attribute<int>(
-      "Cuts", component, ATTR_DOMAIN_POINT, 0);
+
+  bke::FieldRef<int> field = params.get_input_field<int>("Cuts");
+  bke::FieldInputs field_inputs = field->prepare_inputs();
+  Vector<std::unique_ptr<bke::FieldInputValue>> field_input_values;
+  prepare_field_inputs(field_inputs, component, ATTR_DOMAIN_POINT, field_input_values);
+  bke::FieldOutput field_output = field->evaluate(
+      IndexRange(component.attribute_domain_size(ATTR_DOMAIN_POINT)), field_inputs);
+
+  GVArray_Typed<int> cuts{field_output.varray_ref()};
+
   if (cuts->is_single() && cuts->get_internal_single() < 1) {
-    params.set_output("Geometry", geometry_set);
+    params.set_output("Geometry", std::move(geometry_set));
     return;
   }
 
@@ -383,13 +366,6 @@ void register_node_type_geo_curve_subdivide()
 
   geo_node_type_base(&ntype, GEO_NODE_CURVE_SUBDIVIDE, "Curve Subdivide", NODE_CLASS_GEOMETRY, 0);
   node_type_socket_templates(&ntype, geo_node_curve_subdivide_in, geo_node_curve_subdivide_out);
-  ntype.draw_buttons = geo_node_curve_subdivide_layout;
-  node_type_storage(&ntype,
-                    "NodeGeometryCurveSubdivide",
-                    node_free_standard_storage,
-                    node_copy_standard_storage);
-  node_type_init(&ntype, geo_node_curve_subdivide_init);
-  node_type_update(&ntype, blender::nodes::geo_node_curve_subdivide_update);
   ntype.geometry_node_execute = blender::nodes::geo_node_subdivide_exec;
   nodeRegisterType(&ntype);
 }



More information about the Bf-blender-cvs mailing list