BsMeshUtility.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. (e.g. a vertex on a corner
  27. * of a cube should be split into three vertices used by three triangles in order for the normals to be valid.)
  28. */
  29. static void calculateNormals(Vector3* vertices, UINT8* indices, UINT32 numVertices,
  30. UINT32 numIndices, Vector3* normals, UINT32 indexSize = 4);
  31. /**
  32. * Calculates per-vertex tangents and bitangents based on the provided vertices, uv coordinates and indices.
  33. *
  34. * @param[in] vertices Set of vertices containing vertex positions.
  35. * @param[in] normals Set of normals to use when calculating tangents. Must the the same length as the number
  36. * of vertices.
  37. * @param[in] uv Set of UV coordinates to use when calculating tangents. Must the the same length as the
  38. * number of vertices.
  39. * @param[in] indices Set of indices containing indexes into vertex array for each triangle.
  40. * @param[in] numVertices Number of vertices in the @p vertices, @p normals and @p uv arrays.
  41. * @param[in] numIndices Number of indices in the @p indices array. Must be a multiple of three.
  42. * @param[out] tangents Pre-allocated buffer that will contain the calculated tangents. Must be the same size
  43. * as the vertex array.
  44. * @param[out] bitangents Pre-allocated buffer that will contain the calculated bitangents. Must be the same size
  45. * as the vertex array.
  46. * @param[in] indexSize Size of a single index in the indices array, in bytes.
  47. *
  48. * @note
  49. * Vertices should be split before calling this method if there are any discontinuities. (e.g. a vertex on a corner
  50. * of a cube should be split into three vertices used by three triangles in order for the normals to be valid.)
  51. */
  52. static void calculateTangents(Vector3* vertices, Vector3* normals, Vector2* uv, UINT8* indices, UINT32 numVertices,
  53. UINT32 numIndices, Vector3* tangents, Vector3* bitangents, UINT32 indexSize = 4);
  54. /**
  55. * Calculates per-vertex tangent space (normal, tangent, bitangent) based on the provided vertices, uv coordinates
  56. * and indices.
  57. *
  58. * @param[in] vertices Set of vertices containing vertex positions.
  59. * @param[in] uv Set of UV coordinates to use when calculating tangents.
  60. * @param[in] indices Set of indices containing indexes into vertex array for each triangle.
  61. * @param[in] numVertices Number of vertices in the "vertices" array.
  62. * @param[in] numIndices Number of indices in the "indices" array. Must be a multiple of three.
  63. * @param[out] normals Pre-allocated buffer that will contain the calculated normals. Must be the same size
  64. * as the vertex array.
  65. * @param[out] tangents Pre-allocated buffer that will contain the calculated tangents. Must be the same size
  66. * as the vertex array.
  67. * @param[out] bitangents Pre-allocated buffer that will contain the calculated bitangents. Must be the same size
  68. * as the vertex array.
  69. * @param[in] indexSize Size of a single index in the indices array, in bytes.
  70. *
  71. * @note
  72. * Vertices should be split before calling this method if there are any discontinuities. (e.g. a vertex on a corner
  73. * of a cube should be split into three vertices used by three triangles in order for the normals to be valid.)
  74. */
  75. static void calculateTangentSpace(Vector3* vertices, Vector2* uv, UINT8* indices, UINT32 numVertices,
  76. UINT32 numIndices, Vector3* normals, Vector3* tangents, Vector3* bitangents, UINT32 indexSize = 4);
  77. };
  78. /** @} */
  79. }