mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 10:47:53 +02:00
Added AnimVariant, renamed AnimClipTests to AnimTests.
* Added test for AnimVariant.
This commit is contained in:
parent
4bdb00bbc5
commit
62f86e6a46
4 changed files with 156 additions and 55 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
class AnimClip : public AnimNode {
|
||||
public:
|
||||
friend class AnimClipTests;
|
||||
friend class AnimTests;
|
||||
|
||||
AnimClip(const std::string& id, const std::string& url, float startFrame, float endFrame, float timeScale, bool loopFlag);
|
||||
virtual ~AnimClip() override;
|
||||
|
|
63
libraries/animation/src/AnimVariant.h
Normal file
63
libraries/animation/src/AnimVariant.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
//
|
||||
// AnimVariant.h
|
||||
//
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_AnimVariant_h
|
||||
#define hifi_AnimVariant_h
|
||||
|
||||
#include <cassert>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
class AnimVariant {
|
||||
public:
|
||||
enum Type {
|
||||
BoolType = 0,
|
||||
FloatType,
|
||||
Vec3Type,
|
||||
QuatType,
|
||||
Mat4Type,
|
||||
NumTypes
|
||||
};
|
||||
|
||||
AnimVariant() : _type(BoolType) { memset(&_val, 0, sizeof(_val)); }
|
||||
AnimVariant(bool value) : _type(BoolType) { _val.boolVal = value; }
|
||||
AnimVariant(float value) : _type(FloatType) { _val.floats[0] = value; }
|
||||
AnimVariant(const glm::vec3& value) : _type(Vec3Type) { *reinterpret_cast<glm::vec3*>(&_val) = value; }
|
||||
AnimVariant(const glm::quat& value) : _type(QuatType) { *reinterpret_cast<glm::quat*>(&_val) = value; }
|
||||
AnimVariant(const glm::mat4& value) : _type(Mat4Type) { *reinterpret_cast<glm::mat4*>(&_val) = value; }
|
||||
|
||||
bool isBool() const { return _type == BoolType; }
|
||||
bool isFloat() const { return _type == FloatType; }
|
||||
bool isVec3() const { return _type == Vec3Type; }
|
||||
bool isQuat() const { return _type == QuatType; }
|
||||
bool isMat4() const { return _type == Mat4Type; }
|
||||
|
||||
void setBool(bool value) { assert(_type == BoolType); _val.boolVal = value; }
|
||||
void setFloat(float value) { assert(_type == FloatType); _val.floats[0] = value; }
|
||||
void setVec3(const glm::vec3& value) { assert(_type == Vec3Type); *reinterpret_cast<glm::vec3*>(&_val) = value; }
|
||||
void setQuat(const glm::quat& value) { assert(_type == QuatType); *reinterpret_cast<glm::quat*>(&_val) = value; }
|
||||
void setMat4(const glm::mat4& value) { assert(_type == Mat4Type); *reinterpret_cast<glm::mat4*>(&_val) = value; }
|
||||
|
||||
bool getBool() { assert(_type == BoolType); return _val.boolVal; }
|
||||
float getFloat() { assert(_type == FloatType); return _val.floats[0]; }
|
||||
const glm::vec3& getVec3() { assert(_type == Vec3Type); return *reinterpret_cast<glm::vec3*>(&_val); }
|
||||
const glm::quat& getQuat() { assert(_type == QuatType); return *reinterpret_cast<glm::quat*>(&_val); }
|
||||
const glm::mat4& getMat4() { assert(_type == Mat4Type); return *reinterpret_cast<glm::mat4*>(&_val); }
|
||||
|
||||
protected:
|
||||
Type _type;
|
||||
union {
|
||||
bool boolVal;
|
||||
float floats[16];
|
||||
} _val;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, AnimVariant> AnimVarantMap;
|
||||
|
||||
#endif // hifi_AnimVariant_h
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// AnimClipTests.cpp
|
||||
// AnimTests.cpp
|
||||
//
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
|
@ -7,28 +7,29 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "AnimClipTests.h"
|
||||
#include "AnimTests.h"
|
||||
#include "AnimNodeLoader.h"
|
||||
#include "AnimClip.h"
|
||||
#include "AnimBlendLinear.h"
|
||||
#include "AnimationLogging.h"
|
||||
#include "AnimVariant.h"
|
||||
|
||||
#include <../QTestExtensions.h>
|
||||
|
||||
QTEST_MAIN(AnimClipTests)
|
||||
QTEST_MAIN(AnimTests)
|
||||
|
||||
const float EPSILON = 0.001f;
|
||||
|
||||
void AnimClipTests::initTestCase() {
|
||||
void AnimTests::initTestCase() {
|
||||
auto animationCache = DependencyManager::set<AnimationCache>();
|
||||
auto resourceCacheSharedItems = DependencyManager::set<ResourceCacheSharedItems>();
|
||||
}
|
||||
|
||||
void AnimClipTests::cleanupTestCase() {
|
||||
void AnimTests::cleanupTestCase() {
|
||||
DependencyManager::destroy<AnimationCache>();
|
||||
}
|
||||
|
||||
void AnimClipTests::testAccessors() {
|
||||
void AnimTests::testAccessors() {
|
||||
std::string id = "my anim clip";
|
||||
std::string url = "https://hifi-public.s3.amazonaws.com/ozan/support/FightClubBotTest1/Animations/standard_idle.fbx";
|
||||
float startFrame = 2.0f;
|
||||
|
@ -71,7 +72,7 @@ static float framesToSec(float secs) {
|
|||
return secs / FRAMES_PER_SECOND;
|
||||
}
|
||||
|
||||
void AnimClipTests::testEvaulate() {
|
||||
void AnimTests::testEvaulate() {
|
||||
std::string id = "my clip node";
|
||||
std::string url = "https://hifi-public.s3.amazonaws.com/ozan/support/FightClubBotTest1/Animations/standard_idle.fbx";
|
||||
float startFrame = 2.0f;
|
||||
|
@ -94,7 +95,7 @@ void AnimClipTests::testEvaulate() {
|
|||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 22.0f, EPSILON);
|
||||
}
|
||||
|
||||
void AnimClipTests::testLoader() {
|
||||
void AnimTests::testLoader() {
|
||||
auto url = QUrl("https://gist.githubusercontent.com/hyperlogic/857129fe04567cbe670f/raw/8ba57a8f0a76f88b39a11f77f8d9df04af9cec95/test.json");
|
||||
AnimNodeLoader loader(url);
|
||||
|
||||
|
@ -104,45 +105,8 @@ void AnimClipTests::testLoader() {
|
|||
timer.setInterval(timeout);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
bool done = false;
|
||||
connect(&loader, &AnimNodeLoader::success, [&](AnimNode::Pointer node) {
|
||||
QVERIFY((bool)node);
|
||||
QVERIFY(node->getID() == "blend");
|
||||
QVERIFY(node->getType() == AnimNode::BlendLinearType);
|
||||
|
||||
QVERIFY((bool)node);
|
||||
QVERIFY(node->getID() == "blend");
|
||||
QVERIFY(node->getType() == AnimNode::BlendLinearType);
|
||||
|
||||
auto blend = std::static_pointer_cast<AnimBlendLinear>(node);
|
||||
QVERIFY(blend->getAlpha() == 0.5f);
|
||||
|
||||
QVERIFY(node->getChildCount() == 3);
|
||||
|
||||
std::shared_ptr<AnimNode> nodes[3] = { node->getChild(0), node->getChild(1), node->getChild(2) };
|
||||
|
||||
QVERIFY(nodes[0]->getID() == "test01");
|
||||
QVERIFY(nodes[0]->getChildCount() == 0);
|
||||
QVERIFY(nodes[1]->getID() == "test02");
|
||||
QVERIFY(nodes[1]->getChildCount() == 0);
|
||||
QVERIFY(nodes[2]->getID() == "test03");
|
||||
QVERIFY(nodes[2]->getChildCount() == 0);
|
||||
|
||||
auto test01 = std::static_pointer_cast<AnimClip>(nodes[0]);
|
||||
QVERIFY(test01->getURL() == "test01.fbx");
|
||||
QVERIFY(test01->getStartFrame() == 1.0f);
|
||||
QVERIFY(test01->getEndFrame() == 20.0f);
|
||||
QVERIFY(test01->getTimeScale() == 1.0f);
|
||||
QVERIFY(test01->getLoopFlag() == false);
|
||||
|
||||
auto test02 = std::static_pointer_cast<AnimClip>(nodes[1]);
|
||||
QVERIFY(test02->getURL() == "test02.fbx");
|
||||
QVERIFY(test02->getStartFrame() == 2.0f);
|
||||
QVERIFY(test02->getEndFrame() == 21.0f);
|
||||
QVERIFY(test02->getTimeScale() == 0.9f);
|
||||
QVERIFY(test02->getLoopFlag() == true);
|
||||
done = true;
|
||||
});
|
||||
AnimNode::Pointer node = nullptr;
|
||||
connect(&loader, &AnimNodeLoader::success, [&](AnimNode::Pointer nodeIn) { node = nodeIn; });
|
||||
|
||||
loop.connect(&loader, SIGNAL(success(AnimNode::Pointer)), SLOT(quit()));
|
||||
loop.connect(&loader, SIGNAL(error(int, QString)), SLOT(quit()));
|
||||
|
@ -150,5 +114,78 @@ void AnimClipTests::testLoader() {
|
|||
timer.start();
|
||||
loop.exec();
|
||||
|
||||
QVERIFY(done);
|
||||
QVERIFY((bool)node);
|
||||
|
||||
QVERIFY(node->getID() == "blend");
|
||||
QVERIFY(node->getType() == AnimNode::BlendLinearType);
|
||||
|
||||
QVERIFY((bool)node);
|
||||
QVERIFY(node->getID() == "blend");
|
||||
QVERIFY(node->getType() == AnimNode::BlendLinearType);
|
||||
|
||||
auto blend = std::static_pointer_cast<AnimBlendLinear>(node);
|
||||
QVERIFY(blend->getAlpha() == 0.5f);
|
||||
|
||||
QVERIFY(node->getChildCount() == 3);
|
||||
|
||||
std::shared_ptr<AnimNode> nodes[3] = { node->getChild(0), node->getChild(1), node->getChild(2) };
|
||||
|
||||
QVERIFY(nodes[0]->getID() == "test01");
|
||||
QVERIFY(nodes[0]->getChildCount() == 0);
|
||||
QVERIFY(nodes[1]->getID() == "test02");
|
||||
QVERIFY(nodes[1]->getChildCount() == 0);
|
||||
QVERIFY(nodes[2]->getID() == "test03");
|
||||
QVERIFY(nodes[2]->getChildCount() == 0);
|
||||
|
||||
auto test01 = std::static_pointer_cast<AnimClip>(nodes[0]);
|
||||
QVERIFY(test01->getURL() == "test01.fbx");
|
||||
QVERIFY(test01->getStartFrame() == 1.0f);
|
||||
QVERIFY(test01->getEndFrame() == 20.0f);
|
||||
QVERIFY(test01->getTimeScale() == 1.0f);
|
||||
QVERIFY(test01->getLoopFlag() == false);
|
||||
|
||||
auto test02 = std::static_pointer_cast<AnimClip>(nodes[1]);
|
||||
QVERIFY(test02->getURL() == "test02.fbx");
|
||||
QVERIFY(test02->getStartFrame() == 2.0f);
|
||||
QVERIFY(test02->getEndFrame() == 21.0f);
|
||||
QVERIFY(test02->getTimeScale() == 0.9f);
|
||||
QVERIFY(test02->getLoopFlag() == true);
|
||||
}
|
||||
|
||||
void AnimTests::testVariant() {
|
||||
auto defaultVar = AnimVariant();
|
||||
auto boolVar = AnimVariant(true);
|
||||
auto floatVar = AnimVariant(1.0f);
|
||||
auto vec3Var = AnimVariant(glm::vec3(1.0f, 2.0f, 3.0f));
|
||||
auto quatVar = AnimVariant(glm::quat(1.0f, 2.0f, 3.0f, 4.0f));
|
||||
auto mat4Var = AnimVariant(glm::mat4(glm::vec4(1.0f, 2.0f, 3.0f, 4.0f),
|
||||
glm::vec4(5.0f, 6.0f, 7.0f, 8.0f),
|
||||
glm::vec4(9.0f, 10.0f, 11.0f, 12.0f),
|
||||
glm::vec4(13.0f, 14.0f, 15.0f, 16.0f)));
|
||||
QVERIFY(defaultVar.isBool());
|
||||
QVERIFY(defaultVar.getBool() == false);
|
||||
|
||||
QVERIFY(boolVar.isBool());
|
||||
QVERIFY(boolVar.getBool() == true);
|
||||
|
||||
QVERIFY(floatVar.isFloat());
|
||||
QVERIFY(floatVar.getFloat() == 1.0f);
|
||||
|
||||
QVERIFY(vec3Var.isVec3());
|
||||
auto v = vec3Var.getVec3();
|
||||
QVERIFY(v.x == 1.0f);
|
||||
QVERIFY(v.y == 2.0f);
|
||||
QVERIFY(v.z == 3.0f);
|
||||
|
||||
QVERIFY(quatVar.isQuat());
|
||||
auto q = quatVar.getQuat();
|
||||
QVERIFY(q.w == 1.0f);
|
||||
QVERIFY(q.x == 2.0f);
|
||||
QVERIFY(q.y == 3.0f);
|
||||
QVERIFY(q.z == 4.0f);
|
||||
|
||||
QVERIFY(mat4Var.isMat4());
|
||||
auto m = mat4Var.getMat4();
|
||||
QVERIFY(m[0].x == 1.0f);
|
||||
QVERIFY(m[3].w == 16.0f);
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
//
|
||||
// AnimClipTests.h
|
||||
// AnimTests.h
|
||||
//
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_AnimClipTests_h
|
||||
#define hifi_AnimClipTests_h
|
||||
#ifndef hifi_AnimTests_h
|
||||
#define hifi_AnimTests_h
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class AnimClipTests : public QObject {
|
||||
class AnimTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
@ -21,6 +21,7 @@ private slots:
|
|||
void testAccessors();
|
||||
void testEvaulate();
|
||||
void testLoader();
|
||||
void testVariant();
|
||||
};
|
||||
|
||||
#endif // hifi_AnimClipTests_h
|
||||
#endif // hifi_AnimTests_h
|
Loading…
Reference in a new issue