2
0

NetworkAnimationComponent.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Source/AutoGen/NetworkAnimationComponent.AutoComponent.h>
  9. #include <Multiplayer/Components/NetBindComponent.h>
  10. #include <Integration/ActorComponentBus.h>
  11. #include <Integration/AnimGraphComponentBus.h>
  12. namespace EMotionFX
  13. {
  14. class AnimGraphComponentNetworkRequests;
  15. namespace Integration
  16. {
  17. class ActorComponentRequests;
  18. class AnimGraphComponentRequests;
  19. }
  20. }
  21. namespace MultiplayerSample
  22. {
  23. // This is not documented, you kind of have to jump into mcore to find this, but invalid parameter index values are max uint32_t
  24. // See MCORE_INVALIDINDEX32 in Gems/EMotionFX/Code/MCore/Source/Config.h
  25. constexpr uint32_t InvalidParamIndex = 0xFFFFFFFF;
  26. constexpr int32_t InvalidBoneId = -1;
  27. class NetworkAnimationComponent
  28. : public NetworkAnimationComponentBase
  29. , private EMotionFX::Integration::ActorComponentNotificationBus::Handler
  30. , private EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler
  31. {
  32. public:
  33. AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::NetworkAnimationComponent, s_networkAnimationComponentConcreteUuid, MultiplayerSample::NetworkAnimationComponentBase);
  34. static void Reflect(AZ::ReflectContext* context);
  35. NetworkAnimationComponent();
  36. void OnInit() override;
  37. void OnActivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  38. void OnDeactivate(Multiplayer::EntityIsMigrating entityIsMigrating) override;
  39. int32_t GetBoneIdByName(const char* boneName) const;
  40. bool GetJointTransformByName(const char* a_BoneName, AZ::Transform& outJointTransform) const;
  41. bool GetJointTransformById(int32_t a_BoneId, AZ::Transform& outJointTransform) const;
  42. private:
  43. void OnPreRender(float deltaTime, float blendFactor);
  44. //! EMotionFX::Integration::ActorComponentNotificationBus::Handler
  45. //! @{
  46. void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance) override;
  47. void OnActorInstanceDestroyed(EMotionFX::ActorInstance* actorInstance) override;
  48. //! @}
  49. //! EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler
  50. //! @{
  51. void OnAnimGraphInstanceCreated(EMotionFX::AnimGraphInstance* animGraphInstance) override;
  52. //! @}
  53. Multiplayer::EntityPreRenderEvent::Handler m_preRenderEventHandler;
  54. EMotionFX::Integration::ActorComponentRequests* m_actorRequests = nullptr;
  55. EMotionFX::AnimGraphComponentNetworkRequests* m_networkRequests = nullptr;
  56. EMotionFX::Integration::AnimGraphComponentRequests* m_animationGraph = nullptr;
  57. // Hardcoded parameters, be nice if this was flexible and configurable from within the editor
  58. uint32_t m_velocityParamId = InvalidParamIndex;
  59. uint32_t m_aimTargetParamId = InvalidParamIndex;
  60. uint32_t m_crouchParamId = InvalidParamIndex;
  61. uint32_t m_aimingParamId = InvalidParamIndex;
  62. uint32_t m_shootParamId = InvalidParamIndex;
  63. uint32_t m_jumpParamId = InvalidParamIndex;
  64. uint32_t m_fallParamId = InvalidParamIndex;
  65. uint32_t m_landParamId = InvalidParamIndex;
  66. uint32_t m_hitParamId = InvalidParamIndex;
  67. uint32_t m_deathParamId = InvalidParamIndex;
  68. };
  69. }