123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /*
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #pragma once
- #include <AzCore/EBus/EBus.h>
- #include <AzCore/Component/ComponentBus.h>
- #include <AzCore/Math/Vector2.h>
- #include <AzCore/Math/Vector3.h>
- #include <AzCore/Math/Quaternion.h>
- #include <AzCore/Asset/AssetCommon.h>
- namespace EMotionFX
- {
- class AnimGraphInstance;
- }
- namespace EMotionFX
- {
- namespace Integration
- {
- /**
- * EmotionFX Anim Graph Component Request Bus
- * Used for making requests to the EMotionFX Anim Graph Components.
- */
- class AnimGraphComponentRequests
- : public AZ::ComponentBus
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- /// Retrieves the component's live graph instance.
- /// \return pointer to anim graph instance.
- virtual EMotionFX::AnimGraphInstance* GetAnimGraphInstance() { return nullptr; }
- /// Retrieve parameter index for a given parameter name.
- /// Retrieving the index and using it to set parameter values is more performant than setting by name.
- /// \param parameterName - name of parameter for which to retrieve the index.
- /// \return parameter index
- virtual size_t FindParameterIndex(const char* parameterName) = 0;
- /// Retrieve parameter name for a given parameter index.
- /// \param parameterName - index of parameter for which to retrieve the name.
- /// \return parameter name
- virtual const char* FindParameterName(size_t parameterIndex) = 0;
- /// Updates a anim graph property given a float value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterFloat(size_t parameterIndex, float value) = 0;
- /// Updates a anim graph property given a boolean value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterBool(size_t parameterIndex, bool value) = 0;
- /// Updates a anim graph property given a string value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterString(size_t parameterIndex, const char* value) = 0;
- /// Updates a anim graph property given a Vector2 value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterVector2(size_t parameterIndex, const AZ::Vector2& value) = 0;
- /// Updates a anim graph property given a Vector3 value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterVector3(size_t parameterIndex, const AZ::Vector3& value) = 0;
- /// Updates a anim graph property given euler rotation values.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterRotationEuler(size_t parameterIndex, const AZ::Vector3& value) = 0;
- /// Updates a anim graph property given a quaternion value.
- /// \param parameterIndex - index of parameter to set
- /// \param value - value to set
- virtual void SetParameterRotation(size_t parameterIndex, const AZ::Quaternion& value) = 0;
- /// Updates a anim graph property given a float value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterFloat(const char* parameterName, float value) = 0;
- /// Updates a anim graph property given a boolean value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterBool(const char* parameterName, bool value) = 0;
- /// Updates a anim graph property given a string value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterString(const char* parameterName, const char* value) = 0;
- /// Updates a anim graph property given a Vector2 value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterVector2(const char* parameterName, const AZ::Vector2& value) = 0;
- /// Updates a anim graph property given a Vector3 value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterVector3(const char* parameterName, const AZ::Vector3& value) = 0;
- /// Updates a anim graph property given euler rotation values.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterRotationEuler(const char* parameterName, const AZ::Vector3& value) = 0;
- /// Updates a anim graph property given a quaternion value.
- /// \param parameterName - name of parameter to set
- /// \param value
- virtual void SetNamedParameterRotation(const char* parameterName, const AZ::Quaternion& value) = 0;
- /// Enable or disable debug draw visualization inside the anim graph instance.
- virtual void SetVisualizeEnabled(bool enabled) = 0;
- /// Retrieves a anim graph property as a float value.
- /// \param parameterIndex - index of parameter to set
- virtual float GetParameterFloat(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property as a boolean value.
- /// \param parameterIndex - index of parameter to set
- virtual bool GetParameterBool(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property given a string value.
- /// \param parameterIndex - index of parameter to set
- virtual AZStd::string GetParameterString(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property as a Vector2 value.
- /// \param parameterIndex - index of parameter to set
- virtual AZ::Vector2 GetParameterVector2(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property as a Vector3 value.
- /// \param parameterIndex - index of parameter to set
- virtual AZ::Vector3 GetParameterVector3(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property given as euler rotation values.
- /// \param parameterIndex - index of parameter to set
- virtual AZ::Vector3 GetParameterRotationEuler(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property as a quaternion value.
- /// \param parameterIndex - index of parameter to set
- virtual AZ::Quaternion GetParameterRotation(size_t parameterIndex) = 0;
- /// Retrieves a anim graph property as a float value.
- /// \param parameterName - name of parameter to get
- virtual float GetNamedParameterFloat(const char* parameterName) = 0;
- /// Retrieves a anim graph property as a boolean value.
- /// \param parameterName - name of parameter to get
- virtual bool GetNamedParameterBool(const char* parameterName) = 0;
- /// Retrieves a anim graph property given a string value.
- /// \param parameterName - name of parameter to get
- virtual AZStd::string GetNamedParameterString(const char* parameterName) = 0;
- /// Retrieves a anim graph property as a Vector2 value.
- /// \param parameterName - name of parameter to get
- virtual AZ::Vector2 GetNamedParameterVector2(const char* parameterName) = 0;
- /// Retrieves a anim graph property as a Vector3 value.
- /// \param parameterName - name of parameter to get
- virtual AZ::Vector3 GetNamedParameterVector3(const char* parameterName) = 0;
- /// Retrieves a anim graph property given as euler rotation values.
- /// \param parameterName - name of parameter to get
- virtual AZ::Vector3 GetNamedParameterRotationEuler(const char* parameterName) = 0;
- /// Retrieves a anim graph property as a quaternion value.
- /// \param parameterName - name of parameter to get
- virtual AZ::Quaternion GetNamedParameterRotation(const char* parameterName) = 0;
- /// Check whether debug visualization is enabled or not.
- virtual bool GetVisualizeEnabled() = 0;
- /// Making a request to sync the anim graph with another animg graph
- /// \param leaderEntityId - the entity id of another anim graph.
- virtual void SyncAnimGraph(AZ::EntityId leaderEntityId) = 0;
- /// Making a request to desync from the anim graph to its leader graph
- /// \param leaderEntityId - the entity id of another anim graph.
- virtual void DesyncAnimGraph(AZ::EntityId leaderEntityId) = 0;
- /// Set the name of the active motion set.
- virtual void SetActiveMotionSet(const char* activeMotionSetName) = 0;
- };
- using AnimGraphComponentRequestBus = AZ::EBus<AnimGraphComponentRequests>;
- /**
- * EmotionFX Anim Graph Component Notification Bus
- * Used for monitoring events from Anim Graph components.
- */
- class AnimGraphComponentNotifications
- : public AZ::ComponentBus
- {
- public:
- //////////////////////////////////////////////////////////////////////////
- /**
- * Custom connection policy notifies connecting listeners immediately if anim graph instance is already created.
- */
- template<class Bus>
- struct AssetConnectionPolicy
- : public AZ::EBusConnectionPolicy<Bus>
- {
- static void Connect(typename Bus::BusPtr& busPtr, typename Bus::Context& context, typename Bus::HandlerNode& handler, typename Bus::Context::ConnectLockGuard& connectLock, const typename Bus::BusIdType& id = 0)
- {
- AZ::EBusConnectionPolicy<Bus>::Connect(busPtr, context, handler, connectLock, id);
- EMotionFX::AnimGraphInstance* instance = nullptr;
- AnimGraphComponentRequestBus::EventResult(instance, id, &AnimGraphComponentRequestBus::Events::GetAnimGraphInstance);
- if (instance)
- {
- handler->OnAnimGraphInstanceCreated(instance);
- }
- }
- };
- template<typename Bus>
- using ConnectionPolicy = AssetConnectionPolicy<Bus>;
- //////////////////////////////////////////////////////////////////////////
- /// Notifies listeners when the component has created a graph instance.
- /// \param animGraphInstance - pointer to anim graph instance
- virtual void OnAnimGraphInstanceCreated(EMotionFX::AnimGraphInstance* /*animGraphInstance*/) {};
- /// Notifies listeners when the component is destroying a graph instance.
- /// \param animGraphInstance - pointer to anim graph instance
- virtual void OnAnimGraphInstanceDestroyed(EMotionFX::AnimGraphInstance* /*animGraphInstance*/) {};
- /// Notifies listeners when a float parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphFloatParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] float beforeValue, [[maybe_unused]] float afterValue) {};
- /// Notifies listeners when a bool parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphBoolParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] bool beforeValue, [[maybe_unused]] bool afterValue) {};
- /// Notifies listeners when a string parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphStringParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] const char* beforeValue, [[maybe_unused]] const char* afterValue) {};
- /// Notifies listeners when a vector2 parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphVector2ParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] const AZ::Vector2& beforeValue, [[maybe_unused]] const AZ::Vector2& afterValue) {};
- /// Notifies listeners when a vector3 parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphVector3ParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] const AZ::Vector3& beforeValue, [[maybe_unused]] const AZ::Vector3& afterValue) {};
- /// Notifies listeners when a rotation parameter changes
- /// \param animGraphInstance - pointer to anim graph instance
- /// \param parameterIndex - index of changed parameter
- /// \param beforeValue - value before the change
- /// \param afterValue - value after the change
- virtual void OnAnimGraphRotationParameterChanged(EMotionFX::AnimGraphInstance* /*animGraphInstance*/, [[maybe_unused]] size_t parameterIndex, [[maybe_unused]] const AZ::Quaternion& beforeValue, [[maybe_unused]] const AZ::Quaternion& afterValue) {};
- /// Notifies listeners when an another anim graph trying to sync this graph
- /// \param animGraphInstance - pointer to the follower anim graph instance
- virtual void OnAnimGraphSynced(EMotionFX::AnimGraphInstance* /*animGraphInstance(Follower)*/) {};
- /// Notifies listeners when an another anim graph trying to desync this graph
- /// \param animGraphInstance - pointer to the follower anim graph instance
- virtual void OnAnimGraphDesynced(EMotionFX::AnimGraphInstance* /*animGraphInstance(Follower)*/) {};
- };
- using AnimGraphComponentNotificationBus = AZ::EBus<AnimGraphComponentNotifications>;
- //Editor
- class EditorAnimGraphComponentRequests
- : public AZ::ComponentBus
- {
- public:
- static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
- /// Retrieves the component's Animgraph AssetId.
- /// \return assetId
- virtual const AZ::Data::AssetId& GetAnimGraphAssetId() = 0;
- /// Retrieves the component's MotionSet AssetId.
- /// \return assetId
- virtual const AZ::Data::AssetId& GetMotionSetAssetId() = 0;
- };
- using EditorAnimGraphComponentRequestBus = AZ::EBus<EditorAnimGraphComponentRequests>;
- } // namespace Integration
- } // namespace EMotionFX
|