working on the ease in function for the talk idle

This commit is contained in:
amantley 2019-04-23 18:13:15 -07:00
parent 70d8200bdc
commit 7f3101eefb
6 changed files with 46 additions and 13 deletions

View file

@ -949,7 +949,7 @@
"type": "clip",
"data": {
"url": "qrc:///avatar/animations/talk.fbx",
"startFrame": 0.0,
"startFrame": 1.0,
"endFrame": 800.0,
"timeScale": 1.0,
"loopFlag": true
@ -1011,7 +1011,7 @@
"type": "clip",
"data": {
"url": "qrc:///avatar/animations/talk.fbx",
"startFrame": 0.0,
"startFrame": 1.0,
"endFrame": 800.0,
"timeScale": 1.0,
"loopFlag": true
@ -1066,7 +1066,7 @@
"type": "clip",
"data": {
"url": "qrc:///avatar/animations/talk.fbx",
"startFrame": 0.0,
"startFrame": 1.0,
"endFrame": 800.0,
"timeScale": 1.0,
"loopFlag": true
@ -1078,7 +1078,7 @@
"type": "clip",
"data": {
"url": "qrc:///avatar/animations/talk.fbx",
"startFrame": 0.0,
"startFrame": 1.0,
"endFrame": 800.0,
"timeScale": 1.0,
"loopFlag": true
@ -1090,7 +1090,7 @@
"type": "clip",
"data": {
"url": "qrc:///avatar/animations/talk.fbx",
"startFrame": 0.0,
"startFrame": 1.0,
"endFrame": 800.0,
"timeScale": 1.0,
"loopFlag": true

View file

@ -806,12 +806,15 @@ bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObje
assert(smNode);
READ_STRING(currentState, jsonObj, nodeId, jsonUrl, false);
READ_OPTIONAL_FLOAT(randomSwitchTimeMin, jsonObj, -1.0f);
READ_OPTIONAL_FLOAT(randomSwitchTimeMax, jsonObj, -1.0f);
READ_STRING(triggerRandomSwitch, jsonObj, nodeId, jsonUrl, false);
READ_OPTIONAL_FLOAT(triggerTimeMin, jsonObj, 1.0f);
READ_OPTIONAL_FLOAT(triggerTimeMax, jsonObj, 1.0f);
READ_OPTIONAL_FLOAT(triggerTimeMin, jsonObj, -1.0f);
READ_OPTIONAL_FLOAT(triggerTimeMax, jsonObj, -1.0f);
READ_OPTIONAL_STRING(transitionVar, jsonObj);
auto statesValue = jsonObj.value("states");
if (!statesValue.isArray()) {
qCCritical(animation) << "AnimNodeLoader, bad array \"states\" in random switch state Machine node, id =" << nodeId;
@ -921,6 +924,8 @@ bool processRandomSwitchStateMachineNode(AnimNode::Pointer node, const QJsonObje
qCCritical(animation) << "AnimNodeLoader, bad currentState =" << currentState << "could not find child node" << "id =" << nodeId;
}
smNode->setCurrentState(iter->second);
smNode->setRandomSwitchTimeMin(randomSwitchTimeMin);
smNode->setRandomSwitchTimeMax(randomSwitchTimeMax);
smNode->setTriggerRandomSwitchVar(triggerRandomSwitch);
smNode->setTriggerTimeMin(triggerTimeMin);
smNode->setTriggerTimeMax(triggerTimeMax);

View file

@ -52,24 +52,31 @@ const AnimPoseVec& AnimRandomSwitch::evaluate(const AnimVariantMap& animVars, co
}
}
_triggerTime = randFloatInRange(_triggerTimeMin, _triggerTimeMax);
_randomSwitchTime = randFloatInRange(_randomSwitchTimeMin, _randomSwitchTimeMax);
} else {
// here we are checking to see if we want a temporary movement
// evaluate currentState transitions
auto desiredState = evaluateTransitions(animVars);
if (desiredState != _currentState) {
auto transitionState = evaluateTransitions(animVars);
if (transitionState != _currentState) {
_duringInterp = true;
switchRandomState(animVars, context, desiredState, _duringInterp);
switchRandomState(animVars, context, transitionState, _duringInterp);
_triggerTime = randFloatInRange(_triggerTimeMin, _triggerTimeMax);
_randomSwitchTime = randFloatInRange(_randomSwitchTimeMin, _randomSwitchTimeMax);
}
}
_triggerTime -= dt;
if (_triggerTime < 0.0f) {
if ((_triggerTime < 0.0f) && (_triggerTimeMin > 0.0f) && (_triggerTimeMax > 0.0f)) {
_triggerTime = randFloatInRange(_triggerTimeMin, _triggerTimeMax);
triggersOut.setTrigger(_transitionVar);
}
_randomSwitchTime -= dt;
if ((_randomSwitchTime < 0.0f) && (_randomSwitchTimeMin > 0.0f) && (_randomSwitchTimeMax > 0.0f)) {
_randomSwitchTime = randFloatInRange(_randomSwitchTimeMin, _randomSwitchTimeMax);
triggersOut.setTrigger(_triggerRandomSwitchVar);
}
assert(_currentState);
auto currentStateNode = _children[_currentState->getChildIndex()];

View file

@ -133,6 +133,8 @@ protected:
void setCurrentState(RandomSwitchState::Pointer randomState);
void setTriggerRandomSwitchVar(const QString& triggerRandomSwitchVar) { _triggerRandomSwitchVar = triggerRandomSwitchVar; }
void setRandomSwitchTimeMin(float randomSwitchTimeMin) { _randomSwitchTimeMin = randomSwitchTimeMin; }
void setRandomSwitchTimeMax(float randomSwitchTimeMax) { _randomSwitchTimeMax = randomSwitchTimeMax; }
void setTransitionVar(const QString& transitionVar) { _transitionVar = transitionVar; }
void setTriggerTimeMin(float triggerTimeMin) { _triggerTimeMin = triggerTimeMin; }
void setTriggerTimeMax(float triggerTimeMax) { _triggerTimeMax = triggerTimeMax; }
@ -168,6 +170,9 @@ protected:
float _triggerTimeMin { 10.0f };
float _triggerTimeMax { 20.0f };
float _triggerTime { 0.0f };
float _randomSwitchTimeMin { 10.0f };
float _randomSwitchTimeMax { 20.0f };
float _randomSwitchTime { 0.0f };
private:
// no copies

View file

@ -2011,11 +2011,25 @@ void Rig::updateFromControllerParameters(const ControllerParameters& params, flo
return;
}
const float OVERLAY_RAMP_RATE = 8.0f;
if (params.isTalking) {
_animVars.set("idleOverlayAlpha", 1.0f);
if (_talkIdleInterpTime < 1.0f) {
_talkIdleInterpTime += dt;
_talkIdleOverlayAlpha = glm::clamp((_talkIdleInterpTime*_talkIdleInterpTime*_talkIdleInterpTime), 0.0f, 1.0f);
//_talkIdleOverlayAlpha = glm::clamp(_talkIdleOverlayAlpha + OVERLAY_RAMP_RATE * dt, 0.0f, 1.0f);
} else {
_talkIdleInterpTime = 1.0f;
}
} else {
_animVars.set("idleOverlayAlpha", 0.0f);
if (_talkIdleOverlayAlpha > 0.0f) {
_talkIdleInterpTime += dt;
_talkIdleOverlayAlpha = glm::clamp((_talkIdleInterpTime*_talkIdleInterpTime*_talkIdleInterpTime), 0.0f, 1.0f);
// _talkIdleOverlayAlpha = glm::clamp(_talkIdleOverlayAlpha - OVERLAY_RAMP_RATE * dt, 0.0f, 1.0f);
} else {
_talkIdleInterpTime = 0.0f;
}
}
_animVars.set("idleOverlayAlpha", _talkIdleOverlayAlpha);
_headEnabled = params.primaryControllerFlags[PrimaryControllerType_Head] & (uint8_t)ControllerFlags::Enabled;
bool leftHandEnabled = params.primaryControllerFlags[PrimaryControllerType_LeftHand] & (uint8_t)ControllerFlags::Enabled;

View file

@ -422,6 +422,8 @@ protected:
float _leftHandOverlayAlpha { 0.0f };
float _rightHandOverlayAlpha { 0.0f };
float _talkIdleOverlayAlpha { 0.0f };
float _talkIdleInterpTime { 0.0f };
SimpleMovingAverage _averageForwardSpeed { 10 };
SimpleMovingAverage _averageLateralSpeed { 10 };