summaryrefslogtreecommitdiffstats
path: root/tests/auto/render/geometryloaders
diff options
context:
space:
mode:
authorGuillermo A. Amaral <gamaral@kdab.com>2016-10-12 12:48:46 -0700
committerSean Harmer <sean.harmer@kdab.com>2017-01-20 13:56:25 +0000
commit4338a85487788bb553cef0eaa5e5a3f929934eea (patch)
tree8befa1065412ecaa90a1c931968d7876a9e24413 /tests/auto/render/geometryloaders
parentcef6d5406267787d22deee75600ee9d3653a3109 (diff)
QMesh geometry loading via plugin system
Ported ObjLoader to a plugin based system. Change-Id: I4bf50fe869f04173c022b6a22c45944ecdad4703 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/render/geometryloaders')
-rw-r--r--tests/auto/render/geometryloaders/cube.obj26
-rw-r--r--tests/auto/render/geometryloaders/geometryloaders.pro12
-rw-r--r--tests/auto/render/geometryloaders/geometryloaders.qrc5
-rw-r--r--tests/auto/render/geometryloaders/tst_geometryloaders.cpp105
4 files changed, 148 insertions, 0 deletions
diff --git a/tests/auto/render/geometryloaders/cube.obj b/tests/auto/render/geometryloaders/cube.obj
new file mode 100644
index 000000000..1b384b46d
--- /dev/null
+++ b/tests/auto/render/geometryloaders/cube.obj
@@ -0,0 +1,26 @@
+# Blender v2.77 (sub 0) OBJ File: ''
+# www.blender.org
+mtllib cube.mtl
+o Cube
+v 1.000000 -1.000000 -1.000000
+v 1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 1.000000
+v -1.000000 -1.000000 -1.000000
+v 1.000000 1.000000 -0.999999
+v 0.999999 1.000000 1.000001
+v -1.000000 1.000000 1.000000
+v -1.000000 1.000000 -1.000000
+vn 0.0000 -1.0000 0.0000
+vn 0.0000 1.0000 0.0000
+vn 1.0000 0.0000 0.0000
+vn -0.0000 -0.0000 1.0000
+vn -1.0000 -0.0000 -0.0000
+vn 0.0000 0.0000 -1.0000
+usemtl Material
+s off
+f 1//1 2//1 3//1 4//1
+f 5//2 8//2 7//2 6//2
+f 1//3 5//3 6//3 2//3
+f 2//4 6//4 7//4 3//4
+f 3//5 7//5 8//5 4//5
+f 5//6 1//6 4//6 8//6
diff --git a/tests/auto/render/geometryloaders/geometryloaders.pro b/tests/auto/render/geometryloaders/geometryloaders.pro
new file mode 100644
index 000000000..6231c896d
--- /dev/null
+++ b/tests/auto/render/geometryloaders/geometryloaders.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+
+TARGET = tst_geometryloaders
+
+QT += 3dcore 3dcore-private 3drender 3drender-private testlib 3dextras
+
+CONFIG += testcase
+
+SOURCES += tst_geometryloaders.cpp
+
+RESOURCES += \
+ geometryloaders.qrc
diff --git a/tests/auto/render/geometryloaders/geometryloaders.qrc b/tests/auto/render/geometryloaders/geometryloaders.qrc
new file mode 100644
index 000000000..597a56e5e
--- /dev/null
+++ b/tests/auto/render/geometryloaders/geometryloaders.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>cube.obj</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/render/geometryloaders/tst_geometryloaders.cpp b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp
new file mode 100644
index 000000000..a51364e0e
--- /dev/null
+++ b/tests/auto/render/geometryloaders/tst_geometryloaders.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+
+#include <QtCore/QScopedPointer>
+#include <QtCore/private/qfactoryloader_p.h>
+
+#include <Qt3DRender/qattribute.h>
+#include <Qt3DRender/qgeometry.h>
+
+#include <Qt3DRender/private/qgeometryloaderfactory_p.h>
+#include <Qt3DRender/private/qgeometryloaderinterface_p.h>
+
+using namespace Qt3DRender;
+
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, geometryLoader,
+ (QGeometryLoaderFactory_iid, QLatin1String("/geometryloaders"), Qt::CaseInsensitive))
+
+class tst_geometryloaders : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testOBJLoader();
+};
+
+void tst_geometryloaders::testOBJLoader()
+{
+ QScopedPointer<QGeometryLoaderInterface> loader;
+ loader.reset(qLoadPlugin<QGeometryLoaderInterface, QGeometryLoaderFactory>(geometryLoader(), QStringLiteral("obj")));
+ QVERIFY(loader);
+ if (!loader)
+ return;
+
+ QFile file(QStringLiteral(":/cube.obj"));
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qDebug("Could not open test file for reading");
+ return;
+ }
+
+ bool loaded = loader->load(&file, QStringLiteral("Cube"));
+ QVERIFY(loaded);
+ if (!loaded)
+ return;
+
+ QGeometry *geometry = loader->geometry();
+ QVERIFY(geometry);
+ if (!geometry)
+ return;
+
+ QCOMPARE(geometry->attributes().count(), 3);
+ for (QAttribute *attr : geometry->attributes()) {
+ switch (attr->attributeType()) {
+ case QAttribute::IndexAttribute:
+ QCOMPARE(attr->count(), 36u);
+ break;
+ case QAttribute::VertexAttribute:
+ QCOMPARE(attr->count(), 24u);
+ break;
+ }
+ }
+
+ file.close();
+}
+
+QTEST_MAIN(tst_geometryloaders)
+
+#include "tst_geometryloaders.moc"