1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DPARTICLEMODELSHAPE_H |
5 | #define QQUICK3DPARTICLEMODELSHAPE_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquick3dparticleabstractshape_p.h" |
19 | #include <QVector3D> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QQuick3DModel; |
24 | class QQmlComponent; |
25 | |
26 | class Q_QUICK3DPARTICLES_EXPORT QQuick3DParticleModelShape : public QQuick3DParticleAbstractShape |
27 | { |
28 | Q_OBJECT |
29 | Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged) |
30 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) |
31 | QML_NAMED_ELEMENT(ParticleModelShape3D) |
32 | QML_ADDED_IN_VERSION(6, 2) |
33 | |
34 | public: |
35 | QQuick3DParticleModelShape(QObject *parent = nullptr); |
36 | ~QQuick3DParticleModelShape() override; |
37 | |
38 | bool fill() const; |
39 | QQmlComponent *delegate() const; |
40 | |
41 | public Q_SLOTS: |
42 | void setFill(bool fill); |
43 | void setDelegate(QQmlComponent *delegate); |
44 | |
45 | // Returns point inside this shape |
46 | QVector3D getPosition(int particleIndex) override; |
47 | |
48 | Q_SIGNALS: |
49 | void fillChanged(); |
50 | void delegateChanged(); |
51 | |
52 | private: |
53 | QVector3D randomPositionModel(int particleIndex); |
54 | void createModel(); |
55 | void clearModelVertexPositions(); |
56 | void calculateModelVertexPositions(); |
57 | |
58 | QQmlComponent *m_delegate = nullptr; |
59 | QQuick3DModel *m_model = nullptr; |
60 | QVector<QVector3D> m_vertexPositions; |
61 | float m_modelTriangleAreasSum = 0; |
62 | QVector<float> m_modelTriangleAreas; |
63 | QVector3D m_modelTriangleCenter; |
64 | bool m_fill = true; |
65 | }; |
66 | |
67 | QT_END_NAMESPACE |
68 | |
69 | #endif // QQUICK3DPARTICLEMODELSHAPE_H |
70 |