SoftBodyUpdateContext.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2023 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Core/NonCopyable.h>
  6. #include <Jolt/Physics/Body/MotionProperties.h>
  7. JPH_NAMESPACE_BEGIN
  8. class Body;
  9. class SoftBodyMotionProperties;
  10. class SoftBodyContactListener;
  11. class SimShapeFilter;
  12. /// Temporary data used by the update of a soft body
  13. class SoftBodyUpdateContext : public NonCopyable
  14. {
  15. public:
  16. static constexpr uint cVertexCollisionBatch = 64; ///< Number of vertices to process in a batch in DetermineCollisionPlanes
  17. static constexpr uint cVertexConstraintBatch = 256; ///< Number of vertices to group for processing batches of constraints in ApplyEdgeConstraints
  18. // Input
  19. Body * mBody; ///< Body that is being updated
  20. SoftBodyMotionProperties * mMotionProperties; ///< Motion properties of that body
  21. SoftBodyContactListener * mContactListener; ///< Contact listener to fire callbacks to
  22. const SimShapeFilter * mSimShapeFilter; ///< Shape filter to use for collision detection
  23. RMat44 mCenterOfMassTransform; ///< Transform of the body relative to the soft body
  24. Vec3 mGravity; ///< Gravity vector in local space of the soft body
  25. Vec3 mDisplacementDueToGravity; ///< Displacement of the center of mass due to gravity in the current time step
  26. float mDeltaTime; ///< Delta time for the current time step
  27. float mSubStepDeltaTime; ///< Delta time for each sub step
  28. /// Describes progress in the current update
  29. enum class EState
  30. {
  31. DetermineCollisionPlanes, ///< Determine collision planes for vertices in parallel
  32. DetermineSensorCollisions, ///< Determine collisions with sensors in parallel
  33. ApplyConstraints, ///< Apply constraints in parallel
  34. Done ///< Update is finished
  35. };
  36. // State of the update
  37. atomic<EState> mState { EState::DetermineCollisionPlanes };///< Current state of the update
  38. atomic<uint> mNextCollisionVertex { 0 }; ///< Next vertex to process for DetermineCollisionPlanes
  39. atomic<uint> mNumCollisionVerticesProcessed { 0 }; ///< Number of vertices processed by DetermineCollisionPlanes, used to determine if we can go to the next step
  40. atomic<uint> mNextSensorIndex { 0 }; ///< Next sensor to process for DetermineCollisionPlanes
  41. atomic<uint> mNumSensorsProcessed { 0 }; ///< Number of sensors processed by DetermineSensorCollisions, used to determine if we can go to the next step
  42. atomic<uint> mNextIteration { 0 }; ///< Next simulation iteration to process
  43. atomic<uint> mNextConstraintGroup { 0 }; ///< Next constraint group to process
  44. atomic<uint> mNumConstraintGroupsProcessed { 0 }; ///< Number of groups processed, used to determine if we can go to the next iteration
  45. // Output
  46. Vec3 mDeltaPosition; ///< Delta position of the body in the current time step, should be applied after the update
  47. ECanSleep mCanSleep; ///< Can the body sleep? Should be applied after the update
  48. };
  49. JPH_NAMESPACE_END