| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: http://www.qt-project.org/legal | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #ifndef QT3DANIMATION_ANIMATION_FCURVE_P_H | 
| 38 | #define QT3DANIMATION_ANIMATION_FCURVE_P_H | 
| 39 |  | 
| 40 | // | 
| 41 | //  W A R N I N G | 
| 42 | //  ------------- | 
| 43 | // | 
| 44 | // This file is not part of the Qt API.  It exists for the convenience | 
| 45 | // of other Qt classes.  This header file may change from version to | 
| 46 | // version without notice, or even be removed. | 
| 47 | // | 
| 48 | // We mean it. | 
| 49 | // | 
| 50 |  | 
| 51 | #include "keyframe_p.h" | 
| 52 | #include "functionrangefinder_p.h" | 
| 53 |  | 
| 54 | #include <Qt3DAnimation/qchannel.h> | 
| 55 | #include <Qt3DAnimation/qchannelcomponent.h> | 
| 56 | #include <Qt3DAnimation/qkeyframe.h> | 
| 57 | #include <QtCore/qvector.h> | 
| 58 |  | 
| 59 | #ifndef QT_NO_DEBUG_STREAM | 
| 60 | #include <QtCore/qdebug.h> | 
| 61 | #endif | 
| 62 |  | 
| 63 | QT_BEGIN_NAMESPACE | 
| 64 |  | 
| 65 | namespace Qt3DAnimation { | 
| 66 | namespace Animation { | 
| 67 |  | 
| 68 | class Q_AUTOTEST_EXPORT FCurve | 
| 69 | { | 
| 70 | public: | 
| 71 |     FCurve(); | 
| 72 |  | 
| 73 |     int keyframeCount() const { return m_localTimes.size(); } | 
| 74 |     void appendKeyframe(float localTime, const Keyframe &keyframe); | 
| 75 |     void clearKeyframes() { m_localTimes.clear(); m_keyframes.clear(); } | 
| 76 |  | 
| 77 |     const float &localTime(int index) const { return m_localTimes[index]; } | 
| 78 |     float &localTime(int index) { return m_localTimes[index]; } | 
| 79 |     const Keyframe &keyframe(int index) const { return m_keyframes[index]; } | 
| 80 |     Keyframe &keyframe(int index) { return m_keyframes[index]; } | 
| 81 |  | 
| 82 |     float startTime() const; | 
| 83 |     float endTime() const; | 
| 84 |  | 
| 85 |     float evaluateAtTime(float localTime) const; | 
| 86 |     float evaluateAtTime(float localTime, int lowerBound) const; | 
| 87 |     float evaluateAtTimeAsSlerp(float localTime, int lowerBound, float halfTheta, float sinHalfTheta, float reverseQ1) const; | 
| 88 |     int lowerKeyframeBound(float localTime) const; | 
| 89 |  | 
| 90 |     void read(const QJsonObject &json); | 
| 91 |     void setFromQChannelComponent(const QChannelComponent &qcc); | 
| 92 |  | 
| 93 | private: | 
| 94 |     QVector<float> m_localTimes; | 
| 95 |     QVector<Keyframe> m_keyframes; | 
| 96 |  | 
| 97 |     FunctionRangeFinder m_rangeFinder; | 
| 98 | }; | 
| 99 |  | 
| 100 | #ifndef QT_NO_DEBUG_STREAM | 
| 101 | inline QDebug operator<<(QDebug dbg, const FCurve &fcurve) | 
| 102 | { | 
| 103 |     QDebugStateSaver saver(dbg); | 
| 104 |     dbg << "Keyframe Count = "  << fcurve.keyframeCount() << Qt::endl; | 
| 105 |     for (int i = 0; i < fcurve.keyframeCount(); ++i) { | 
| 106 |         const Keyframe &kf = fcurve.keyframe(index: i); | 
| 107 |         switch (kf.interpolation) { | 
| 108 |         case QKeyFrame::BezierInterpolation: { | 
| 109 |             dbg << "t = "  << fcurve.localTime(index: i) | 
| 110 |                 << ", value = "  << kf.value | 
| 111 |                 << ", leftHandle = "  << kf.leftControlPoint | 
| 112 |                 << ", rightHandle = "  << kf.rightControlPoint | 
| 113 |                 << Qt::endl; | 
| 114 |             break; | 
| 115 |         } | 
| 116 |         case QKeyFrame::ConstantInterpolation: | 
| 117 |         case QKeyFrame::LinearInterpolation: { | 
| 118 |             dbg << "t = "  << fcurve.localTime(index: i) | 
| 119 |                 << ", value = "  << kf.value | 
| 120 |                 << Qt::endl; | 
| 121 |             break; | 
| 122 |         } | 
| 123 |         } | 
| 124 |     } | 
| 125 |     return dbg; | 
| 126 | } | 
| 127 | #endif | 
| 128 |  | 
| 129 | struct ChannelComponent | 
| 130 | { | 
| 131 |     QString name; | 
| 132 |     FCurve fcurve; | 
| 133 |  | 
| 134 |     void read(const QJsonObject &json); | 
| 135 |     void setFromQChannelComponent(const QChannelComponent &qcc); | 
| 136 | }; | 
| 137 |  | 
| 138 | #ifndef QT_NO_DEBUG_STREAM | 
| 139 | inline QDebug operator<<(QDebug dbg, const ChannelComponent &channelComponent) | 
| 140 | { | 
| 141 |     QDebugStateSaver saver(dbg); | 
| 142 |     dbg << "Channel Component Name: "  << channelComponent.name << Qt::endl | 
| 143 |         << "FCurve:"  << channelComponent.fcurve << Qt::endl; | 
| 144 |     return dbg; | 
| 145 | } | 
| 146 | #endif | 
| 147 |  | 
| 148 | struct Channel | 
| 149 | { | 
| 150 |     QString name; | 
| 151 |     int jointIndex = -1; | 
| 152 |     QVector<ChannelComponent> channelComponents; | 
| 153 |  | 
| 154 |     void read(const QJsonObject &json); | 
| 155 |     void setFromQChannel(const QChannel &qch); | 
| 156 | }; | 
| 157 |  | 
| 158 | #ifndef QT_NO_DEBUG_STREAM | 
| 159 | inline QDebug operator<<(QDebug dbg, const Channel &channel) | 
| 160 | { | 
| 161 |     QDebugStateSaver saver(dbg); | 
| 162 |     dbg << "Channel Name: "  << channel.name << Qt::endl | 
| 163 |         << "Channels:"  << channel.channelComponents.size() << Qt::endl; | 
| 164 |  | 
| 165 |     for (const auto &channelComponent : qAsConst(t: channel.channelComponents)) { | 
| 166 |         dbg << channelComponent; | 
| 167 |     } | 
| 168 |     return dbg; | 
| 169 | } | 
| 170 | #endif | 
| 171 |  | 
| 172 | } // namespace Animation | 
| 173 | } // namespace Qt3DAnimation | 
| 174 |  | 
| 175 | QT_END_NAMESPACE | 
| 176 |  | 
| 177 | #endif // QT3DANIMATION_ANIMATION_FCURVE_P_H | 
| 178 |  |