| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qquick3dparticledynamicburst_p.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | /*! |
| 9 | \qmltype DynamicBurst3D |
| 10 | \inherits EmitBurst3D |
| 11 | \inqmlmodule QtQuick3D.Particles3D |
| 12 | \brief Dynamic emitter bursts. |
| 13 | \since 6.3 |
| 14 | |
| 15 | This element defines particle bursts in the \l ParticleEmitter3D. These bursts are |
| 16 | dynamic, meaning that they are evaluated while the particlesystem runs. Use these |
| 17 | instead of \l EmitBurst3D for example when the emitter moves, so that emitting |
| 18 | happens at the correct position. |
| 19 | |
| 20 | For example, to emit 100 particles at 1 second time and 200 particles at 2 second: |
| 21 | |
| 22 | \qml |
| 23 | ParticleEmitter3D { |
| 24 | ... |
| 25 | emitBursts: [ |
| 26 | DynamicBurst3D { |
| 27 | time: 1000 |
| 28 | amount: 100 |
| 29 | }, |
| 30 | DynamicBurst3D { |
| 31 | time: 2000 |
| 32 | amount: 200 |
| 33 | } |
| 34 | ] |
| 35 | } |
| 36 | \endqml |
| 37 | */ |
| 38 | |
| 39 | QQuick3DParticleDynamicBurst::QQuick3DParticleDynamicBurst(QObject *parent) |
| 40 | : QQuick3DParticleEmitBurst(parent) |
| 41 | { |
| 42 | |
| 43 | } |
| 44 | |
| 45 | /*! |
| 46 | \qmlproperty bool DynamicBurst3D::enabled |
| 47 | |
| 48 | If enabled is set to \c false, this burst will not emit any particles. |
| 49 | |
| 50 | The default value is \c true. |
| 51 | */ |
| 52 | bool QQuick3DParticleDynamicBurst::enabled() const |
| 53 | { |
| 54 | return m_enabled; |
| 55 | } |
| 56 | |
| 57 | /*! |
| 58 | \qmlproperty int DynamicBurst3D::amountVariation |
| 59 | |
| 60 | This property defines the random variation in particle emit amount. |
| 61 | |
| 62 | For example, to have a random range between 0 and 10 |
| 63 | \qml |
| 64 | DynamicBurst3D { |
| 65 | time: 1000 |
| 66 | amount: 5 |
| 67 | amountVariation: 5 |
| 68 | } |
| 69 | \endqml |
| 70 | |
| 71 | The default value is \c 0. |
| 72 | */ |
| 73 | int QQuick3DParticleDynamicBurst::amountVariation() const |
| 74 | { |
| 75 | return m_amountVariation; |
| 76 | } |
| 77 | |
| 78 | /*! |
| 79 | \qmlproperty ShapeType DynamicBurst3D::triggerMode |
| 80 | |
| 81 | This property defines the emitting mode. |
| 82 | |
| 83 | The default value is \c TriggerMode.TriggerTime. |
| 84 | */ |
| 85 | |
| 86 | /*! |
| 87 | \qmlproperty enumeration DynamicBurst3D::TriggerMode |
| 88 | |
| 89 | Defines the mode of the bursting. |
| 90 | |
| 91 | \value DynamicBurst3D.TriggerTime |
| 92 | The particles are emitted when the burst \l {EmitBurst3D::time}{time} is due. |
| 93 | \value DynamicBurst3D.TriggerStart |
| 94 | The particles are emitted when the followed particle is emitted. |
| 95 | \note This property is restricted to only work with trail emitters. |
| 96 | \note In this mode, \c time and \c duration properties don't have an effect. |
| 97 | \value DynamicBurst3D.TriggerEnd |
| 98 | The particles are emitted when the followed particle \c lifeSpan ends. |
| 99 | \note This property is restricted to only work with trail emitters. |
| 100 | \note In this mode, \c time and \c duration properties don't have an effect. |
| 101 | */ |
| 102 | |
| 103 | QQuick3DParticleDynamicBurst::TriggerMode QQuick3DParticleDynamicBurst::triggerMode() const |
| 104 | { |
| 105 | return m_triggerMode; |
| 106 | } |
| 107 | |
| 108 | void QQuick3DParticleDynamicBurst::setEnabled(bool enabled) |
| 109 | { |
| 110 | if (m_enabled == enabled) |
| 111 | return; |
| 112 | |
| 113 | m_enabled = enabled; |
| 114 | Q_EMIT enabledChanged(); |
| 115 | } |
| 116 | |
| 117 | void QQuick3DParticleDynamicBurst::setAmountVariation(int value) |
| 118 | { |
| 119 | if (m_amountVariation == value) |
| 120 | return; |
| 121 | |
| 122 | if (value < 0) { |
| 123 | qWarning () << "DynamicBurst3D: Amount variation must be positive." ; |
| 124 | return; |
| 125 | } |
| 126 | m_amountVariation = value; |
| 127 | Q_EMIT amountVariationChanged(); |
| 128 | } |
| 129 | |
| 130 | void QQuick3DParticleDynamicBurst::setTriggerMode(TriggerMode mode) |
| 131 | { |
| 132 | if (m_triggerMode == mode) |
| 133 | return; |
| 134 | |
| 135 | m_triggerMode = mode; |
| 136 | Q_EMIT triggerModeChanged(); |
| 137 | } |
| 138 | |
| 139 | QT_END_NAMESPACE |
| 140 | |