1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
// Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <Qt3DCore/qjoint.h>
#include <Qt3DCore/qskeleton.h>
#include <Qt3DAnimation/private/skeleton_p.h>
#include <Qt3DAnimation/private/handler_p.h>
#include <Qt3DCore/private/qscene_p.h>
#include <Qt3DCore/private/qbackendnode_p.h>
#include <qbackendnodetester.h>
#include <testarbiter.h>
using namespace Qt3DCore;
using namespace Qt3DAnimation;
using namespace Qt3DAnimation::Animation;
Q_DECLARE_METATYPE(Skeleton*)
class tst_Skeleton : public QBackendNodeTester
{
Q_OBJECT
private Q_SLOTS:
void checkPeerPropertyMirroring()
{
// GIVEN
Handler handler;
Skeleton backendSkeleton;
backendSkeleton.setHandler(&handler);
QSkeleton skeleton;
auto rootJoint = new QJoint();
rootJoint->setName(QLatin1String("rootJoint"));
auto childJoint = new QJoint();
childJoint->setName(QLatin1String("childJoint"));
rootJoint->addChildJoint(childJoint);
skeleton.setRootJoint(rootJoint);
// WHEN
simulateInitializationSync(&skeleton, &backendSkeleton);
// THEN - nothing mirrored from frontend
QCOMPARE(backendSkeleton.peerId(), skeleton.id());
QCOMPARE(backendSkeleton.isEnabled(), skeleton.isEnabled());
QCOMPARE(backendSkeleton.jointNames().size(), 0);
QCOMPARE(backendSkeleton.jointLocalPoses().size(), 0);
}
void checkJointName()
{
// GIVEN
Skeleton backendSkeleton;
const QVector<QString> jointNames = { QLatin1String("rootJoint"),
QLatin1String("child1Joint"),
QLatin1String("child2Joint") };
// WHEN
backendSkeleton.setJointNames(jointNames);
// THEN
const int jointNameCount = jointNames.size();
for (int i = 0; i < jointNameCount; ++i) {
QCOMPARE(jointNames[i], backendSkeleton.jointName(i));
}
}
void checkInitialAndCleanedUpState()
{
// GIVEN
Handler handler;
Skeleton backendSkeleton;
backendSkeleton.setHandler(&handler);
// THEN
QVERIFY(backendSkeleton.peerId().isNull());
QCOMPARE(backendSkeleton.isEnabled(), false);
QCOMPARE(backendSkeleton.jointNames().size(), 0);
QCOMPARE(backendSkeleton.jointLocalPoses().size(), 0);
// GIVEN
const QVector<QString> names = { QLatin1String("root"),
QLatin1String("child1"),
QLatin1String("child2") };
const QVector<Sqt> localPoses = { Sqt(), Sqt(), Sqt() };
// WHEN
backendSkeleton.setJointNames(names);
backendSkeleton.setJointLocalPoses(localPoses);
backendSkeleton.cleanup();
// THEN
QCOMPARE(backendSkeleton.isEnabled(), false);
QCOMPARE(backendSkeleton.jointNames().size(), 0);
QCOMPARE(backendSkeleton.jointLocalPoses().size(), 0);
}
void checkPropertyChanges()
{
// GIVEN
Handler handler;
Skeleton backendSkeleton;
backendSkeleton.setHandler(&handler);
QSkeleton skeleton;
simulateInitializationSync(&skeleton, &backendSkeleton);
// WHEN
skeleton.setEnabled(false);
backendSkeleton.syncFromFrontEnd(&skeleton, false);
// THEN
QCOMPARE(backendSkeleton.isEnabled(), false);
}
void checkJointTransforms_data()
{
QTest::addColumn<Skeleton*>("skeleton");
QTest::addColumn<QList<Sqt>>("jointTransforms");
const int count = 5;
auto skeleton = new Skeleton;
skeleton->setJointCount(count);
QList<Sqt> jointTransforms;
jointTransforms.reserve(count);
for (int i = 0; i < count; ++i) {
const float f = float(i);
Sqt transform;
transform.scale = QVector3D(f, f, f);
transform.rotation = QQuaternion(f, 1.0f, 0.0f, 0.0f).normalized();
transform.translation = QVector3D(1.0 * f, 2.0 * f, 3.0 * f);
skeleton->setJointScale(i, transform.scale);
skeleton->setJointRotation(i, transform.rotation);
skeleton->setJointTranslation(i, transform.translation);
jointTransforms.push_back(transform);
}
QTest::newRow("5 joints") << skeleton << jointTransforms;
}
void checkJointTransforms()
{
// GIVEN
QFETCH(Skeleton*, skeleton);
QFETCH(QList<Sqt>, jointTransforms);
const int count = skeleton->jointCount();
for (int i = 0; i < count; ++i) {
// WHEN
const QVector3D s = skeleton->jointScale(i);
// THEN
QCOMPARE(s, jointTransforms[i].scale);
// WHEN
const QQuaternion q = skeleton->jointRotation(i);
// THEN
QCOMPARE(q, jointTransforms[i].rotation);
// WHEN
const QVector3D t = skeleton->jointTranslation(i);
// THEN
QCOMPARE(t, jointTransforms[i].translation);
}
// Cleanup
delete skeleton;
}
};
QTEST_APPLESS_MAIN(tst_Skeleton)
#include "tst_skeleton.moc"
|