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 <miikka.heikkinen@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Antti Määttä
2021-11-22 13:27:22 +02:00
parent 478f68042b
commit bf6f41322c
2 changed files with 59 additions and 9 deletions

View File

@@ -104,6 +104,12 @@
#endif
#endif
#ifdef QUICK3D_PARTICLES_MODULE
#include <QtQuick3DParticles/private/qquick3dparticle_p.h>
#include <QtQuick3DParticles/private/qquick3dparticleaffector_p.h>
#include <QtQuick3DParticles/private/qquick3dparticleemitter_p.h>
#endif
#ifdef IMPORT_QUICK3D_ASSETS
#include <QtQuick3DAssetImport/private/qssgassetimportmanager_p.h>
#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 <typename T>
static QQuick3DParticleSystem *systemProperty(QObject *object)
{
return qobject_cast<T>(object) ? qobject_cast<T>(object)->system() : nullptr;
}
static QQuick3DParticleSystem *getSystemOrSystemProperty(QObject *selectedObject)
{
QQuick3DParticleSystem *system = nullptr;
system = qobject_cast<QQuick3DParticleSystem *>(selectedObject);
if (system)
return system;
system = systemProperty<QQuick3DParticle *>(selectedObject);
if (system)
return system;
system = systemProperty<QQuick3DParticleAffector *>(selectedObject);
if (system)
return system;
system = systemProperty<QQuick3DParticleEmitter *>(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<QQuick3DParticleSystem *>(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

View File

@@ -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;