11 #ifndef hifi_AnimRandomSwitch_h
12 #define hifi_AnimRandomSwitch_h
47 class AnimRandomSwitch :
public AnimNode {
49 friend class AnimNodeLoader;
50 friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node,
const QJsonObject& jsonObj,
const QString& nodeId,
const QUrl& jsonUrl);
52 enum class InterpType {
61 class RandomSwitchState {
63 friend AnimRandomSwitch;
64 friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node,
const QJsonObject& jsonObj,
const QString& nodeId,
const QUrl& jsonUrl);
66 using Pointer = std::shared_ptr<RandomSwitchState>;
67 using ConstPointer = std::shared_ptr<const RandomSwitchState>;
71 friend AnimRandomSwitch;
72 Transition(
const QString& var, RandomSwitchState::Pointer randomState) : _var(var), _randomSwitchState(randomState) {}
75 RandomSwitchState::Pointer _randomSwitchState;
78 RandomSwitchState(
const QString&
id,
int childIndex,
float interpTarget,
float interpDuration, InterpType interpType, EasingType easingType,
float priority,
bool resume) :
80 _childIndex(childIndex),
81 _interpTarget(interpTarget),
82 _interpDuration(interpDuration),
83 _interpType(interpType),
84 _easingType(easingType),
89 void setInterpTargetVar(
const QString& interpTargetVar) { _interpTargetVar = interpTargetVar; }
90 void setInterpDurationVar(
const QString& interpDurationVar) { _interpDurationVar = interpDurationVar; }
91 void setInterpTypeVar(
const QString& interpTypeVar) { _interpTypeVar = interpTypeVar; }
93 int getChildIndex()
const {
return _childIndex; }
94 float getPriority()
const {
return _priority; }
95 bool getResume()
const {
return _resume; }
96 const QString& getID()
const {
return _id; }
100 void setInterpTarget(
float interpTarget) { _interpTarget = interpTarget; }
101 void setInterpDuration(
float interpDuration) { _interpDuration = interpDuration; }
102 void setPriority(
float priority) { _priority = priority; }
103 void setResumeFlag(
bool resume) { _resume = resume; }
105 void addTransition(
const Transition& transition) { _transitions.push_back(transition); }
110 float _interpDuration;
111 InterpType _interpType;
112 EasingType _easingType;
113 float _priority {0.0f};
114 bool _resume {
false};
116 QString _interpTargetVar;
117 QString _interpDurationVar;
118 QString _interpTypeVar;
120 std::vector<Transition> _transitions;
123 Q_DISABLE_COPY(RandomSwitchState)
128 explicit AnimRandomSwitch(
const QString&
id);
129 virtual ~AnimRandomSwitch()
override;
131 virtual const AnimPoseVec& evaluate(
const AnimVariantMap& animVars,
const AnimContext& context,
float dt, AnimVariantMap& triggersOut)
override;
133 void setCurrentStateVar(QString& currentStateVar) { _currentStateVar = currentStateVar; }
137 void setCurrentState(RandomSwitchState::Pointer randomState);
138 void setTriggerRandomSwitchVar(
const QString& triggerRandomSwitchVar) { _triggerRandomSwitchVar = triggerRandomSwitchVar; }
139 void setRandomSwitchTimeMin(
float randomSwitchTimeMin) { _randomSwitchTimeMin = randomSwitchTimeMin; }
140 void setRandomSwitchTimeMax(
float randomSwitchTimeMax) { _randomSwitchTimeMax = randomSwitchTimeMax; }
141 void setTransitionVar(
const QString& transitionVar) { _transitionVar = transitionVar; }
142 void setTriggerTimeMin(
float triggerTimeMin) { _triggerTimeMin = triggerTimeMin; }
143 void setTriggerTimeMax(
float triggerTimeMax) { _triggerTimeMax = triggerTimeMax; }
145 void addState(RandomSwitchState::Pointer randomState);
147 void switchRandomState(
const AnimVariantMap& animVars,
const AnimContext& context, RandomSwitchState::Pointer desiredState,
bool shouldInterp);
148 RandomSwitchState::Pointer evaluateTransitions(
const AnimVariantMap& animVars)
const;
151 virtual const AnimPoseVec& getPosesInternal()
const override;
152 virtual void setActiveInternal(
bool active)
override;
156 bool _triggerNewRandomState =
false;
158 bool _duringInterp =
false;
159 InterpType _interpType { InterpType::SnapshotPrev };
160 EasingType _easingType { EasingType_Linear };
161 float _alphaVel = 0.0f;
163 AnimPoseVec _prevPoses;
164 AnimPoseVec _nextPoses;
166 RandomSwitchState::Pointer _currentState;
167 RandomSwitchState::Pointer _previousState;
168 std::vector<RandomSwitchState::Pointer> _randomStates;
170 QString _currentStateVar;
171 QString _triggerRandomSwitchVar;
172 QString _transitionVar;
173 float _triggerTimeMin { 10.0f };
174 float _triggerTimeMax { 20.0f };
175 float _triggerTime { 0.0f };
176 float _randomSwitchTimeMin { 10.0f };
177 float _randomSwitchTimeMax { 20.0f };
178 float _randomSwitchTime { 0.0f };
179 QString _lastPlayedState;
182 Q_DISABLE_COPY(AnimRandomSwitch)