18 #include <QEasingCurve>
19 #include <QDomDocument>
25 return mKeyframes.isEmpty() ? 0 : mKeyframes.constLast().time;
30 if ( mKeyframes.isEmpty() )
33 if ( time < mKeyframes.constFirst().time )
35 return mKeyframes.first();
37 else if ( time >= mKeyframes.constLast().time )
39 return mKeyframes.last();
47 for (
int i = 0; i < mKeyframes.size() - 1; i++ )
49 const Keyframe &k0 = mKeyframes.at( i );
50 const Keyframe &k1 = mKeyframes.at( i + 1 );
51 if ( time >= k0.
time && time <= k1.
time )
53 const float ip = ( time - k0.
time ) / ( k1.
time - k0.
time );
54 const float eIp = mEasingCurve.valueForProgress( ip );
55 const float eIip = 1.0f - eIp;
66 float yaw0 = fmod( k0.
yaw, 360 ), yaw1 = fmod( k1.
yaw, 360 );
67 if ( std::abs( yaw0 - yaw1 ) > 180 )
75 kf.
yaw = yaw0 * eIip + yaw1 * eIp;
86 mEasingCurve = QEasingCurve( ( QEasingCurve::Type ) elem.attribute( QStringLiteral(
"interpolation" ), QStringLiteral(
"0" ) ).toInt() );
90 const QDomElement elemKeyframes = elem.firstChildElement( QStringLiteral(
"keyframes" ) );
91 QDomElement elemKeyframe = elemKeyframes.firstChildElement( QStringLiteral(
"keyframe" ) );
92 while ( !elemKeyframe.isNull() )
95 kf.
time = elemKeyframe.attribute( QStringLiteral(
"time" ) ).toFloat();
96 kf.
point.
set( elemKeyframe.attribute( QStringLiteral(
"x" ) ).toDouble(),
97 elemKeyframe.attribute( QStringLiteral(
"y" ) ).toDouble(),
98 elemKeyframe.attribute( QStringLiteral(
"z" ) ).toDouble() );
99 kf.
dist = elemKeyframe.attribute( QStringLiteral(
"dist" ) ).toFloat();
100 kf.
pitch = elemKeyframe.attribute( QStringLiteral(
"pitch" ) ).toFloat();
101 kf.
yaw = elemKeyframe.attribute( QStringLiteral(
"yaw" ) ).toFloat();
102 mKeyframes.append( kf );
103 elemKeyframe = elemKeyframe.nextSiblingElement( QStringLiteral(
"keyframe" ) );
109 QDomElement elem = doc.createElement( QStringLiteral(
"animation3d" ) );
110 elem.setAttribute( QStringLiteral(
"interpolation" ), mEasingCurve.type() );
112 QDomElement elemKeyframes = doc.createElement( QStringLiteral(
"keyframes" ) );
114 for (
const Keyframe &keyframe : mKeyframes )
116 QDomElement elemKeyframe = doc.createElement( QStringLiteral(
"keyframe" ) );
117 elemKeyframe.setAttribute( QStringLiteral(
"time" ), keyframe.time );
118 elemKeyframe.setAttribute( QStringLiteral(
"x" ), keyframe.point.x() );
119 elemKeyframe.setAttribute( QStringLiteral(
"y" ), keyframe.point.y() );
120 elemKeyframe.setAttribute( QStringLiteral(
"z" ), keyframe.point.z() );
121 elemKeyframe.setAttribute( QStringLiteral(
"dist" ), keyframe.dist );
122 elemKeyframe.setAttribute( QStringLiteral(
"pitch" ), keyframe.pitch );
123 elemKeyframe.setAttribute( QStringLiteral(
"yaw" ), keyframe.yaw );
124 elemKeyframes.appendChild( elemKeyframe );
127 elem.appendChild( elemKeyframes );