Geometry Nodes: Rewrite mesh delete geometry node #108435

Merged
Hans Goudey merged 24 commits from HooglyBoogly/blender:delete-mesh-rewrite into main 2023-06-01 14:55:27 +02:00
3 changed files with 30 additions and 21 deletions
Showing only changes of commit eaecd3303b - Show all commits

View File

@ -2,6 +2,8 @@
#pragma once #pragma once
#include <optional>
#include "BKE_attribute.h" #include "BKE_attribute.h"
struct Mesh; struct Mesh;
@ -17,18 +19,18 @@ class AnonymousAttributePropagationInfo;
namespace blender::geometry { namespace blender::geometry {
Mesh *mesh_copy_selection(const Mesh &src_mesh, std::optional<Mesh *>mesh_copy_selection(const Mesh &src_mesh,
const fn::Field<bool> &selection, const fn::Field<bool> &selection,
eAttrDomain selection_domain, eAttrDomain selection_domain,
const bke::AnonymousAttributePropagationInfo &propagation_info); const bke::AnonymousAttributePropagationInfo &propagation_info);
Mesh *mesh_copy_selection_keep_verts( std::optional<Mesh *>mesh_copy_selection_keep_verts(
const Mesh &src_mesh, const Mesh &src_mesh,
const fn::Field<bool> &selection, const fn::Field<bool> &selection,
eAttrDomain selection_domain, eAttrDomain selection_domain,
const bke::AnonymousAttributePropagationInfo &propagation_info); const bke::AnonymousAttributePropagationInfo &propagation_info);
Mesh *mesh_copy_selection_keep_edges( std::optional<Mesh *>mesh_copy_selection_keep_edges(
const Mesh &mesh, const Mesh &mesh,
const fn::Field<bool> &selection, const fn::Field<bool> &selection,
const eAttrDomain selection_domain, const eAttrDomain selection_domain,

View File

@ -159,10 +159,11 @@ static IndexMask poly_selection_from_edge(const OffsetIndices<int> polys,
return poly_selection_from_mapped_corner(polys, corner_edges, edge_mask, memory); return poly_selection_from_mapped_corner(polys, corner_edges, edge_mask, memory);
} }
Mesh *mesh_copy_selection(const Mesh &src_mesh, std::optional<Mesh *> mesh_copy_selection(
const fn::Field<bool> &selection_field, const Mesh &src_mesh,
const eAttrDomain selection_domain, const fn::Field<bool> &selection_field,
const bke::AnonymousAttributePropagationInfo &propagation_info) const eAttrDomain selection_domain,
const bke::AnonymousAttributePropagationInfo &propagation_info)
{ {
const Span<int2> src_edges = src_mesh.edges(); const Span<int2> src_edges = src_mesh.edges();
const OffsetIndices src_polys = src_mesh.polys(); const OffsetIndices src_polys = src_mesh.polys();
@ -176,7 +177,7 @@ Mesh *mesh_copy_selection(const Mesh &src_mesh,
evaluator.evaluate(); evaluator.evaluate();
const VArray<bool> selection = evaluator.get_evaluated<bool>(0); const VArray<bool> selection = evaluator.get_evaluated<bool>(0);
if (const std::optional<bool> single = selection.get_if_single()) { if (const std::optional<bool> single = selection.get_if_single()) {
return *single ? BKE_mesh_copy_for_eval(&src_mesh) : nullptr; return *single ? std::nullopt : std::make_optional<Mesh *>(nullptr);
} }
threading::EnumerableThreadSpecific<IndexMaskMemory> memory; threading::EnumerableThreadSpecific<IndexMaskMemory> memory;
@ -235,7 +236,7 @@ Mesh *mesh_copy_selection(const Mesh &src_mesh,
return nullptr; return nullptr;
} }
if (vert_mask.size() == src_mesh.totvert) { if (vert_mask.size() == src_mesh.totvert) {
return BKE_mesh_copy_for_eval(&src_mesh); return std::nullopt;
} }
Mesh *dst_mesh = BKE_mesh_new_nomain(vert_mask.size(), edge_mask.size(), poly_mask.size(), 0); Mesh *dst_mesh = BKE_mesh_new_nomain(vert_mask.size(), edge_mask.size(), poly_mask.size(), 0);
@ -300,7 +301,7 @@ Mesh *mesh_copy_selection(const Mesh &src_mesh,
return dst_mesh; return dst_mesh;
} }
Mesh *mesh_copy_selection_keep_verts( std::optional<Mesh *> mesh_copy_selection_keep_verts(
const Mesh &src_mesh, const Mesh &src_mesh,
const fn::Field<bool> &selection_field, const fn::Field<bool> &selection_field,
const eAttrDomain selection_domain, const eAttrDomain selection_domain,
@ -318,7 +319,7 @@ Mesh *mesh_copy_selection_keep_verts(
evaluator.evaluate(); evaluator.evaluate();
const VArray<bool> selection = evaluator.get_evaluated<bool>(0); const VArray<bool> selection = evaluator.get_evaluated<bool>(0);
if (const std::optional<bool> single = selection.get_if_single()) { if (const std::optional<bool> single = selection.get_if_single()) {
return *single ? BKE_mesh_copy_for_eval(&src_mesh) : nullptr; return *single ? std::nullopt : std::make_optional<Mesh *>(nullptr);
} }
threading::EnumerableThreadSpecific<IndexMaskMemory> memory; threading::EnumerableThreadSpecific<IndexMaskMemory> memory;
@ -367,7 +368,7 @@ Mesh *mesh_copy_selection_keep_verts(
return nullptr; return nullptr;
} }
if (edge_mask.size() == src_mesh.totedge) { if (edge_mask.size() == src_mesh.totedge) {
return BKE_mesh_copy_for_eval(&src_mesh); return std::nullopt;
} }
Mesh *dst_mesh = BKE_mesh_new_nomain(0, edge_mask.size(), poly_mask.size(), 0); Mesh *dst_mesh = BKE_mesh_new_nomain(0, edge_mask.size(), poly_mask.size(), 0);
@ -416,7 +417,7 @@ Mesh *mesh_copy_selection_keep_verts(
return dst_mesh; return dst_mesh;
} }
Mesh *mesh_copy_selection_keep_edges( std::optional<Mesh *> mesh_copy_selection_keep_edges(
const Mesh &src_mesh, const Mesh &src_mesh,
const fn::Field<bool> &selection_field, const fn::Field<bool> &selection_field,
const eAttrDomain selection_domain, const eAttrDomain selection_domain,
@ -428,9 +429,10 @@ Mesh *mesh_copy_selection_keep_edges(
const bke::MeshFieldContext context(src_mesh, selection_domain); const bke::MeshFieldContext context(src_mesh, selection_domain);
fn::FieldEvaluator evaluator(context, src_attributes.domain_size(selection_domain)); fn::FieldEvaluator evaluator(context, src_attributes.domain_size(selection_domain));
evaluator.add(selection_field); evaluator.add(selection_field);
evaluator.evaluate();
const VArray<bool> selection = evaluator.get_evaluated<bool>(0); const VArray<bool> selection = evaluator.get_evaluated<bool>(0);
if (const std::optional<bool> single = selection.get_if_single()) { if (const std::optional<bool> single = selection.get_if_single()) {
return *single ? BKE_mesh_copy_for_eval(&src_mesh) : nullptr; return *single ? std::nullopt : std::make_optional<Mesh *>(nullptr);
} }
IndexMaskMemory memory; IndexMaskMemory memory;
@ -456,7 +458,7 @@ Mesh *mesh_copy_selection_keep_edges(
return nullptr; return nullptr;
} }
if (poly_mask.size() == src_mesh.totpoly) { if (poly_mask.size() == src_mesh.totpoly) {
return BKE_mesh_copy_for_eval(&src_mesh); return std::nullopt;
} }
Mesh *dst_mesh = BKE_mesh_new_nomain(0, 0, poly_mask.size(), 0); Mesh *dst_mesh = BKE_mesh_new_nomain(0, 0, poly_mask.size(), 0);

View File

@ -108,11 +108,12 @@ static void delete_selected_instances(GeometrySet &geometry_set,
instances.remove(selection, propagation_info); instances.remove(selection, propagation_info);
} }
static Mesh *separate_mesh_selection(const Mesh &mesh, static std::optional<Mesh *> separate_mesh_selection(
const Field<bool> &selection, const Mesh &mesh,
const eAttrDomain selection_domain, const Field<bool> &selection,
const GeometryNodeDeleteGeometryMode mode, const eAttrDomain selection_domain,
const AnonymousAttributePropagationInfo &propagation_info) const GeometryNodeDeleteGeometryMode mode,
const AnonymousAttributePropagationInfo &propagation_info)
{ {
switch (mode) { switch (mode) {
case GEO_NODE_DELETE_GEOMETRY_MODE_ALL: case GEO_NODE_DELETE_GEOMETRY_MODE_ALL:
@ -153,7 +154,11 @@ void separate_geometry(GeometrySet &geometry_set,
} }
if (const Mesh *mesh = geometry_set.get_mesh_for_read()) { if (const Mesh *mesh = geometry_set.get_mesh_for_read()) {
if (ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE, ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER)) { if (ELEM(domain, ATTR_DOMAIN_POINT, ATTR_DOMAIN_EDGE, ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER)) {
file_ns::separate_mesh_selection(*mesh, selection, domain, mode, propagation_info); std::optional<Mesh *> dst_mesh = file_ns::separate_mesh_selection(
*mesh, selection, domain, mode, propagation_info);
if (dst_mesh) {
geometry_set.replace_mesh(*dst_mesh);
}
some_valid_domain = true; some_valid_domain = true;
} }
} }