Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-12-29 20:31:58 +0300
committerHans Goudey <h.goudey@me.com>2021-12-29 20:31:58 +0300
commita94d80716e688aaa5350b63bd49a952fb1fbca97 (patch)
treef2ae7b0113d38546b029a9cc66bd6b8da1a7f560 /source/blender/nodes
parenta836ded9902d67359ea94a03c45de7edd4f826fb (diff)
Geometry Nodes: Support instances in the delete geometry node
Ever since the instance domain was added, this was exposed, it just didn't do anything. This patch implements the instances domain in the delete and separate geometry nodes, where it acts on the top-level instances. We act on a mutable instances input, with the idea that eventually copy on write attribute layers will make this less expensive. It also allows us to keep the instance references in place and to do less work in some situations. Ref T93554 Differential Revision: https://developer.blender.org/D13565
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc32
1 files changed, 31 insertions, 1 deletions
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 a5197b23adb..7d41242b8bc 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
@@ -529,6 +529,30 @@ static void separate_point_cloud_selection(GeometrySet &geometry_set,
geometry_set.replace_pointcloud(pointcloud);
}
+static void separate_instance_selection(GeometrySet &geometry_set,
+ const Field<bool> &selection_field,
+ const bool invert)
+{
+ InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>();
+ GeometryComponentFieldContext field_context{instances, ATTR_DOMAIN_INSTANCE};
+
+ const int domain_size = instances.attribute_domain_size(ATTR_DOMAIN_INSTANCE);
+ fn::FieldEvaluator evaluator{field_context, domain_size};
+ evaluator.add(selection_field);
+ evaluator.evaluate();
+ const VArray_Span<bool> &selection = evaluator.get_evaluated<bool>(0);
+
+ Vector<int64_t> indices;
+ const IndexMask mask = index_mask_indices(selection, invert, indices);
+
+ if (mask.size() == 0) {
+ geometry_set.remove<InstancesComponent>();
+ return;
+ }
+
+ instances.remove_instances(mask);
+}
+
static void compute_selected_vertices_from_vertex_selection(const Span<bool> vertex_selection,
const bool invert,
MutableSpan<int> r_vertex_map,
@@ -1261,7 +1285,7 @@ void separate_geometry(GeometrySet &geometry_set,
}
}
if (geometry_set.has_mesh()) {
- if (domain != ATTR_DOMAIN_CURVE) {
+ if (ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE, ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER)) {
separate_mesh_selection(geometry_set, selection_field, domain, mode, invert);
some_valid_domain = true;
}
@@ -1272,6 +1296,12 @@ void separate_geometry(GeometrySet &geometry_set,
some_valid_domain = true;
}
}
+ if (geometry_set.has_instances()) {
+ if (domain == ATTR_DOMAIN_INSTANCE) {
+ separate_instance_selection(geometry_set, selection_field, invert);
+ some_valid_domain = true;
+ }
+ }
r_is_error = !some_valid_domain && geometry_set.has_realized_data();
}