| 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 "Resources/BsResource.h" |
| 7 | |
| 8 | namespace bs |
| 9 | { |
| 10 | /** @addtogroup Physics |
| 11 | * @{ |
| 12 | */ |
| 13 | |
| 14 | class FPhysicsMesh; |
| 15 | |
| 16 | /** |
| 17 | * Represents a physics mesh that can be used with a MeshCollider. Physics mesh can be a generic triangle mesh |
| 18 | * or a convex mesh. Convex meshes are limited to 255 faces. |
| 19 | */ |
| 20 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Physics) PhysicsMesh : public Resource |
| 21 | { |
| 22 | public: |
| 23 | PhysicsMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type); |
| 24 | virtual ~PhysicsMesh() = default; |
| 25 | |
| 26 | /** Returns the type of the physics mesh. */ |
| 27 | BS_SCRIPT_EXPORT(n:Type,pr:getter) |
| 28 | PhysicsMeshType getType() const; |
| 29 | |
| 30 | /** Returns the mesh's indices and vertices. */ |
| 31 | SPtr<MeshData> getMeshData() const; |
| 32 | |
| 33 | /** |
| 34 | * Creates a new physics mesh. |
| 35 | * |
| 36 | * @param[in] meshData Index and vertices of the mesh data. |
| 37 | * @param[in] type Type of the mesh. If convex the provided mesh geometry will be converted into a convex |
| 38 | * mesh (that might not be the same as the provided mesh data). |
| 39 | */ |
| 40 | static HPhysicsMesh create(const SPtr<MeshData>& meshData, PhysicsMeshType type = PhysicsMeshType::Convex); |
| 41 | |
| 42 | /** @name Internal |
| 43 | * @{ |
| 44 | */ |
| 45 | |
| 46 | /** Returns the internal implementation of the physics mesh. */ |
| 47 | virtual FPhysicsMesh* _getInternal() { return mInternal.get(); } |
| 48 | |
| 49 | /** |
| 50 | * @copydoc create() |
| 51 | * |
| 52 | * For internal use. Requires manual initialization after creation. |
| 53 | */ |
| 54 | static SPtr<PhysicsMesh> _createPtr(const SPtr<MeshData>& meshData, PhysicsMeshType type); |
| 55 | |
| 56 | /** @} */ |
| 57 | |
| 58 | protected: |
| 59 | /** @copydoc Resource::initialize() */ |
| 60 | void initialize() override; |
| 61 | |
| 62 | SPtr<FPhysicsMesh> mInternal; |
| 63 | SPtr<MeshData> mInitMeshData; // Transient, only used during initalization |
| 64 | PhysicsMeshType mType; // Transient, only used during initalization |
| 65 | |
| 66 | /************************************************************************/ |
| 67 | /* SERIALIZATION */ |
| 68 | /************************************************************************/ |
| 69 | public: |
| 70 | friend class PhysicsMeshRTTI; |
| 71 | static RTTITypeBase* getRTTIStatic(); |
| 72 | RTTITypeBase* getRTTI() const override; |
| 73 | }; |
| 74 | |
| 75 | /** @} */ |
| 76 | /** @addtogroup Physics-Internal |
| 77 | * @{ |
| 78 | */ |
| 79 | |
| 80 | /** Foundation that contains a specific implementation of a PhysicsMesh. */ |
| 81 | class BS_CORE_EXPORT FPhysicsMesh : public IReflectable |
| 82 | { |
| 83 | public: |
| 84 | FPhysicsMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type); |
| 85 | virtual ~FPhysicsMesh(); |
| 86 | |
| 87 | /** Returns the mesh's indices and vertices. */ |
| 88 | virtual SPtr<MeshData> getMeshData() const = 0; |
| 89 | |
| 90 | protected: |
| 91 | friend class PhysicsMesh; |
| 92 | |
| 93 | PhysicsMeshType mType; |
| 94 | |
| 95 | /************************************************************************/ |
| 96 | /* SERIALIZATION */ |
| 97 | /************************************************************************/ |
| 98 | public: |
| 99 | friend class FPhysicsMeshRTTI; |
| 100 | static RTTITypeBase* getRTTIStatic(); |
| 101 | RTTITypeBase* getRTTI() const override; |
| 102 | }; |
| 103 | |
| 104 | /** @} */ |
| 105 | } |