From bfc9ea8f4e33702ed6af46b74621c75258b66ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaj=20Gr=C3=B6nholm?= Date: Thu, 22 Nov 2018 10:59:44 +0200 Subject: Add stereoscopic QML example This example demonstrates stereoscopic QML API using ViewerSettings. It contains simple presentation, optimal for stereoscopic viewing and allows opening also other uip files. Task-number: QT3DS-2695 Change-Id: I3003b312e2da23a83076f930227006d1e28724ef Reviewed-by: Laszlo Agocs --- examples/3dstudioruntime2/3dstudioruntime2.pro | 3 +- .../stereoscopicqml/SettingsPanel.qml | 211 +++++++++++++++++++++ .../stereoscopicqml/StereoTester/StereoTester.uip | 93 +++++++++ .../3dstudioruntime2/stereoscopicqml/arrow.png | Bin 0 -> 829 bytes .../stereoscopicqml/doc/images/stereoscopicqml.png | Bin 0 -> 129657 bytes .../stereoscopicqml/doc/src/stereoscopicqml.qdoc | 47 +++++ examples/3dstudioruntime2/stereoscopicqml/main.cpp | 69 +++++++ examples/3dstudioruntime2/stereoscopicqml/main.qml | 117 ++++++++++++ .../stereoscopicqml/stereoscopicqml.pro | 15 ++ .../stereoscopicqml/stereoscopicqml.qrc | 8 + 10 files changed, 562 insertions(+), 1 deletion(-) create mode 100644 examples/3dstudioruntime2/stereoscopicqml/SettingsPanel.qml create mode 100644 examples/3dstudioruntime2/stereoscopicqml/StereoTester/StereoTester.uip create mode 100644 examples/3dstudioruntime2/stereoscopicqml/arrow.png create mode 100644 examples/3dstudioruntime2/stereoscopicqml/doc/images/stereoscopicqml.png create mode 100644 examples/3dstudioruntime2/stereoscopicqml/doc/src/stereoscopicqml.qdoc create mode 100644 examples/3dstudioruntime2/stereoscopicqml/main.cpp create mode 100644 examples/3dstudioruntime2/stereoscopicqml/main.qml create mode 100644 examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.pro create mode 100644 examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.qrc (limited to 'examples') diff --git a/examples/3dstudioruntime2/3dstudioruntime2.pro b/examples/3dstudioruntime2/3dstudioruntime2.pro index d03ce05..d30bbc0 100644 --- a/examples/3dstudioruntime2/3dstudioruntime2.pro +++ b/examples/3dstudioruntime2/3dstudioruntime2.pro @@ -8,7 +8,8 @@ qtHaveModule(quick) { SUBDIRS += simpleqml \ qmldatainput \ layersinquick \ - scenemanip + scenemanip \ + stereoscopicqml } qtHaveModule(widgets) { diff --git a/examples/3dstudioruntime2/stereoscopicqml/SettingsPanel.qml b/examples/3dstudioruntime2/stereoscopicqml/SettingsPanel.qml new file mode 100644 index 0000000..2350448 --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/SettingsPanel.qml @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $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.4 +import QtStudio3D 2.0 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 + +Item { + id: rootItem + + property bool isOpen: true + property real isOpenState: isOpen + + width: 250 + height: parent.height + x: parent.width - (isOpenState * width) + opacity: 0.4 + isOpenState * 0.6 + + Behavior on isOpenState { + NumberAnimation { + duration: 500 + easing.type: Easing.InOutQuad + } + } + + Item { + width: 60 + height: 60 + anchors.right: parent.left + Image { + anchors.centerIn: parent + source: "arrow.png" + width: 16 + height: width + rotation: isOpenState * 180 + } + + MouseArea { + anchors.fill: parent + anchors.margins: -20 + onClicked: { + rootItem.isOpen = !rootItem.isOpen + } + } + } + + Rectangle { + anchors.fill: parent + color: "#404040" + border.width: 1 + border.color: "#e0e0e0" + opacity: 0.6 + } + + Column { + width: parent.width - 32 + anchors.horizontalCenter: parent.horizontalCenter + y: 16 + spacing: 16 + visible: isOpenState > 0 + Text { + id: fpsCount + anchors.horizontalCenter: parent.horizontalCenter + color: "#ffffff" + text: " " + Timer { + running: true + repeat: true + interval: 2000 + onTriggered: { + fpsCount.text = "~" + (mainView.frameCount/2).toFixed(1) + " FPS"; + mainView.frameCount = 0; + } + } + } + ComboBox { + id: stereoModeComboBox + property var modesModel: [ + "StereoModeMono", + "StereoModeTopBottom", + "StereoModeLeftRight", + "StereoModeAnaglyphRedCyan", + "StereoModeAnaglyphGreenMagenta"] + width: parent.width + model: modesModel + currentIndex: 1 + onCurrentTextChanged: { + viewSettings.stereoMode = stereoModeComboBox.currentText; + } + } + Slider { + id: eyeSeparationSlider + width: parent.width + from: 0 + to: 15.0 + value: mainView.eyeSeparation + focusPolicy: Qt.NoFocus + enabled: stereoModeComboBox.currentIndex != 0 + opacity: enabled ? 1.0: 0.2 + onValueChanged: { + mainView.eyeSeparation = value; + } + Text { + anchors.horizontalCenter: parent.horizontalCenter + y: -8 + z: 10 + text: "EYE SEPARATION: " + mainView.eyeSeparation.toFixed(2) + color: "#ffffff" + } + } + Item { + width: 1 + height: 1 + } + Button { + width: parent.width + text: "RELOAD" + onClicked: s3dpres.reload() + focusPolicy: Qt.NoFocus + } + Button { + width: parent.width + text: "OPEN" + onClicked: openDialog.open() + focusPolicy: Qt.NoFocus + } + Button { + width: parent.width + text: "FULLSCREEN" + onClicked: mainView.toggleFullscreen(); + focusPolicy: Qt.NoFocus + } + Item { + width: 1 + height: 1 + } + Button { + id: profTogBtn + width: parent.width + text: "PROFILE UI" + focusPolicy: Qt.NoFocus + onClicked: s3dpres.profileUiVisible = !s3dpres.profileUiVisible + } + Slider { + id: profScaleSlider + width: parent.width + from: 50 + to: 400 + value: 100 + focusPolicy: Qt.NoFocus + enabled: s3dpres.profileUiVisible + opacity: enabled ? 1.0: 0.2 + onValueChanged: s3dpres.profileUiScale = value/100 + Text { + anchors.horizontalCenter: parent.horizontalCenter + y: -8 + z: 10 + text: "PROFILE UI SCALE: " + s3dpres.profileUiScale.toFixed(2) + color: "#ffffff" + } + } + } +} diff --git a/examples/3dstudioruntime2/stereoscopicqml/StereoTester/StereoTester.uip b/examples/3dstudioruntime2/stereoscopicqml/StereoTester/StereoTester.uip new file mode 100644 index 0000000..0bd5b0e --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/StereoTester/StereoTester.uip @@ -0,0 +1,93 @@ + + + + + #7391ff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 -400 100 100 4 -100 100 100 6 0 100 100 10 -400 100 100 + 0 200 100 100 4 -40 100 100 6 40 100 100 10 200 100 100 + 0 0 100 100 4 -300 100 100 6 -360 100 100 10 0 100 100 + 0 -80 100 100 4 50 100 100 10 -80 100 100 + 0 0 100 100 4 50 100 100 10 0 100 100 + 0 0 100 100 4 50 100 100 10 0 100 100 + + + + + 0 0 100 100 5 0 100 100 10 0 100 100 + 0 0 100 100 5 0 100 100 10 0 100 100 + 0 -400 100 100 5 100 100 100 10 -400 100 100 + 0 -20 100 100 5 -20 100 100 10 -20 100 100 + 0 -20 100 100 5 -20 100 100 10 -20 100 100 + 0 0 100 100 5 360 100 100 10 0 100 100 + + + + + 0 30 100 100 2.5 -20 100 100 5 30 100 100 7.5 -20 100 100 10 30 100 100 + 0 0 100 100 2.5 0 100 100 5 0 100 100 7.5 0 100 100 10 0 100 100 + 0 10 100 100 2.5 -10 100 100 5 10 100 100 7.5 -10 100 100 10 10 100 100 + + + + + 0 30 100 100 2.5 -20 100 100 5 30 100 100 7.5 -20 100 100 10 30 100 100 + 0 0 100 100 2.5 0 100 100 5 0 100 100 7.5 0 100 100 10 0 100 100 + 0 10 100 100 2.5 -10 100 100 5 10 100 100 7.5 -10 100 100 10 10 100 100 + + + + + 0 0 100 100 10 0 100 100 + 0 0 100 100 10 360 100 100 + 0 -10 100 100 10 -10 100 100 + + + + + + + + diff --git a/examples/3dstudioruntime2/stereoscopicqml/arrow.png b/examples/3dstudioruntime2/stereoscopicqml/arrow.png new file mode 100644 index 0000000..5ae608b Binary files /dev/null and b/examples/3dstudioruntime2/stereoscopicqml/arrow.png differ diff --git a/examples/3dstudioruntime2/stereoscopicqml/doc/images/stereoscopicqml.png b/examples/3dstudioruntime2/stereoscopicqml/doc/images/stereoscopicqml.png new file mode 100644 index 0000000..cf656c7 Binary files /dev/null and b/examples/3dstudioruntime2/stereoscopicqml/doc/images/stereoscopicqml.png differ diff --git a/examples/3dstudioruntime2/stereoscopicqml/doc/src/stereoscopicqml.qdoc b/examples/3dstudioruntime2/stereoscopicqml/doc/src/stereoscopicqml.qdoc new file mode 100644 index 0000000..4fc7c22 --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/doc/src/stereoscopicqml.qdoc @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt 3D Studio. +** +** $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 stereoscopicqml + \title Qt 3D Studio Runtime: Stereoscopic QML Example + \ingroup qt3dstudioruntime2-examples-qml + \brief Demonstrates using the stereoscopic QML API of Studio3D ViewerSettings + + \image stereoscopicqml.png + + \e {This example demonstrates stereoscopic QML API of Studio3D ViewerSettings} + + \include examples-run.qdocinc + + \section1 Description + + This example demonstrates usage of \l Studio3D, \l Presentation and + \l ViewerSettings to adjust the stereoscopic mode (mono, top-bottom, + left-right, anaglyph) and eye separation value. Sample Qt 3D Studio + presentation is provided, but it is also possible to open other + uip presentation files. +*/ diff --git a/examples/3dstudioruntime2/stereoscopicqml/main.cpp b/examples/3dstudioruntime2/stereoscopicqml/main.cpp new file mode 100644 index 0000000..85afad1 --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/main.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $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 // for MessageDialog +#include +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + qputenv("QSG_INFO", "1"); + QApplication app(argc, argv); + + // Use the ideal format (i.e. OpenGL version and profile) recommended by + // the Qt 3D Studio runtime. Without this the format set on the QQuickView + // would be used instead. + QSurfaceFormat::setDefaultFormat(Q3DS::surfaceFormat()); + + QQmlApplicationEngine engine; + engine.load("qrc:/main.qml"); + return app.exec(); +} diff --git a/examples/3dstudioruntime2/stereoscopicqml/main.qml b/examples/3dstudioruntime2/stereoscopicqml/main.qml new file mode 100644 index 0000000..b347208 --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/main.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $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.0 +import QtStudio3D 2.3 +import QtQuick.Window 2.3 +import QtQuick.Controls 2.2 +import Qt.labs.platform 1.0 + +Window { + id: mainView + + property int frameCount: 0 + property real eyeSeparation: 4.0 + + title: qsTr("Qt 3D Studio Stereoscopic Tester") + color: "#000000" + width: 1280 + height: 720 + visible: true + + function toggleFullscreen() { + if (mainView.visibility == Window.FullScreen) + mainView.showNormal(); + else + mainView.showFullScreen(); + } + + Studio3D { + id: s3d + focus: true + anchors.fill: parent + + onFrameUpdate: frameCount += 1 + + ViewerSettings { + id: viewSettings + stereoMode: ViewerSettings.StereoModeTopBottom + stereoEyeSeparation: mainView.eyeSeparation + } + + Presentation { + id: s3dpres + source: "qrc:/StereoTester/StereoTester.uip" + profilingEnabled: true + } + + onErrorChanged: { + if (s3d.error !== "") { + errorDialog.text = s3d.error; + errorDialog.open(); + } + } + } + + SettingsPanel { + id: settingsPanel + } + + MessageDialog { + id: errorDialog + } + + FileDialog { + id: openDialog + fileMode: FileDialog.OpenFile + nameFilters: ["UIP files (*.uip)", "UIA files (*.uia)", "All files (*)"] + onAccepted: s3dpres.source = file + } +} diff --git a/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.pro b/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.pro new file mode 100644 index 0000000..6e50c4a --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.pro @@ -0,0 +1,15 @@ +TEMPLATE = app + +QT += widgets qml quick 3dstudioruntime2 + +SOURCES += \ + main.cpp + +RESOURCES += stereoscopicqml.qrc + +OTHER_FILES += \ + main.qml \ + SettingsPanel.qml + +target.path = $$[QT_INSTALL_EXAMPLES]/3dstudioruntime2/$$TARGET +INSTALLS += target diff --git a/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.qrc b/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.qrc new file mode 100644 index 0000000..378f012 --- /dev/null +++ b/examples/3dstudioruntime2/stereoscopicqml/stereoscopicqml.qrc @@ -0,0 +1,8 @@ + + + main.qml + SettingsPanel.qml + arrow.png + StereoTester/StereoTester.uip + + -- cgit v1.2.3