SoftBodySkinnedConstraintTest.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class SoftBodySkinnedConstraintTest : public Test
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(JPH_NO_EXPORT, SoftBodySkinnedConstraintTest)
  11. // Description of the test
  12. virtual const char * GetDescription() const override
  13. {
  14. return "Shows how to attach a soft body to a skinned mesh and control the animation.";
  15. }
  16. // See: Test
  17. virtual void Initialize() override;
  18. virtual void PrePhysicsUpdate(const PreUpdateParams &inParams) override;
  19. virtual void GetInitialCamera(CameraState &ioState) const override { ioState.mPos = RVec3(15, 30, 15); }
  20. virtual void SaveState(StateRecorder &inStream) const override;
  21. virtual void RestoreState(StateRecorder &inStream) override;
  22. virtual bool HasSettingsMenu() const override { return true; }
  23. virtual void CreateSettingsMenu(DebugUI *inUI, UIElement *inSubMenu) override;
  24. private:
  25. // Size and spacing of the cloth
  26. static constexpr int cNumVerticesX = 10;
  27. static constexpr int cNumVerticesZ = 50;
  28. static constexpr float cVertexSpacing = 0.5f;
  29. // Number of joints that drive the cloth
  30. static constexpr int cNumJoints = 11;
  31. // Position of the body
  32. static constexpr float cBodyPosY = 20.0f;
  33. // Get a procedurally generated pose
  34. Array<Mat44> GetWorldSpacePose(float inTime) const;
  35. // Skin the vertices of the soft body to the pose
  36. void SkinVertices(bool inHardSkinAll);
  37. // The soft body
  38. Body * mBody;
  39. // Current time
  40. float mTime = 0.0f;
  41. // Settings
  42. static inline float sTimeScale = 1.0f;
  43. static inline bool sUpdateSkinning = true;
  44. static inline bool sEnableSkinConstraints = true;
  45. static inline float sMaxDistanceMultiplier = 1.0f;
  46. };