BsMeshUtility.h 4.4 KB

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