11 #ifndef hifi_AnimStateMachine_h
12 #define hifi_AnimStateMachine_h
43 class AnimStateMachine :
public AnimNode {
45 friend class AnimNodeLoader;
46 friend bool processStateMachineNode(AnimNode::Pointer node,
const QJsonObject& jsonObj,
const QString& nodeId,
const QUrl& jsonUrl);
48 enum class InterpType {
59 friend AnimStateMachine;
60 friend bool processStateMachineNode(AnimNode::Pointer node,
const QJsonObject& jsonObj,
const QString& nodeId,
const QUrl& jsonUrl);
62 using Pointer = std::shared_ptr<State>;
63 using ConstPointer = std::shared_ptr<const State>;
67 friend AnimStateMachine;
68 Transition(
const QString& var, State::Pointer state) : _var(var), _state(state) {}
71 State::Pointer _state;
74 State(
const QString&
id,
int childIndex,
float interpTarget,
float interpDuration, InterpType interpType, EasingType easingType) :
76 _childIndex(childIndex),
77 _interpTarget(interpTarget),
78 _interpDuration(interpDuration),
79 _interpType(interpType),
80 _easingType(easingType) {}
82 void setInterpTargetVar(
const QString& interpTargetVar) { _interpTargetVar = interpTargetVar; }
83 void setInterpDurationVar(
const QString& interpDurationVar) { _interpDurationVar = interpDurationVar; }
84 void setInterpTypeVar(
const QString& interpTypeVar) { _interpTypeVar = interpTypeVar; }
86 int getChildIndex()
const {
return _childIndex; }
87 const QString& getID()
const {
return _id; }
91 void setInterpTarget(
float interpTarget) { _interpTarget = interpTarget; }
92 void setInterpDuration(
float interpDuration) { _interpDuration = interpDuration; }
94 void addTransition(
const Transition& transition) { _transitions.push_back(transition); }
99 float _interpDuration;
100 InterpType _interpType;
101 EasingType _easingType;
103 QString _interpTargetVar;
104 QString _interpDurationVar;
105 QString _interpTypeVar;
107 std::vector<Transition> _transitions;
110 Q_DISABLE_COPY(State)
115 explicit AnimStateMachine(
const QString&
id);
116 virtual ~AnimStateMachine()
override;
118 virtual const AnimPoseVec& evaluate(
const AnimVariantMap& animVars,
const AnimContext& context,
float dt, AnimVariantMap& triggersOut)
override;
120 void setCurrentStateVar(QString& currentStateVar) { _currentStateVar = currentStateVar; }
121 const QString& getCurrentStateID()
const;
125 void setCurrentState(State::Pointer state);
127 void addState(State::Pointer state);
129 void switchState(
const AnimVariantMap& animVars,
const AnimContext& context, State::Pointer desiredState);
130 State::Pointer evaluateTransitions(
const AnimVariantMap& animVars)
const;
133 virtual const AnimPoseVec& getPosesInternal()
const override;
138 bool _duringInterp =
false;
139 InterpType _interpType { InterpType::SnapshotPrev };
140 EasingType _easingType { EasingType_Linear };
141 float _alphaVel = 0.0f;
143 AnimPoseVec _prevPoses;
144 AnimPoseVec _nextPoses;
146 State::Pointer _currentState;
147 State::Pointer _previousState;
148 std::vector<State::Pointer> _states;
150 QString _currentStateVar;
153 Q_DISABLE_COPY(AnimStateMachine)