mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:48:38 +02:00
Make Animation Tests Pass Again
This commit is contained in:
parent
9c8e21ec6b
commit
2c40b120ca
6 changed files with 40 additions and 41 deletions
|
@ -151,10 +151,10 @@ void AnimBlendLinearMove::setFrameAndPhase(float dt, float alpha, int prevPoseIn
|
||||||
if (_phase < 0.0f) {
|
if (_phase < 0.0f) {
|
||||||
_phase = 0.0f;
|
_phase = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect loop trigger events
|
// detect loop trigger events
|
||||||
if (_phase >= 1.0f) {
|
if (_phase >= 1.0f) {
|
||||||
triggersOut.setTrigger(_id + "Loop");
|
triggersOut.setTrigger(_id + "OnLoop");
|
||||||
_phase = glm::fract(_phase);
|
_phase = glm::fract(_phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,15 +209,14 @@ public:
|
||||||
void set(const QString& key, const QString& value) { _map[key] = AnimVariant(value); }
|
void set(const QString& key, const QString& value) { _map[key] = AnimVariant(value); }
|
||||||
void unset(const QString& key) { _map.erase(key); }
|
void unset(const QString& key) { _map.erase(key); }
|
||||||
|
|
||||||
void setTrigger(const QString& key) { _triggers.insert(key); }
|
void setTrigger(const QString& key) { _map[key] = AnimVariant(true); }
|
||||||
void clearTriggers() { _triggers.clear(); }
|
|
||||||
|
|
||||||
void setRigToGeometryTransform(const glm::mat4& rigToGeometry) {
|
void setRigToGeometryTransform(const glm::mat4& rigToGeometry) {
|
||||||
_rigToGeometryMat = rigToGeometry;
|
_rigToGeometryMat = rigToGeometry;
|
||||||
_rigToGeometryRot = glmExtractRotation(rigToGeometry);
|
_rigToGeometryRot = glmExtractRotation(rigToGeometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMap() { _map.clear(); }
|
void clearMap() { _map.clear(); _triggers.clear(); }
|
||||||
bool hasKey(const QString& key) const { return _map.find(key) != _map.end(); }
|
bool hasKey(const QString& key) const { return _map.find(key) != _map.end(); }
|
||||||
|
|
||||||
const AnimVariant& get(const QString& key) const {
|
const AnimVariant& get(const QString& key) const {
|
||||||
|
@ -238,7 +237,7 @@ public:
|
||||||
// For stat debugging.
|
// For stat debugging.
|
||||||
std::map<QString, QString> toDebugMap() const;
|
std::map<QString, QString> toDebugMap() const;
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifndef NDEBUG
|
||||||
void dump() const {
|
void dump() const {
|
||||||
qCDebug(animation) << "AnimVariantMap =";
|
qCDebug(animation) << "AnimVariantMap =";
|
||||||
for (auto& pair : _map) {
|
for (auto& pair : _map) {
|
||||||
|
|
|
@ -1207,9 +1207,7 @@ void Rig::updateAnimations(float deltaTime, const glm::mat4& rootTransform, cons
|
||||||
_networkPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses();
|
_networkPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses();
|
||||||
}
|
}
|
||||||
_lastAnimVars = _animVars;
|
_lastAnimVars = _animVars;
|
||||||
_animVars.clearTriggers();
|
|
||||||
_animVars = triggersOut;
|
_animVars = triggersOut;
|
||||||
_networkVars.clearTriggers();
|
|
||||||
_networkVars = networkTriggersOut;
|
_networkVars = networkTriggersOut;
|
||||||
_lastContext = context;
|
_lastContext = context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Declare dependencies
|
# Declare dependencies
|
||||||
macro (setup_testcase_dependencies)
|
macro (setup_testcase_dependencies)
|
||||||
# link in the shared libraries
|
# link in the shared libraries
|
||||||
link_hifi_libraries(shared animation gpu fbx graphics networking test-utils)
|
link_hifi_libraries(shared animation gpu fbx hfm graphics networking test-utils)
|
||||||
|
|
||||||
package_libraries_for_deployment()
|
package_libraries_for_deployment()
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
|
@ -143,7 +143,7 @@ void AnimInverseKinematicsTests::testSingleChain() {
|
||||||
ikDoll.setTargetVars(QString("D"), QString("positionD"), QString("rotationD"), QString("targetTypeD"),
|
ikDoll.setTargetVars(QString("D"), QString("positionD"), QString("rotationD"), QString("targetTypeD"),
|
||||||
QString("weightD"), 1.0f, flexCoefficients, QString("poleVectorEnabledD"),
|
QString("weightD"), 1.0f, flexCoefficients, QString("poleVectorEnabledD"),
|
||||||
QString("poleReferenceVectorD"), QString("poleVectorD"));
|
QString("poleReferenceVectorD"), QString("poleVectorD"));
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
|
|
||||||
// the IK solution should be:
|
// the IK solution should be:
|
||||||
//
|
//
|
||||||
|
@ -236,7 +236,7 @@ void AnimInverseKinematicsTests::testSingleChain() {
|
||||||
ikDoll.setTargetVars(QString("D"), QString("positionD"), QString("rotationD"), QString("targetTypeD"),
|
ikDoll.setTargetVars(QString("D"), QString("positionD"), QString("rotationD"), QString("targetTypeD"),
|
||||||
QString("weightD"), 1.0f, flexCoefficients, QString("poleVectorEnabledD"),
|
QString("weightD"), 1.0f, flexCoefficients, QString("poleVectorEnabledD"),
|
||||||
QString("poleReferenceVectorD"), QString("poleVectorD"));
|
QString("poleReferenceVectorD"), QString("poleVectorD"));
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
|
|
||||||
// the IK solution should be:
|
// the IK solution should be:
|
||||||
//
|
//
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include <AddressManager.h>
|
#include <AddressManager.h>
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
#include <ResourceManager.h>
|
#include <ResourceManager.h>
|
||||||
|
#include <ResourceRequestObserver.h>
|
||||||
#include <StatTracker.h>
|
#include <StatTracker.h>
|
||||||
#include <test-utils/QTestExtensions.h>
|
#include <test-utils/QTestExtensions.h>
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ void AnimTests::initTestCase() {
|
||||||
DependencyManager::set<NodeList>(NodeType::Agent);
|
DependencyManager::set<NodeList>(NodeType::Agent);
|
||||||
DependencyManager::set<ResourceManager>();
|
DependencyManager::set<ResourceManager>();
|
||||||
DependencyManager::set<AnimationCache>();
|
DependencyManager::set<AnimationCache>();
|
||||||
|
DependencyManager::set<ResourceRequestObserver>();
|
||||||
DependencyManager::set<ResourceCacheSharedItems>();
|
DependencyManager::set<ResourceCacheSharedItems>();
|
||||||
DependencyManager::set<StatTracker>();
|
DependencyManager::set<StatTracker>();
|
||||||
}
|
}
|
||||||
|
@ -84,26 +86,26 @@ void AnimTests::testClipEvaulate() {
|
||||||
|
|
||||||
AnimClip clip(id, url, startFrame, endFrame, timeScale, loopFlag, mirrorFlag);
|
AnimClip clip(id, url, startFrame, endFrame, timeScale, loopFlag, mirrorFlag);
|
||||||
|
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
clip.evaluate(vars, context, framesToSec(10.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(10.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 12.0f, TEST_EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 12.0f, TEST_EPSILON);
|
||||||
|
|
||||||
// does it loop?
|
// does it loop?
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
clip.evaluate(vars, context, framesToSec(12.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(12.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, TEST_EPSILON); // Note: frame 3 and not 4, because extra frame between start and end.
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, TEST_EPSILON); // Note: frame 3 and not 4, because extra frame between start and end.
|
||||||
|
|
||||||
// did we receive a loop trigger?
|
// did we receive a loop trigger?
|
||||||
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnLoop") != triggers.end());
|
QVERIFY(triggers.hasKey("myClipNodeOnLoop"));
|
||||||
|
|
||||||
// does it pause at end?
|
// does it pause at end?
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
clip.setLoopFlagVar("FalseVar");
|
clip.setLoopFlagVar("FalseVar");
|
||||||
clip.evaluate(vars, context, framesToSec(20.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(20.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 22.0f, TEST_EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 22.0f, TEST_EPSILON);
|
||||||
|
|
||||||
// did we receive a done trigger?
|
// did we receive a done trigger?
|
||||||
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnDone") != triggers.end());
|
QVERIFY(triggers.hasKey("myClipNodeOnDone"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimTests::testClipEvaulateWithVars() {
|
void AnimTests::testClipEvaulateWithVars() {
|
||||||
|
@ -133,7 +135,7 @@ void AnimTests::testClipEvaulateWithVars() {
|
||||||
clip.setTimeScaleVar("timeScale2");
|
clip.setTimeScaleVar("timeScale2");
|
||||||
clip.setLoopFlagVar("loopFlag2");
|
clip.setLoopFlagVar("loopFlag2");
|
||||||
|
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
clip.evaluate(vars, context, framesToSec(0.1f), triggers);
|
clip.evaluate(vars, context, framesToSec(0.1f), triggers);
|
||||||
|
|
||||||
// verify that the values from the AnimVariantMap made it into the clipNode's
|
// verify that the values from the AnimVariantMap made it into the clipNode's
|
||||||
|
@ -284,11 +286,11 @@ void AnimTests::testAccumulateTime() {
|
||||||
timeScale = 1.0f;
|
timeScale = 1.0f;
|
||||||
float dt = 1.0f;
|
float dt = 1.0f;
|
||||||
QString id = "testNode";
|
QString id = "testNode";
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
float loopFlag = true;
|
float loopFlag = true;
|
||||||
float resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
float resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
||||||
// a one frame looping animation should NOT trigger onLoop events
|
// a one frame looping animation should NOT trigger onLoop events
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
|
|
||||||
const uint32_t MAX_TRIGGER_COUNT = 3;
|
const uint32_t MAX_TRIGGER_COUNT = 3;
|
||||||
|
|
||||||
|
@ -296,45 +298,45 @@ void AnimTests::testAccumulateTime() {
|
||||||
endFrame = 1.1f;
|
endFrame = 1.1f;
|
||||||
timeScale = 10.0f;
|
timeScale = 10.0f;
|
||||||
dt = 10.0f;
|
dt = 10.0f;
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
loopFlag = true;
|
loopFlag = true;
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
||||||
// a short animation with a large dt & a large timescale, should only create a MAXIMUM of 3 loop events.
|
// a short animation with a large dt & a large timescale, should generate a onLoop event.
|
||||||
QVERIFY(triggers.size() <= MAX_TRIGGER_COUNT);
|
QVERIFY(triggers.hasKey("testNodeOnLoop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimTests::testAccumulateTimeWithParameters(float startFrame, float endFrame, float timeScale) const {
|
void AnimTests::testAccumulateTimeWithParameters(float startFrame, float endFrame, float timeScale) const {
|
||||||
|
|
||||||
float dt = (1.0f / 30.0f) / timeScale; // sec
|
float dt = (1.0f / 30.0f) / timeScale; // sec
|
||||||
QString id = "testNode";
|
QString id = "testNode";
|
||||||
AnimNode::Triggers triggers;
|
AnimVariantMap triggers;
|
||||||
bool loopFlag = false;
|
bool loopFlag = false;
|
||||||
|
|
||||||
float resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
float resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == startFrame + 1.0f);
|
QVERIFY(resultFrame == startFrame + 1.0f);
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == startFrame + 2.0f);
|
QVERIFY(resultFrame == startFrame + 2.0f);
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == startFrame + 3.0f);
|
QVERIFY(resultFrame == startFrame + 3.0f);
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
// test onDone trigger and frame clamping.
|
// test onDone trigger and frame clamping.
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == endFrame);
|
QVERIFY(resultFrame == endFrame);
|
||||||
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnDone");
|
QVERIFY(triggers.hasKey("testNodeOnDone"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == endFrame);
|
QVERIFY(resultFrame == endFrame);
|
||||||
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnDone");
|
QVERIFY(triggers.hasKey("testNodeOnDone"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
// test onLoop trigger and looping frame logic
|
// test onLoop trigger and looping frame logic
|
||||||
loopFlag = true;
|
loopFlag = true;
|
||||||
|
@ -342,26 +344,26 @@ void AnimTests::testAccumulateTimeWithParameters(float startFrame, float endFram
|
||||||
// should NOT trigger loop even though we stop at last frame, because there is an extra frame between end and start frames.
|
// should NOT trigger loop even though we stop at last frame, because there is an extra frame between end and start frames.
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == endFrame);
|
QVERIFY(resultFrame == endFrame);
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
// now we should hit loop trigger
|
// now we should hit loop trigger
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == startFrame);
|
QVERIFY(resultFrame == startFrame);
|
||||||
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnLoop");
|
QVERIFY(triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
// should NOT trigger loop, even though we move past the end frame, because of extra frame between end and start.
|
// should NOT trigger loop, even though we move past the end frame, because of extra frame between end and start.
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == endFrame + 0.5f);
|
QVERIFY(resultFrame == endFrame + 0.5f);
|
||||||
QVERIFY(triggers.empty());
|
QVERIFY(!triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
|
|
||||||
// now we should hit loop trigger
|
// now we should hit loop trigger
|
||||||
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
QVERIFY(resultFrame == startFrame + 0.5f);
|
QVERIFY(resultFrame == startFrame + 0.5f);
|
||||||
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnLoop");
|
QVERIFY(triggers.hasKey("testNodeOnLoop"));
|
||||||
triggers.clear();
|
triggers.clearMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimTests::testAnimPose() {
|
void AnimTests::testAnimPose() {
|
||||||
|
|
Loading…
Reference in a new issue