BsMeshUtility.h 4.7 KB

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