PhysicsMaterial.h 1.8 KB

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