made changes requested

This commit is contained in:
Angus Antley 2019-04-25 14:42:41 -07:00
parent 76164ecee8
commit 27ed468946
8 changed files with 96 additions and 99 deletions

View file

@ -989,7 +989,6 @@
"type": "randomSwitchStateMachine", "type": "randomSwitchStateMachine",
"data": { "data": {
"currentState": "masterIdle", "currentState": "masterIdle",
"triggerRandomSwitch": "idleSwitch",
"triggerTimeMin": 10.0, "triggerTimeMin": 10.0,
"triggerTimeMax": 40.0, "triggerTimeMax": 40.0,
"transitionVar": "timeToFidget", "transitionVar": "timeToFidget",
@ -1105,7 +1104,6 @@
"type": "randomSwitchStateMachine", "type": "randomSwitchStateMachine",
"data": { "data": {
"currentState": "movement", "currentState": "movement",
"triggerRandomSwitch": "fidgetSwitch",
"states": [ "states": [
{ {
"id": "movement", "id": "movement",
@ -1131,7 +1129,6 @@
"type": "randomSwitchStateMachine", "type": "randomSwitchStateMachine",
"data": { "data": {
"currentState": "movement1", "currentState": "movement1",
"triggerRandomSwitch": "movementSwitch",
"states": [ "states": [
{ {
"id": "movement1", "id": "movement1",
@ -1303,7 +1300,6 @@
"type": "randomSwitchStateMachine", "type": "randomSwitchStateMachine",
"data": { "data": {
"currentState": "transitionToAltIdle1", "currentState": "transitionToAltIdle1",
"triggerRandomSwitch": "altIdleSwitch",
"triggerTimeMin": 10.0, "triggerTimeMin": 10.0,
"triggerTimeMax": 40.0, "triggerTimeMax": 40.0,
"transitionVar": "finishAltIdle2", "transitionVar": "finishAltIdle2",

View file

@ -11,12 +11,12 @@
#include "AnimContext.h" #include "AnimContext.h"
AnimContext::AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints, bool enableDebugDrawIKChains, AnimContext::AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints, bool enableDebugDrawIKChains,
const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix, int framesAnimatedThisSession) : const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix, int evaluationCount) :
_enableDebugDrawIKTargets(enableDebugDrawIKTargets), _enableDebugDrawIKTargets(enableDebugDrawIKTargets),
_enableDebugDrawIKConstraints(enableDebugDrawIKConstraints), _enableDebugDrawIKConstraints(enableDebugDrawIKConstraints),
_enableDebugDrawIKChains(enableDebugDrawIKChains), _enableDebugDrawIKChains(enableDebugDrawIKChains),
_geometryToRigMatrix(geometryToRigMatrix), _geometryToRigMatrix(geometryToRigMatrix),
_rigToWorldMatrix(rigToWorldMatrix), _rigToWorldMatrix(rigToWorldMatrix),
_framesAnimatedThisSession(framesAnimatedThisSession) _evaluationCount(evaluationCount)
{ {
} }

View file

@ -38,14 +38,14 @@ class AnimContext {
public: public:
AnimContext() {} AnimContext() {}
AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints, bool enableDebugDrawIKChains, AnimContext(bool enableDebugDrawIKTargets, bool enableDebugDrawIKConstraints, bool enableDebugDrawIKChains,
const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix, int framesAnimatedThisSession); const glm::mat4& geometryToRigMatrix, const glm::mat4& rigToWorldMatrix, int evaluationCount);
bool getEnableDebugDrawIKTargets() const { return _enableDebugDrawIKTargets; } bool getEnableDebugDrawIKTargets() const { return _enableDebugDrawIKTargets; }
bool getEnableDebugDrawIKConstraints() const { return _enableDebugDrawIKConstraints; } bool getEnableDebugDrawIKConstraints() const { return _enableDebugDrawIKConstraints; }
bool getEnableDebugDrawIKChains() const { return _enableDebugDrawIKChains; } bool getEnableDebugDrawIKChains() const { return _enableDebugDrawIKChains; }
const glm::mat4& getGeometryToRigMatrix() const { return _geometryToRigMatrix; } const glm::mat4& getGeometryToRigMatrix() const { return _geometryToRigMatrix; }
const glm::mat4& getRigToWorldMatrix() const { return _rigToWorldMatrix; } const glm::mat4& getRigToWorldMatrix() const { return _rigToWorldMatrix; }
int getFramesAnimatedThisSession() const { return _framesAnimatedThisSession; } int getEvaluationCount() const { return _evaluationCount; }
float getDebugAlpha(const QString& key) const { float getDebugAlpha(const QString& key) const {
auto it = _debugAlphaMap.find(key); auto it = _debugAlphaMap.find(key);
@ -87,7 +87,7 @@ protected:
bool _enableDebugDrawIKChains { false }; bool _enableDebugDrawIKChains { false };
glm::mat4 _geometryToRigMatrix; glm::mat4 _geometryToRigMatrix;
glm::mat4 _rigToWorldMatrix; glm::mat4 _rigToWorldMatrix;
int _framesAnimatedThisSession { 0 }; int _evaluationCount{ 0 };
// used for debugging internal state of animation system. // used for debugging internal state of animation system.
mutable DebugAlphaMap _debugAlphaMap; mutable DebugAlphaMap _debugAlphaMap;

View file

@ -25,7 +25,7 @@ const AnimPoseVec& AnimRandomSwitch::evaluate(const AnimVariantMap& animVars, co
float parentDebugAlpha = context.getDebugAlpha(_id); float parentDebugAlpha = context.getDebugAlpha(_id);
AnimRandomSwitch::RandomSwitchState::Pointer desiredState = _currentState; AnimRandomSwitch::RandomSwitchState::Pointer desiredState = _currentState;
if (abs(_framesActive - context.getFramesAnimatedThisSession()) > 1 || animVars.lookup(_triggerRandomSwitchVar, false)) { if (abs(_randomSwitchEvaluationCount - context.getEvaluationCount()) > 1 || animVars.lookup(_triggerRandomSwitchVar, false)) {
// get a random number and decide which motion to choose. // get a random number and decide which motion to choose.
bool currentStateHasPriority = false; bool currentStateHasPriority = false;
float dice = randFloatInRange(0.0f, 1.0f); float dice = randFloatInRange(0.0f, 1.0f);
@ -43,7 +43,7 @@ const AnimPoseVec& AnimRandomSwitch::evaluate(const AnimVariantMap& animVars, co
currentStateHasPriority = currentStateHasPriority || (_currentState == randState); currentStateHasPriority = currentStateHasPriority || (_currentState == randState);
} }
} }
if (abs(_framesActive - context.getFramesAnimatedThisSession()) > 1) { if (abs(_randomSwitchEvaluationCount - context.getEvaluationCount()) > 1) {
_duringInterp = false; _duringInterp = false;
switchRandomState(animVars, context, desiredState, _duringInterp); switchRandomState(animVars, context, desiredState, _duringInterp);
} else { } else {
@ -126,7 +126,7 @@ const AnimPoseVec& AnimRandomSwitch::evaluate(const AnimVariantMap& animVars, co
_poses = currentStateNode->evaluate(animVars, context, dt, triggersOut); _poses = currentStateNode->evaluate(animVars, context, dt, triggersOut);
} }
_framesActive = context.getFramesAnimatedThisSession(); _randomSwitchEvaluationCount = context.getEvaluationCount();
processOutputJoints(triggersOut); processOutputJoints(triggersOut);
context.addStateMachineInfo(_id, _currentState->getID(), _previousState->getID(), _duringInterp, _alpha); context.addStateMachineInfo(_id, _currentState->getID(), _previousState->getID(), _duringInterp, _alpha);

View file

@ -35,103 +35,104 @@
// * priority - this number represents how likely this Random Switch State will be chosen. // * priority - this number represents how likely this Random Switch State will be chosen.
// the priority for each Random Switch State will be normalized, so their relative size is what is important // the priority for each Random Switch State will be normalized, so their relative size is what is important
// * resume - if resume is false then if this state is chosen twice in a row it will remember what frame it was playing on. // * resume - if resume is false then if this state is chosen twice in a row it will remember what frame it was playing on.
// * SnapshotBoth: Stores two snapshots, the previous animation before interpolation begins and the target state at the // * SnapshotBoth: Stores two snapshots, the previous animation before interpolation begins and the target state at the
// interTarget frame. Then during the interpolation period the two snapshots are interpolated to produce smooth motion between them. // interTarget frame. Then during the interpolation period the two snapshots are interpolated to produce smooth motion between them.
// * SnapshotPrev: Stores a snapshot of the previous animation before interpolation begins. However the target state is // * SnapshotPrev: Stores a snapshot of the previous animation before interpolation begins. However the target state is
// evaluated dynamically. During the interpolation period the previous snapshot is interpolated with the target pose // evaluated dynamically. During the interpolation period the previous snapshot is interpolated with the target pose
// to produce smooth motion between them. This mode is useful for interping into a blended animation where the actual // to produce smooth motion between them. This mode is useful for interping into a blended animation where the actual
// blend factor is not known at the start of the interp or is might change dramatically during the interp. // blend factor is not known at the start of the interp or is might change dramatically during the interp.
//
class AnimRandomSwitch : public AnimNode { class AnimRandomSwitch : public AnimNode {
public: public:
friend class AnimNodeLoader; friend class AnimNodeLoader;
friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj, const QString& nodeId, const QUrl& jsonUrl); friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj, const QString& nodeId, const QUrl& jsonUrl);
enum class InterpType { enum class InterpType {
SnapshotBoth = 0, SnapshotBoth = 0,
SnapshotPrev, SnapshotPrev,
NumTypes NumTypes
}; };
protected: protected:
class RandomSwitchState { class RandomSwitchState {
public: public:
friend AnimRandomSwitch; friend AnimRandomSwitch;
friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj, const QString& nodeId, const QUrl& jsonUrl); friend bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObject& jsonObj, const QString& nodeId, const QUrl& jsonUrl);
using Pointer = std::shared_ptr<RandomSwitchState>; using Pointer = std::shared_ptr<RandomSwitchState>;
using ConstPointer = std::shared_ptr<const RandomSwitchState>; using ConstPointer = std::shared_ptr<const RandomSwitchState>;
class Transition { class Transition {
public: public:
friend AnimRandomSwitch; friend AnimRandomSwitch;
Transition(const QString& var, RandomSwitchState::Pointer randomState) : _var(var), _randomSwitchState(randomState) {} Transition(const QString& var, RandomSwitchState::Pointer randomState) : _var(var), _randomSwitchState(randomState) {}
protected: protected:
QString _var; QString _var;
RandomSwitchState::Pointer _randomSwitchState; RandomSwitchState::Pointer _randomSwitchState;
}; };
RandomSwitchState(const QString& id, int childIndex, float interpTarget, float interpDuration, InterpType interpType, float priority, bool resume) : RandomSwitchState(const QString& id, int childIndex, float interpTarget, float interpDuration, InterpType interpType, float priority, bool resume) :
_id(id), _id(id),
_childIndex(childIndex), _childIndex(childIndex),
_interpTarget(interpTarget), _interpTarget(interpTarget),
_interpDuration(interpDuration), _interpDuration(interpDuration),
_interpType(interpType), _interpType(interpType),
_priority(priority), _priority(priority),
_resume(resume){ _resume(resume){
} }
void setInterpTargetVar(const QString& interpTargetVar) { _interpTargetVar = interpTargetVar; } void setInterpTargetVar(const QString& interpTargetVar) { _interpTargetVar = interpTargetVar; }
void setInterpDurationVar(const QString& interpDurationVar) { _interpDurationVar = interpDurationVar; } void setInterpDurationVar(const QString& interpDurationVar) { _interpDurationVar = interpDurationVar; }
void setInterpTypeVar(const QString& interpTypeVar) { _interpTypeVar = interpTypeVar; } void setInterpTypeVar(const QString& interpTypeVar) { _interpTypeVar = interpTypeVar; }
int getChildIndex() const { return _childIndex; } int getChildIndex() const { return _childIndex; }
float getPriority() const { return _priority; } float getPriority() const { return _priority; }
bool getResume() const { return _resume; } bool getResume() const { return _resume; }
const QString& getID() const { return _id; } const QString& getID() const { return _id; }
protected: protected:
void setInterpTarget(float interpTarget) { _interpTarget = interpTarget; } void setInterpTarget(float interpTarget) { _interpTarget = interpTarget; }
void setInterpDuration(float interpDuration) { _interpDuration = interpDuration; } void setInterpDuration(float interpDuration) { _interpDuration = interpDuration; }
void setPriority(float priority) { _priority = priority; } void setPriority(float priority) { _priority = priority; }
void setResumeFlag(bool resume) { _resume = resume; } void setResumeFlag(bool resume) { _resume = resume; }
void addTransition(const Transition& transition) { _transitions.push_back(transition); } void addTransition(const Transition& transition) { _transitions.push_back(transition); }
QString _id; QString _id;
int _childIndex; int _childIndex;
float _interpTarget; // frames float _interpTarget; // frames
float _interpDuration; // frames float _interpDuration; // frames
InterpType _interpType; InterpType _interpType;
float _priority {0.0f}; float _priority {0.0f};
bool _resume {false}; bool _resume {false};
QString _interpTargetVar; QString _interpTargetVar;
QString _interpDurationVar; QString _interpDurationVar;
QString _interpTypeVar; QString _interpTypeVar;
std::vector<Transition> _transitions; std::vector<Transition> _transitions;
private: private:
// no copies // no copies
RandomSwitchState(const RandomSwitchState&) = delete; RandomSwitchState(const RandomSwitchState&) = delete;
RandomSwitchState& operator=(const RandomSwitchState&) = delete; RandomSwitchState& operator=(const RandomSwitchState&) = delete;
}; };
public: public:
explicit AnimRandomSwitch(const QString& id); explicit AnimRandomSwitch(const QString& id);
virtual ~AnimRandomSwitch() override; virtual ~AnimRandomSwitch() override;
virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override; virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override;
void setCurrentStateVar(QString& currentStateVar) { _currentStateVar = currentStateVar; } void setCurrentStateVar(QString& currentStateVar) { _currentStateVar = currentStateVar; }
protected: protected:
void setCurrentState(RandomSwitchState::Pointer randomState); void setCurrentState(RandomSwitchState::Pointer randomState);
void setTriggerRandomSwitchVar(const QString& triggerRandomSwitchVar) { _triggerRandomSwitchVar = triggerRandomSwitchVar; } void setTriggerRandomSwitchVar(const QString& triggerRandomSwitchVar) { _triggerRandomSwitchVar = triggerRandomSwitchVar; }
void setRandomSwitchTimeMin(float randomSwitchTimeMin) { _randomSwitchTimeMin = randomSwitchTimeMin; } void setRandomSwitchTimeMin(float randomSwitchTimeMin) { _randomSwitchTimeMin = randomSwitchTimeMin; }
void setRandomSwitchTimeMax(float randomSwitchTimeMax) { _randomSwitchTimeMax = randomSwitchTimeMax; } void setRandomSwitchTimeMax(float randomSwitchTimeMax) { _randomSwitchTimeMax = randomSwitchTimeMax; }
@ -140,31 +141,31 @@ protected:
void setTriggerTimeMax(float triggerTimeMax) { _triggerTimeMax = triggerTimeMax; } void setTriggerTimeMax(float triggerTimeMax) { _triggerTimeMax = triggerTimeMax; }
void addToPrioritySum(float priority) { _totalPriorities += priority; } void addToPrioritySum(float priority) { _totalPriorities += priority; }
void addState(RandomSwitchState::Pointer randomState); void addState(RandomSwitchState::Pointer randomState);
void switchRandomState(const AnimVariantMap& animVars, const AnimContext& context, RandomSwitchState::Pointer desiredState, bool shouldInterp); void switchRandomState(const AnimVariantMap& animVars, const AnimContext& context, RandomSwitchState::Pointer desiredState, bool shouldInterp);
RandomSwitchState::Pointer evaluateTransitions(const AnimVariantMap& animVars) const; RandomSwitchState::Pointer evaluateTransitions(const AnimVariantMap& animVars) const;
// for AnimDebugDraw rendering // for AnimDebugDraw rendering
virtual const AnimPoseVec& getPosesInternal() const override; virtual const AnimPoseVec& getPosesInternal() const override;
AnimPoseVec _poses; AnimPoseVec _poses;
int _framesActive { 0 }; int _randomSwitchEvaluationCount { 0 };
// interpolation state // interpolation state
bool _duringInterp = false; bool _duringInterp = false;
InterpType _interpType{ InterpType::SnapshotPrev }; InterpType _interpType{ InterpType::SnapshotPrev };
float _alphaVel = 0.0f; float _alphaVel = 0.0f;
float _alpha = 0.0f; float _alpha = 0.0f;
AnimPoseVec _prevPoses; AnimPoseVec _prevPoses;
AnimPoseVec _nextPoses; AnimPoseVec _nextPoses;
float _totalPriorities { 0.0f }; float _totalPriorities { 0.0f };
RandomSwitchState::Pointer _currentState; RandomSwitchState::Pointer _currentState;
RandomSwitchState::Pointer _previousState; RandomSwitchState::Pointer _previousState;
std::vector<RandomSwitchState::Pointer> _randomStates; std::vector<RandomSwitchState::Pointer> _randomStates;
QString _currentStateVar; QString _currentStateVar;
QString _triggerRandomSwitchVar; QString _triggerRandomSwitchVar;
QString _transitionVar; QString _transitionVar;
float _triggerTimeMin { 10.0f }; float _triggerTimeMin { 10.0f };
@ -175,9 +176,9 @@ protected:
float _randomSwitchTime { 0.0f }; float _randomSwitchTime { 0.0f };
private: private:
// no copies // no copies
AnimRandomSwitch(const AnimRandomSwitch&) = delete; AnimRandomSwitch(const AnimRandomSwitch&) = delete;
AnimRandomSwitch& operator=(const AnimRandomSwitch&) = delete; AnimRandomSwitch& operator=(const AnimRandomSwitch&) = delete;
}; };
#endif // hifi_AnimRandomSwitch_h #endif // hifi_AnimRandomSwitch_h

View file

@ -1480,7 +1480,7 @@ void Rig::updateAnimations(float deltaTime, const glm::mat4& rootTransform, cons
if (_animNode && _enabledAnimations) { if (_animNode && _enabledAnimations) {
DETAILED_PERFORMANCE_TIMER("handleTriggers"); DETAILED_PERFORMANCE_TIMER("handleTriggers");
++_framesAnimatedThisSession; ++_evaluationCount;
updateAnimationStateHandlers(); updateAnimationStateHandlers();
_animVars.setRigToGeometryTransform(_rigToGeometryTransform); _animVars.setRigToGeometryTransform(_rigToGeometryTransform);
@ -1488,7 +1488,7 @@ void Rig::updateAnimations(float deltaTime, const glm::mat4& rootTransform, cons
_networkVars.setRigToGeometryTransform(_rigToGeometryTransform); _networkVars.setRigToGeometryTransform(_rigToGeometryTransform);
} }
AnimContext context(_enableDebugDrawIKTargets, _enableDebugDrawIKConstraints, _enableDebugDrawIKChains, AnimContext context(_enableDebugDrawIKTargets, _enableDebugDrawIKConstraints, _enableDebugDrawIKChains,
getGeometryToRigTransform(), rigToWorldTransform, _framesAnimatedThisSession); getGeometryToRigTransform(), rigToWorldTransform, _evaluationCount);
// evaluate the animation // evaluate the animation
AnimVariantMap triggersOut; AnimVariantMap triggersOut;

View file

@ -418,7 +418,7 @@ protected:
HandAnimState _rightHandAnimState; HandAnimState _rightHandAnimState;
HandAnimState _leftHandAnimState; HandAnimState _leftHandAnimState;
std::map<QString, RoleAnimState> _roleAnimStates; std::map<QString, RoleAnimState> _roleAnimStates;
int _framesAnimatedThisSession { 0 }; int _evaluationCount{ 0 };
float _leftHandOverlayAlpha { 0.0f }; float _leftHandOverlayAlpha { 0.0f };
float _rightHandOverlayAlpha { 0.0f }; float _rightHandOverlayAlpha { 0.0f };

View file

@ -94,7 +94,7 @@ void makeTestFBXJoints(HFMModel& hfmModel) {
void AnimInverseKinematicsTests::testSingleChain() { void AnimInverseKinematicsTests::testSingleChain() {
AnimContext context(false, false, false, glm::mat4(), glm::mat4(),0); AnimContext context(false, false, false, glm::mat4(), glm::mat4(), 0);
HFMModel hfmModel; HFMModel hfmModel;
makeTestFBXJoints(hfmModel); makeTestFBXJoints(hfmModel);