3
0

AnimGraphFactory.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 <EMotionFX/Source/AnimGraph.h>
  9. #include <EMotionFX/Source/AnimGraphMotionNode.h>
  10. #include <EMotionFX/Source/AnimGraphStateMachine.h>
  11. #include <EMotionFX/Source/AnimGraphStateTransition.h>
  12. #include <MCore/Source/ReflectionSerializer.h>
  13. #include <Tests/TestAssetCode/AnimGraphFactory.h>
  14. namespace EMotionFX
  15. {
  16. EmptyAnimGraph::EmptyAnimGraph()
  17. {
  18. // Emptry animgraph with nothing inside.
  19. SetRootStateMachine(aznew AnimGraphStateMachine());
  20. GetRootStateMachine()->SetName("rootStateMachine");
  21. }
  22. void EmptyAnimGraph::Reflect(AZ::ReflectContext* context)
  23. {
  24. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  25. if (serializeContext)
  26. {
  27. serializeContext->Class<EmptyAnimGraph>()
  28. ->Version(1);
  29. }
  30. }
  31. AnimGraphInstance* EmptyAnimGraph::GetAnimGraphInstance(ActorInstance* actorInstance, MotionSet* motionSet)
  32. {
  33. // TODO: Move this method to AnimGraphInstanceFactory when we create it.
  34. AnimGraphInstance* animGraphInstance = AnimGraphInstance::Create(this, actorInstance, motionSet);
  35. actorInstance->SetAnimGraphInstance(animGraphInstance);
  36. animGraphInstance->IncreaseReferenceCount();
  37. animGraphInstance->RecursiveInvalidateUniqueDatas();
  38. return animGraphInstance;
  39. }
  40. TwoMotionNodeAnimGraph::TwoMotionNodeAnimGraph()
  41. {
  42. /*
  43. Inside the root state machine:
  44. +-----------+
  45. |motionNodeA|
  46. +-----------+
  47. +-----------+
  48. |motionNodeB|
  49. +-----------+
  50. */
  51. m_motionNodeA = aznew AnimGraphMotionNode();
  52. m_motionNodeB = aznew AnimGraphMotionNode();
  53. m_motionNodeA->SetName("A");
  54. m_motionNodeB->SetName("B");
  55. GetRootStateMachine()->SetName("rootStateMachine");
  56. GetRootStateMachine()->AddChildNode(m_motionNodeA);
  57. GetRootStateMachine()->AddChildNode(m_motionNodeB);
  58. GetRootStateMachine()->SetEntryState(m_motionNodeA);
  59. }
  60. void TwoMotionNodeAnimGraph::Reflect(AZ::ReflectContext* context)
  61. {
  62. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  63. if (serializeContext)
  64. {
  65. serializeContext->Class<TwoMotionNodeAnimGraph>()
  66. ->Version(1);
  67. }
  68. }
  69. AnimGraphMotionNode* TwoMotionNodeAnimGraph::GetMotionNodeA()
  70. {
  71. return m_motionNodeA;
  72. }
  73. AnimGraphMotionNode* TwoMotionNodeAnimGraph::GetMotionNodeB()
  74. {
  75. return m_motionNodeB;
  76. }
  77. OneBlendTreeNodeAnimGraph::OneBlendTreeNodeAnimGraph()
  78. {
  79. /*
  80. +-----------+
  81. |m_blendTree|
  82. +-----------+
  83. */
  84. m_blendTree = aznew BlendTree();
  85. GetRootStateMachine()->AddChildNode(m_blendTree);
  86. GetRootStateMachine()->SetEntryState(m_blendTree);
  87. }
  88. void OneBlendTreeNodeAnimGraph::Reflect(AZ::ReflectContext* context)
  89. {
  90. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  91. if (serializeContext)
  92. {
  93. serializeContext->Class<OneBlendTreeNodeAnimGraph>()
  94. ->Version(1);
  95. }
  96. }
  97. BlendTree* OneBlendTreeNodeAnimGraph::GetBlendTreeNode() const
  98. {
  99. return m_blendTree;
  100. }
  101. OneBlendTreeParameterNodeAnimGraph::OneBlendTreeParameterNodeAnimGraph()
  102. {
  103. /*
  104. Inside blend tree:
  105. +---------------+ +-----------+
  106. |m_parameterNode| |m_finalNode|
  107. +---------------+ +-----------+
  108. */
  109. m_parameterNode = aznew BlendTreeParameterNode();
  110. m_parameterNode->SetName("Parameters0");
  111. m_finalNode = aznew BlendTreeFinalNode();
  112. m_finalNode->SetName("FinalNode0");
  113. BlendTree* blendTree = aznew BlendTree();
  114. blendTree->SetName("BlendTree0");
  115. blendTree->AddChildNode(m_parameterNode);
  116. blendTree->AddChildNode(m_finalNode);
  117. GetRootStateMachine()->AddChildNode(blendTree);
  118. GetRootStateMachine()->SetEntryState(blendTree);
  119. InitAfterLoading();
  120. }
  121. BlendTreeParameterNode* OneBlendTreeParameterNodeAnimGraph::GetParameterNode() const
  122. {
  123. return m_parameterNode;
  124. }
  125. } // namespace EMotionFX