BsMeshUtility.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Performs various operations on mesh geometry.
  7. */
  8. class BS_CORE_EXPORT MeshUtility
  9. {
  10. public:
  11. /**
  12. * @brief Calculates per-vertex normals based on the provided vertices and indices.
  13. *
  14. * @param vertices Set of vertices containing vertex positions.
  15. * @param indices Set of indices containing indexes into vertex array for each triangle.
  16. * @param numVertices Number of vertices in the "vertices" array.
  17. * @param numIndices Number of indices in the "indices" array. Must be a multiple of three.
  18. * @param normals Pre-allocated buffer that will contain the calculated normals. Must be the same size
  19. * as the vertex array.
  20. * @param indexSize Size of a single index in the indices array, in bytes.
  21. *
  22. * @note Vertices should be split before calling this method if there are any discontinuities. (e.g. a vertex
  23. * on a corner of a cube should be split into three vertices used by three triangles in order for the normals
  24. * to be valid.)
  25. */
  26. static void calculateNormals(Vector3* vertices, UINT8* indices, UINT32 numVertices,
  27. UINT32 numIndices, Vector3* normals, UINT32 indexSize = 4);
  28. /**
  29. * @brief Calculates per-vertex tangents and bitangents based on the provided vertices, uv coordinates and indices.
  30. *
  31. * @param vertices Set of vertices containing vertex positions.
  32. * @param normals Set of normals to use when calculating tangents. Must the the same length
  33. * as the number of vertices.
  34. * @param uv Set of UV coordinates to use when calculating tangents. Must the the same length
  35. * as the number of vertices.
  36. * @param indices Set of indices containing indexes into vertex array for each triangle.
  37. * @param numVertices Number of vertices in the "vertices", "normals" and "uv" arrays.
  38. * @param numIndices Number of indices in the "indices" array. Must be a multiple of three.
  39. * @param tangents Pre-allocated buffer that will contain the calculated tangents. Must be the same size
  40. * as the vertex array.
  41. * @param bitangents Pre-allocated buffer that will contain the calculated bitangents. Must be the same size
  42. * as the vertex array.
  43. * @param indexSize Size of a single index in the indices array, in bytes.
  44. *
  45. * @note Vertices should be split before calling this method if there are any discontinuities. (e.g. a vertex
  46. * on a corner of a cube should be split into three vertices used by three triangles in order for the normals
  47. * to be valid.)
  48. */
  49. static void calculateTangents(Vector3* vertices, Vector3* normals, Vector2* uv, UINT8* indices, UINT32 numVertices,
  50. UINT32 numIndices, Vector3* tangents, Vector3* bitangents, UINT32 indexSize = 4);
  51. /**
  52. * @brief Calculates per-vertex tangent space (normal, tangent, bitangent) based on the provided
  53. * vertices, uv coordinates and indices.
  54. *
  55. * @param vertices Set of vertices containing vertex positions.
  56. * @param uv Set of UV coordinates to use when calculating tangents.
  57. * @param indices Set of indices containing indexes into vertex array for each triangle.
  58. * @param numVertices Number of vertices in the "vertices" array.
  59. * @param numIndices Number of indices in the "indices" array. Must be a multiple of three.
  60. * @param normals Pre-allocated buffer that will contain the calculated normals. Must be the same size
  61. * as the vertex array.
  62. * @param tangents Pre-allocated buffer that will contain the calculated tangents. Must be the same size
  63. * as the vertex array.
  64. * @param bitangents Pre-allocated buffer that will contain the calculated bitangents. Must be the same size
  65. * as the vertex array.
  66. * @param indexSize Size of a single index in the indices array, in bytes.
  67. *
  68. * @note Vertices should be split before calling this method if there are any discontinuities. (e.g. a vertex
  69. * on a corner of a cube should be split into three vertices used by three triangles in order for the normals
  70. * to be valid.)
  71. */
  72. static void calculateTangentSpace(Vector3* vertices, Vector2* uv, UINT8* indices, UINT32 numVertices,
  73. UINT32 numIndices, Vector3* normals, Vector3* tangents, Vector3* bitangents, UINT32 indexSize = 4);
  74. };
  75. }