BsMeshCollider.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Physics/BsCollider.h"
  6. #include "Resources/BsIResourceListener.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Physics
  10. * @{
  11. */
  12. /** A collider represented by an arbitrary mesh. */
  13. class BS_CORE_EXPORT MeshCollider : public Collider, public IResourceListener
  14. {
  15. public:
  16. MeshCollider();
  17. /**
  18. * Sets a mesh that represents the collider geometry. This can be a generic triangle mesh, or and convex mesh.
  19. * Triangle meshes are not supported as triggers, nor are they supported for colliders that are parts of a
  20. * non-kinematic rigidbody.
  21. */
  22. void setMesh(const HPhysicsMesh& mesh) { mMesh = mesh; onMeshChanged(); markListenerResourcesDirty(); }
  23. /** @copydoc setMesh() */
  24. HPhysicsMesh getMesh() const { return mMesh; }
  25. /**
  26. * Creates a new mesh collider.
  27. *
  28. * @param[in] position Position of the collider.
  29. * @param[in] rotation Rotation of the collider.
  30. */
  31. static SPtr<MeshCollider> create(const Vector3& position = Vector3::ZERO,
  32. const Quaternion& rotation = Quaternion::IDENTITY);
  33. protected:
  34. /** @copydoc IResourceListener::getListenerResources */
  35. void getListenerResources(Vector<HResource>& resources) override;
  36. /** @copydoc IResourceListener::notifyResourceLoaded */
  37. void notifyResourceLoaded(const HResource& resource) override;
  38. /** @copydoc IResourceListener::notifyResourceChanged */
  39. void notifyResourceChanged(const HResource& resource) override;
  40. /**
  41. * Triggered by the resources system whenever the attached collision mesh changed (e.g. was reimported) or loaded.
  42. */
  43. virtual void onMeshChanged() { }
  44. HPhysicsMesh mMesh;
  45. };
  46. /** @} */
  47. }