diff options
author | Janne Kangas <janne.kangas@qt.io> | 2018-11-14 13:40:38 +0200 |
---|---|---|
committer | Janne Kangas <janne.kangas@qt.io> | 2019-02-06 06:13:26 +0000 |
commit | 9a5714c4051f6e0c9a16ba1ff6f27eb471994496 (patch) | |
tree | 1e9c7d5645e08330f024ea2d82c8125565e5bedb /examples | |
parent | e3529c59f265c3cd4834c9c2ebddaff839b0bd8a (diff) |
Implement datainput getter API in Q3DSPresentation
Returns QVariantList containing Q3DSDataInput* allowing both QML
and C++ iterate through datainputs defined in the presentation. Also
implement isValid() that checks that datainput name is valid and datainput
is associated with a presentation. Modify qmldatainput example and provide
"cppdatainput" example for C++ side.
Change-Id: I83afda1b03326390f4cf4f23c68219248a9d3ae2
Task-id: QT3DS-2204
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'examples')
9 files changed, 264 insertions, 22 deletions
diff --git a/examples/3dstudioruntime2/3dstudioruntime2.pro b/examples/3dstudioruntime2/3dstudioruntime2.pro index d30bbc0..b1b2946 100644 --- a/examples/3dstudioruntime2/3dstudioruntime2.pro +++ b/examples/3dstudioruntime2/3dstudioruntime2.pro @@ -2,7 +2,8 @@ TEMPLATE = subdirs SUBDIRS += \ simplewindow \ - simpleoffscreen + simpleoffscreen \ + cppdatainput qtHaveModule(quick) { SUBDIRS += simpleqml \ diff --git a/examples/3dstudioruntime2/cppdatainput/cppdatainput.pro b/examples/3dstudioruntime2/cppdatainput/cppdatainput.pro new file mode 100644 index 0000000..d8753c0 --- /dev/null +++ b/examples/3dstudioruntime2/cppdatainput/cppdatainput.pro @@ -0,0 +1,11 @@ +CONFIG += c++11 +QT += widgets qml quick 3dstudioruntime2 + +target.path = $$[QT_INSTALL_EXAMPLES]/3dstudioruntime2/$$TARGET +INSTALLS += target + +SOURCES += \ + main.cpp + +RESOURCES += \ + res.qrc diff --git a/examples/3dstudioruntime2/cppdatainput/main.cpp b/examples/3dstudioruntime2/cppdatainput/main.cpp new file mode 100644 index 0000000..0ae25fb --- /dev/null +++ b/examples/3dstudioruntime2/cppdatainput/main.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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 <QGuiApplication> +#include <QQmlApplicationEngine> +#include <Q3DSSurfaceViewer> +#include <QWindow> +#include <QSurface> +#include <Q3DSPresentation> +#include <QOpenGLContext> +#include <Q3DSDataInput> +#include <QVector3D> +#include <QTimer> +// Required for Ubuntu build +#include <cmath> + +int main(int argc, char *argv[]) +{ + float colorRed = 0.0f; + int range = 0; + + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + QSurfaceFormat::setDefaultFormat(Q3DS::surfaceFormat()); + + QOpenGLContext context; + if (!context.create()) + qFatal("Failed to create OpenGL context"); + + QWindow window; + window.setSurfaceType(QSurface::OpenGLSurface); + window.setFormat(context.format()); + window.create(); + + Q3DSSurfaceViewer viewer; + + QObject::connect(&viewer, &Q3DSSurfaceViewer:: presentationLoaded, &viewer, [&] { + const QVariantList diList = viewer.presentation()->getDataInputs(); + for (const auto &it : diList) { + Q3DSDataInput *dynDi = qvariant_cast<Q3DSDataInput *>(it); + if (dynDi->name().contains(QLatin1String("color"))) { + if (dynDi->isValid()) { + QObject::connect(&viewer, &Q3DSSurfaceViewer::frameUpdate, + [&colorRed, dynDi] { + dynDi->setValue(QVector3D(colorRed, 0.5, 0.5)); + colorRed = std::fmod(colorRed + 0.001f, 1.0f); + }); + } + } else if (dynDi->name().contains(QLatin1String("range"))) { + if (dynDi->isValid()) { + QObject::connect(&viewer, &Q3DSSurfaceViewer::frameUpdate, [&range, dynDi] { + dynDi->setValue(range); + range = (range + 1) % 360; + }); + } + } + } + }); + + viewer.presentation()->setSource(QUrl(QStringLiteral("qrc:presentation/datainput.uia"))); + viewer.setUpdateInterval(0); // enable automatic updates + + viewer.create(&window, &context); + + window.setTitle(QStringLiteral("Qt 3D Studio Example")); + window.resize(800, 480); + window.show(); + + return app.exec(); +} diff --git a/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uia b/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uia new file mode 100644 index 0000000..cbe778f --- /dev/null +++ b/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uia @@ -0,0 +1,17 @@ +<?xml version='1.0' encoding='UTF-8'?> +<application> + <assets initial="datainput"> + <presentation id="datainput" src="datainput.uip"/> + <dataInput name="colorInput" type="Vector3"/> + <dataInput name="rangeInput" type="Ranged Number" min="0" max="360"/> + </assets> + <statemachine ref="#logic"> + <visual-states> + <state ref="Initial"> + <enter> + <goto-slide element="main:Scene" rel="next"/> + </enter> + </state> + </visual-states> + </statemachine> +</application> diff --git a/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uip b/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uip new file mode 100644 index 0000000..d54f210 --- /dev/null +++ b/examples/3dstudioruntime2/cppdatainput/presentation/datainput.uip @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<UIP version="5" > + <Project > + <ProjectSettings author="" company="" presentationWidth="800" presentationHeight="480" maintainAspect="False" preferKtx="False" > + <CustomColors count="16" >#ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff</CustomColors> + </ProjectSettings> + <Graph > + <Scene id="Scene" controlledproperty="$rangeInput @timeline" > + <Layer id="Layer" > + <Camera id="Camera" /> + <Light id="Light" /> + <Text id="Text" /> + <Text id="Text2" /> + <Model id="Cylinder" > + <Material id="Default_002" name="Default" /> + </Model> + <Text id="Text4" /> + <Model id="Rectangle" > + <Material id="Default_001" name="Default" /> + </Model> + </Layer> + </Scene> + </Graph> + <Logic > + <State name="Master Slide" component="#Scene" > + <Add ref="#Layer" multisampleaa="SSAA" progressiveaa="8x" /> + <Add ref="#Camera" controlledproperty="" pivot="0 0 0" position="0 0 -800" rotation="0 0 0" /> + <Add ref="#Light" castshadow="True" controlledproperty="$colorInput lightdiffuse" lightdiffuse="1 0 0" lighttype="Point" position="-300.444 70.829 -30" shdwfactor="11.89" shdwfilter="6.94" shdwmapres="11" /> + <State id="Scene-Slide1" name="Slide1" initialplaystate="Pause" > + <Add ref="#Text" name="Text" controlledproperty="$rangeInput textstring" font="TitilliumWeb-Regular" position="216.513 76.6172 -113.498" scale="1 1 1" size="24" textstring="0" > + <AnimationTrack property="rotation.x" type="EaseInOut" >0 0 0 0 10 0 0 0</AnimationTrack> + <AnimationTrack property="rotation.y" type="EaseInOut" >0 0 0 0 10 0 0 0</AnimationTrack> + <AnimationTrack property="rotation.z" type="EaseInOut" >0 0 0 0 10 -360 0 0</AnimationTrack> + </Add> + <Add ref="#Text2" name="Text2" controlledproperty="" font="TitilliumWeb-Regular" position="259.808 217.95 0" scale="1 1 1" size="16" textstring="Text control Rotation animation control via datainput timeline control" /> + <Add ref="#Cylinder" name="Cylinder" controlledproperty="" position="15.877 -141.932 0" sourcepath="#Cylinder" /> + <Add ref="#Default_002" diffuse="0.666667 1 0.498039" /> + <Add ref="#Text4" name="Text4" font="TitilliumWeb-Regular" position="-373.353 201.004 0" size="18" textstring="Directional light color control" /> + <Add ref="#Rectangle" name="Rectangle" position="0 -400 20" rotation="90.5 0 0" scale="11.0468 7.99191 9.12813" sourcepath="#Rectangle" /> + <Add ref="#Default_001" diffuse="0.623529 0.623529 0.623529" /> + </State> + </State> + </Logic> + </Project> +</UIP> diff --git a/examples/3dstudioruntime2/cppdatainput/res.qrc b/examples/3dstudioruntime2/cppdatainput/res.qrc new file mode 100644 index 0000000..9beb456 --- /dev/null +++ b/examples/3dstudioruntime2/cppdatainput/res.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>presentation/datainput.uia</file> + <file>presentation/datainput.uip</file> + </qresource> +</RCC> diff --git a/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uia b/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uia index 66b1518..67014ae 100644 --- a/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uia +++ b/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uia @@ -1,21 +1,22 @@ -<?xml version="1.0" encoding="UTF-8" ?> +<?xml version='1.0' encoding='UTF-8'?> <application> - <assets initial="datainput"> - <presentation id="datainput" src="datainput.uip"/> - <dataInput name="cameraRotInput" type="Vector3"/> - <dataInput name="colorInput" type="Vector3"/> - <dataInput name="rangeInput" type="Ranged Number" min="0" max="360"/> - <dataInput name="scaleInput" type="Vector3"/> - <dataInput name="stringInput" type="String"/> - <dataInput name="variantInput" type="Variant"/> - </assets> - <statemachine ref="#logic"> - <visual-states> - <state ref="Initial"> - <enter> - <goto-slide element="main:Scene" rel="next"/> - </enter> - </state> - </visual-states> - </statemachine> + <assets initial="datainput"> + <presentation id="datainput" src="datainput.uip"/> + <dataInput name="cameraRotInput" type="Vector3"/> + <dataInput name="colorInput" type="Vector3"/> + <dataInput name="queriedInput" type="String"/> + <dataInput name="rangeInput" type="Ranged Number" min="0" max="360"/> + <dataInput name="scaleInput" type="Vector3"/> + <dataInput name="stringInput" type="String"/> + <dataInput name="variantInput" type="Variant"/> + </assets> + <statemachine ref="#logic"> + <visual-states> + <state ref="Initial"> + <enter> + <goto-slide rel="next" element="main:Scene"/> + </enter> + </state> + </visual-states> + </statemachine> </application> diff --git a/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uip b/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uip index e4e6ba1..7475629 100644 --- a/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uip +++ b/examples/3dstudioruntime2/qmldatainput/presentation/datainput.uip @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> -<UIP version="4" > +<UIP version="5" > <Project > - <ProjectSettings author="" company="" presentationWidth="800" presentationHeight="480" maintainAspect="False" > + <ProjectSettings author="" company="" presentationWidth="800" presentationHeight="480" maintainAspect="False" preferKtx="False" > <CustomColors count="16" >#ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff</CustomColors> </ProjectSettings> <Graph > @@ -29,6 +29,7 @@ <Image id="Default_001_diffusemap" /> </Material> </Model> + <Text id="Text5" /> </Layer> </Scene> </Graph> @@ -57,6 +58,7 @@ <Add ref="#Rectangle" name="Rectangle" position="0 -400 20" rotation="90.5 0 0" scale="11.0468 7.99191 9.12813" sourcepath="#Rectangle" /> <Add ref="#Default_001" diffuse="0.623529 0.623529 0.623529" diffusemap="#Default_001_diffusemap" /> <Add ref="#Default_001_diffusemap" sourcepath="Paper05.png" /> + <Add ref="#Text5" name="Text5" controlledproperty="$queriedInput textstring" font="TitilliumWeb-Regular" position="-57.7348 3.84888 0" textstring="Text from queried QML Datainput" /> </State> </State> </Logic> diff --git a/examples/3dstudioruntime2/qmldatainput/qml/qmldatainput/main.qml b/examples/3dstudioruntime2/qmldatainput/qml/qmldatainput/main.qml index c0757e2..696c3d7 100644 --- a/examples/3dstudioruntime2/qmldatainput/qml/qmldatainput/main.qml +++ b/examples/3dstudioruntime2/qmldatainput/qml/qmldatainput/main.qml @@ -57,9 +57,44 @@ Item { height: 768 visible: true + // Show the list of datainputs queried by Q3DSPresentation queried from Presentation + Column { + id : diColumn + opacity: 50 + z: 1 + + Text { text: "Datainputs"; color: "red"; bottomPadding: 5; } + + Repeater { + id: diList + height: childrenRect.height + + function updateModel() { + // Datainput list is accessible from QML as JS array + var diList = studio3D.presentation.getDataInputs(); + model = diList; + for (var i = 0; i < count; ++i) { + // Use dynamically queried datainput to set value. + if (itemAt(i).text === "queriedInput") { + console.log("Updating " + diList[i].name); + diList[i].value = "This text is controlled by " + diList[i].name; + } + } + } + + Text { + id: diItem + color: "red" + text: modelData.name + } + } + } + Studio3D { id: studio3D anchors.fill: parent + height: 900 + width: 1280 property real inputNumber: 0 property vector3d inputColorVec3: Qt.vector3d(0, 0, 0) @@ -68,6 +103,10 @@ Item { property string inputString: "" property variant inputVariant: 0 + onPresentationLoaded: { + diList.updateModel(); + } + // A changing property to demonstrate DataInput NumberAnimation { target: studio3D @@ -127,6 +166,8 @@ Item { // Presentation item is used to control the presentation. //![1] Presentation { + id: presentation + source: "qrc:/presentation/datainput.uia" DataInput { // Name must match the data input name specified in the presentation |