1/****************************************************************************
2**
3** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QTest>
30#include <QObject>
31#include <Qt3DExtras/qcuboidgeometry.h>
32#include <Qt3DRender/qattribute.h>
33#include <Qt3DRender/qbuffer.h>
34#include <Qt3DRender/qbufferdatagenerator.h>
35#include <qopenglcontext.h>
36#include <QtGui/qvector2d.h>
37#include <QtGui/qvector3d.h>
38#include <QtGui/qvector4d.h>
39#include <QtCore/qdebug.h>
40#include <QtCore/qsharedpointer.h>
41#include <QSignalSpy>
42
43#include "geometrytesthelper.h"
44
45class tst_QCuboidGeometry : public QObject
46{
47 Q_OBJECT
48private Q_SLOTS:
49 void defaultConstruction()
50 {
51 // WHEN
52 Qt3DExtras::QCuboidGeometry geometry;
53
54 // THEN
55 QCOMPARE(geometry.xExtent(), 1.0f);
56 QCOMPARE(geometry.yExtent(), 1.0f);
57 QCOMPARE(geometry.zExtent(), 1.0f);
58 QCOMPARE(geometry.xyMeshResolution(), QSize(2, 2));
59 QCOMPARE(geometry.yzMeshResolution(), QSize(2, 2));
60 QCOMPARE(geometry.xzMeshResolution(), QSize(2, 2));
61 QVERIFY(geometry.positionAttribute() != nullptr);
62 QCOMPARE(geometry.positionAttribute()->name(), Qt3DRender::QAttribute::defaultPositionAttributeName());
63 QVERIFY(geometry.normalAttribute() != nullptr);
64 QCOMPARE(geometry.normalAttribute()->name(), Qt3DRender::QAttribute::defaultNormalAttributeName());
65 QVERIFY(geometry.texCoordAttribute() != nullptr);
66 QCOMPARE(geometry.texCoordAttribute()->name(), Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName());
67 QVERIFY(geometry.tangentAttribute() != nullptr);
68 QCOMPARE(geometry.tangentAttribute()->name(), Qt3DRender::QAttribute::defaultTangentAttributeName());
69 QVERIFY(geometry.indexAttribute() != nullptr);
70 }
71
72 void properties()
73 {
74 // GIVEN
75 Qt3DExtras::QCuboidGeometry geometry;
76
77 {
78 // WHEN
79 QSignalSpy spy(&geometry, SIGNAL(xExtentChanged(float)));
80 const float newValue = 2.0f;
81 geometry.setXExtent(newValue);
82
83 // THEN
84 QCOMPARE(geometry.xExtent(), newValue);
85 QCOMPARE(spy.count(), 1);
86
87 // WHEN
88 spy.clear();
89 geometry.setXExtent(newValue);
90
91 // THEN
92 QCOMPARE(geometry.xExtent(), newValue);
93 QCOMPARE(spy.count(), 0);
94 }
95
96 {
97 // WHEN
98 QSignalSpy spy(&geometry, SIGNAL(yExtentChanged(float)));
99 const float newValue = 2.0f;
100 geometry.setYExtent(newValue);
101
102 // THEN
103 QCOMPARE(geometry.yExtent(), newValue);
104 QCOMPARE(spy.count(), 1);
105
106 // WHEN
107 spy.clear();
108 geometry.setYExtent(newValue);
109
110 // THEN
111 QCOMPARE(geometry.yExtent(), newValue);
112 QCOMPARE(spy.count(), 0);
113 }
114
115 {
116 // WHEN
117 QSignalSpy spy(&geometry, SIGNAL(zExtentChanged(float)));
118 const float newValue = 2.0f;
119 geometry.setZExtent(newValue);
120
121 // THEN
122 QCOMPARE(geometry.zExtent(), newValue);
123 QCOMPARE(spy.count(), 1);
124
125 // WHEN
126 spy.clear();
127 geometry.setZExtent(newValue);
128
129 // THEN
130 QCOMPARE(geometry.zExtent(), newValue);
131 QCOMPARE(spy.count(), 0);
132 }
133
134 {
135 // WHEN
136 QSignalSpy spy(&geometry, SIGNAL(xyMeshResolutionChanged(QSize)));
137 const auto newValue = QSize(4, 8);
138 geometry.setXYMeshResolution(newValue);
139
140 // THEN
141 QCOMPARE(geometry.xyMeshResolution(), newValue);
142 QCOMPARE(spy.count(), 1);
143
144 // WHEN
145 spy.clear();
146 geometry.setXYMeshResolution(newValue);
147
148 // THEN
149 QCOMPARE(geometry.xyMeshResolution(), newValue);
150 QCOMPARE(spy.count(), 0);
151 }
152
153 {
154 // WHEN
155 QSignalSpy spy(&geometry, SIGNAL(yzMeshResolutionChanged(QSize)));
156 const auto newValue = QSize(4, 8);
157 geometry.setYZMeshResolution(newValue);
158
159 // THEN
160 QCOMPARE(geometry.yzMeshResolution(), newValue);
161 QCOMPARE(spy.count(), 1);
162
163 // WHEN
164 spy.clear();
165 geometry.setYZMeshResolution(newValue);
166
167 // THEN
168 QCOMPARE(geometry.yzMeshResolution(), newValue);
169 QCOMPARE(spy.count(), 0);
170 }
171
172 {
173 // WHEN
174 QSignalSpy spy(&geometry, SIGNAL(xzMeshResolutionChanged(QSize)));
175 const auto newValue = QSize(4, 8);
176 geometry.setXZMeshResolution(newValue);
177
178 // THEN
179 QCOMPARE(geometry.xzMeshResolution(), newValue);
180 QCOMPARE(spy.count(), 1);
181
182 // WHEN
183 spy.clear();
184 geometry.setXZMeshResolution(newValue);
185
186 // THEN
187 QCOMPARE(geometry.xzMeshResolution(), newValue);
188 QCOMPARE(spy.count(), 0);
189 }
190 }
191
192 void generatedGeometryShouldBeConsistent_data()
193 {
194 QTest::addColumn<float>(name: "xExtent");
195 QTest::addColumn<float>(name: "yExtent");
196 QTest::addColumn<float>(name: "zExtent");
197 QTest::addColumn<QSize>(name: "xyMeshResolution");
198 QTest::addColumn<QSize>(name: "yzMeshResolution");
199 QTest::addColumn<QSize>(name: "xzMeshResolution");
200 QTest::addColumn<int>(name: "triangleIndex");
201 QTest::addColumn<QVector<quint16>>(name: "indices");
202 QTest::addColumn<QVector<QVector3D>>(name: "positions");
203 QTest::addColumn<QVector<QVector3D>>(name: "normals");
204 QTest::addColumn<QVector<QVector2D>>(name: "texCoords");
205 QTest::addColumn<QVector<QVector4D>>(name: "tangents");
206
207 {
208 const int triangleIndex = 0;
209 const auto indices = (QVector<quint16>() << 0 << 1 << 2);
210 const auto positions = (QVector<QVector3D>()
211 << QVector3D(0.5f, -0.5f, -0.5f)
212 << QVector3D(0.5f, 0.5f, -0.5f)
213 << QVector3D(0.5f, -0.5f, 0.5f));
214 const auto normals = (QVector<QVector3D>()
215 << QVector3D(1.0f, 0.0f, 0.0f)
216 << QVector3D(1.0f, 0.0f, 0.0f)
217 << QVector3D(1.0f, 0.0f, 0.0f));
218 const auto texCoords = (QVector<QVector2D>()
219 << QVector2D(1.0f, 0.0f)
220 << QVector2D(1.0f, 1.0f)
221 << QVector2D(0.0f, 0.0f));
222 const auto tangents = (QVector<QVector4D>()
223 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f)
224 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f)
225 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f));
226 QTest::newRow(dataTag: "default_positiveX_firstTriangle")
227 << 1.0f << 1.0f << 1.0f
228 << QSize(2,2) << QSize(2,2) << QSize(2,2)
229 << triangleIndex
230 << indices << positions << normals << texCoords << tangents;
231 }
232
233 {
234 const int triangleIndex = 3;
235 const auto indices = (QVector<quint16>() << 6 << 5 << 7);
236 const auto positions = (QVector<QVector3D>()
237 << QVector3D(-0.5f, -0.5f, -0.5f)
238 << QVector3D(-0.5f, 0.5f, 0.5f)
239 << QVector3D(-0.5f, 0.5f, -0.5f));
240 const auto normals = (QVector<QVector3D>()
241 << QVector3D(-1.0f, 0.0f, 0.0f)
242 << QVector3D(-1.0f, 0.0f, 0.0f)
243 << QVector3D(-1.0f, 0.0f, 0.0f));
244 const auto texCoords = (QVector<QVector2D>()
245 << QVector2D(0.0f, 0.0f)
246 << QVector2D(1.0f, 1.0f)
247 << QVector2D(0.0f, 1.0f));
248 const auto tangents = (QVector<QVector4D>()
249 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f)
250 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f)
251 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f));
252 QTest::newRow(dataTag: "default_negativeX_lastTriangle")
253 << 1.0f << 1.0f << 1.0f
254 << QSize(2,2) << QSize(2,2) << QSize(2,2)
255 << triangleIndex
256 << indices << positions << normals << texCoords << tangents;
257 }
258
259 {
260 const int triangleIndex = 4;
261 const auto indices = (QVector<quint16>() << 8 << 9 << 10);
262 const auto positions = (QVector<QVector3D>()
263 << QVector3D(-0.5f, 0.5f, 0.5f)
264 << QVector3D(0.5f, 0.5f, 0.5f)
265 << QVector3D(-0.5f, 0.5f, -0.5f));
266 const auto normals = (QVector<QVector3D>()
267 << QVector3D(0.0f, 1.0f, 0.0f)
268 << QVector3D(0.0f, 1.0f, 0.0f)
269 << QVector3D(0.0f, 1.0f, 0.0f));
270 const auto texCoords = (QVector<QVector2D>()
271 << QVector2D(0.0f, 0.0f)
272 << QVector2D(1.0f, 0.0f)
273 << QVector2D(0.0f, 1.0f));
274 const auto tangents = (QVector<QVector4D>()
275 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
276 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
277 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
278 QTest::newRow(dataTag: "default_positiveY_firstTriangle")
279 << 1.0f << 1.0f << 1.0f
280 << QSize(2,2) << QSize(2,2) << QSize(2,2)
281 << triangleIndex
282 << indices << positions << normals << texCoords << tangents;
283 }
284
285 {
286 const int triangleIndex = 7;
287 const auto indices = (QVector<quint16>() << 14 << 13 << 15);
288 const auto positions = (QVector<QVector3D>()
289 << QVector3D(-0.5f, -0.5f, 0.5f)
290 << QVector3D(0.5f, -0.5f, -0.5f)
291 << QVector3D(0.5f, -0.5f, 0.5f));
292 const auto normals = (QVector<QVector3D>()
293 << QVector3D(0.0f, -1.0f, 0.0f)
294 << QVector3D(0.0f, -1.0f, 0.0f)
295 << QVector3D(0.0f, -1.0f, 0.0f));
296 const auto texCoords = (QVector<QVector2D>()
297 << QVector2D(0.0f, 1.0f)
298 << QVector2D(1.0f, 0.0f)
299 << QVector2D(1.0f, 1.0f));
300 const auto tangents = (QVector<QVector4D>()
301 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
302 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
303 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
304 QTest::newRow(dataTag: "default_negativeY_lastTriangle")
305 << 1.0f << 1.0f << 1.0f
306 << QSize(2,2) << QSize(2,2) << QSize(2,2)
307 << triangleIndex
308 << indices << positions << normals << texCoords << tangents;
309 }
310
311 {
312 const int triangleIndex = 8;
313 const auto indices = (QVector<quint16>() << 16 << 17 << 18);
314 const auto positions = (QVector<QVector3D>()
315 << QVector3D(-0.5f, -0.5f, 0.5f)
316 << QVector3D(0.5f, -0.5f, 0.5f)
317 << QVector3D(-0.5f, 0.5f, 0.5f));
318 const auto normals = (QVector<QVector3D>()
319 << QVector3D(0.0f, 0.0f, 1.0f)
320 << QVector3D(0.0f, 0.0f, 1.0f)
321 << QVector3D(0.0f, 0.0f, 1.0f));
322 const auto texCoords = (QVector<QVector2D>()
323 << QVector2D(0.0f, 0.0f)
324 << QVector2D(1.0f, 0.0f)
325 << QVector2D(0.0f, 1.0f));
326 const auto tangents = (QVector<QVector4D>()
327 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
328 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
329 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
330 QTest::newRow(dataTag: "default_positiveZ_firstTriangle")
331 << 1.0f << 1.0f << 1.0f
332 << QSize(2,2) << QSize(2,2) << QSize(2,2)
333 << triangleIndex
334 << indices << positions << normals << texCoords << tangents;
335 }
336
337 {
338 const int triangleIndex = 11;
339 const auto indices = (QVector<quint16>() << 22 << 21 << 23);
340 const auto positions = (QVector<QVector3D>()
341 << QVector3D(0.5f, 0.5f, -0.5f)
342 << QVector3D(-0.5f, -0.5f, -0.5f)
343 << QVector3D(-0.5f, 0.5f, -0.5f));
344 const auto normals = (QVector<QVector3D>()
345 << QVector3D(0.0f, 0.0f, -1.0f)
346 << QVector3D(0.0f, 0.0f, -1.0f)
347 << QVector3D(0.0f, 0.0f, -1.0f));
348 const auto texCoords = (QVector<QVector2D>()
349 << QVector2D(0.0f, 1.0f)
350 << QVector2D(1.0f, 0.0f)
351 << QVector2D(1.0f, 1.0f));
352 const auto tangents = (QVector<QVector4D>()
353 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
354 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
355 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f));
356 QTest::newRow(dataTag: "default_negativeZ_lastTriangle")
357 << 1.0f << 1.0f << 1.0f
358 << QSize(2,2) << QSize(2,2) << QSize(2,2)
359 << triangleIndex
360 << indices << positions << normals << texCoords << tangents;
361 }
362
363 {
364 const int triangleIndex = 0;
365 const auto indices = (QVector<quint16>() << 0 << 1 << 2);
366 const auto positions = (QVector<QVector3D>()
367 << QVector3D(1.0f, -1.5f, -2.5f)
368 << QVector3D(1.0f, 1.5f, -2.5f)
369 << QVector3D(1.0f, -1.5f, -1.25f));
370 const auto normals = (QVector<QVector3D>()
371 << QVector3D(1.0f, 0.0f, 0.0f)
372 << QVector3D(1.0f, 0.0f, 0.0f)
373 << QVector3D(1.0f, 0.0f, 0.0f));
374 const auto texCoords = (QVector<QVector2D>()
375 << QVector2D(1.0f, 0.0f)
376 << QVector2D(1.0f, 1.0f)
377 << QVector2D(0.75f, 0.0f));
378 const auto tangents = (QVector<QVector4D>()
379 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f)
380 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f)
381 << QVector4D(0.0f, 0.0f, -1.0f, 1.0f));
382 QTest::newRow(dataTag: "default_positiveX_firstTriangle_nonSymmetric")
383 << 2.0f << 3.0f << 5.0f
384 << QSize(2,3) << QSize(2,5) << QSize(2,9)
385 << triangleIndex
386 << indices << positions << normals << texCoords << tangents;
387 }
388
389 {
390 const int triangleIndex = 15;
391 const auto indices = (QVector<quint16>() << 18 << 17 << 19);
392 const auto positions = (QVector<QVector3D>()
393 << QVector3D(-1.0f, -1.5f, -2.5f)
394 << QVector3D(-1.0f, 1.5f, -1.25f)
395 << QVector3D(-1.0f, 1.5f, -2.5f));
396 const auto normals = (QVector<QVector3D>()
397 << QVector3D(-1.0f, 0.0f, 0.0f)
398 << QVector3D(-1.0f, 0.0f, 0.0f)
399 << QVector3D(-1.0f, 0.0f, 0.0f));
400 const auto texCoords = (QVector<QVector2D>()
401 << QVector2D(0.0f, 0.0f)
402 << QVector2D(0.25f, 1.0f)
403 << QVector2D(0.0f, 1.0f));
404 const auto tangents = (QVector<QVector4D>()
405 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f)
406 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f)
407 << QVector4D(0.0f, 0.0f, 1.0f, 1.0f));
408 QTest::newRow(dataTag: "default_negativeX_lastTriangle_nonSymmetric")
409 << 2.0f << 3.0f << 5.0f
410 << QSize(2,3) << QSize(2,5) << QSize(2,9)
411 << triangleIndex
412 << indices << positions << normals << texCoords << tangents;
413 }
414
415 {
416 const int triangleIndex = 16;
417 const auto indices = (QVector<quint16>() << 20 << 21 << 22);
418 const auto positions = (QVector<QVector3D>()
419 << QVector3D(-1.0f, 1.5f, 2.5f)
420 << QVector3D(1.0f, 1.5f, 2.5f)
421 << QVector3D(-1.0f, 1.5f, 1.875f));
422 const auto normals = (QVector<QVector3D>()
423 << QVector3D(0.0f, 1.0f, 0.0f)
424 << QVector3D(0.0f, 1.0f, 0.0f)
425 << QVector3D(0.0f, 1.0f, 0.0f));
426 const auto texCoords = (QVector<QVector2D>()
427 << QVector2D(0.0f, 0.0f)
428 << QVector2D(1.0f, 0.0f)
429 << QVector2D(0.0f, 0.125f));
430 const auto tangents = (QVector<QVector4D>()
431 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
432 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
433 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
434 QTest::newRow(dataTag: "default_positiveY_firstTriangle_nonSymmetric")
435 << 2.0f << 3.0f << 5.0f
436 << QSize(2,3) << QSize(2,5) << QSize(2,9)
437 << triangleIndex
438 << indices << positions << normals << texCoords << tangents;
439 }
440
441 {
442 const int triangleIndex = 47;
443 const auto indices = (QVector<quint16>() << 54 << 53 << 55);
444 const auto positions = (QVector<QVector3D>()
445 << QVector3D(-1.0f, -1.5f, 2.5f)
446 << QVector3D(1.0f, -1.5f, 1.875f)
447 << QVector3D(1.0f, -1.5f, 2.5f));
448 const auto normals = (QVector<QVector3D>()
449 << QVector3D(0.0f, -1.0f, 0.0f)
450 << QVector3D(0.0f, -1.0f, 0.0f)
451 << QVector3D(0.0f, -1.0f, 0.0f));
452 const auto texCoords = (QVector<QVector2D>()
453 << QVector2D(0.0f, 1.0f)
454 << QVector2D(1.0f, 0.875f)
455 << QVector2D(1.0f, 1.0f));
456 const auto tangents = (QVector<QVector4D>()
457 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
458 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
459 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
460 QTest::newRow(dataTag: "default_negativeY_lastTriangle_nonSymmetric")
461 << 2.0f << 3.0f << 5.0f
462 << QSize(2,3) << QSize(2,5) << QSize(2,9)
463 << triangleIndex
464 << indices << positions << normals << texCoords << tangents;
465 }
466
467 {
468 const int triangleIndex = 48;
469 const auto indices = (QVector<quint16>() << 56 << 57 << 58);
470 const auto positions = (QVector<QVector3D>()
471 << QVector3D(-1.0f, -1.5f, 2.5f)
472 << QVector3D(1.0f, -1.5f, 2.5f)
473 << QVector3D(-1.0f, 0.0f, 2.5f));
474 const auto normals = (QVector<QVector3D>()
475 << QVector3D(0.0f, 0.0f, 1.0f)
476 << QVector3D(0.0f, 0.0f, 1.0f)
477 << QVector3D(0.0f, 0.0f, 1.0f));
478 const auto texCoords = (QVector<QVector2D>()
479 << QVector2D(0.0f, 0.0f)
480 << QVector2D(1.0f, 0.0f)
481 << QVector2D(0.0f, 0.5f));
482 const auto tangents = (QVector<QVector4D>()
483 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
484 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f)
485 << QVector4D(1.0f, 0.0f, 0.0f, 1.0f));
486 QTest::newRow(dataTag: "default_positiveZ_firstTriangle_nonSymmetric")
487 << 2.0f << 3.0f << 5.0f
488 << QSize(2,3) << QSize(2,5) << QSize(2,9)
489 << triangleIndex
490 << indices << positions << normals << texCoords << tangents;
491 }
492
493 {
494 const int triangleIndex = 55;
495 const auto indices = (QVector<quint16>() << 66 << 65 << 67);
496 const auto positions = (QVector<QVector3D>()
497 << QVector3D(1.0f, 1.5f, -2.5f)
498 << QVector3D(-1.0f, 0.0f, -2.5f)
499 << QVector3D(-1.0f, 1.5f, -2.5f));
500 const auto normals = (QVector<QVector3D>()
501 << QVector3D(0.0f, 0.0f, -1.0f)
502 << QVector3D(0.0f, 0.0f, -1.0f)
503 << QVector3D(0.0f, 0.0f, -1.0f));
504 const auto texCoords = (QVector<QVector2D>()
505 << QVector2D(0.0f, 1.0f)
506 << QVector2D(1.0f, 0.5f)
507 << QVector2D(1.0f, 1.0f));
508 const auto tangents = (QVector<QVector4D>()
509 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
510 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f)
511 << QVector4D(-1.0f, 0.0f, 0.0f, 1.0f));
512 QTest::newRow(dataTag: "default_negativeZ_lastTriangle_nonSymmetric")
513 << 2.0f << 3.0f << 5.0f
514 << QSize(2,3) << QSize(2,5) << QSize(2,9)
515 << triangleIndex
516 << indices << positions << normals << texCoords << tangents;
517 }
518 }
519
520 void generatedGeometryShouldBeConsistent()
521 {
522 // GIVEN
523 Qt3DExtras::QCuboidGeometry geometry;
524 const QVector<Qt3DRender::QAttribute *> attributes = geometry.attributes();
525 Qt3DRender::QAttribute *positionAttribute = geometry.positionAttribute();
526 Qt3DRender::QAttribute *normalAttribute = geometry.normalAttribute();
527 Qt3DRender::QAttribute *texCoordAttribute = geometry.texCoordAttribute();
528 Qt3DRender::QAttribute *tangentAttribute = geometry.tangentAttribute();
529 Qt3DRender::QAttribute *indexAttribute = geometry.indexAttribute();
530
531 // WHEN
532 QFETCH(float, xExtent);
533 QFETCH(float, yExtent);
534 QFETCH(float, zExtent);
535 QFETCH(QSize, xyMeshResolution);
536 QFETCH(QSize, yzMeshResolution);
537 QFETCH(QSize, xzMeshResolution);
538 geometry.setXExtent(xExtent);
539 geometry.setYExtent(yExtent);
540 geometry.setZExtent(zExtent);
541 geometry.setXYMeshResolution(xyMeshResolution);
542 geometry.setYZMeshResolution(yzMeshResolution);
543 geometry.setXZMeshResolution(xzMeshResolution);
544
545 generateGeometry(geometry);
546
547 // THEN
548
549 // Check buffer of each attribute is valid and actually has some data
550 for (const auto &attribute : attributes) {
551 Qt3DRender::QBuffer *buffer = attribute->buffer();
552 QVERIFY(buffer != nullptr);
553 QVERIFY(buffer->data().size() != 0);
554 }
555
556 // Check some data in the buffers
557
558 // Check specific indices and vertex attributes of triangle under test
559 QFETCH(int, triangleIndex);
560 QFETCH(QVector<quint16>, indices);
561 QFETCH(QVector<QVector3D>, positions);
562 QFETCH(QVector<QVector3D>, normals);
563 QFETCH(QVector<QVector2D>, texCoords);
564 QFETCH(QVector<QVector4D>, tangents);
565
566 int i = 0;
567 for (auto index : indices) {
568 const auto testIndex = extractIndexData<quint16>(attribute: indexAttribute, index: 3 * triangleIndex + i);
569 QCOMPARE(testIndex, indices.at(i));
570
571 const auto position = extractVertexData<QVector3D, quint32>(attribute: positionAttribute, index);
572 QCOMPARE(position, positions.at(i));
573
574 const auto normal = extractVertexData<QVector3D, quint32>(attribute: normalAttribute, index);
575 QCOMPARE(normal, normals.at(i));
576
577 const auto texCoord = extractVertexData<QVector2D, quint32>(attribute: texCoordAttribute, index);
578 QCOMPARE(texCoord, texCoords.at(i));
579
580 const auto tangent = extractVertexData<QVector4D, quint32>(attribute: tangentAttribute, index);
581 QCOMPARE(tangent, tangents.at(i));
582
583 ++i;
584 }
585 }
586};
587
588
589QTEST_APPLESS_MAIN(tst_QCuboidGeometry)
590
591#include "tst_qcuboidgeometry.moc"
592

source code of qt3d/tests/auto/extras/qcuboidgeometry/tst_qcuboidgeometry.cpp