/* SPDX-License-Identifier: GPL-2.0-or-later */ #include "BKE_mesh.h" #include "BKE_mesh_mapping.h" #include "node_geometry_util.hh" namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc { static void node_declare(NodeDeclarationBuilder &b) { b.add_input(N_("Corner Index")) .implicit_field(implicit_field_inputs::index) .description( N_("The corner to retrieve data from. Defaults to the corner from the context")); b.add_output(N_("Face Index")) .dependent_field() .description(N_("The index of the face the corner is a part of")); b.add_output(N_("Index in Face")) .dependent_field() .description(N_("The index of the corner starting from the first corner in the face")); } class CornerFaceIndexInput final : public bke::MeshFieldInput { public: CornerFaceIndexInput() : bke::MeshFieldInput(CPPType::get(), "Corner Face Index") { category_ = Category::Generated; } GVArray get_varray_for_context(const Mesh &mesh, const eAttrDomain domain, const IndexMask /*mask*/) const final { if (domain != ATTR_DOMAIN_CORNER) { return {}; } return VArray::ForContainer( bke::mesh_topology::build_loop_to_poly_map(mesh.polys(), mesh.totloop)); } uint64_t hash() const final { return 2348712958475728; } bool is_equal_to(const fn::FieldNode &other) const final { return dynamic_cast(&other) != nullptr; } }; class CornerIndexInFaceInput final : public bke::MeshFieldInput { public: CornerIndexInFaceInput() : bke::MeshFieldInput(CPPType::get(), "Corner Index In Face") { category_ = Category::Generated; } GVArray get_varray_for_context(const Mesh &mesh, const eAttrDomain domain, const IndexMask /*mask*/) const final { if (domain != ATTR_DOMAIN_CORNER) { return {}; } const Span polys = mesh.polys(); Array loop_to_poly_map = bke::mesh_topology::build_loop_to_poly_map(polys, mesh.totloop); return VArray::ForFunc( mesh.totloop, [polys, loop_to_poly_map = std::move(loop_to_poly_map)](const int corner_i) { const int poly_i = loop_to_poly_map[corner_i]; return corner_i - polys[poly_i].loopstart; }); } uint64_t hash() const final { return 97837176448; } bool is_equal_to(const fn::FieldNode &other) const final { if (dynamic_cast(&other)) { return true; } return false; } std::optional preferred_domain(const Mesh & /*mesh*/) const final { return ATTR_DOMAIN_CORNER; } }; static void node_geo_exec(GeoNodeExecParams params) { const Field corner_index = params.extract_input>("Corner Index"); if (params.output_is_required("Face Index")) { params.set_output("Face Index", Field(std::make_shared( corner_index, Field(std::make_shared()), ATTR_DOMAIN_CORNER))); } if (params.output_is_required("Index in Face")) { params.set_output("Index in Face", Field(std::make_shared( corner_index, Field(std::make_shared()), ATTR_DOMAIN_CORNER))); } } } // namespace blender::nodes::node_geo_mesh_topology_face_of_corner_cc void register_node_type_geo_mesh_topology_face_of_corner() { namespace file_ns = blender::nodes::node_geo_mesh_topology_face_of_corner_cc; static bNodeType ntype; geo_node_type_base( &ntype, GEO_NODE_MESH_TOPOLOGY_FACE_OF_CORNER, "Face of Corner", NODE_CLASS_INPUT); ntype.geometry_node_execute = file_ns::node_geo_exec; ntype.declare = file_ns::node_declare; nodeRegisterType(&ntype); }