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 "BsPhysXPrerequisites.h"
6#include "Physics/BsPhysicsMesh.h"
7#include "PxMaterial.h"
8
9namespace bs
10{
11 /** @addtogroup PhysX
12 * @{
13 */
14
15 /** PhysX implementation of a PhysicsMesh. */
16 class PhysXMesh : public PhysicsMesh
17 {
18 public:
19 PhysXMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type);
20
21 private:
22 /** @copydoc PhysicsMesh::initialize() */
23 void initialize() override;
24
25 /** @copydoc PhysicsMesh::initialize() */
26 void destroy() override;
27
28 // Note: Must not have its own RTTI type, it's important it shares the same type ID as PhysicsMesh so the
29 // system knows to recognize it. Use FPhysicsMesh instead.
30 };
31
32 /** PhysX implementation of the PhysicsMesh foundation, FPhysicsMesh. */
33 class FPhysXMesh : public FPhysicsMesh
34 {
35 public:
36 FPhysXMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type);
37 ~FPhysXMesh();
38
39 /** @copydoc PhysicsMesh::getMeshData */
40 SPtr<MeshData> getMeshData() const override;
41
42 /**
43 * Returns the internal PhysX representation of a triangle mesh. Caller must ensure the physics mesh type is
44 * triangle.
45 */
46 physx::PxTriangleMesh* _getTriangle() const { assert(mType == PhysicsMeshType::Triangle); return mTriangleMesh; }
47
48 /**
49 * Returns the internal PhysX representation of a convex mesh. Caller must ensure the physics mesh type is
50 * convex.
51 */
52 physx::PxConvexMesh* _getConvex() const { assert(mType == PhysicsMeshType::Convex); return mConvexMesh; }
53
54 private:
55 /** Creates the internal triangle/convex mesh */
56 void initialize();
57
58 physx::PxTriangleMesh* mTriangleMesh = nullptr;
59 physx::PxConvexMesh* mConvexMesh = nullptr;
60
61 UINT8* mCookedData = nullptr;
62 UINT32 mCookedDataSize = 0;
63
64 /************************************************************************/
65 /* SERIALIZATION */
66 /************************************************************************/
67 public:
68 FPhysXMesh(); // Serialization only
69
70 friend class FPhysXMeshRTTI;
71 static RTTITypeBase* getRTTIStatic();
72 RTTITypeBase* getRTTI() const override;
73 };
74
75 /** @} */
76}