TangentSpaceHelper.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/RTTI/RTTI.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/std/containers/array.h>
  12. #include <NvCloth/ITangentSpaceHelper.h>
  13. namespace NvCloth
  14. {
  15. //! Implementation of the ITangentSpaceHelper interface.
  16. class TangentSpaceHelper
  17. : public AZ::Interface<ITangentSpaceHelper>::Registrar
  18. {
  19. public:
  20. AZ_RTTI(TangentSpaceHelper, "{2F8400BF-045A-49C3-B9D1-356011907E62}", ITangentSpaceHelper);
  21. protected:
  22. // ITangentSpace overrides ...
  23. bool CalculateNormals(
  24. const AZStd::vector<SimParticleFormat>& vertices,
  25. const AZStd::vector<SimIndexType>& indices,
  26. AZStd::vector<AZ::Vector3>& outNormals) override;
  27. bool CalculateTangentsAndBitagents(
  28. const AZStd::vector<SimParticleFormat>& vertices,
  29. const AZStd::vector<SimIndexType>& indices,
  30. const AZStd::vector<SimUVType>& uvs,
  31. const AZStd::vector<AZ::Vector3>& normals,
  32. AZStd::vector<AZ::Vector3>& outTangents,
  33. AZStd::vector<AZ::Vector3>& outBitangents) override;
  34. bool CalculateTangentSpace(
  35. const AZStd::vector<SimParticleFormat>& vertices,
  36. const AZStd::vector<SimIndexType>& indices,
  37. const AZStd::vector<SimUVType>& uvs,
  38. AZStd::vector<AZ::Vector3>& outTangents,
  39. AZStd::vector<AZ::Vector3>& outBitangents,
  40. AZStd::vector<AZ::Vector3>& outNormals) override;
  41. private:
  42. using TriangleIndices = AZStd::array<SimIndexType, 3>;
  43. using TrianglePositions = AZStd::array<AZ::Vector3, 3>;
  44. using TriangleUVs = AZStd::array<SimUVType, 3>;
  45. using TriangleEdges = AZStd::array<AZ::Vector3, 2>;
  46. void GetTriangleData(
  47. size_t triangleIndex,
  48. const AZStd::vector<SimIndexType>& indices,
  49. const AZStd::vector<SimParticleFormat>& vertices,
  50. TriangleIndices& triangleIndices,
  51. TrianglePositions& trianglePositions,
  52. TriangleEdges& triangleEdges);
  53. void GetTriangleData(
  54. size_t triangleIndex,
  55. const AZStd::vector<SimIndexType>& indices,
  56. const AZStd::vector<SimParticleFormat>& vertices,
  57. const AZStd::vector<SimUVType>& uvs,
  58. TriangleIndices& triangleIndices,
  59. TrianglePositions& trianglePositions,
  60. TriangleEdges& triangleEdges,
  61. TriangleUVs& triangleUVs);
  62. bool ComputeNormal(const TriangleEdges& triangleEdges, AZ::Vector3& normal);
  63. bool ComputeTangentAndBitangent(
  64. const TriangleUVs& triangleUVs, const TriangleEdges& triangleEdges,
  65. AZ::Vector3& tangent, AZ::Vector3& bitangent);
  66. void AdjustTangentAndBitangent(
  67. const AZ::Vector3& normal, AZ::Vector3& tangent, AZ::Vector3& bitangent);
  68. float GetVertexWeightInTriangle(AZ::u32 vertexIndexInTriangle, const TrianglePositions& trianglePositions);
  69. };
  70. } // namespace NvCloth