LWOAnimation.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2022, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file LWOAnimation.cpp
  34. * @brief LWOAnimationResolver utility class
  35. *
  36. * It's a very generic implementation of LightWave's system of
  37. * component-wise-animated stuff. The one and only fully free
  38. * implementation of LightWave envelopes of which I know.
  39. */
  40. #if (!defined ASSIMP_BUILD_NO_LWO_IMPORTER) && (!defined ASSIMP_BUILD_NO_LWS_IMPORTER)
  41. #include <functional>
  42. // internal headers
  43. #include "LWOFileData.h"
  44. #include <assimp/anim.h>
  45. using namespace Assimp;
  46. using namespace Assimp::LWO;
  47. // ------------------------------------------------------------------------------------------------
  48. // Construct an animation resolver from a given list of envelopes
  49. AnimResolver::AnimResolver(std::list<Envelope> &_envelopes, double tick) :
  50. envelopes(_envelopes),
  51. sample_rate(0.),
  52. envl_x(),
  53. envl_y(),
  54. envl_z(),
  55. end_x(),
  56. end_y(),
  57. end_z(),
  58. flags(),
  59. sample_delta() {
  60. trans_x = trans_y = trans_z = nullptr;
  61. rotat_x = rotat_y = rotat_z = nullptr;
  62. scale_x = scale_y = scale_z = nullptr;
  63. first = last = 150392.;
  64. // find transformation envelopes
  65. for (std::list<LWO::Envelope>::iterator it = envelopes.begin(); it != envelopes.end(); ++it) {
  66. (*it).old_first = 0;
  67. (*it).old_last = (*it).keys.size() - 1;
  68. if ((*it).keys.empty()) {
  69. continue;
  70. }
  71. if ((int)(*it).type < 1 || (int)(*it).type>EnvelopeType_Unknown) {
  72. continue;
  73. }
  74. switch ((*it).type) {
  75. // translation
  76. case LWO::EnvelopeType_Position_X:
  77. trans_x = &*it;
  78. break;
  79. case LWO::EnvelopeType_Position_Y:
  80. trans_y = &*it;
  81. break;
  82. case LWO::EnvelopeType_Position_Z:
  83. trans_z = &*it;
  84. break;
  85. // rotation
  86. case LWO::EnvelopeType_Rotation_Heading:
  87. rotat_x = &*it;
  88. break;
  89. case LWO::EnvelopeType_Rotation_Pitch:
  90. rotat_y = &*it;
  91. break;
  92. case LWO::EnvelopeType_Rotation_Bank:
  93. rotat_z = &*it;
  94. break;
  95. // scaling
  96. case LWO::EnvelopeType_Scaling_X:
  97. scale_x = &*it;
  98. break;
  99. case LWO::EnvelopeType_Scaling_Y:
  100. scale_y = &*it;
  101. break;
  102. case LWO::EnvelopeType_Scaling_Z:
  103. scale_z = &*it;
  104. break;
  105. default:
  106. continue;
  107. };
  108. // convert from seconds to ticks
  109. for (std::vector<LWO::Key>::iterator d = (*it).keys.begin(); d != (*it).keys.end(); ++d)
  110. (*d).time *= tick;
  111. // set default animation range (minimum and maximum time value for which we have a keyframe)
  112. first = std::min(first, (*it).keys.front().time);
  113. last = std::max(last, (*it).keys.back().time);
  114. }
  115. // deferred setup of animation range to increase performance.
  116. // typically the application will want to specify its own.
  117. need_to_setup = true;
  118. }
  119. // ------------------------------------------------------------------------------------------------
  120. // Reset all envelopes to their original contents
  121. void AnimResolver::ClearAnimRangeSetup() {
  122. for (std::list<LWO::Envelope>::iterator it = envelopes.begin(); it != envelopes.end(); ++it) {
  123. (*it).keys.erase((*it).keys.begin(), (*it).keys.begin() + (*it).old_first);
  124. (*it).keys.erase((*it).keys.begin() + (*it).old_last + 1, (*it).keys.end());
  125. }
  126. }
  127. // ------------------------------------------------------------------------------------------------
  128. // Insert additional keys to match LWO's pre& post behaviors.
  129. void AnimResolver::UpdateAnimRangeSetup() {
  130. // XXX doesn't work yet (hangs if more than one envelope channels needs to be interpolated)
  131. for (std::list<LWO::Envelope>::iterator it = envelopes.begin(); it != envelopes.end(); ++it) {
  132. if ((*it).keys.empty()) continue;
  133. const double my_first = (*it).keys.front().time;
  134. const double my_last = (*it).keys.back().time;
  135. const double delta = my_last - my_first;
  136. const size_t old_size = (*it).keys.size();
  137. const float value_delta = (*it).keys.back().value - (*it).keys.front().value;
  138. // NOTE: We won't handle reset, linear and constant here.
  139. // See DoInterpolation() for their implementation.
  140. // process pre behavior
  141. switch ((*it).pre) {
  142. case LWO::PrePostBehaviour_OffsetRepeat:
  143. case LWO::PrePostBehaviour_Repeat:
  144. case LWO::PrePostBehaviour_Oscillate: {
  145. const double start_time = delta - std::fmod(my_first - first, delta);
  146. std::vector<LWO::Key>::iterator n = std::find_if((*it).keys.begin(), (*it).keys.end(),
  147. [start_time](double t) { return start_time > t; }),
  148. m;
  149. size_t ofs = 0;
  150. if (n != (*it).keys.end()) {
  151. // copy from here - don't use iterators, insert() would invalidate them
  152. ofs = (*it).keys.end() - n;
  153. (*it).keys.insert((*it).keys.begin(), ofs, LWO::Key());
  154. std::copy((*it).keys.end() - ofs, (*it).keys.end(), (*it).keys.begin());
  155. }
  156. // do full copies. again, no iterators
  157. const unsigned int num = (unsigned int)((my_first - first) / delta);
  158. (*it).keys.resize((*it).keys.size() + num * old_size);
  159. n = (*it).keys.begin() + ofs;
  160. bool reverse = false;
  161. for (unsigned int i = 0; i < num; ++i) {
  162. m = n + old_size * (i + 1);
  163. std::copy(n, n + old_size, m);
  164. const bool res = ((*it).pre == LWO::PrePostBehaviour_Oscillate);
  165. reverse = !reverse;
  166. if (res && reverse) {
  167. std::reverse(m, m + old_size - 1);
  168. }
  169. }
  170. // update time values
  171. n = (*it).keys.end() - (old_size + 1);
  172. double cur_minus = delta;
  173. unsigned int tt = 1;
  174. for (const double tmp = delta * (num + 1); cur_minus <= tmp; cur_minus += delta, ++tt) {
  175. m = (delta == tmp ? (*it).keys.begin() : n - (old_size + 1));
  176. for (; m != n; --n) {
  177. (*n).time -= cur_minus;
  178. // offset repeat? add delta offset to key value
  179. if ((*it).pre == LWO::PrePostBehaviour_OffsetRepeat) {
  180. (*n).value += tt * value_delta;
  181. }
  182. }
  183. }
  184. break;
  185. }
  186. default:
  187. // silence compiler warning
  188. break;
  189. }
  190. // process post behavior
  191. switch ((*it).post) {
  192. case LWO::PrePostBehaviour_OffsetRepeat:
  193. case LWO::PrePostBehaviour_Repeat:
  194. case LWO::PrePostBehaviour_Oscillate:
  195. break;
  196. default:
  197. // silence compiler warning
  198. break;
  199. }
  200. }
  201. }
  202. // ------------------------------------------------------------------------------------------------
  203. // Extract bind pose matrix
  204. void AnimResolver::ExtractBindPose(aiMatrix4x4 &out) {
  205. // If we have no envelopes, return identity
  206. if (envelopes.empty()) {
  207. out = aiMatrix4x4();
  208. return;
  209. }
  210. aiVector3D angles, scaling(1.f, 1.f, 1.f), translation;
  211. if (trans_x) translation.x = trans_x->keys[0].value;
  212. if (trans_y) translation.y = trans_y->keys[0].value;
  213. if (trans_z) translation.z = trans_z->keys[0].value;
  214. if (rotat_x) angles.x = rotat_x->keys[0].value;
  215. if (rotat_y) angles.y = rotat_y->keys[0].value;
  216. if (rotat_z) angles.z = rotat_z->keys[0].value;
  217. if (scale_x) scaling.x = scale_x->keys[0].value;
  218. if (scale_y) scaling.y = scale_y->keys[0].value;
  219. if (scale_z) scaling.z = scale_z->keys[0].value;
  220. // build the final matrix
  221. aiMatrix4x4 s, rx, ry, rz, t;
  222. aiMatrix4x4::RotationZ(angles.z, rz);
  223. aiMatrix4x4::RotationX(angles.y, rx);
  224. aiMatrix4x4::RotationY(angles.x, ry);
  225. aiMatrix4x4::Translation(translation, t);
  226. aiMatrix4x4::Scaling(scaling, s);
  227. out = t * ry * rx * rz * s;
  228. }
  229. // ------------------------------------------------------------------------------------------------
  230. // Do a single interpolation on a channel
  231. void AnimResolver::DoInterpolation(std::vector<LWO::Key>::const_iterator cur,
  232. LWO::Envelope *envl, double time, float &fill) {
  233. if (envl->keys.size() == 1) {
  234. fill = envl->keys[0].value;
  235. return;
  236. }
  237. // check whether we're at the beginning of the animation track
  238. if (cur == envl->keys.begin()) {
  239. // ok ... this depends on pre behaviour now
  240. // we don't need to handle repeat&offset repeat&oszillate here, see UpdateAnimRangeSetup()
  241. switch (envl->pre) {
  242. case LWO::PrePostBehaviour_Linear:
  243. DoInterpolation2(cur, cur + 1, time, fill);
  244. return;
  245. case LWO::PrePostBehaviour_Reset:
  246. fill = 0.f;
  247. return;
  248. default: //case LWO::PrePostBehaviour_Constant:
  249. fill = (*cur).value;
  250. return;
  251. }
  252. }
  253. // check whether we're at the end of the animation track
  254. else if (cur == envl->keys.end() - 1 && time > envl->keys.rbegin()->time) {
  255. // ok ... this depends on post behaviour now
  256. switch (envl->post) {
  257. case LWO::PrePostBehaviour_Linear:
  258. DoInterpolation2(cur, cur - 1, time, fill);
  259. return;
  260. case LWO::PrePostBehaviour_Reset:
  261. fill = 0.f;
  262. return;
  263. default: //case LWO::PrePostBehaviour_Constant:
  264. fill = (*cur).value;
  265. return;
  266. }
  267. }
  268. // Otherwise do a simple interpolation
  269. DoInterpolation2(cur - 1, cur, time, fill);
  270. }
  271. // ------------------------------------------------------------------------------------------------
  272. // Almost the same, except we won't handle pre/post conditions here
  273. void AnimResolver::DoInterpolation2(std::vector<LWO::Key>::const_iterator beg,
  274. std::vector<LWO::Key>::const_iterator end, double time, float &fill) {
  275. switch ((*end).inter) {
  276. case LWO::IT_STEP:
  277. // no interpolation at all - take the value of the last key
  278. fill = (*beg).value;
  279. return;
  280. default:
  281. // silence compiler warning
  282. break;
  283. }
  284. // linear interpolation - default
  285. double duration = (*end).time - (*beg).time;
  286. if (duration > 0.0) {
  287. fill = (*beg).value + ((*end).value - (*beg).value) * (float)(((time - (*beg).time) / duration));
  288. } else {
  289. fill = (*beg).value;
  290. }
  291. }
  292. // ------------------------------------------------------------------------------------------------
  293. // Subsample animation track by given key values
  294. void AnimResolver::SubsampleAnimTrack(std::vector<aiVectorKey> & /*out*/,
  295. double /*time*/, double /*sample_delta*/) {
  296. //ai_assert(out.empty() && sample_delta);
  297. //const double time_start = out.back().mTime;
  298. // for ()
  299. }
  300. // ------------------------------------------------------------------------------------------------
  301. // Track interpolation
  302. void AnimResolver::InterpolateTrack(std::vector<aiVectorKey> &out, aiVectorKey &fill, double time) {
  303. // subsample animation track?
  304. if (flags & AI_LWO_ANIM_FLAG_SAMPLE_ANIMS) {
  305. SubsampleAnimTrack(out, time, sample_delta);
  306. }
  307. fill.mTime = time;
  308. // get x
  309. if ((*cur_x).time == time) {
  310. fill.mValue.x = (*cur_x).value;
  311. if (cur_x != envl_x->keys.end() - 1) /* increment x */
  312. ++cur_x;
  313. else
  314. end_x = true;
  315. } else
  316. DoInterpolation(cur_x, envl_x, time, (float &)fill.mValue.x);
  317. // get y
  318. if ((*cur_y).time == time) {
  319. fill.mValue.y = (*cur_y).value;
  320. if (cur_y != envl_y->keys.end() - 1) /* increment y */
  321. ++cur_y;
  322. else
  323. end_y = true;
  324. } else
  325. DoInterpolation(cur_y, envl_y, time, (float &)fill.mValue.y);
  326. // get z
  327. if ((*cur_z).time == time) {
  328. fill.mValue.z = (*cur_z).value;
  329. if (cur_z != envl_z->keys.end() - 1) /* increment z */
  330. ++cur_z;
  331. else
  332. end_x = true;
  333. } else
  334. DoInterpolation(cur_z, envl_z, time, (float &)fill.mValue.z);
  335. }
  336. // ------------------------------------------------------------------------------------------------
  337. // Build linearly subsampled keys from three single envelopes, one for each component (x,y,z)
  338. void AnimResolver::GetKeys(std::vector<aiVectorKey> &out,
  339. LWO::Envelope *_envl_x,
  340. LWO::Envelope *_envl_y,
  341. LWO::Envelope *_envl_z,
  342. unsigned int _flags) {
  343. envl_x = _envl_x;
  344. envl_y = _envl_y;
  345. envl_z = _envl_z;
  346. flags = _flags;
  347. // generate default channels if none are given
  348. LWO::Envelope def_x, def_y, def_z;
  349. LWO::Key key_dummy;
  350. key_dummy.time = 0.f;
  351. if ((envl_x && envl_x->type == LWO::EnvelopeType_Scaling_X) ||
  352. (envl_y && envl_y->type == LWO::EnvelopeType_Scaling_Y) ||
  353. (envl_z && envl_z->type == LWO::EnvelopeType_Scaling_Z)) {
  354. key_dummy.value = 1.f;
  355. } else
  356. key_dummy.value = 0.f;
  357. if (!envl_x) {
  358. envl_x = &def_x;
  359. envl_x->keys.push_back(key_dummy);
  360. }
  361. if (!envl_y) {
  362. envl_y = &def_y;
  363. envl_y->keys.push_back(key_dummy);
  364. }
  365. if (!envl_z) {
  366. envl_z = &def_z;
  367. envl_z->keys.push_back(key_dummy);
  368. }
  369. // guess how many keys we'll get
  370. size_t reserve;
  371. double sr = 1.;
  372. if (flags & AI_LWO_ANIM_FLAG_SAMPLE_ANIMS) {
  373. if (!sample_rate)
  374. sr = 100.f;
  375. else
  376. sr = sample_rate;
  377. sample_delta = 1.f / sr;
  378. reserve = (size_t)(
  379. std::max(envl_x->keys.rbegin()->time,
  380. std::max(envl_y->keys.rbegin()->time, envl_z->keys.rbegin()->time)) *
  381. sr);
  382. } else
  383. reserve = std::max(envl_x->keys.size(), std::max(envl_x->keys.size(), envl_z->keys.size()));
  384. out.reserve(reserve + (reserve >> 1));
  385. // Iterate through all three arrays at once - it's tricky, but
  386. // rather interesting to implement.
  387. cur_x = envl_x->keys.begin();
  388. cur_y = envl_y->keys.begin();
  389. cur_z = envl_z->keys.begin();
  390. end_x = end_y = end_z = false;
  391. while (1) {
  392. aiVectorKey fill;
  393. if ((*cur_x).time == (*cur_y).time && (*cur_x).time == (*cur_z).time) {
  394. // we have a keyframe for all of them defined .. this means
  395. // we don't need to interpolate here.
  396. fill.mTime = (*cur_x).time;
  397. fill.mValue.x = (*cur_x).value;
  398. fill.mValue.y = (*cur_y).value;
  399. fill.mValue.z = (*cur_z).value;
  400. // subsample animation track
  401. if (flags & AI_LWO_ANIM_FLAG_SAMPLE_ANIMS) {
  402. //SubsampleAnimTrack(out,cur_x, cur_y, cur_z, d, sample_delta);
  403. }
  404. }
  405. // Find key with lowest time value
  406. else if ((*cur_x).time <= (*cur_y).time && !end_x) {
  407. if ((*cur_z).time <= (*cur_x).time && !end_z) {
  408. InterpolateTrack(out, fill, (*cur_z).time);
  409. } else {
  410. InterpolateTrack(out, fill, (*cur_x).time);
  411. }
  412. } else if ((*cur_z).time <= (*cur_y).time && !end_y) {
  413. InterpolateTrack(out, fill, (*cur_y).time);
  414. } else if (!end_y) {
  415. // welcome on the server, y
  416. InterpolateTrack(out, fill, (*cur_y).time);
  417. } else {
  418. // we have reached the end of at least 2 channels,
  419. // only one is remaining. Extrapolate the 2.
  420. if (end_y) {
  421. InterpolateTrack(out, fill, (end_x ? (*cur_z) : (*cur_x)).time);
  422. } else if (end_x) {
  423. InterpolateTrack(out, fill, (end_z ? (*cur_y) : (*cur_z)).time);
  424. } else { // if (end_z)
  425. InterpolateTrack(out, fill, (end_y ? (*cur_x) : (*cur_y)).time);
  426. }
  427. }
  428. double lasttime = fill.mTime;
  429. out.push_back(fill);
  430. if (lasttime >= (*cur_x).time) {
  431. if (cur_x != envl_x->keys.end() - 1)
  432. ++cur_x;
  433. else
  434. end_x = true;
  435. }
  436. if (lasttime >= (*cur_y).time) {
  437. if (cur_y != envl_y->keys.end() - 1)
  438. ++cur_y;
  439. else
  440. end_y = true;
  441. }
  442. if (lasttime >= (*cur_z).time) {
  443. if (cur_z != envl_z->keys.end() - 1)
  444. ++cur_z;
  445. else
  446. end_z = true;
  447. }
  448. if (end_x && end_y && end_z) /* finished? */
  449. break;
  450. }
  451. if (flags & AI_LWO_ANIM_FLAG_START_AT_ZERO) {
  452. for (std::vector<aiVectorKey>::iterator it = out.begin(); it != out.end(); ++it)
  453. (*it).mTime -= first;
  454. }
  455. }
  456. // ------------------------------------------------------------------------------------------------
  457. // Extract animation channel
  458. void AnimResolver::ExtractAnimChannel(aiNodeAnim **out, unsigned int /*= 0*/) {
  459. *out = nullptr;
  460. //FIXME: crashes if more than one component is animated at different timings, to be resolved.
  461. // If we have no envelopes, return nullptr
  462. if (envelopes.empty()) {
  463. return;
  464. }
  465. // We won't spawn an animation channel if we don't have at least one envelope with more than one keyframe defined.
  466. const bool trans = ((trans_x && trans_x->keys.size() > 1) || (trans_y && trans_y->keys.size() > 1) || (trans_z && trans_z->keys.size() > 1));
  467. const bool rotat = ((rotat_x && rotat_x->keys.size() > 1) || (rotat_y && rotat_y->keys.size() > 1) || (rotat_z && rotat_z->keys.size() > 1));
  468. const bool scale = ((scale_x && scale_x->keys.size() > 1) || (scale_y && scale_y->keys.size() > 1) || (scale_z && scale_z->keys.size() > 1));
  469. if (!trans && !rotat && !scale)
  470. return;
  471. // Allocate the output animation
  472. aiNodeAnim *anim = *out = new aiNodeAnim();
  473. // Setup default animation setup if necessary
  474. if (need_to_setup) {
  475. UpdateAnimRangeSetup();
  476. need_to_setup = false;
  477. }
  478. // copy translation keys
  479. if (trans) {
  480. std::vector<aiVectorKey> keys;
  481. GetKeys(keys, trans_x, trans_y, trans_z, flags);
  482. anim->mPositionKeys = new aiVectorKey[anim->mNumPositionKeys = static_cast<unsigned int>(keys.size())];
  483. std::copy(keys.begin(), keys.end(), anim->mPositionKeys);
  484. }
  485. // copy rotation keys
  486. if (rotat) {
  487. std::vector<aiVectorKey> keys;
  488. GetKeys(keys, rotat_x, rotat_y, rotat_z, flags);
  489. anim->mRotationKeys = new aiQuatKey[anim->mNumRotationKeys = static_cast<unsigned int>(keys.size())];
  490. // convert heading, pitch, bank to quaternion
  491. // mValue.x=Heading=Rot(Y), mValue.y=Pitch=Rot(X), mValue.z=Bank=Rot(Z)
  492. // Lightwave's rotation order is ZXY
  493. aiVector3D X(1.0, 0.0, 0.0);
  494. aiVector3D Y(0.0, 1.0, 0.0);
  495. aiVector3D Z(0.0, 0.0, 1.0);
  496. for (unsigned int i = 0; i < anim->mNumRotationKeys; ++i) {
  497. aiQuatKey &qk = anim->mRotationKeys[i];
  498. qk.mTime = keys[i].mTime;
  499. qk.mValue = aiQuaternion(Y, keys[i].mValue.x) * aiQuaternion(X, keys[i].mValue.y) * aiQuaternion(Z, keys[i].mValue.z);
  500. }
  501. }
  502. // copy scaling keys
  503. if (scale) {
  504. std::vector<aiVectorKey> keys;
  505. GetKeys(keys, scale_x, scale_y, scale_z, flags);
  506. anim->mScalingKeys = new aiVectorKey[anim->mNumScalingKeys = static_cast<unsigned int>(keys.size())];
  507. std::copy(keys.begin(), keys.end(), anim->mScalingKeys);
  508. }
  509. }
  510. #endif // no lwo or no lws