3
0

SkinMetaAsset.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <AzCore/RTTI/ReflectContext.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <Atom/RPI.Reflect/Model/SkinMetaAsset.h>
  11. namespace AZ
  12. {
  13. namespace RPI
  14. {
  15. void SkinMetaAsset::Reflect(ReflectContext* context)
  16. {
  17. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  18. {
  19. serializeContext->Class<SkinMetaAsset>()
  20. ->Version(1)
  21. ->Field("jointIndexToNameMap", &SkinMetaAsset::m_jointNameToIndexMap)
  22. ;
  23. }
  24. }
  25. AZ::Data::AssetId SkinMetaAsset::ConstructAssetId(const AZ::Data::AssetId& modelAssetId, const AZStd::string& modelAssetName)
  26. {
  27. if (modelAssetName.empty())
  28. {
  29. AZ_Error("SkinMetaAsset", false, "Cannot construct asset id for skin meta asset. Model asset name is empty.");
  30. return {};
  31. }
  32. // The sub id of any model related assets starts with the same prefix for first 8 bits and uses the name hash for the last 24 bits.
  33. uint32_t productSubId = SkinMetaAsset::s_assetIdPrefix | AZ::Crc32(modelAssetName) & 0xffffff;
  34. return {modelAssetId.m_guid, productSubId};
  35. }
  36. void SkinMetaAsset::SetReady()
  37. {
  38. m_status = Data::AssetData::AssetStatus::Ready;
  39. }
  40. void SkinMetaAsset::SetJointNameToIndexMap(const AZStd::unordered_map<AZStd::string, uint16_t>& jointNameToIndexMap)
  41. {
  42. m_jointNameToIndexMap = jointNameToIndexMap;
  43. }
  44. const AZStd::unordered_map<AZStd::string, uint16_t>& SkinMetaAsset::GetJointNameToIndexMap() const
  45. {
  46. return m_jointNameToIndexMap;
  47. }
  48. uint16_t SkinMetaAsset::GetJointIndexByName(const AZStd::string& jointName) const
  49. {
  50. const auto findIter = m_jointNameToIndexMap.find(jointName);
  51. if (findIter != m_jointNameToIndexMap.end())
  52. {
  53. return findIter->second;
  54. }
  55. return InvalidJointIndex;
  56. }
  57. } //namespace RPI
  58. } // namespace AZ