diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/viewer/simple_cube_animation/simple_cube_animation.uia | 6 | ||||
-rw-r--r-- | tests/auto/viewer/simple_cube_animation/simple_cube_animation.uip | 50 | ||||
-rw-r--r-- | tests/auto/viewer/tst_qt3dsviewer.cpp | 163 | ||||
-rw-r--r-- | tests/auto/viewer/tst_qt3dsviewer.h | 2 | ||||
-rw-r--r-- | tests/auto/viewer/tst_qt3dsviewer.qml | 6 | ||||
-rw-r--r-- | tests/auto/viewer/viewer.qrc | 6 |
6 files changed, 169 insertions, 64 deletions
diff --git a/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uia b/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uia deleted file mode 100644 index b3dffbd2..00000000 --- a/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uia +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<application xmlns="http://qt.io/qt3dstudio/uia"> - <assets initial="simple_cube_animation"> - <presentation id="simple_cube_animation" src="simple_cube_animation.uip"/> - </assets> -</application> diff --git a/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uip b/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uip deleted file mode 100644 index 22584127..00000000 --- a/tests/auto/viewer/simple_cube_animation/simple_cube_animation.uip +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<UIP version="3" > - <Project > - <ProjectSettings author="" company="" presentationWidth="640" presentationHeight="480" maintainAspect="False" /> - <Graph > - <Scene id="Scene" > - <Layer id="Layer" > - <Camera id="Camera" /> - <Light id="Light" /> - <Model id="Cube" > - <Material id="Material" /> - </Model> - <Model id="Cube_001" > - <Material id="Material_001" /> - </Model> - </Layer> - </Scene> - </Graph> - <Logic > - <State name="Master Slide" component="#Scene" > - <Add ref="#Layer" /> - <Add ref="#Camera" > - <AnimationTrack property="rotation.x" type="EaseInOut" /> - <AnimationTrack property="rotation.y" type="EaseInOut" /> - <AnimationTrack property="rotation.z" type="EaseInOut" /> - </Add> - <Add ref="#Light" lightdiffuse="0 1 0" lightspecular="1 1 1" > - <AnimationTrack property="rotation.x" type="EaseInOut" /> - <AnimationTrack property="rotation.y" type="EaseInOut" /> - <AnimationTrack property="rotation.z" type="EaseInOut" /> - </Add> - <State id="Scene-Slide1" name="Slide1" playmode="Play Through To..." playthroughto="#Scene-Slide2" > - <Add ref="#Cube" name="Cube" scale="1 1 1" sourcepath="#Cube" > - <AnimationTrack property="rotation.x" type="EaseInOut" >0 0 100 100 0.963 45 100 100 1.926 45 100 100 2.944 45 100 100 6.942 0 100 100 8.022 0 100 100 8.98 0 100 100</AnimationTrack> - <AnimationTrack property="rotation.y" type="EaseInOut" >0 0 100 100 0.963 0 100 100 1.926 45 100 100 2.944 45 100 100 6.942 45 100 100 8.022 0 100 100 8.98 0 100 100</AnimationTrack> - <AnimationTrack property="rotation.z" type="EaseInOut" >0 0 100 100 0.963 0 100 100 1.926 0 100 100 2.944 45 100 100 6.942 45 100 100 8.022 45 100 100 8.98 0 100 100</AnimationTrack> - <AnimationTrack property="scale.x" type="EaseInOut" dynamic="True" >0 1 100 100 3.958 2 100 100 4.902 2 100 100 5.981 2 100 100 10 1 100 100</AnimationTrack> - <AnimationTrack property="scale.y" type="EaseInOut" dynamic="True" >0 1 100 100 3.958 1 100 100 4.902 2 100 100 5.981 2 100 100 10 1 100 100</AnimationTrack> - <AnimationTrack property="scale.z" type="EaseInOut" dynamic="True" >0 1 100 100 3.958 1 100 100 4.902 1 100 100 5.981 2 100 100 10 1 100 100</AnimationTrack> - </Add> - <Add ref="#Material" /> - </State> - <State id="Scene-Slide2" name="Slide2" initialplaystate="Play" playmode="Stop at end" playthroughto="Previous" > - <Add ref="#Cube_001" name="Cube" scale="100 100 2" sourcepath="#Cube" /> - <Add ref="#Material_001" /> - </State> - </State> - </Logic> - </Project> -</UIP> diff --git a/tests/auto/viewer/tst_qt3dsviewer.cpp b/tests/auto/viewer/tst_qt3dsviewer.cpp index c6692c3d..90c89b28 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.cpp +++ b/tests/auto/viewer/tst_qt3dsviewer.cpp @@ -30,6 +30,10 @@ #include <QtQuick/QQuickItem> #include <QtGui/QSurfaceFormat> +#include <QtStudio3D/Q3DSPresentation> +#include <QtStudio3D/Q3DSElement> +#include <QtStudio3D/Q3DSViewerSettings> +#include <QtCore/QRandomGenerator> void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -75,10 +79,20 @@ void tst_qt3dsviewer::init() m_viewer.setSource(QUrl("qrc:/tst_qt3dsviewer.qml")); m_studio3DItem = m_viewer.rootObject(); + m_presentation = nullptr; + m_settings = nullptr; + QVERIFY(m_studio3DItem); - m_presentation = static_cast<Q3DSPresentation *>(m_studio3DItem->children().at(0)); + + const auto children = m_studio3DItem->children(); + for (auto &child : children) { + if (!m_presentation) + m_presentation = qobject_cast<Q3DSPresentation *>(child); + if (!m_settings) + m_settings = qobject_cast<Q3DSViewerSettings *>(child); + } + QVERIFY(m_presentation); - m_settings = static_cast<Q3DSViewerSettings *>(m_studio3DItem->children().at(1)); QVERIFY(m_settings); } @@ -149,4 +163,149 @@ void tst_qt3dsviewer::testSettings() QVERIFY(m_settings->matteColor() == QColor("#0000ff")); } +void tst_qt3dsviewer::testCreateElement() +{ + // Currently this method is very bare bones on actual testing. + // It can be used to visually check if items are getting created. + m_viewer.show(); + + m_settings->setShowRenderStats(true); + m_settings->setScaleMode(Q3DSViewerSettings::ScaleModeFill); + + QSignalSpy spyExited(m_presentation, + SIGNAL(slideExited(const QString &, unsigned int, const QString &))); + + int animValue = 0; + + QHash<QString, QVariant> data; + data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder")); + data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Cylinder")); + data.insert(QStringLiteral("material"), QString()); + data.insert(QStringLiteral("starttime"), 0); + data.insert(QStringLiteral("endtime"), 4500); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(200, 300, 200))); + data.insert(QStringLiteral("opacity"), 20.0); + + m_presentation->createElement(QStringLiteral("Scene.Layer"), QStringLiteral("Slide1"), data); + + // Elements can be registered before they are created + Q3DSElement newCylinder(m_presentation, QStringLiteral("Scene.Layer.New Cylinder")); + Q3DSElement newCylinder2(m_presentation, + QStringLiteral("Scene.Layer.New Cylinder.New Cylinder 2")); + Q3DSElement newSphere(m_presentation, QStringLiteral("Scene.Layer.Cube2.New Sphere")); + + QTimer animationTimer; + animationTimer.setInterval(10); + int animDir = 1; + QObject::connect(&animationTimer, &QTimer::timeout, [&]() { + if (qAbs(animValue) > 100) + animDir = -animDir; + animValue += animDir; + newCylinder.setAttribute(QStringLiteral("rotation.x"), animValue * 4); + newCylinder2.setAttribute(QStringLiteral("position.y"), animValue * 3); + newSphere.setAttribute(QStringLiteral("position.x"), 50 + animValue * 2); + }); + + // Create objects to slides 1 & 2 while slide 1 is executing + QTimer::singleShot(1000, [&]() { + data.clear(); + data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder 2")); + data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Cylinder")); + data.insert(QStringLiteral("material"), QStringLiteral("Basic Red")); + data.insert(QStringLiteral("starttime"), 500); + data.insert(QStringLiteral("endtime"), 5000); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(50, animValue, 50))); + + m_presentation->createElement(QStringLiteral("Scene.Layer.New Cylinder"), + QStringLiteral("Slide1"), data); + + data.clear(); + data.insert(QStringLiteral("name"), QStringLiteral("New Sphere")); + data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Sphere")); + data.insert(QStringLiteral("material"), QStringLiteral("Basic Green")); + data.insert(QStringLiteral("starttime"), 1000); + data.insert(QStringLiteral("endtime"), 4000); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(animValue, 75, 0))); + + m_presentation->createElement(QStringLiteral("Scene.Layer.Cube2"), + QStringLiteral("Slide2"), data); + + animationTimer.start(); + }); + + // Switch to slide 2 + QVERIFY(spyExited.wait(20000)); + + // Create objects to slides 1 and 2 while slide 2 is executing + QTimer::singleShot(2000, [&]() { + data.clear(); + data.insert(QStringLiteral("name"), QStringLiteral("New Cylinder 3")); + data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Cylinder")); + data.insert(QStringLiteral("material"), QStringLiteral("Basic Green")); + data.insert(QStringLiteral("starttime"), 0); + data.insert(QStringLiteral("endtime"), 3000); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(-100, -100, 0))); + + m_presentation->createElement(QStringLiteral("Scene.Layer"), QStringLiteral("Slide1"), + data); + + data.clear(); + data.insert(QStringLiteral("name"), QStringLiteral("New Sphere 2")); + data.insert(QStringLiteral("sourcepath"), QStringLiteral("#Sphere")); + data.insert(QStringLiteral("material"), QStringLiteral("Basic Green")); + data.insert(QStringLiteral("starttime"), 0); + data.insert(QStringLiteral("endtime"), 5000); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(-100, 100, 0))); + + m_presentation->createElement(QStringLiteral("Scene.Layer"), QStringLiteral("Slide2"), + data); + }); + + // Switch to slide 1 + QVERIFY(spyExited.wait(20000)); + + QTimer createTimer; + createTimer.setInterval(0); + static int elemCounter = 0; + QRandomGenerator rnd; + + QObject::connect(&createTimer, &QTimer::timeout, [&]() { + // Create a bunch of cubes to slide 2 in small batches to avoid slowdown + for (int i = 0; i < 5; ++i) { + ++elemCounter; + data.clear(); + data.insert(QStringLiteral("name"), QStringLiteral("MassCube_%1").arg(elemCounter)); + data.insert(QStringLiteral("sourcepath"), + elemCounter % 2 ? QStringLiteral("#Cube") : QStringLiteral("#Cone")); + data.insert(QStringLiteral("material"), + elemCounter % 2 ? QStringLiteral("Basic Green") + : QStringLiteral("Basic Red")); + data.insert(QStringLiteral("position"), + QVariant::fromValue<QVector3D>(QVector3D(rnd.bounded(-600, 600), + rnd.bounded(-600, 600), + rnd.bounded(800, 1200)))); + + m_presentation->createElement(QStringLiteral("Scene.Layer"), QStringLiteral("Slide2"), + data); + } + if (elemCounter >= 1000) { + qDebug() << "Extra cubes created:" << elemCounter; + createTimer.stop(); + } + }); + qDebug() << "Start creating extra cubes!"; + createTimer.start(); + + // Switch to slide 2 + QVERIFY(spyExited.wait(20000)); + + // Switch to slide 1 + QVERIFY(spyExited.wait(20000)); +} + QTEST_MAIN(tst_qt3dsviewer) diff --git a/tests/auto/viewer/tst_qt3dsviewer.h b/tests/auto/viewer/tst_qt3dsviewer.h index 1fe60bb5..f50bf935 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.h +++ b/tests/auto/viewer/tst_qt3dsviewer.h @@ -55,13 +55,13 @@ private Q_SLOTS: void testSlides(); void testFrameUpdates(); void testSettings(); + void testCreateElement(); private: QQuickView m_viewer; QObject *m_studio3DItem = nullptr; Q3DSPresentation *m_presentation = nullptr; Q3DSViewerSettings *m_settings = nullptr; - }; #endif // TST_QT3DSVIEWER diff --git a/tests/auto/viewer/tst_qt3dsviewer.qml b/tests/auto/viewer/tst_qt3dsviewer.qml index 794928f6..2368f039 100644 --- a/tests/auto/viewer/tst_qt3dsviewer.qml +++ b/tests/auto/viewer/tst_qt3dsviewer.qml @@ -52,10 +52,10 @@ import QtStudio3D.OpenGL 2.4 Studio3D { id: studio3D - width: 640 - height: 480 + width: 800 + height: 800 Presentation { - source: "qrc:/simple_cube_animation/simple_cube_animation.uia" + source: "qrc:/../../scenes/simple_cube_animation/simple_cube_animation.uia" } ViewerSettings { } diff --git a/tests/auto/viewer/viewer.qrc b/tests/auto/viewer/viewer.qrc index 2f38ba14..d85ee786 100644 --- a/tests/auto/viewer/viewer.qrc +++ b/tests/auto/viewer/viewer.qrc @@ -1,7 +1,9 @@ <RCC> <qresource prefix="/"> - <file>simple_cube_animation/simple_cube_animation.uia</file> - <file>simple_cube_animation/simple_cube_animation.uip</file> + <file>../../scenes/simple_cube_animation/simple_cube_animation.uia</file> + <file>../../scenes/simple_cube_animation/presentations/simple_cube_animation.uip</file> + <file>../../scenes/simple_cube_animation/materials/Basic Green.materialdef</file> + <file>../../scenes/simple_cube_animation/materials/Basic Red.materialdef</file> <file>tst_qt3dsviewer.qml</file> </qresource> </RCC> |