3
0

MorphTargetMetaAsset.cpp 2.9 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. #include <AzCore/Asset/AssetSerializer.h>
  9. #include <AzCore/RTTI/ReflectContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <Atom/RPI.Reflect/Model/MorphTargetMetaAsset.h>
  12. namespace AZ::RPI
  13. {
  14. void MorphTargetMetaAsset::MorphTarget::Reflect(ReflectContext* context)
  15. {
  16. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  17. {
  18. serializeContext->Class<MorphTargetMetaAsset::MorphTarget>()
  19. ->Version(1)
  20. ->Field("meshNodeName", &MorphTargetMetaAsset::MorphTarget::m_meshNodeName)
  21. ->Field("morphTargetName", &MorphTargetMetaAsset::MorphTarget::m_morphTargetName)
  22. ->Field("startIndex", &MorphTargetMetaAsset::MorphTarget::m_startIndex)
  23. ->Field("numVertices", &MorphTargetMetaAsset::MorphTarget::m_numVertices)
  24. ->Field("minPositionDelta", &MorphTargetMetaAsset::MorphTarget::m_minPositionDelta)
  25. ->Field("maxPositionDelta", &MorphTargetMetaAsset::MorphTarget::m_maxPositionDelta)
  26. ->Field("wrinkleMask", &MorphTargetMetaAsset::MorphTarget::m_wrinkleMask)
  27. ->Field("meshIndex", &MorphTargetMetaAsset::MorphTarget::m_meshIndex)
  28. ;
  29. }
  30. }
  31. void MorphTargetMetaAsset::Reflect(ReflectContext* context)
  32. {
  33. MorphTarget::Reflect(context);
  34. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  35. {
  36. serializeContext->Class<MorphTargetMetaAsset>()
  37. ->Version(1)
  38. ->Field("morphTargets", &MorphTargetMetaAsset::m_morphTargets)
  39. ;
  40. }
  41. }
  42. AZ::Data::AssetId MorphTargetMetaAsset::ConstructAssetId(const AZ::Data::AssetId& modelAssetId, const AZStd::string& modelAssetName)
  43. {
  44. if (modelAssetName.empty())
  45. {
  46. AZ_Error("SkinMetaAsset", false, "Cannot construct asset id for morph target meta asset. Model asset name is empty.");
  47. return {};
  48. }
  49. // 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.
  50. uint32_t productSubId = MorphTargetMetaAsset::s_assetIdPrefix | AZ::Crc32(modelAssetName) & 0xffffff;
  51. return {modelAssetId.m_guid, productSubId};
  52. }
  53. void MorphTargetMetaAsset::SetReady()
  54. {
  55. m_status = Data::AssetData::AssetStatus::Ready;
  56. }
  57. void MorphTargetMetaAsset::AddMorphTarget(const MorphTarget& morphTarget)
  58. {
  59. m_morphTargets.emplace_back(morphTarget);
  60. }
  61. const AZStd::vector<MorphTargetMetaAsset::MorphTarget>& MorphTargetMetaAsset::GetMorphTargets() const
  62. {
  63. return m_morphTargets;
  64. }
  65. } // namespace AZ::RPI