SoftBodySkinnedConstraintTest.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Tests/Test.h>
  6. #include <Jolt/Physics/Body/Body.h>
  7. // This test shows how to skin a soft body to a skeleton and control the animation.
  8. class SoftBodySkinnedConstraintTest : public Test
  9. {
  10. public:
  11. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, SoftBodySkinnedConstraintTest)
  12. // See: Test
  13. virtual void Initialize() override;
  14. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  15. virtual void GetInitialCamera(CameraState &ioState) const override { ioState.mPos = RVec3(15, 30, 15); }
  16. virtual void SaveState(StateRecorder &inStream) const override;
  17. virtual void RestoreState(StateRecorder &inStream) override;
  18. virtual bool HasSettingsMenu() const override { return true; }
  19. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  20. private:
  21. // Size and spacing of the cloth
  22. static constexpr int cNumVerticesX = 10;
  23. static constexpr int cNumVerticesZ = 50;
  24. static constexpr float cVertexSpacing = 0.5f;
  25. // Number of joints that drive the cloth
  26. static constexpr int cNumJoints = 11;
  27. // Position of the body
  28. static constexpr float cBodyPosY = 20.0f;
  29. // Get a procedurally generated pose
  30. Array<Mat44> GetWorldSpacePose(float inTime) const;
  31. // Skin the vertices of the soft body to the pose
  32. void SkinVertices(bool inHardSkinAll);
  33. // The soft body
  34. Body * mBody;
  35. // Current time
  36. float mTime = 0.0f;
  37. // Settings
  38. static inline bool sEnableSkinConstraints = true;
  39. static inline float sMaxDistanceMultiplier = 1.0f;
  40. };