LoadSaveBinaryRigTest.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/Rig/LoadSaveBinaryRigTest.h>
  5. #include <Application/DebugUI.h>
  6. #include <Jolt/Core/StreamWrapper.h>
  7. #include <Utils/Log.h>
  8. #include <Utils/RagdollLoader.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(LoadSaveBinaryRigTest)
  10. {
  11. JPH_ADD_BASE_CLASS(LoadSaveBinaryRigTest, Test)
  12. }
  13. LoadSaveBinaryRigTest::~LoadSaveBinaryRigTest()
  14. {
  15. mRagdoll->RemoveFromPhysicsSystem();
  16. }
  17. void LoadSaveBinaryRigTest::Initialize()
  18. {
  19. // Floor
  20. CreateFloor();
  21. stringstream data;
  22. {
  23. // Load ragdoll
  24. Ref<RagdollSettings> settings = RagdollLoader::sLoad("Assets/Human.tof", EMotionType::Dynamic);
  25. // Save it to a binary stream
  26. StreamOutWrapper stream_out(data);
  27. settings->SaveBinaryState(stream_out, true /* Save shape */, true /* Save group filter */);
  28. }
  29. StreamInWrapper stream_in(data);
  30. RagdollSettings::RagdollResult result = RagdollSettings::sRestoreFromBinaryState(stream_in);
  31. if (result.HasError())
  32. FatalError(result.GetError().c_str());
  33. // Create ragdoll
  34. mRagdoll = result.Get()->CreateRagdoll(0, 0, mPhysicsSystem);
  35. mRagdoll->AddToPhysicsSystem(EActivation::Activate);
  36. }