NetworkAnimationComponent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 EMotionFX's private headers to find this, invalid parameter index values are max size_t
  24. // See InvalidIndex in Gems\EMotionFX\Code\EMotionFX\Source\EMotionFXConfig.h
  25. constexpr size_t InvalidParamIndex = 0xffffffffffffffff;
  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* boneName, AZ::Transform& outJointTransform) const;
  41. bool GetJointTransformById(int32_t boneId, AZ::Transform& outJointTransform) const;
  42. private:
  43. void OnPreRender(float deltaTime);
  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. size_t m_movementDirectionParamId = InvalidParamIndex;
  59. size_t m_movementSpeedParamId = InvalidParamIndex;
  60. size_t m_velocityParamId = InvalidParamIndex;
  61. size_t m_aimTargetParamId = InvalidParamIndex;
  62. size_t m_crouchParamId = InvalidParamIndex;
  63. size_t m_aimingParamId = InvalidParamIndex;
  64. size_t m_shootParamId = InvalidParamIndex;
  65. size_t m_jumpParamId = InvalidParamIndex;
  66. size_t m_fallParamId = InvalidParamIndex;
  67. size_t m_landParamId = InvalidParamIndex;
  68. size_t m_hitParamId = InvalidParamIndex;
  69. size_t m_deathParamId = InvalidParamIndex;
  70. };
  71. }