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:
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.cc67
1 files changed, 31 insertions, 36 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..6b54828b042 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
+ const IndexMask /*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.edges();
- 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 mesh.attributes().adapt_domain<int>(
VArray<int>::ForContainer(std::move(output)), ATTR_DOMAIN_POINT, domain);
}
@@ -68,41 +61,38 @@ class IslandFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const IslandFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
-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
+ const IndexMask /*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.edges();
- 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));
+ return VArray<int>::ForSingle(island_list.size(), mesh.attributes().domain_size(domain));
}
uint64_t hash() const override
@@ -115,6 +105,11 @@ class IslandCountFieldInput final : public GeometryFieldInput {
{
return dynamic_cast<const IslandCountFieldInput *>(&other) != nullptr;
}
+
+ std::optional<eAttrDomain> preferred_domain(const Mesh & /*mesh*/) const override
+ {
+ return ATTR_DOMAIN_POINT;
+ }
};
static void node_geo_exec(GeoNodeExecParams params)