summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-04-18 15:03:27 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-05-13 06:42:28 +0000
commit3bef2c0ca1b7e3fee0adfaf2b53fb11d287c3d55 (patch)
treed1a669423d3c157928f7d97ad6d135760ad5d7a2
parentcbc5f1cf75c1a047af3b991ac8ea96daea420028 (diff)
assimp-cpp example added
Allow to select a mesh file and load it with the assimp scene loader. Change-Id: I0018fbbdbcf76c65f35b0670c1b1082e304cc9df Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--examples/qt3d/assimp-cpp/assimp-cpp.pro5
-rw-r--r--examples/qt3d/assimp-cpp/main.cpp104
-rw-r--r--examples/qt3d/qt3d.pro2
3 files changed, 110 insertions, 1 deletions
diff --git a/examples/qt3d/assimp-cpp/assimp-cpp.pro b/examples/qt3d/assimp-cpp/assimp-cpp.pro
new file mode 100644
index 000000000..68c7b15af
--- /dev/null
+++ b/examples/qt3d/assimp-cpp/assimp-cpp.pro
@@ -0,0 +1,5 @@
+TEMPLATE = app
+
+QT += widgets 3dcore 3drenderer 3dinput
+
+SOURCES += main.cpp
diff --git a/examples/qt3d/assimp-cpp/main.cpp b/examples/qt3d/assimp-cpp/main.cpp
new file mode 100644
index 000000000..2925626cd
--- /dev/null
+++ b/examples/qt3d/assimp-cpp/main.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QFileDialog>
+#include <QApplication>
+
+#include <Qt3DCore/Window>
+#include <Qt3DCore/QCamera>
+#include <Qt3DCore/QEntity>
+#include <Qt3DCore/QAspectEngine>
+#include <Qt3DInput/QInputAspect>
+#include <Qt3DRenderer/QFrameGraph>
+#include <Qt3DRenderer/QSceneLoader>
+#include <Qt3DRenderer/QRenderAspect>
+#include <Qt3DRenderer/QForwardRenderer>
+
+
+int main(int ac, char **av)
+{
+ QApplication app(ac, av);
+
+ Qt3D::Window view;
+
+ Qt3D::QAspectEngine engine;
+ Qt3D::QInputAspect *inputAspect = new Qt3D::QInputAspect();
+ engine.registerAspect(new Qt3D::QRenderAspect());
+ engine.registerAspect(inputAspect);
+ engine.initialize();
+ QVariantMap data;
+ data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view)));
+ data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view));
+ engine.setData(data);
+
+ // Root entity
+ Qt3D::QEntity *sceneRoot = new Qt3D::QEntity();
+
+ // Scene Camera
+ Qt3D::QCamera *basicCamera = new Qt3D::QCamera(sceneRoot);
+ basicCamera->setProjectionType(Qt3D::QCameraLens::PerspectiveProjection);
+ basicCamera->setAspectRatio(view.width() / view.height());
+ basicCamera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f));
+ basicCamera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f));
+ basicCamera->setPosition(QVector3D(0.0f, 3.5f, 25.0f));
+ basicCamera->setNearPlane(0.001f);
+ basicCamera->setFarPlane(10000.0f);
+ // For camera controls
+ inputAspect->setCamera(basicCamera);
+
+ // Forward Renderer FrameGraph
+ Qt3D::QFrameGraph *frameGraphComponent = new Qt3D::QFrameGraph(sceneRoot);
+ Qt3D::QForwardRenderer *forwardRenderer = new Qt3D::QForwardRenderer();
+ forwardRenderer->setCamera(basicCamera);
+ forwardRenderer->setClearColor(Qt::black);
+ frameGraphComponent->setActiveFrameGraph(forwardRenderer);
+ sceneRoot->addComponent(frameGraphComponent);
+
+ // Scene loader
+ Qt3D::QEntity *sceneLoaderEntity = new Qt3D::QEntity(sceneRoot);
+ Qt3D::QSceneLoader *sceneLoader = new Qt3D::QSceneLoader(sceneLoaderEntity);
+ sceneLoaderEntity->addComponent(sceneLoader);
+
+ QWidget *container = new QWidget();
+ QFileDialog dialog;
+ dialog.setFileMode(QFileDialog::AnyFile);
+ sceneLoader->setSource(dialog.getOpenFileUrl(container, QStringLiteral("Open a scene file")));
+
+ engine.setRootEntity(sceneRoot);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro
index ce4ec4576..61b736691 100644
--- a/examples/qt3d/qt3d.pro
+++ b/examples/qt3d/qt3d.pro
@@ -35,7 +35,7 @@ SUBDIRS += \
# TODO Port the old examples to new APIs
#SUBDIRS += qt3d
-#qtHaveModule(qml): SUBDIRS += quick3d
+qtHaveModule(widgets): SUBDIRS += assimp-cpp
# Make all other subdirs depend on exampleresources
for(subdir, SUBDIRS) {