diff options
author | Robert Brock <robert.brock@kdab.com> | 2016-05-10 15:37:17 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-15 13:45:27 +0000 |
commit | eee0745693050bac1e42d2f386d2c8507bd0fda0 (patch) | |
tree | 31efa1bcf14d32670a077ac2e9ca740aafe878b2 /examples | |
parent | ada62a79b3858c9294854664c3058184f358598e (diff) |
Moved assimp-cpp example to manual test
Part of an examples cleanup
Change-Id: I1abf679795f7cdc23922880e598a742e58d9aa0a
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/qt3d/assimp-cpp/assimp-cpp.pro | 11 | ||||
-rw-r--r-- | examples/qt3d/assimp-cpp/main.cpp | 165 | ||||
-rw-r--r-- | examples/qt3d/qt3d.pro | 3 |
3 files changed, 1 insertions, 178 deletions
diff --git a/examples/qt3d/assimp-cpp/assimp-cpp.pro b/examples/qt3d/assimp-cpp/assimp-cpp.pro deleted file mode 100644 index 201cef7a2..000000000 --- a/examples/qt3d/assimp-cpp/assimp-cpp.pro +++ /dev/null @@ -1,11 +0,0 @@ -android|ios|tvos|winrt { - warning( "This example is not supported for android, ios, tvos, or winrt." ) -} - -!include( ../examples.pri ) { - error( "Couldn't find the examples.pri file!" ) -} - -QT += widgets 3dcore 3drender 3dinput 3dextras - -SOURCES += main.cpp diff --git a/examples/qt3d/assimp-cpp/main.cpp b/examples/qt3d/assimp-cpp/main.cpp deleted file mode 100644 index 9701cb66a..000000000 --- a/examples/qt3d/assimp-cpp/main.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QFileDialog> -#include <QApplication> - -#include <Qt3DRender/QCamera> -#include <Qt3DCore/QEntity> -#include <Qt3DCore/QAspectEngine> -#include <Qt3DInput/QInputAspect> -#include <Qt3DRender/QSceneLoader> -#include <Qt3DRender/QRenderAspect> -#include <Qt3DExtras/QForwardRenderer> -#include <Qt3DExtras/qt3dwindow.h> -#include <Qt3DExtras/qfirstpersoncameracontroller.h> - -class SceneWalker : public QObject -{ -public: - SceneWalker(Qt3DRender::QSceneLoader *loader) : m_loader(loader) { } - - void onStatusChanged(); - -private: - void walkEntity(Qt3DCore::QEntity *e, int depth = 0); - - Qt3DRender::QSceneLoader *m_loader; -}; - -void SceneWalker::onStatusChanged() -{ - qDebug() << "Status changed:" << m_loader->status(); - if (m_loader->status() != Qt3DRender::QSceneLoader::Ready) - return; - - // The QSceneLoader instance is a component of an entity. The loaded scene - // tree is added under this entity. - QVector<Qt3DCore::QEntity *> entities = m_loader->entities(); - - // Technically there could be multiple entities referencing the scene loader - // but sharing is discouraged, and in our case there will be one anyhow. - if (entities.isEmpty()) - return; - Qt3DCore::QEntity *root = entities[0]; - // Print the tree. - walkEntity(root); - - // To access a given node (like a named mesh in the scene), use QObject::findChild(). - // The scene structure and names always depend on the asset. - Qt3DCore::QEntity *e = root->findChild<Qt3DCore::QEntity *>(QStringLiteral("PlanePropeller_mesh")); // toyplane.obj - if (e) - qDebug() << "Found propeller node" << e << "with components" << e->components(); -} - -void SceneWalker::walkEntity(Qt3DCore::QEntity *e, int depth) -{ - Qt3DCore::QNodeVector nodes = e->childNodes(); - for (int i = 0; i < nodes.count(); ++i) { - Qt3DCore::QNode *node = nodes[i]; - Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>(node); - if (entity) { - QString indent; - indent.fill(' ', depth * 2); - qDebug().noquote() << indent << "Entity:" << entity << "Components:" << entity->components(); - walkEntity(entity, depth + 1); - } - } -} - -int main(int ac, char **av) -{ - QApplication app(ac, av); - Qt3DExtras::Qt3DWindow view; - view.defaultFramegraph()->setClearColor(Qt::black); - - // Root entity - Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity(); - - // Scene Camera - Qt3DRender::QCamera *camera = view.camera(); - camera->setProjectionType(Qt3DRender::QCameraLens::PerspectiveProjection); - camera->setViewCenter(QVector3D(0.0f, 3.5f, 0.0f)); - camera->setPosition(QVector3D(0.0f, 3.5f, 25.0f)); - camera->setNearPlane(0.001f); - camera->setFarPlane(10000.0f); - - // For camera controls - Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(sceneRoot); - camController->setCamera(camera); - - // Scene loader - Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot); - Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity); - SceneWalker sceneWalker(sceneLoader); - QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged); - sceneLoaderEntity->addComponent(sceneLoader); - - QStringList args = QCoreApplication::arguments(); - QUrl sourceFileName; - if (args.count() <= 1) { - QWidget *container = new QWidget(); - QFileDialog dialog; - dialog.setFileMode(QFileDialog::AnyFile); - sourceFileName = dialog.getOpenFileUrl(container, QStringLiteral("Open a scene file")); - } else { - sourceFileName = QUrl::fromLocalFile(args[1]); - } - - if (sourceFileName.isEmpty()) - return 0; - - sceneLoader->setSource(sourceFileName); - - view.setRootEntity(sceneRoot); - view.show(); - - return app.exec(); -} diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro index d6eaae8e4..b3f5d91a2 100644 --- a/examples/qt3d/qt3d.pro +++ b/examples/qt3d/qt3d.pro @@ -25,5 +25,4 @@ qtHaveModule(multimedia): SUBDIRS += audio-visualizer-qml # TODO Port the old examples to new APIs #SUBDIRS += qt3d -qtHaveModule(widgets): SUBDIRS += assimp-cpp \ - basicshapes-cpp +qtHaveModule(widgets): SUBDIRS += basicshapes-cpp |