PoseDataJointVelocities.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #pragma once
  9. #include <AzCore/Math/Vector3.h>
  10. #include <AzCore/Math/Quaternion.h>
  11. #include <EMotionFX/Source/AnimGraphPosePool.h>
  12. #include <EMotionFX/Source/PoseData.h>
  13. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  14. namespace EMotionFX::MotionMatching
  15. {
  16. //! Extends a given pose with joint-relative linear and angular velocities.
  17. class EMFX_API PoseDataJointVelocities
  18. : public PoseData
  19. {
  20. public:
  21. AZ_RTTI(PoseDataJointVelocities, "{9C082B82-7225-4550-A52C-C920CCC2482C}", PoseData)
  22. AZ_CLASS_ALLOCATOR_DECL
  23. PoseDataJointVelocities();
  24. ~PoseDataJointVelocities();
  25. void Clear();
  26. void LinkToActorInstance(const ActorInstance* actorInstance) override;
  27. void LinkToActor(const Actor* actor) override;
  28. //! Zero all linear and angular velocities.
  29. void Reset() override;
  30. void CopyFrom(const PoseData* from) override;
  31. void Blend(const Pose* destPose, float weight) override;
  32. //! Calculate velocities for all joints in the pose.
  33. //! @param[in] actorInstance The actor instance to use the skeleton and bind pose from.
  34. //! @param[in] posePool Calculating velocities will require to sample the motion across a small window of time. The pose pool is used for storing temporary poses.
  35. //! Note that the pose pool is not thread-safe.
  36. //! @param[in] motion The source motion to use to calculate the velocities.
  37. //! @param[in] requestedSampleTime The point in time in the motion to calculate the velocities for.
  38. //! @param[in] relativeToJointIndex Calculate velocities relative to a given joint transform.
  39. void CalculateVelocity(const ActorInstance* actorInstance, AnimGraphPosePool& posePool, Motion* motion, float requestedSampleTime, size_t relativeToJointIndex);
  40. void DebugDraw(AzFramework::DebugDisplayRequests& debugDisplay, const AZ::Color& color) const override;
  41. AZStd::vector<AZ::Vector3>& GetVelocities() { return m_velocities; }
  42. const AZStd::vector<AZ::Vector3>& GetVelocities() const { return m_velocities; }
  43. const AZ::Vector3& GetVelocity(size_t jointIndex) { return m_velocities[jointIndex]; }
  44. AZStd::vector<AZ::Vector3>& GetAngularVelocities() { return m_angularVelocities; }
  45. const AZStd::vector<AZ::Vector3>& GetAngularVelocities() const { return m_angularVelocities; }
  46. const AZ::Vector3& GetAngularVelocity(size_t jointIndex) { return m_angularVelocities[jointIndex]; }
  47. static void Reflect(AZ::ReflectContext* context);
  48. void SetRelativeToJointIndex(size_t relativeToJointIndex);
  49. private:
  50. AZStd::vector<AZ::Vector3> m_velocities;
  51. AZStd::vector<AZ::Vector3> m_angularVelocities;
  52. size_t m_relativeToJointIndex = InvalidIndex;
  53. };
  54. } // namespace EMotionFX::MotionMatching