SoftBodyUpdateContext.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. /// @cond INTERNAL
  13. /// Temporary data used by the update of a soft body
  14. ///
  15. /// WARNING: This class is an internal part of PhysicsSystem, it has no functions that can be called by users of the library.
  16. class SoftBodyUpdateContext : public NonCopyable
  17. {
  18. public:
  19. static constexpr uint cVertexCollisionBatch = 64; ///< Number of vertices to process in a batch in DetermineCollisionPlanes
  20. static constexpr uint cVertexConstraintBatch = 256; ///< Number of vertices to group for processing batches of constraints in ApplyEdgeConstraints
  21. // Input
  22. Body * mBody; ///< Body that is being updated
  23. SoftBodyMotionProperties * mMotionProperties; ///< Motion properties of that body
  24. SoftBodyContactListener * mContactListener; ///< Contact listener to fire callbacks to
  25. const SimShapeFilter * mSimShapeFilter; ///< Shape filter to use for collision detection
  26. RMat44 mCenterOfMassTransform; ///< Transform of the body relative to the soft body
  27. Vec3 mGravity; ///< Gravity vector in local space of the soft body
  28. Vec3 mDisplacementDueToGravity; ///< Displacement of the center of mass due to gravity in the current time step
  29. float mDeltaTime; ///< Delta time for the current time step
  30. float mSubStepDeltaTime; ///< Delta time for each sub step
  31. /// Describes progress in the current update
  32. enum class EState
  33. {
  34. DetermineCollisionPlanes, ///< Determine collision planes for vertices in parallel
  35. DetermineSensorCollisions, ///< Determine collisions with sensors in parallel
  36. ApplyConstraints, ///< Apply constraints in parallel
  37. Done ///< Update is finished
  38. };
  39. // State of the update
  40. atomic<EState> mState { EState::DetermineCollisionPlanes };///< Current state of the update
  41. atomic<uint> mNextCollisionVertex { 0 }; ///< Next vertex to process for DetermineCollisionPlanes
  42. atomic<uint> mNumCollisionVerticesProcessed { 0 }; ///< Number of vertices processed by DetermineCollisionPlanes, used to determine if we can go to the next step
  43. atomic<uint> mNextSensorIndex { 0 }; ///< Next sensor to process for DetermineCollisionPlanes
  44. atomic<uint> mNumSensorsProcessed { 0 }; ///< Number of sensors processed by DetermineSensorCollisions, used to determine if we can go to the next step
  45. atomic<uint> mNextIteration { 0 }; ///< Next simulation iteration to process
  46. atomic<uint> mNextConstraintGroup { 0 }; ///< Next constraint group to process
  47. atomic<uint> mNumConstraintGroupsProcessed { 0 }; ///< Number of groups processed, used to determine if we can go to the next iteration
  48. // Output
  49. Vec3 mDeltaPosition; ///< Delta position of the body in the current time step, should be applied after the update
  50. ECanSleep mCanSleep; ///< Can the body sleep? Should be applied after the update
  51. };
  52. /// @endcond
  53. JPH_NAMESPACE_END