AssetHelper.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/Component/EntityId.h>
  10. #include <AzCore/Asset/AssetCommon.h>
  11. #include <AzCore/std/smart_ptr/unique_ptr.h>
  12. #include <NvCloth/Types.h>
  13. namespace NvCloth
  14. {
  15. extern const int InvalidIndex;
  16. //! List of mesh nodes (names) inside an Asset.
  17. using MeshNodeList = AZStd::vector<AZStd::string>;
  18. //! Structure holding information about the submeshes of a render mesh node.
  19. //! While the simulation data is a single buffer for vertices and indices,
  20. //! this structure knows how to separate them in different submeshes, this will be
  21. //! be used when the MeshModificationNotificationBus request the modification
  22. //! of a specific submesh (lodLevel and primitiveIndex).
  23. struct MeshNodeInfo
  24. {
  25. //! LOD level of the mesh node inside the asset.
  26. int m_lodLevel = InvalidIndex;
  27. //! Identifies a submesh inside the render mesh.
  28. struct SubMesh
  29. {
  30. //! Primitive index inside the asset.
  31. int m_primitiveIndex = InvalidIndex;
  32. //! First vertex of the submesh.
  33. int m_verticesFirstIndex = InvalidIndex;
  34. //! Number of vertices of the submesh after the first vertex.
  35. int m_numVertices = 0;
  36. //! First index inside the asset.
  37. int m_indicesFirstIndex = InvalidIndex;
  38. //! Number of indices of the submesh after the first index.
  39. int m_numIndices = 0;
  40. };
  41. //! List of submeshes.
  42. AZStd::vector<SubMesh> m_subMeshes;
  43. };
  44. //! Structure with all the cloth information asset helper can obtain from the mesh.
  45. struct MeshClothInfo
  46. {
  47. AZStd::vector<SimParticleFormat> m_particles;
  48. AZStd::vector<SimIndexType> m_indices;
  49. AZStd::vector<SimUVType> m_uvs;
  50. AZStd::vector<float> m_motionConstraints;
  51. AZStd::vector<AZ::Vector2> m_backstopData; //!< X contains offset, Y contains radius.
  52. AZStd::vector<AZ::Vector3> m_tangents;
  53. AZStd::vector<AZ::Vector3> m_bitangents;
  54. AZStd::vector<AZ::Vector3> m_normals;
  55. };
  56. //! Interface to obtain cloth information from inside an Asset.
  57. class AssetHelper
  58. {
  59. public:
  60. AZ_RTTI(AssetHelper, "{8BBDFB6C-4615-4092-B38A-A1FEFEBD1A1F}");
  61. explicit AssetHelper(AZ::EntityId entityId);
  62. virtual ~AssetHelper() = default;
  63. //! Creates the appropriate asset helper depending on the entity's render service.
  64. static AZStd::unique_ptr<AssetHelper> CreateAssetHelper(AZ::EntityId entityId);
  65. //! Populates the list of mesh nodes inside the Asset that contains cloth information.
  66. virtual void GatherClothMeshNodes(MeshNodeList& meshNodes) = 0;
  67. //! Extracts the cloth mesh information of a node inside the Asset.
  68. virtual bool ObtainClothMeshNodeInfo(
  69. const AZStd::string& meshNode,
  70. MeshNodeInfo& meshNodeInfo,
  71. MeshClothInfo& meshClothInfo) = 0;
  72. protected:
  73. static float ConvertBackstopOffset(float backstopOffset);
  74. AZ::EntityId m_entityId;
  75. };
  76. } // namespace NvCloth