ProceduralSkinnedMesh.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/Math/Matrix3x4.h>
  10. #include <AzCore/Math/Aabb.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/containers/array.h>
  13. namespace AtomSampleViewer
  14. {
  15. struct SkinnedMeshConfig
  16. {
  17. int m_segmentCount = 8;
  18. int m_verticesPerSegment = 8;
  19. int m_boneCount = 4;
  20. int m_influencesPerVertex = 4;
  21. int m_subMeshCount = 2;
  22. };
  23. //! Class for creating SkinnedMeshInputBuffers with arbitrary bone/vertex counts
  24. //! Assumes z-up right handed coordinate system
  25. class ProceduralSkinnedMesh
  26. {
  27. public:
  28. void Resize(SkinnedMeshConfig& skinnedMeshConfig);
  29. void UpdateAnimation(float time, bool useOutOfSyncBoneAnimation = false);
  30. uint32_t GetInfluencesPerVertex() const;
  31. uint32_t GetSubMeshCount() const;
  32. float GetSubMeshYOffset() const;
  33. uint32_t GetVertexCount() const;
  34. uint32_t GetAlignedVertCountForRGBStream() const;
  35. uint32_t GetAlignedVertCountForRGBAStream() const;
  36. static const uint32_t MaxInfluencesPerVertex = 4;
  37. // Mesh data that's used for rendering
  38. AZ::Aabb m_aabb = AZ::Aabb::CreateNull();
  39. AZStd::vector<uint32_t> m_indices;
  40. AZStd::vector<float> m_positions;
  41. AZStd::vector<float> m_normals;
  42. AZStd::vector<float> m_tangents;
  43. AZStd::vector<float> m_bitangents;
  44. AZStd::vector<uint32_t> m_blendIndices;
  45. AZStd::vector<float> m_blendWeights;
  46. AZStd::vector<AZStd::array<float, 2>> m_uvs;
  47. AZStd::vector<AZ::Matrix3x4> m_boneMatrices;
  48. private:
  49. void CalculateBones();
  50. void CalculateSegments();
  51. void CalculateVertexBuffers();
  52. // Extra values that are used while generating per-vertex data
  53. AZStd::vector<float> m_boneHeights;
  54. AZStd::vector<float> m_segmentHeights;
  55. AZStd::vector<uint32_t> m_segmentBlendIndices;
  56. AZStd::vector<float> m_segmentBlendWeights;
  57. AZStd::vector<float> m_segmentHeightOffsets;
  58. uint32_t m_boneCount = 0;
  59. uint32_t m_vertexCount = 0;
  60. uint32_t m_alignedVertCountForRGBStream = 0;
  61. uint32_t m_alignedVertCountForRGBAStream = 0;
  62. uint32_t m_verticesPerSegment = 0;
  63. uint32_t m_segmentCount = 0;
  64. uint32_t m_influencesPerVertex = 0;
  65. uint32_t m_subMeshCount = 0;
  66. float m_height = 1.0f;
  67. float m_radius = 0.1f;
  68. };
  69. } // namespace AtomSampleViewer