Guest User

Untitled

a guest
Jul 7th, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. bool GLTFImport::RetargetAnimation(ozz::animation::offline::RawAnimation* anim, const std::vector<ozz::math::Transform>& sourceRestPose, const std::vector<ozz::math::Transform>& targetRestPose)
  2. {
  3.     if (sourceRestPose.size() != targetRestPose.size() || sourceRestPose.size() != anim->num_tracks())
  4.         return false;
  5.  
  6.     using namespace ozz::math;
  7.     std::vector<Transform> diffs;
  8.     diffs.resize(anim->num_tracks());
  9.  
  10.     for (size_t i = 0; i < anim->num_tracks(); i++) {
  11.         auto& diffT = diffs[i];
  12.         auto& targetT = targetRestPose[i];
  13.         auto& sourceT = sourceRestPose[i];
  14.         diffT.rotation = targetT.rotation * Quaternion{ -sourceT.rotation.x, -sourceT.rotation.y, -sourceT.rotation.z, sourceT.rotation.w };
  15.         diffT.translation = targetT.translation - sourceT.translation;
  16.     }
  17.  
  18.     auto diffIter = diffs.begin();
  19.     for (auto& track : anim->tracks) {
  20.         for (auto& rot : track.rotations) {
  21.             rot.value = diffIter->rotation * rot.value;
  22.         }
  23.         for (auto& trans : track.translations) {
  24.             trans.value = diffIter->translation + trans.value;
  25.         }
  26.         diffIter++;
  27.     }
  28.  
  29.     return true;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment