Path: blob/master/thirdparty/jolt_physics/Jolt/Skeleton/SkeletalAnimation.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/Reference.h>7#include <Jolt/Core/Result.h>8#include <Jolt/Core/StreamUtils.h>9#include <Jolt/ObjectStream/SerializableObject.h>1011JPH_NAMESPACE_BEGIN1213class SkeletonPose;1415/// Resource for a skinned animation16class JPH_EXPORT SkeletalAnimation : public RefTarget<SkeletalAnimation>17{18JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, SkeletalAnimation)1920public:21/// Contains the current state of a joint, a local space transformation relative to its parent joint22class JointState23{24JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, JointState)2526public:27/// Convert from a local space matrix28void FromMatrix(Mat44Arg inMatrix);2930/// Convert to matrix representation31inline Mat44 ToMatrix() const { return Mat44::sRotationTranslation(mRotation, mTranslation); }3233Quat mRotation = Quat::sIdentity(); ///< Local space rotation of the joint34Vec3 mTranslation = Vec3::sZero(); ///< Local space translation of the joint35};3637/// Contains the state of a single joint at a particular time38class Keyframe : public JointState39{40JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Keyframe)4142public:43float mTime = 0.0f; ///< Time of keyframe in seconds44};4546using KeyframeVector = Array<Keyframe>;4748/// Contains the animation for a single joint49class AnimatedJoint50{51JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, AnimatedJoint)5253public:54String mJointName; ///< Name of the joint55KeyframeVector mKeyframes; ///< List of keyframes over time56};5758using AnimatedJointVector = Array<AnimatedJoint>;5960/// Get the length (in seconds) of this animation61float GetDuration() const;6263/// Scale the size of all joints by inScale64void ScaleJoints(float inScale);6566/// If the animation is looping or not. If an animation is looping, the animation will continue playing after completion67void SetIsLooping(bool inIsLooping) { mIsLooping = inIsLooping; }68bool IsLooping() const { return mIsLooping; }6970/// Get the (interpolated) joint transforms at time inTime71void Sample(float inTime, SkeletonPose &ioPose) const;7273/// Get joint samples74const AnimatedJointVector & GetAnimatedJoints() const { return mAnimatedJoints; }75AnimatedJointVector & GetAnimatedJoints() { return mAnimatedJoints; }7677/// Saves the state of this animation in binary form to inStream.78void SaveBinaryState(StreamOut &inStream) const;7980using AnimationResult = Result<Ref<SkeletalAnimation>>;8182/// Restore a saved ragdoll from inStream83static AnimationResult sRestoreFromBinaryState(StreamIn &inStream);8485private:86AnimatedJointVector mAnimatedJoints; ///< List of joints and keyframes87bool mIsLooping = true; ///< If this animation loops back to start88};8990JPH_NAMESPACE_END919293