PhysicsMaterial.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PhysicsMaterial)
  20. public:
  21. /// Constructor
  22. PhysicsMaterial() = default;
  23. virtual ~PhysicsMaterial() override = default;
  24. /// Default material that is used when a shape has no materials defined
  25. static RefConst<PhysicsMaterial> sDefault;
  26. // Properties
  27. virtual const char * GetDebugName() const { return "Unknown"; }
  28. virtual Color GetDebugColor() const { return Color::sGrey; }
  29. /// Saves the contents of the material in binary form to inStream.
  30. virtual void SaveBinaryState(StreamOut &inStream) const;
  31. using PhysicsMaterialResult = Result<Ref<PhysicsMaterial>>;
  32. /// Creates a PhysicsMaterial of the correct type and restores its contents from the binary stream inStream.
  33. static PhysicsMaterialResult sRestoreFromBinaryState(StreamIn &inStream);
  34. protected:
  35. /// Don't allow copy constructing this base class, but allow derived classes to copy themselves
  36. PhysicsMaterial(const PhysicsMaterial &) = default;
  37. PhysicsMaterial & operator = (const PhysicsMaterial &) = default;
  38. /// This function should not be called directly, it is used by sRestoreFromBinaryState.
  39. virtual void RestoreBinaryState(StreamIn &inStream);
  40. };
  41. using PhysicsMaterialList = Array<RefConst<PhysicsMaterial>>;
  42. JPH_NAMESPACE_END