1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Physics/BsCollider.h" |
7 | #include "Resources/BsIResourceListener.h" |
8 | |
9 | namespace bs |
10 | { |
11 | class PhysicsScene; |
12 | |
13 | /** @addtogroup Physics |
14 | * @{ |
15 | */ |
16 | |
17 | /** A collider represented by an arbitrary mesh. */ |
18 | class BS_CORE_EXPORT MeshCollider : public Collider, public IResourceListener |
19 | { |
20 | public: |
21 | MeshCollider() = default; |
22 | |
23 | /** |
24 | * Sets a mesh that represents the collider geometry. This can be a generic triangle mesh, or and convex mesh. |
25 | * Triangle meshes are not supported as triggers, nor are they supported for colliders that are parts of a |
26 | * non-kinematic rigidbody. |
27 | */ |
28 | void setMesh(const HPhysicsMesh& mesh) { mMesh = mesh; onMeshChanged(); markListenerResourcesDirty(); } |
29 | |
30 | /** @copydoc setMesh() */ |
31 | HPhysicsMesh getMesh() const { return mMesh; } |
32 | |
33 | /** |
34 | * Creates a new mesh collider. |
35 | * |
36 | * @param[in] scene Scene into which to add the collider to. |
37 | * @param[in] position Position of the collider. |
38 | * @param[in] rotation Rotation of the collider. |
39 | */ |
40 | static SPtr<MeshCollider> create(PhysicsScene& scene, const Vector3& position = Vector3::ZERO, |
41 | const Quaternion& rotation = Quaternion::IDENTITY); |
42 | |
43 | protected: |
44 | /** @copydoc IResourceListener::getListenerResources */ |
45 | void getListenerResources(Vector<HResource>& resources) override; |
46 | |
47 | /** @copydoc IResourceListener::notifyResourceLoaded */ |
48 | void notifyResourceLoaded(const HResource& resource) override; |
49 | |
50 | /** @copydoc IResourceListener::notifyResourceChanged */ |
51 | void notifyResourceChanged(const HResource& resource) override; |
52 | |
53 | /** |
54 | * Triggered by the resources system whenever the attached collision mesh changed (e.g. was reimported) or loaded. |
55 | */ |
56 | virtual void onMeshChanged() { } |
57 | |
58 | HPhysicsMesh mMesh; |
59 | }; |
60 | |
61 | /** @} */ |
62 | } |