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;
64 float yaw0 = fmod( k0.
yaw, 360 ), yaw1 = fmod( k1.
yaw, 360 );
65 if ( std::abs( yaw0 - yaw1 ) > 180 )
73 kf.
yaw = yaw0 * eIip + yaw1 * eIp;
84 mEasingCurve = QEasingCurve( ( QEasingCurve::Type ) elem.attribute( QStringLiteral(
"interpolation" ), QStringLiteral(
"0" ) ).toInt() );
88 const QDomElement elemKeyframes = elem.firstChildElement( QStringLiteral(
"keyframes" ) );
89 QDomElement elemKeyframe = elemKeyframes.firstChildElement( QStringLiteral(
"keyframe" ) );
90 while ( !elemKeyframe.isNull() )
93 kf.
time = elemKeyframe.attribute( QStringLiteral(
"time" ) ).toFloat();
94 kf.
point.
set( elemKeyframe.attribute( QStringLiteral(
"x" ) ).toDouble(), elemKeyframe.attribute( QStringLiteral(
"y" ) ).toDouble(), elemKeyframe.attribute( QStringLiteral(
"z" ) ).toDouble() );
95 kf.
dist = elemKeyframe.attribute( QStringLiteral(
"dist" ) ).toFloat();
96 kf.
pitch = elemKeyframe.attribute( QStringLiteral(
"pitch" ) ).toFloat();
97 kf.
yaw = elemKeyframe.attribute( QStringLiteral(
"yaw" ) ).toFloat();
98 mKeyframes.append( kf );
99 elemKeyframe = elemKeyframe.nextSiblingElement( QStringLiteral(
"keyframe" ) );
105 QDomElement elem = doc.createElement( QStringLiteral(
"animation3d" ) );
106 elem.setAttribute( QStringLiteral(
"interpolation" ), mEasingCurve.type() );
108 QDomElement elemKeyframes = doc.createElement( QStringLiteral(
"keyframes" ) );
110 for (
const Keyframe &keyframe : mKeyframes )
112 QDomElement elemKeyframe = doc.createElement( QStringLiteral(
"keyframe" ) );
113 elemKeyframe.setAttribute( QStringLiteral(
"time" ), keyframe.time );
114 elemKeyframe.setAttribute( QStringLiteral(
"x" ), keyframe.point.x() );
115 elemKeyframe.setAttribute( QStringLiteral(
"y" ), keyframe.point.y() );
116 elemKeyframe.setAttribute( QStringLiteral(
"z" ), keyframe.point.z() );
117 elemKeyframe.setAttribute( QStringLiteral(
"dist" ), keyframe.dist );
118 elemKeyframe.setAttribute( QStringLiteral(
"pitch" ), keyframe.pitch );
119 elemKeyframe.setAttribute( QStringLiteral(
"yaw" ), keyframe.yaw );
120 elemKeyframes.appendChild( elemKeyframe );
123 elem.appendChild( elemKeyframes );