PhysicsMaterial.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Core/Reference.h>
  6. #include <Jolt/Core/Color.h>
  7. #include <Jolt/Core/Result.h>
  8. #include <Jolt/ObjectStream/SerializableObject.h>
  9. JPH_NAMESPACE_BEGIN
  10. class StreamIn;
  11. class StreamOut;
  12. /// This structure describes the surface of (part of) a shape. You should inherit from it to define additional
  13. /// information that is interesting for the simulation. The 2 materials involved in a contact could be used
  14. /// to decide which sound or particle effects to play.
  15. ///
  16. /// If you inherit from this material, don't forget to create a suitable default material in sDefault
  17. class JPH_EXPORT PhysicsMaterial : public SerializableObject, public RefTarget<PhysicsMaterial>
  18. {
  19. public:
  20. JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PhysicsMaterial)
  21. /// Virtual destructor
  22. virtual ~PhysicsMaterial() override = default;
  23. /// Default material that is used when a shape has no materials defined
  24. static RefConst<PhysicsMaterial> sDefault;
  25. // Properties
  26. virtual const char * GetDebugName() const { return "Unknown"; }
  27. virtual Color GetDebugColor() const { return Color::sGrey; }
  28. /// Saves the contents of the material in binary form to inStream.
  29. virtual void SaveBinaryState(StreamOut &inStream) const;
  30. using PhysicsMaterialResult = Result<Ref<PhysicsMaterial>>;
  31. /// Creates a PhysicsMaterial of the correct type and restores its contents from the binary stream inStream.
  32. static PhysicsMaterialResult sRestoreFromBinaryState(StreamIn &inStream);
  33. protected:
  34. /// This function should not be called directly, it is used by sRestoreFromBinaryState.
  35. virtual void RestoreBinaryState(StreamIn &inStream);
  36. };
  37. using PhysicsMaterialList = Array<RefConst<PhysicsMaterial>>;
  38. JPH_NAMESPACE_END