diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-30 19:08:27 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-30 19:08:27 +0300 |
commit | 82a46ea6f8829fc40205d0d3cabf4017eb738d9a (patch) | |
tree | 0db4cf9f7a8767f98435d8b0a6589c5c783325ec /source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc | |
parent | 4d107041ec78c96825dd103cacfe9704a2e59532 (diff) |
Geometry Nodes: Use separate field context for each geometry type
Using the same `GeometryComponentFieldContext` for all situations,
even when only one geometry type is supported is misleading, and mixes
too many different abstraction levels into code that could be simpler.
With the attribute API moved out of geometry components recently,
the "component" system is just getting in the way here.
This commit adds specific field contexts for geometry types: meshes,
curves, point clouds, and instances. There are also separate field input
helper classes, to help reduce boilerplate for fields that only support
specific geometry types.
Another benefit of this change is that it separates geometry components
from fields, which makes it easier to see the purpose of the two concepts,
and how they relate.
Because we want to be able to evaluate a field on just `CurvesGeometry`
rather than the full `Curves` data-block, the generic "geometry context"
had to be changed to avoid using `GeometryComponent`, since there is
no corresponding geometry component type. The resulting void pointer
is ugly, but only turns up in three places in practice. When Apple clang
supports `std::variant`, that could be used instead.
Differential Revision: https://developer.blender.org/D15519
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc | 52 |
1 files changed, 19 insertions, 33 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc index 2c7eef5665f..5752535d149 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_island.cc @@ -22,39 +22,32 @@ static void node_declare(NodeDeclarationBuilder &b) .description(N_("The total number of mesh islands")); } -class IslandFieldInput final : public GeometryFieldInput { +class IslandFieldInput final : public bke::MeshFieldInput { public: - IslandFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Island Index") + IslandFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Island Index") { category_ = Category::Generated; } - GVArray get_varray_for_context(const GeometryComponent &component, + GVArray get_varray_for_context(const Mesh &mesh, const eAttrDomain domain, IndexMask UNUSED(mask)) const final { - if (component.type() != GEO_COMPONENT_TYPE_MESH) { - return {}; - } - const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); - const Mesh *mesh = mesh_component.get_for_read(); - if (mesh == nullptr) { - return {}; - } + const Span<MEdge> edges(mesh.medge, mesh.totedge); - DisjointSet islands(mesh->totvert); - for (const int i : IndexRange(mesh->totedge)) { - islands.join(mesh->medge[i].v1, mesh->medge[i].v2); + DisjointSet islands(mesh.totvert); + for (const int i : edges.index_range()) { + islands.join(edges[i].v1, edges[i].v2); } - Array<int> output(mesh->totvert); + Array<int> output(mesh.totvert); VectorSet<int> ordered_roots; - for (const int i : IndexRange(mesh->totvert)) { + for (const int i : IndexRange(mesh.totvert)) { const int64_t root = islands.find_root(i); output[i] = ordered_roots.index_of_or_add(root); } - return mesh_component.attributes()->adapt_domain<int>( + return bke::mesh_attributes(mesh).adapt_domain<int>( VArray<int>::ForContainer(std::move(output)), ATTR_DOMAIN_POINT, domain); } @@ -70,39 +63,32 @@ class IslandFieldInput final : public GeometryFieldInput { } }; -class IslandCountFieldInput final : public GeometryFieldInput { +class IslandCountFieldInput final : public bke::MeshFieldInput { public: - IslandCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Island Count") + IslandCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Island Count") { category_ = Category::Generated; } - GVArray get_varray_for_context(const GeometryComponent &component, + GVArray get_varray_for_context(const Mesh &mesh, const eAttrDomain domain, IndexMask UNUSED(mask)) const final { - if (component.type() != GEO_COMPONENT_TYPE_MESH) { - return {}; - } - const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); - const Mesh *mesh = mesh_component.get_for_read(); - if (mesh == nullptr) { - return {}; - } + const Span<MEdge> edges(mesh.medge, mesh.totedge); - DisjointSet islands(mesh->totvert); - for (const int i : IndexRange(mesh->totedge)) { - islands.join(mesh->medge[i].v1, mesh->medge[i].v2); + DisjointSet islands(mesh.totvert); + for (const int i : edges.index_range()) { + islands.join(edges[i].v1, edges[i].v2); } Set<int> island_list; - for (const int i_vert : IndexRange(mesh->totvert)) { + for (const int i_vert : IndexRange(mesh.totvert)) { const int64_t root = islands.find_root(i_vert); island_list.add(root); } return VArray<int>::ForSingle(island_list.size(), - mesh_component.attribute_domain_size(domain)); + bke::mesh_attributes(mesh).domain_size(domain)); } uint64_t hash() const override |