ProceduralSkinnedMesh.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. static const uint32_t MaxInfluencesPerVertex = 4;
  34. // Mesh data that's used for rendering
  35. AZ::Aabb m_aabb = AZ::Aabb::CreateNull();
  36. AZStd::vector<uint32_t> m_indices;
  37. AZStd::vector< AZStd::array<float, 3>> m_positions;
  38. AZStd::vector< AZStd::array<float, 3>> m_normals;
  39. AZStd::vector< AZStd::array<float, 4>> m_tangents;
  40. AZStd::vector< AZStd::array<float, 3>> m_bitangents;
  41. AZStd::vector<uint32_t> m_blendIndices;
  42. AZStd::vector<float> m_blendWeights;
  43. AZStd::vector<AZStd::array<float, 2>> m_uvs;
  44. AZStd::vector<AZ::Matrix3x4> m_boneMatrices;
  45. private:
  46. void CalculateBones();
  47. void CalculateSegments();
  48. void CalculateVertexBuffers();
  49. // Extra values that are used while generating per-vertex data
  50. AZStd::vector<float> m_boneHeights;
  51. AZStd::vector<float> m_segmentHeights;
  52. AZStd::vector<uint32_t> m_segmentBlendIndices;
  53. AZStd::vector<float> m_segmentBlendWeights;
  54. AZStd::vector<float> m_segmentHeightOffsets;
  55. uint32_t m_boneCount = 0;
  56. uint32_t m_vertexCount = 0;
  57. uint32_t m_verticesPerSegment = 0;
  58. uint32_t m_segmentCount = 0;
  59. uint32_t m_influencesPerVertex = 0;
  60. uint32_t m_subMeshCount = 0;
  61. float m_height = 1.0f;
  62. float m_radius = 0.1f;
  63. };
  64. } // namespace AtomSampleViewer