1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DANIMATION_ANIMATION_ANIMATIONCLIP_P_H |
5 | #define QT3DANIMATION_ANIMATION_ANIMATIONCLIP_P_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 for the convenience |
12 | // of other Qt classes. 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 <Qt3DAnimation/private/backendnode_p.h> |
19 | #include <Qt3DAnimation/qanimationclipdata.h> |
20 | #include <Qt3DAnimation/qanimationcliploader.h> |
21 | #include <Qt3DAnimation/private/fcurve_p.h> |
22 | #include <QtCore/qurl.h> |
23 | #include <QtCore/qmutex.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | namespace Qt3DAnimation { |
28 | namespace Animation { |
29 | |
30 | class Handler; |
31 | |
32 | class Q_AUTOTEST_EXPORT AnimationClip : public BackendNode |
33 | { |
34 | public: |
35 | AnimationClip(); |
36 | |
37 | void cleanup(); |
38 | void setSource(const QUrl &source) { m_source = source; } |
39 | QUrl source() const { return m_source; } |
40 | void setStatus(QAnimationClipLoader::Status status); |
41 | QAnimationClipLoader::Status status() const { return m_status; } |
42 | void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; |
43 | |
44 | void addDependingClipAnimator(const Qt3DCore::QNodeId &id); |
45 | void addDependingBlendedClipAnimator(const Qt3DCore::QNodeId &id); |
46 | |
47 | QString name() const { return m_name; } |
48 | const QVector<Channel> &channels() const { return m_channels; } |
49 | |
50 | // Called from jobs |
51 | void loadAnimation(); |
52 | void setDuration(float duration); |
53 | float duration() const { return m_duration; } |
54 | qsizetype channelIndex(const QString &channelName, qsizetype jointIndex) const; |
55 | qsizetype channelCount() const { return m_channelComponentCount; } |
56 | qsizetype channelComponentBaseIndex(qsizetype channelGroupIndex) const; |
57 | |
58 | // Allow unit tests to set the data type |
59 | #if !defined(QT_BUILD_INTERNAL) |
60 | private: |
61 | #endif |
62 | enum ClipDataType { |
63 | Unknown, |
64 | File, |
65 | Data |
66 | }; |
67 | #if defined(QT_BUILD_INTERNAL) |
68 | public: |
69 | void setDataType(ClipDataType dataType) { m_dataType = dataType; } |
70 | #endif |
71 | |
72 | private: |
73 | void loadAnimationFromUrl(); |
74 | void loadAnimationFromData(); |
75 | void clearData(); |
76 | float findDuration(); |
77 | qsizetype findChannelComponentCount(); |
78 | |
79 | QMutex m_mutex; |
80 | |
81 | QUrl m_source; |
82 | QAnimationClipLoader::Status m_status; |
83 | QAnimationClipData m_clipData; |
84 | ClipDataType m_dataType; |
85 | |
86 | QString m_name; |
87 | QVector<Channel> m_channels; |
88 | float m_duration; |
89 | qsizetype m_channelComponentCount; |
90 | |
91 | Qt3DCore::QNodeIdVector m_dependingAnimators; |
92 | Qt3DCore::QNodeIdVector m_dependingBlendedAnimators; |
93 | }; |
94 | |
95 | #ifndef QT_NO_DEBUG_STREAM |
96 | inline QDebug operator<<(QDebug dbg, const AnimationClip &animationClip) |
97 | { |
98 | QDebugStateSaver saver(dbg); |
99 | dbg << "QNodeId =" << animationClip.peerId() << Qt::endl |
100 | << "Name =" << animationClip.name() << Qt::endl |
101 | << "Duration: " << animationClip.duration() << Qt::endl |
102 | << "Channels:" << Qt::endl; |
103 | |
104 | const auto &channels = animationClip.channels(); |
105 | for (const auto &channel : channels) |
106 | dbg << channel; |
107 | |
108 | return dbg; |
109 | } |
110 | #endif |
111 | |
112 | } // namespace Animation |
113 | } // namespace Qt3DAnimation |
114 | |
115 | |
116 | QT_END_NAMESPACE |
117 | |
118 | #endif // QT3DANIMATION_ANIMATION_ANIMATIONCLIP_P_H |
119 | |