[Bf-blender-cvs] [801034ba6a2] temp-geometry-nodes-fields-prototype: Support field selection in the geometry delete node
Hans Goudey
noreply at git.blender.org
Tue Aug 3 04:42:45 CEST 2021
Commit: 801034ba6a2e934d51274ad1454cdeae05e3c456
Author: Hans Goudey
Date: Mon Aug 2 22:42:34 2021 -0400
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB801034ba6a2e934d51274ad1454cdeae05e3c456
Support field selection in the geometry delete node
===================================================================
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/NOD_static_types.h
M source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
===================================================================
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 4cbed2b6a33..a235c521033 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9146,6 +9146,18 @@ static void def_geo_attribute_convert(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
+static void def_geo_delete(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "custom1");
+ RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items);
+ RNA_def_property_enum_default(prop, ATTR_DOMAIN_POINT);
+ RNA_def_property_ui_text(prop, "Domain", "");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
static void def_geo_attribute_math(StructRNA *srna)
{
PropertyRNA *prop;
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 699fedd9fcd..5a9f6f6af4b 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -308,7 +308,7 @@ DefNode(GeometryNode, GEO_NODE_CURVE_SUBDIVIDE, def_geo_curve_subdivide, "CURVE_
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", "")
-DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, 0, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "")
+DefNode(GeometryNode, GEO_NODE_DELETE_GEOMETRY, def_geo_delete, "DELETE_GEOMETRY", DeleteGeometry, "Delete Geometry", "")
DefNode(GeometryNode, GEO_NODE_EDGE_SPLIT, 0, "EDGE_SPLIT", EdgeSplit, "Edge Split", "")
DefNode(GeometryNode, GEO_NODE_INDEX, 0, "INDEX", Index, "Index", "")
DefNode(GeometryNode, GEO_NODE_INPUT_MATERIAL, def_geo_input_material, "INPUT_MATERIAL", InputMaterial, "Material", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
index 8c697275f88..2b29c4cae4f 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
@@ -24,6 +24,9 @@
#include "BKE_pointcloud.h"
#include "BKE_spline.hh"
+#include "UI_interface.h"
+#include "UI_resources.h"
+
#include "node_geometry_util.hh"
using blender::bke::CustomDataAttributes;
@@ -45,8 +48,7 @@ extern void copy_masked_polys_to_new_mesh(const Mesh &src_mesh,
static bNodeSocketTemplate geo_node_delete_geometry_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
- {SOCK_STRING, N_("Selection")},
- {SOCK_BOOLEAN, N_("Invert")},
+ {SOCK_BOOLEAN, N_("Selection"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_HIDE_VALUE},
{-1, ""},
};
@@ -55,6 +57,18 @@ static bNodeSocketTemplate geo_node_delete_geometry_out[] = {
{-1, ""},
};
+static void geo_node_delete_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+ uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
+}
+
+static void geo_node_delete_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ node->custom1 = ATTR_DOMAIN_POINT;
+}
+
namespace blender::nodes {
template<typename T> static void copy_data(Span<T> data, MutableSpan<T> r_data, IndexMask mask)
@@ -130,7 +144,8 @@ static SplinePtr spline_delete(const Spline &spline, const IndexMask mask)
}
static std::unique_ptr<CurveEval> curve_delete(const CurveEval &input_curve,
- const StringRef name,
+ const AttributeDomain domain,
+ const Span<bool> selection,
const bool invert)
{
Span<SplinePtr> input_splines = input_curve.splines();
@@ -139,8 +154,7 @@ static std::unique_ptr<CurveEval> curve_delete(const CurveEval &input_curve,
/* Keep track of which splines were copied to the result to copy spline domain attributes. */
Vector<int64_t> copied_splines;
- if (input_curve.attributes.get_for_read(name)) {
- GVArray_Typed<bool> selection = input_curve.attributes.get_for_read<bool>(name, false);
+ if (domain == ATTR_DOMAIN_CURVE) {
for (const int i : input_splines.index_range()) {
if (selection[i] == invert) {
output_curve->add_spline(input_splines[i]->copy());
@@ -148,17 +162,18 @@ static std::unique_ptr<CurveEval> curve_delete(const CurveEval &input_curve,
}
}
}
- else {
+ else if (domain == ATTR_DOMAIN_POINT) {
/* Reuse index vector for each spline. */
Vector<int64_t> indices_to_copy;
+ Array<int> offsets = input_curve.control_point_offsets();
+
for (const int i : input_splines.index_range()) {
const Spline &spline = *input_splines[i];
- GVArray_Typed<bool> selection = spline.attributes.get_for_read<bool>(name, false);
indices_to_copy.clear();
for (const int i_point : IndexRange(spline.size())) {
- if (selection[i_point] == invert) {
+ if (selection[offsets[i] + i_point] == invert) {
indices_to_copy.append(i_point);
}
}
@@ -187,11 +202,24 @@ static std::unique_ptr<CurveEval> curve_delete(const CurveEval &input_curve,
static void delete_curve_selection(const CurveComponent &in_component,
CurveComponent &r_component,
- const StringRef selection_name,
+ const GeoNodeExecParams ¶ms,
const bool invert)
{
+ const AttributeDomain selection_domain = static_cast<AttributeDomain>(params.node().custom1);
+
+ bke::FieldRef<bool> field = params.get_input_field<bool>("Selection");
+ bke::FieldInputs field_inputs = field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> field_input_values;
+ prepare_field_inputs(field_inputs, in_component, selection_domain, field_input_values);
+ bke::FieldOutput field_output = field->evaluate(
+ IndexRange(in_component.attribute_domain_size(selection_domain)), field_inputs);
+
+ GVArray_Typed<bool> selection_gvarray{field_output.varray_ref()};
+ VArray_Span<bool> selection{selection_gvarray};
+
std::unique_ptr<CurveEval> r_curve = curve_delete(
- *in_component.get_for_read(), selection_name, invert);
+ *in_component.get_for_read(), selection_domain, selection, invert);
+
if (r_curve) {
r_component.replace(r_curve.release());
}
@@ -202,12 +230,20 @@ static void delete_curve_selection(const CurveComponent &in_component,
static void delete_point_cloud_selection(const PointCloudComponent &in_component,
PointCloudComponent &out_component,
- const StringRef selection_name,
+ const GeoNodeExecParams ¶ms,
const bool invert)
{
- const GVArray_Typed<bool> selection_attribute = in_component.attribute_get_for_read<bool>(
- selection_name, ATTR_DOMAIN_POINT, false);
- VArray_Span<bool> selection{selection_attribute};
+ const AttributeDomain selection_domain = static_cast<AttributeDomain>(params.node().custom1);
+
+ bke::FieldRef<bool> field = params.get_input_field<bool>("Selection");
+ bke::FieldInputs field_inputs = field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> field_input_values;
+ prepare_field_inputs(field_inputs, in_component, selection_domain, field_input_values);
+ bke::FieldOutput field_output = field->evaluate(
+ IndexRange(in_component.attribute_domain_size(selection_domain)), field_inputs);
+
+ GVArray_Typed<bool> selection_gvarray{field_output.varray_ref()};
+ VArray_Span<bool> selection{selection_gvarray};
const int total = selection.count(invert);
if (total == 0) {
@@ -567,34 +603,21 @@ static Mesh *delete_mesh_selection(const Mesh &mesh_in,
return result;
}
-static AttributeDomain get_mesh_selection_domain(MeshComponent &component, const StringRef name)
-{
- std::optional<AttributeMetaData> selection_attribute = component.attribute_get_meta_data(name);
- if (!selection_attribute) {
- /* The node will not do anything in this case, but this function must return something. */
- return ATTR_DOMAIN_POINT;
- }
-
- /* Corners can't be deleted separately, so interpolate corner attributes
- * to the face domain. Note that this choice is somewhat arbitrary. */
- if (selection_attribute->domain == ATTR_DOMAIN_CORNER) {
- return ATTR_DOMAIN_FACE;
- }
-
- return selection_attribute->domain;
-}
-
static void delete_mesh_selection(MeshComponent &component,
const Mesh &mesh_in,
- const StringRef selection_name,
+ const GeoNodeExecParams ¶ms,
const bool invert)
{
- /* Figure out the best domain to use. */
- const AttributeDomain selection_domain = get_mesh_selection_domain(component, selection_name);
+ const AttributeDomain selection_domain = static_cast<AttributeDomain>(params.node().custom1);
- /* This already checks if the attribute exists, and displays a warning in that case. */
- GVArray_Typed<bool> selection = component.attribute_get_for_read<bool>(
- selection_name, selection_domain, false);
+ bke::FieldRef<bool> field = params.get_input_field<bool>("Selection");
+ bke::FieldInputs field_inputs = field->prepare_inputs();
+ Vector<std::unique_ptr<bke::FieldInputValue>> field_input_values;
+ prepare_field_inputs(field_inputs, component, selection_domain, field_input_values);
+ bke::FieldOutput field_output = field->evaluate(
+ IndexRange(component.attribute_domain_size(selection_domain)), field_inputs);
+
+ GVArray_Typed<bool> selection{field_output.varray_ref()};
/* Check if there
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list