summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-08-08 14:45:29 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-08-27 17:08:23 +0200
commit91dc1e1a61651a82a0ee5ce6ad3b24e82f526be6 (patch)
treef54c30c337a9bae1e0b5d9c8622dd599344f46bf /examples
parentf9306d34bde648975b2a3e24eea01aaa4b6bd679 (diff)
Introduce Scene3DView
Allows to render several 3D scenes using a single Scene3D. To be used when you need multiple Scene3D instances. [ChangeLog] Introduce Scene3DView to render multiple distinct 3D scenes Change-Id: I5d51c5935218cc84c15d57def3703aa0d92040ba Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/qt3d/qt3d.pro3
-rw-r--r--examples/qt3d/scene3dview/AnimatedEntity.qml143
-rw-r--r--examples/qt3d/scene3dview/doc/images/scene3dview.pngbin0 -> 28772 bytes
-rw-r--r--examples/qt3d/scene3dview/doc/src/scene3dview.qdoc62
-rw-r--r--examples/qt3d/scene3dview/main.cpp66
-rw-r--r--examples/qt3d/scene3dview/main.qml142
-rw-r--r--examples/qt3d/scene3dview/scene3dview.pro15
-rw-r--r--examples/qt3d/scene3dview/scene3dview.qrc6
8 files changed, 436 insertions, 1 deletions
diff --git a/examples/qt3d/qt3d.pro b/examples/qt3d/qt3d.pro
index 2f8d624af..91163a0d1 100644
--- a/examples/qt3d/qt3d.pro
+++ b/examples/qt3d/qt3d.pro
@@ -21,7 +21,8 @@ SUBDIRS += \
scene2d \
phong-cubes \
pbr-materials \
- controlsunderlay
+ controlsunderlay \
+ scene3dview
qtHaveModule(multimedia): SUBDIRS += audio-visualizer-qml
diff --git a/examples/qt3d/scene3dview/AnimatedEntity.qml b/examples/qt3d/scene3dview/AnimatedEntity.qml
new file mode 100644
index 000000000..12575b314
--- /dev/null
+++ b/examples/qt3d/scene3dview/AnimatedEntity.qml
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+import Qt3D.Core 2.0
+import Qt3D.Render 2.0
+import Qt3D.Input 2.0
+import Qt3D.Extras 2.0
+
+import QtQuick 2.0 as QQ2
+
+
+Entity {
+ id: sceneRoot
+ property color sceneColor
+ property bool clearColor: true
+
+ Camera {
+ id: camera
+ projectionType: CameraLens.PerspectiveProjection
+ fieldOfView: 45
+ nearPlane : 0.1
+ farPlane : 1000.0
+ position: Qt.vector3d( 0.0, 0.0, 40.0 )
+ upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
+ viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
+ }
+
+ FirstPersonCameraController { camera: camera }
+
+ components: [
+ RenderSettings {
+ activeFrameGraph: ForwardRenderer {
+ camera: camera
+ clearColor: "transparent"
+ clearBuffers: sceneRoot.clearColor ? ClearBuffers.ColorDepthBuffer : ClearBuffers.DepthBuffer
+ }
+ },
+ InputSettings { }
+ ]
+
+ PhongMaterial {
+ id: material
+ diffuse: sceneColor
+ }
+
+ TorusMesh {
+ id: torusMesh
+ radius: 5
+ minorRadius: 1
+ rings: 100
+ slices: 20
+ }
+
+ Transform {
+ id: torusTransform
+ scale3D: Qt.vector3d(1.5, 1, 0.5)
+ rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
+ }
+
+ Entity {
+ id: torusEntity
+ components: [ torusMesh, material, torusTransform ]
+ }
+
+ SphereMesh {
+ id: sphereMesh
+ radius: 3
+ }
+
+ Transform {
+ id: sphereTransform
+ property real userAngle: 0.0
+ matrix: {
+ var m = Qt.matrix4x4();
+ m.rotate(userAngle, Qt.vector3d(0, 1, 0))
+ m.translate(Qt.vector3d(20, 0, 0));
+ return m;
+ }
+ }
+
+ QQ2.NumberAnimation {
+ target: sphereTransform
+ property: "userAngle"
+ duration: 10000
+ from: 0
+ to: 360
+
+ loops: QQ2.Animation.Infinite
+ running: true
+ }
+
+ Entity {
+ id: sphereEntity
+ components: [ sphereMesh, material, sphereTransform ]
+ }
+}
diff --git a/examples/qt3d/scene3dview/doc/images/scene3dview.png b/examples/qt3d/scene3dview/doc/images/scene3dview.png
new file mode 100644
index 000000000..d697d1850
--- /dev/null
+++ b/examples/qt3d/scene3dview/doc/images/scene3dview.png
Binary files differ
diff --git a/examples/qt3d/scene3dview/doc/src/scene3dview.qdoc b/examples/qt3d/scene3dview/doc/src/scene3dview.qdoc
new file mode 100644
index 000000000..721929350
--- /dev/null
+++ b/examples/qt3d/scene3dview/doc/src/scene3dview.qdoc
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example scene3dview
+ \title Qt 3D: Scene3DView QML Example
+ \ingroup qt3d-examples-qml
+ \brief A QML application that demonstrates visualizing multiple 3D scenes
+ using Scene3D and Scene3DView.
+
+ \image scene3dview.png
+
+ This example demonstrates visualizing multiple 3D scenes from a Qt Quick
+ application usinc Scene3D and Scene3DView. Each 3D scene contains a single
+ active camera and a single active light source. Visualized data is assumed
+ to be at a fixed location.
+
+ \include examples-run.qdocinc
+
+ \section1 Visualizing 3D Scenes
+
+ First we set up a Scene3D instance that will be required for our
+ Scene3DView instanced.
+
+ \snippet scene3dview/main.qml 0
+
+ Then we instanciate our Scene3DView instances and make them reference the
+ Scene3D. We also provide a root Entity for each Scene3DView with a \e
+ scene3dview/AnimatedEntity.qml.
+
+ \snippet scene3dview/main.qml 1
+
+ Care has to be taken that only the first Scene3DView clears the color
+ buffer. We don't want each Scene3DView to clear the screen as that would
+ erase content for all but the last Scene3DView.
+
+ \snippet scene3dview/main.qml 1.1
+*/
diff --git a/examples/qt3d/scene3dview/main.cpp b/examples/qt3d/scene3dview/main.cpp
new file mode 100644
index 000000000..8886263f4
--- /dev/null
+++ b/examples/qt3d/scene3dview/main.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** 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 <QGuiApplication>
+#include <QQuickView>
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickView view;
+
+ view.resize(500, 500);
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:/main.qml"));
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/qt3d/scene3dview/main.qml b/examples/qt3d/scene3dview/main.qml
new file mode 100644
index 000000000..d2a3fc3e0
--- /dev/null
+++ b/examples/qt3d/scene3dview/main.qml
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 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$
+**
+****************************************************************************/
+
+import QtQuick 2.14
+import QtQuick.Scene3D 2.14
+import QtQuick.Controls 2.14
+import QtQuick.Layouts 1.14
+
+Item {
+
+ //! [0]
+ Scene3D {
+ id: scene3dInstance
+ anchors.fill: parent
+ focus: true
+ aspects: ["input", "logic"]
+ cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
+ multisample: true
+ }
+ //! [0]
+
+ ColumnLayout {
+ anchors.fill: parent
+ Grid {
+ id: grid
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ columns: 2
+ rows: 2
+ spacing: 50
+
+ readonly property int cellWidth: (width - spacing ) * 0.5
+ readonly property int cellHeight: (height -spacing) * 0.5
+ readonly property var colors: ["green", "gray", "orange", "blue"]
+ readonly property int maxInstances: grid.rows * grid.columns
+
+ Repeater {
+ id: gridRepeater
+ model: grid.rows * grid.columns
+
+ //! [1]
+ Rectangle {
+ width: grid.cellWidth
+ height: grid.cellHeight
+ color: "darkRed"
+ scale: ma.pressed || ma.containsMouse ? 0.8 : 1
+ Behavior on scale { NumberAnimation { duration: 750 } }
+
+ Scene3DView {
+ onXChanged: console.log(("X (%1): %2").arg(model.index).arg(x))
+ scene3D: scene3dInstance
+ anchors.fill: parent
+ AnimatedEntity {
+ sceneColor: grid.colors[model.index]
+ //! [1.1]
+ // Only clear the color for the first Scene3DView
+ clearColor: model.index === 0
+ //! [1.1]
+ }
+ }
+ Text {
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ bottom: parent.bottom
+ }
+
+ color: "white"
+ font.bold: true
+ text: "Scene3DView " + (model.index + 1)
+ }
+
+ MouseArea {
+ id: ma
+ anchors.fill: parent
+ hoverEnabled: true
+ }
+ }
+ //! [1]
+ }
+ }
+
+ RowLayout {
+ Layout.alignment: Qt.AlignHCenter
+ Button {
+ text: "-"
+ onClicked: gridRepeater.model = Math.max(1, gridRepeater.count - 1);
+ }
+ Text { text: "Instances (%1/%2)".arg(gridRepeater.count).arg(grid.maxInstances) }
+ Button {
+ text: "+"
+ onClicked: gridRepeater.model = Math.min(grid.maxInstances, gridRepeater.count + 1);
+ }
+ }
+ }
+}
diff --git a/examples/qt3d/scene3dview/scene3dview.pro b/examples/qt3d/scene3dview/scene3dview.pro
new file mode 100644
index 000000000..4e1052b7b
--- /dev/null
+++ b/examples/qt3d/scene3dview/scene3dview.pro
@@ -0,0 +1,15 @@
+!include( ../examples.pri ) {
+ error( "Couldn't find the examples.pri file!" )
+}
+
+QT += qml quick 3dinput
+
+SOURCES += \
+ main.cpp
+
+OTHER_FILES += \
+ AnimatedEntity.qml \
+ main.qml
+
+RESOURCES += \
+ scene3dview.qrc
diff --git a/examples/qt3d/scene3dview/scene3dview.qrc b/examples/qt3d/scene3dview/scene3dview.qrc
new file mode 100644
index 000000000..dff72ed5a
--- /dev/null
+++ b/examples/qt3d/scene3dview/scene3dview.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>AnimatedEntity.qml</file>
+ <file>main.qml</file>
+ </qresource>
+</RCC>