diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-02-15 19:47:25 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-02-28 16:28:39 +0000 |
commit | 7ccaf0f9a917f49e1cde551c2a4f4dcff575406c (patch) | |
tree | 3dd47490fce2cf99f783b0bad608cf97d84fd6ab /examples | |
parent | 66b26f86856ff57713ffab35fb689d087aa91ecc (diff) |
Added NodeInstantiator
Hopefully in the long term we can make the renderer smart enough
that it can automatically use instancing to render such things.
Change-Id: I9f5cfabeea11f5e6b925d5ad2466afa8e601e6f8
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bigmodel-qml/MyEntity.qml | 52 | ||||
-rw-r--r-- | examples/bigmodel-qml/bigmodel-qml.pro | 6 | ||||
-rw-r--r-- | examples/bigmodel-qml/bigmodel-qml.qrc | 1 | ||||
-rw-r--r-- | examples/bigmodel-qml/main.cpp | 14 | ||||
-rw-r--r-- | examples/bigmodel-qml/main.qml | 58 |
5 files changed, 88 insertions, 43 deletions
diff --git a/examples/bigmodel-qml/MyEntity.qml b/examples/bigmodel-qml/MyEntity.qml new file mode 100644 index 000000000..fd30c1071 --- /dev/null +++ b/examples/bigmodel-qml/MyEntity.qml @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +import Qt3D 2.0 +import Qt3D.Render 2.0 + +Entity { + id: root + property alias x: translation.dx + property alias y: translation.dy + property alias z: translation.dz + property alias diffuse: material.diffuse + + components: [ + Transform { Translate { id: translation } }, + SphereMesh { radius: 2 }, + PhongMaterial { id: material } + ] +} diff --git a/examples/bigmodel-qml/bigmodel-qml.pro b/examples/bigmodel-qml/bigmodel-qml.pro index e0535a346..7787217f8 100644 --- a/examples/bigmodel-qml/bigmodel-qml.pro +++ b/examples/bigmodel-qml/bigmodel-qml.pro @@ -6,7 +6,11 @@ SOURCES += \ main.cpp OTHER_FILES += \ - main.qml + main.qml \ + MyEntity.qml RESOURCES += \ bigmodel-qml.qrc + +DISTFILES += \ + MyEntity.qml diff --git a/examples/bigmodel-qml/bigmodel-qml.qrc b/examples/bigmodel-qml/bigmodel-qml.qrc index 5f6483ac3..6cc293f70 100644 --- a/examples/bigmodel-qml/bigmodel-qml.qrc +++ b/examples/bigmodel-qml/bigmodel-qml.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/"> <file>main.qml</file> + <file>MyEntity.qml</file> </qresource> </RCC> diff --git a/examples/bigmodel-qml/main.cpp b/examples/bigmodel-qml/main.cpp index a8d22bcfa..6e76f1f5a 100644 --- a/examples/bigmodel-qml/main.cpp +++ b/examples/bigmodel-qml/main.cpp @@ -35,7 +35,7 @@ ****************************************************************************/ #include <Qt3DCore/window.h> -#include <Qt3DRenderer/qrenderaspect.h> +#include <Qt3DRenderer/QRenderAspect> #include <Qt3DInput/QInputAspect> #include <Qt3DQuick/QQmlAspectEngine> @@ -47,23 +47,11 @@ int main(int argc, char* argv[]) { QGuiApplication app(argc, argv); - - QCommandLineParser parser; - parser.addPositionalArgument(QStringLiteral("meshfile"), QStringLiteral("The mesh file to load")); - parser.process(app); - - const QStringList meshFileNames = parser.positionalArguments(); - if (meshFileNames.length() == 0) { - std::cerr << "Please specify mesh files to load" << std::endl; - return 1; - } - Qt3D::Window view; Qt3D::Quick::QQmlAspectEngine engine; engine.aspectEngine()->registerAspect(new Qt3D::QRenderAspect()); engine.aspectEngine()->registerAspect(new Qt3D::QInputAspect()); - engine.qmlEngine()->rootContext()->setContextProperty("_meshFileNames", meshFileNames); QVariantMap data; data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); diff --git a/examples/bigmodel-qml/main.qml b/examples/bigmodel-qml/main.qml index 9c8604d2c..9d6a16264 100644 --- a/examples/bigmodel-qml/main.qml +++ b/examples/bigmodel-qml/main.qml @@ -41,40 +41,40 @@ import QtQuick 2.2 as QQ2 Entity { id: sceneRoot - Camera { - id: camera - lens : CameraLens { - projectionType: CameraLens.PerspectiveProjection - fieldOfView: 45 - aspectRatio: 16/9 - nearPlane : 0.1 - farPlane : 1000.0 - } + Configuration { controlledCamera: mainCamera } - transform : Transform { - LookAt { - position: Qt.vector3d( 0.0, 0.0, -20.0 ) - upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) - viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) - } - } - } + components: [ + FrameGraph { activeFrameGraph: ForwardRenderer { camera: mainCamera } } + ] - Configuration { - controlledCamera: camera + Camera { + id: mainCamera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 22.5 + aspectRatio: 16 / 9 + nearPlane: 0.01 + farPlane: 1000.0 + position: Qt.vector3d( 0.0, 25.0, 40.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) } - FrameGraph { - id : external_forward_renderer - activeFrameGraph : ForwardRenderer { - camera: camera - } - } + NodeInstantiator { + id: collection + property int count: 64 + property real spacing: 5 + property int cols: 8 + property int _rows: count / cols - components: [external_forward_renderer] + model: count + delegate: MyEntity { + id: myEntity + property real _lightness: 0.2 + 0.7 / collection._rows * Math.floor(index / collection.cols) + property real _hue: (index % collection.cols) / collection.cols - Instantiator { - model: _meshFileNames - delegate: SceneLoader { source: modelData; } + x: collection.spacing * (index % collection.cols - 0.5 * (collection.cols - 1)) + z: collection.spacing * (Math.floor(index / collection.cols) - 0.5 * collection._rows) + diffuse: Qt.hsla( _hue, 0.5, _lightness, 1.0 ) + } } } |