From bf6f41322c76b340e1db9dcc1f5eaffcd5fa8efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 22 Nov 2021 13:27:22 +0200 Subject: [PATCH] Handle particle system animation when selecting child object Do not stop particle system animation when user selects particle system child object. Instead continue particle system animation and if the child parent particle system is another particle system, enable that animation. Task-number: QDS-5562 Change-Id: I334f522536b53e7fb5cbebf8f7e9914f6394d165 Reviewed-by: Miikka Heikkinen Reviewed-by: Reviewed-by: Thomas Hartmann --- .../qt5informationnodeinstanceserver.cpp | 66 ++++++++++++++++--- .../qt5informationnodeinstanceserver.h | 2 +- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp index b4c8513dc50..6eb7a7146e0 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.cpp @@ -104,6 +104,12 @@ #endif #endif +#ifdef QUICK3D_PARTICLES_MODULE +#include +#include +#include +#endif + #ifdef IMPORT_QUICK3D_ASSETS #include #endif @@ -412,7 +418,7 @@ void Qt5InformationNodeInstanceServer::resetParticleSystem() void Qt5InformationNodeInstanceServer::handleParticleSystemSelected(QQuick3DParticleSystem* targetParticleSystem) { - if (!m_particleAnimationDriver) + if (!m_particleAnimationDriver || targetParticleSystem == m_targetParticleSystem) return; m_particleAnimationDriver->reset(); @@ -453,7 +459,46 @@ static QString baseProperty(const QString &property) return property; } -void Qt5InformationNodeInstanceServer::handleParticleSystemDeselected() +template +static QQuick3DParticleSystem *systemProperty(QObject *object) +{ + return qobject_cast(object) ? qobject_cast(object)->system() : nullptr; +} + +static QQuick3DParticleSystem *getSystemOrSystemProperty(QObject *selectedObject) +{ + QQuick3DParticleSystem *system = nullptr; + system = qobject_cast(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + system = systemProperty(selectedObject); + if (system) + return system; + return nullptr; +} + +static QQuick3DParticleSystem *parentParticleSystem(QObject *selectedObject) +{ + auto *ps = getSystemOrSystemProperty(selectedObject); + if (ps) + return ps; + QObject *parent = selectedObject->parent(); + while (parent) { + ps = getSystemOrSystemProperty(parent); + if (ps) + return ps; + parent = parent->parent(); + } + return nullptr; +} + +void Qt5InformationNodeInstanceServer::handleParticleSystemDeselected(QObject *selectedObject) { m_targetParticleSystem = nullptr; const auto anim = animations(); @@ -1824,9 +1869,7 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm { if (!m_editView3DSetupDone) return; -#ifdef QUICK3D_PARTICLES_MODULE - resetParticleSystem(); -#endif + m_lastSelectionChangeCommand = command; if (m_selectionChangeTimer.isActive()) { // If selection was recently changed by puppet, hold updating the selection for a bit to @@ -1855,10 +1898,17 @@ void Qt5InformationNodeInstanceServer::changeSelection(const ChangeSelectionComm #ifdef QUICK3D_PARTICLES_MODULE auto particlesystem = qobject_cast(instance.internalObject()); - if (particlesystem) + if (particlesystem) { handleParticleSystemSelected(particlesystem); - else - handleParticleSystemDeselected(); + } else { + particlesystem = parentParticleSystem(instance.internalObject()); + if (particlesystem) { + if (particlesystem != m_targetParticleSystem) + handleParticleSystemSelected(particlesystem); + } else { + handleParticleSystemDeselected(instance.internalObject()); + } + } #endif auto isSelectableAsRoot = [&]() -> bool { #ifdef QUICK3D_MODULE diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h index 25a4b900ce8..ef6f576dac9 100644 --- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h +++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/qt5informationnodeinstanceserver.h @@ -149,7 +149,7 @@ private: #ifdef QUICK3D_PARTICLES_MODULE void handleParticleSystemSelected(QQuick3DParticleSystem* targetParticleSystem); void resetParticleSystem(); - void handleParticleSystemDeselected(); + void handleParticleSystemDeselected(QObject *selectedObject); #endif RenderViewData m_editView3DData;