💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.6 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP
  20. #define ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP
  21. #include <engine/geom/primitives/box.hpp>
  22. #include <engine/geom/mesh.hpp>
  23. #include <engine/utility/fundamental-types.hpp>
  24. #include <array>
  25. #include <vector>
  26. namespace geom {
  27. /**
  28. * Creates a triangle mesh from a list of vertices and indices.
  29. *
  30. * @param[out] mesh Mesh to which vertices, edges, and faces will be added.
  31. * @param vertices Vertex positions
  32. * @param triangles Triangle indices
  33. * @return Newly created triangle mesh.
  34. */
  35. void create_triangle_mesh(mesh& mesh, const std::vector<float3>& vertices, const std::vector<std::array<std::uint_fast32_t, 3>>& triangles);
  36. /**
  37. * Calculates normals for each face.
  38. *
  39. * @param[out] Array in which faceted normals will be stored.
  40. */
  41. void calculate_face_normals(float3* normals, const mesh& mesh);
  42. float3 calculate_face_normal(const mesh::face& face);
  43. /**
  44. * Calculates smooth tangents per-vertex.
  45. *
  46. * @param[out] tangents Array in which vertex tangents will be stored. A bitangent sign is stored in each tangent vector's fourth component.
  47. * @param[in] texcoords Array containing vertex texture coordinates.
  48. * @param[in] normals Array containing vertex normals.
  49. */
  50. void calculate_vertex_tangents(float4* tangents, const float2* texcoords, const float3* normals, const mesh& mesh);
  51. /**
  52. * Calculates the AABB bounds of a mesh.
  53. */
  54. box<float> calculate_bounds(const mesh& mesh);
  55. /**
  56. * Triangulates a face by adding a new vertex in the center, then creating triangles between the edges of the original face and the new vertex.
  57. *
  58. * @param mesh Mesh containing the face to poke.
  59. * @param index Index of the face to poke.
  60. * @return Pointer to the newly-created vertex in the center of the face, or `nullptr` if the face could not be poked.
  61. */
  62. mesh::vertex* poke_face(mesh& mesh, std::size_t index);
  63. } // namespace geom
  64. #endif // ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP