LookAtTrack.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/Serialization/SerializeContext.h>
  9. #include "LookAtTrack.h"
  10. //////////////////////////////////////////////////////////////////////////
  11. /// @deprecated Serialization for Sequence data in Component Entity Sequences now occurs through AZ::SerializeContext and the Sequence Component
  12. bool CLookAtTrack::Serialize(XmlNodeRef& xmlNode, bool bLoading, bool bLoadEmptyTracks)
  13. {
  14. if (bLoading)
  15. {
  16. xmlNode->getAttr("AnimationLayer", m_iAnimationLayer);
  17. }
  18. else
  19. {
  20. xmlNode->setAttr("AnimationLayer", m_iAnimationLayer);
  21. }
  22. return TAnimTrack<ILookAtKey>::Serialize(xmlNode, bLoading, bLoadEmptyTracks);
  23. }
  24. void CLookAtTrack::SerializeKey(ILookAtKey& key, XmlNodeRef& keyNode, bool bLoading)
  25. {
  26. if (bLoading)
  27. {
  28. const char* szSelection;
  29. f32 smoothTime;
  30. if (!keyNode->getAttr("smoothTime", smoothTime))
  31. {
  32. smoothTime = 0.0f;
  33. }
  34. const char* lookPose = keyNode->getAttr("lookPose");
  35. if (lookPose)
  36. {
  37. key.lookPose = lookPose;
  38. }
  39. szSelection = keyNode->getAttr("node");
  40. if (szSelection)
  41. {
  42. key.szSelection = szSelection;
  43. }
  44. key.smoothTime = smoothTime;
  45. }
  46. else
  47. {
  48. keyNode->setAttr("node", key.szSelection.c_str());
  49. keyNode->setAttr("smoothTime", key.smoothTime);
  50. keyNode->setAttr("lookPose", key.lookPose.c_str());
  51. }
  52. }
  53. //////////////////////////////////////////////////////////////////////////
  54. void CLookAtTrack::GetKeyInfo(int key, const char*& description, float& duration)
  55. {
  56. assert(key >= 0 && key < (int)m_keys.size());
  57. CheckValid();
  58. description = 0;
  59. duration = m_keys[key].fDuration;
  60. if (!m_keys[key].szSelection.empty())
  61. {
  62. description = m_keys[key].szSelection.c_str();
  63. }
  64. }
  65. //////////////////////////////////////////////////////////////////////////
  66. static bool LookAtTrackVersionConverter(
  67. AZ::SerializeContext& serializeContext,
  68. AZ::SerializeContext::DataElementNode& rootElement)
  69. {
  70. if (rootElement.GetVersion() < 3)
  71. {
  72. rootElement.AddElement(serializeContext, "BaseClass1", azrtti_typeid<IAnimTrack>());
  73. }
  74. return true;
  75. }
  76. template<>
  77. inline void TAnimTrack<ILookAtKey>::Reflect(AZ::ReflectContext* context)
  78. {
  79. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  80. {
  81. serializeContext->Class<TAnimTrack<ILookAtKey>, IAnimTrack>()
  82. ->Version(3, &LookAtTrackVersionConverter)
  83. ->Field("Flags", &TAnimTrack<ILookAtKey>::m_flags)
  84. ->Field("Range", &TAnimTrack<ILookAtKey>::m_timeRange)
  85. ->Field("ParamType", &TAnimTrack<ILookAtKey>::m_nParamType)
  86. ->Field("Keys", &TAnimTrack<ILookAtKey>::m_keys)
  87. ->Field("Id", &TAnimTrack<ILookAtKey>::m_id);
  88. }
  89. }
  90. //////////////////////////////////////////////////////////////////////////
  91. void CLookAtTrack::Reflect(AZ::ReflectContext* context)
  92. {
  93. TAnimTrack<ILookAtKey>::Reflect(context);
  94. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  95. {
  96. serializeContext->Class<CLookAtTrack, TAnimTrack<ILookAtKey>>()
  97. ->Version(1)
  98. ->Field("AnimationLayer", &CLookAtTrack::m_iAnimationLayer);
  99. }
  100. }