diff options
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc | 66 |
1 files changed, 25 insertions, 41 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc index a225ce61b14..9e85eae3a31 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_input_mesh_face_neighbors.cc @@ -19,48 +19,41 @@ static void node_declare(NodeDeclarationBuilder &b) .description(N_("Number of faces which share an edge with the face")); } -static VArray<int> construct_neighbor_count_gvarray(const MeshComponent &component, - const eAttrDomain domain) +static VArray<int> construct_neighbor_count_varray(const Mesh &mesh, const eAttrDomain domain) { - const Mesh *mesh = component.get_for_read(); - if (mesh == nullptr) { - return {}; - } + const Span<MPoly> polys = mesh.polys(); + const Span<MLoop> loops = mesh.loops(); - Array<int> edge_count(mesh->totedge, 0); - for (const int i : IndexRange(mesh->totloop)) { - edge_count[mesh->mloop[i].e]++; + Array<int> edge_count(mesh.totedge, 0); + for (const MLoop &loop : loops) { + edge_count[loop.e]++; } - Array<int> poly_count(mesh->totpoly, 0); - for (const int poly_num : IndexRange(mesh->totpoly)) { - MPoly &poly = mesh->mpoly[poly_num]; - for (const int loop_num : IndexRange(poly.loopstart, poly.totloop)) { - poly_count[poly_num] += edge_count[mesh->mloop[loop_num].e] - 1; + Array<int> poly_count(polys.size(), 0); + for (const int poly_index : polys.index_range()) { + const MPoly &poly = polys[poly_index]; + for (const MLoop &loop : loops.slice(poly.loopstart, poly.totloop)) { + poly_count[poly_index] += edge_count[loop.e] - 1; } } - return component.attributes()->adapt_domain<int>( + return mesh.attributes().adapt_domain<int>( VArray<int>::ForContainer(std::move(poly_count)), ATTR_DOMAIN_FACE, domain); } -class FaceNeighborCountFieldInput final : public GeometryFieldInput { +class FaceNeighborCountFieldInput final : public bke::MeshFieldInput { public: FaceNeighborCountFieldInput() - : GeometryFieldInput(CPPType::get<int>(), "Face Neighbor Count Field") + : bke::MeshFieldInput(CPPType::get<int>(), "Face Neighbor Count Field") { 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) { - const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); - return construct_neighbor_count_gvarray(mesh_component, domain); - } - return {}; + return construct_neighbor_count_varray(mesh, domain); } uint64_t hash() const override @@ -75,37 +68,28 @@ class FaceNeighborCountFieldInput final : public GeometryFieldInput { } }; -static VArray<int> construct_vertex_count_gvarray(const MeshComponent &component, - const eAttrDomain domain) +static VArray<int> construct_vertex_count_varray(const Mesh &mesh, const eAttrDomain domain) { - const Mesh *mesh = component.get_for_read(); - if (mesh == nullptr) { - return {}; - } - - return component.attributes()->adapt_domain<int>( - VArray<int>::ForFunc(mesh->totpoly, - [mesh](const int i) -> float { return mesh->mpoly[i].totloop; }), + const Span<MPoly> polys = mesh.polys(); + return mesh.attributes().adapt_domain<int>( + VArray<int>::ForFunc(polys.size(), + [polys](const int i) -> float { return polys[i].totloop; }), ATTR_DOMAIN_FACE, domain); } -class FaceVertexCountFieldInput final : public GeometryFieldInput { +class FaceVertexCountFieldInput final : public bke::MeshFieldInput { public: - FaceVertexCountFieldInput() : GeometryFieldInput(CPPType::get<int>(), "Vertex Count Field") + FaceVertexCountFieldInput() : bke::MeshFieldInput(CPPType::get<int>(), "Vertex Count Field") { 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) { - const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component); - return construct_vertex_count_gvarray(mesh_component, domain); - } - return {}; + return construct_vertex_count_varray(mesh, domain); } uint64_t hash() const override |