summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2019-06-27 09:47:07 +0300
committerAntti Määttä <antti.maatta@qt.io>2019-06-28 09:31:22 +0300
commit9677851febf223cb3e74aa0d11edf95d0c08b919 (patch)
treecce42160d48e178e01fe7194da2e2f77b6219250
parent3a014b324f1948192cb973c62c40150464ce5aa2 (diff)
Fix simpleqml example
- Reset source when window changes because it will cause new renderer to be created and it would not have proper source without it. - Update the example codes and resources - Change how the init timer is initialized to get proper result each time the presentation gets reloaded. Task-number: QT3DS-3681 Change-Id: I64d4f6980b87b6efcbb906bb4ad241956ce0a7bc Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--examples/studio3d/simpleqml/main.qml21
-rw-r--r--examples/studio3d/simpleqml/presentation/barrel.uia28
-rw-r--r--examples/studio3d/simpleqml/presentation/barrel.uip16
-rw-r--r--src/api/studio3dqml/q3dsrenderer.cpp8
-rw-r--r--src/api/studio3dqml/q3dsrenderer_p.h5
-rw-r--r--src/api/studio3dqml/q3dsstudio3d.cpp15
-rw-r--r--src/api/studio3dqml/q3dsstudio3d_p.h2
-rw-r--r--src/engine/Qt3DSRuntimeView.cpp3
8 files changed, 61 insertions, 37 deletions
diff --git a/examples/studio3d/simpleqml/main.qml b/examples/studio3d/simpleqml/main.qml
index 06321a7..ed0278e 100644
--- a/examples/studio3d/simpleqml/main.qml
+++ b/examples/studio3d/simpleqml/main.qml
@@ -70,9 +70,13 @@ Rectangle {
anchors.fill: parent
property string textValue: "hello world"
+ ViewerSettings {
+ id: viewerSettings
+ }
+
Presentation {
id: s3dpres
- source: "qrc:/presentation/barrel.uip"
+ source: "qrc:/presentation/barrel.uia"
onCustomSignalEmitted: customSignalName.text = Date.now() + ": " + name
onSlideEntered: slideEnter.text = "Entered slide " + name + "(index " + index + ") on " + elementPath
onSlideExited: slideExit.text = "Exited slide " + name + "(index " + index + ") on " + elementPath
@@ -169,7 +173,11 @@ Rectangle {
}
Button {
text: "Reload"
- onClicked: s3dpres.reload()
+ onClicked: {
+ var src = s3dpres.source
+ s3dpres.source = ""
+ s3dpres.source = src
+ }
focusPolicy: Qt.NoFocus
}
Button {
@@ -185,9 +193,10 @@ Rectangle {
}
Button {
text: "Toggle camera"
+ property bool eyeball: true
onClicked: {
- var v = s3dpres.getAttribute("Scene.Layer.Camera", "eyeball")
- s3dpres.setAttribute("Scene.Layer.Camera", "eyeball", !v)
+ eyeball = !eyeball
+ s3dpres.setAttribute("Scene.Layer.Camera", "eyeball", eyeball)
}
focusPolicy: Qt.NoFocus
}
@@ -258,11 +267,11 @@ Rectangle {
Button {
id: profTogBtn
- text: "Toggle profile UI"
+ text: "Toggle render stats"
anchors.right: parent.right
anchors.bottom: parent.bottom
focusPolicy: Qt.NoFocus
- onClicked: s3dpres.profileUiVisible = !s3dpres.profileUiVisible
+ onClicked: viewerSettings.showRenderStats = !viewerSettings.showRenderStats
}
Slider {
id: profUiScale
diff --git a/examples/studio3d/simpleqml/presentation/barrel.uia b/examples/studio3d/simpleqml/presentation/barrel.uia
index d936e42..209d13a 100644
--- a/examples/studio3d/simpleqml/presentation/barrel.uia
+++ b/examples/studio3d/simpleqml/presentation/barrel.uia
@@ -1,16 +1,16 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version='1.0' encoding='UTF-8'?>
<application>
- <assets initial="barrel">
- <dataInput name="di_text" type="String"/>
- <presentation id="barrel" src="barrel.uip"/>
- </assets>
- <statemachine ref="#logic">
- <visual-states>
- <state ref="Initial">
- <enter>
- <goto-slide element="main:Scene" rel="next"/>
- </enter>
- </state>
- </visual-states>
- </statemachine>
+ <assets initial="barrel">
+ <presentation id="barrel" src="barrel.uip"/>
+ <dataInput metadata="" name="di_text" type="String"/>
+ </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/studio3d/simpleqml/presentation/barrel.uip b/examples/studio3d/simpleqml/presentation/barrel.uip
index 48b4edc..7b9b2fb 100644
--- a/examples/studio3d/simpleqml/presentation/barrel.uip
+++ b/examples/studio3d/simpleqml/presentation/barrel.uip
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<UIP version="6" >
<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 >
<Scene id="Scene" >
- <Layer id="Layer" >
+ <Layer id="Layer" variants="" >
<Camera id="Camera" />
<Light id="Light" />
- <Model id="Barrel" >
+ <Model id="Barrel" variants="" >
<Material id="Material" >
<Image id="Material_diffusemap" />
<Image id="Material_normalmap" />
@@ -17,8 +17,8 @@
<Image id="Material_specularmap" />
</Material>
</Model>
- <Text id="Text" />
- <Text id="Text2" />
+ <Text id="Text" variants="" />
+ <Text id="Text2" variants="" />
</Layer>
</Scene>
</Graph>
@@ -34,14 +34,14 @@
<AnimationTrack property="rotation.y" type="EaseInOut" >0 0 100 100 5 -302 100 100 10 0 100 100</AnimationTrack>
<AnimationTrack property="rotation.z" type="EaseInOut" >0 0 100 100 5 0 100 100 10 0 100 100</AnimationTrack>
</Add>
- <Add ref="#Material" bumpamount="0" diffuse="1 1 1" diffusemap="#Material_diffusemap" emissivemap="#Material_emissivemap" fresnelPower="25" normalmap="#Material_normalmap" specularamount="4" specularmap="#Material_specularmap" specularmodel="Default" specularroughness="0.001" >
+ <Add ref="#Material" bumpamount="0" diffuse="1 1 1 1" diffusemap="#Material_diffusemap" emissivemap="#Material_emissivemap" fresnelPower="25" normalmap="#Material_normalmap" specularamount="4" specularmap="#Material_specularmap" specularmodel="Default" specularroughness="0.001" >
<AnimationTrack property="bumpamount" type="EaseInOut" >0 0 100 100 5 1 100 100</AnimationTrack>
</Add>
<Add ref="#Material_diffusemap" sourcepath=".\maps\barrel_barrel_Diffuse.png" />
<Add ref="#Material_normalmap" sourcepath=".\maps\barrel_barrel_Normal.png" />
<Add ref="#Material_emissivemap" sourcepath=".\maps\barrel_barrel_Emissive.png" />
<Add ref="#Material_specularmap" sourcepath=".\maps\barrel_barrel_Specular.png" />
- <Add ref="#Text" name="Text" font="Arimo-Regular" position="-486.418 297.128 50.5569" textcolor="0 1 0" textstring="Barrel!" tracking="0" >
+ <Add ref="#Text" name="Text" font="Arimo-Regular" position="-486.418 297.128 50.5569" textcolor="0 1 0 1" textstring="Barrel!" tracking="0" >
<AnimationTrack property="opacity" type="EaseInOut" >0 100 100 100 5.009 43.75 100 100 10 100 100 100</AnimationTrack>
<AnimationTrack property="rotation.x" type="EaseInOut" >0 0 100 100 4.997 0 100 100 5.009 0 100 100 10 0 100 100</AnimationTrack>
<AnimationTrack property="rotation.y" type="EaseInOut" >0 0 100 100 4.997 0 100 100 5.009 0 100 100 10 360 100 100</AnimationTrack>
@@ -50,7 +50,7 @@
<AnimationTrack property="textcolor.y" type="EaseInOut" >0 1 100 100 5.009 0.235294 100 100 10 1 100 100</AnimationTrack>
<AnimationTrack property="textcolor.z" type="EaseInOut" >0 0 100 100 5.009 0.333333 100 100 10 0 100 100</AnimationTrack>
</Add>
- <Add ref="#Text2" name="Text2" controlledproperty="di_text textstring" font="Arimo-Regular" position="435.899 267.025 0" />
+ <Add ref="#Text2" name="Text2" controlledproperty="$di_text textstring" font="Arimo-Regular" position="437.342 256.921 0" />
</State>
</State>
</Logic>
diff --git a/src/api/studio3dqml/q3dsrenderer.cpp b/src/api/studio3dqml/q3dsrenderer.cpp
index 33c7b98..e3fce5c 100644
--- a/src/api/studio3dqml/q3dsrenderer.cpp
+++ b/src/api/studio3dqml/q3dsrenderer.cpp
@@ -48,7 +48,8 @@ using namespace Q3DSViewer;
QT_BEGIN_NAMESPACE
-Q3DSRenderer::Q3DSRenderer(bool visibleFlag, qt3ds::Qt3DSAssetVisitor *assetVisitor)
+Q3DSRenderer::Q3DSRenderer(bool visibleFlag, qt3ds::Qt3DSAssetVisitor *assetVisitor,
+ QElapsedTimer *startupTimer)
: m_visibleFlag(visibleFlag)
, m_initElements(false)
, m_runtime(0)
@@ -58,8 +59,9 @@ Q3DSRenderer::Q3DSRenderer(bool visibleFlag, qt3ds::Qt3DSAssetVisitor *assetVisi
, m_visitor(assetVisitor)
, m_settings(new Q3DSViewerSettings(this))
, m_presentation(new Q3DSPresentation(this))
+ , m_startupTimer(startupTimer)
{
- m_startupTimer.start();
+
}
Q3DSRenderer::~Q3DSRenderer()
@@ -170,7 +172,7 @@ void Q3DSRenderer::draw()
bool Q3DSRenderer::initializeRuntime(QOpenGLFramebufferObject *inFbo)
{
- m_runtime = &Q3DSViewerApp::Create(nullptr, new Qt3DSAudioPlayerImpl(), &m_startupTimer);
+ m_runtime = &Q3DSViewerApp::Create(nullptr, new Qt3DSAudioPlayerImpl(), m_startupTimer);
Q_ASSERT(m_runtime);
// Connect presentation ready signal before initializing the app
diff --git a/src/api/studio3dqml/q3dsrenderer_p.h b/src/api/studio3dqml/q3dsrenderer_p.h
index 6d044ff..8927f34 100644
--- a/src/api/studio3dqml/q3dsrenderer_p.h
+++ b/src/api/studio3dqml/q3dsrenderer_p.h
@@ -59,7 +59,8 @@ class Q3DSRenderer : public QObject,
Q_OBJECT
public:
- Q3DSRenderer(bool visibleFlag, qt3ds::Qt3DSAssetVisitor *assetVisitor);
+ Q3DSRenderer(bool visibleFlag, qt3ds::Qt3DSAssetVisitor *assetVisitor,
+ QElapsedTimer *startupTimer);
~Q3DSRenderer();
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override;
@@ -102,7 +103,7 @@ protected:
Q3DSViewerSettings *m_settings;
Q3DSPresentation *m_presentation;
QString m_error;
- QElapsedTimer m_startupTimer;
+ QElapsedTimer *m_startupTimer;
};
QT_END_NAMESPACE
diff --git a/src/api/studio3dqml/q3dsstudio3d.cpp b/src/api/studio3dqml/q3dsstudio3d.cpp
index deb4f04..38d32d4 100644
--- a/src/api/studio3dqml/q3dsstudio3d.cpp
+++ b/src/api/studio3dqml/q3dsstudio3d.cpp
@@ -152,6 +152,8 @@ Q3DSStudio3D::Q3DSStudio3D()
connect(this, &Q3DSStudio3D::visibleChanged, this, &Q3DSStudio3D::handleVisibleChanged);
updateEventMasks();
+ m_startupTimer.reset(new QElapsedTimer());
+ m_startupTimer->restart();
}
Q3DSStudio3D::~Q3DSStudio3D()
@@ -278,6 +280,10 @@ void Q3DSStudio3D::componentComplete()
QQmlContext *ctx = QQmlEngine::contextForObject(this);
m_presentation->d_ptr->streamProxy()->setEngine(ctx->engine());
+ QObject::connect(m_presentation, &Q3DSPresentationItem::sourceChanged, [this]() {
+ m_startupTimer->restart();
+ });
+
QQuickFramebufferObject::componentComplete();
}
@@ -296,6 +302,8 @@ void Q3DSStudio3D::handleWindowChanged(QQuickWindow *window)
connect(window, &QQuickWindow::afterAnimating, this, &Q3DSStudio3D::tick);
// Call update after the frame is handled to queue another frame
connect(window, &QQuickWindow::afterSynchronizing, this, &Q3DSStudio3D::update);
+
+ reset();
}
/*!
@@ -315,9 +323,9 @@ void Q3DSStudio3D::reset()
{
// Fake a source change to trigger a reloading of the presentation
m_pendingCommands.m_sourceChanged = true;
- m_pendingCommands.m_source = m_presentation->source();
+ m_pendingCommands.m_source = m_presentation ? m_presentation->source() : QString();
m_pendingCommands.m_variantListChanged = true;
- m_pendingCommands.m_variantList = m_presentation->variantList();
+ m_pendingCommands.m_variantList = m_presentation ? m_presentation->variantList() : QStringList();
}
/*!
@@ -371,7 +379,8 @@ QQuickFramebufferObject::Renderer *Q3DSStudio3D::createRenderer() const
// It is "illegal" to create a connection between the renderer
// and the plugin, and vice-versa. The only valid time the two
// may communicate is during Q3DSRenderer::synchronize().
- Q3DSRenderer *renderer = new Q3DSRenderer(isVisible(), m_presentation->d_ptr->streamProxy());
+ Q3DSRenderer *renderer = new Q3DSRenderer(isVisible(), m_presentation->d_ptr->streamProxy(),
+ m_startupTimer.get());
connect(renderer, &Q3DSRenderer::enterSlide,
m_presentation->d_ptr, &Q3DSPresentationPrivate::handleSlideEntered);
diff --git a/src/api/studio3dqml/q3dsstudio3d_p.h b/src/api/studio3dqml/q3dsstudio3d_p.h
index eed8459..0fa91d6 100644
--- a/src/api/studio3dqml/q3dsstudio3d_p.h
+++ b/src/api/studio3dqml/q3dsstudio3d_p.h
@@ -45,6 +45,7 @@
#include <QtStudio3D/private/q3dscommandqueue_p.h>
#include <QtGui/qopenglframebufferobject.h>
#include <QtQuick/qquickframebufferobject.h>
+#include <QtCore/qelapsedtimer.h>
QT_BEGIN_NAMESPACE
@@ -128,6 +129,7 @@ protected:
CommandQueue m_pendingCommands;
qreal m_pixelRatio;
QString m_error;
+ QScopedPointer<QElapsedTimer> m_startupTimer;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(Q3DSStudio3D::EventIgnoreFlags)
diff --git a/src/engine/Qt3DSRuntimeView.cpp b/src/engine/Qt3DSRuntimeView.cpp
index c1f3b3d..90a2562 100644
--- a/src/engine/Qt3DSRuntimeView.cpp
+++ b/src/engine/Qt3DSRuntimeView.cpp
@@ -260,6 +260,7 @@ CRuntimeView::~CRuntimeView()
bool CRuntimeView::BeginLoad(const QString &sourcePath, const QStringList &variantList)
{
bool theResult = false;
+ m_startupTime = -1;
// boot up the application
BootupPreGraphicsInitObjects();
@@ -372,7 +373,7 @@ void CRuntimeView::Render()
m_Application->UpdateAndRender();
- if (m_startupTime < 0 && m_startupTimer) {
+ if (m_startupTime < 0 && m_startupTimer && m_startupTimer->isValid()) {
m_startupTime = m_startupTimer->elapsed();
m_startupTimer->invalidate();
}