LoadSaveBinaryRigTest.cpp 1.2 KB

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