BsPhysXMesh.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPhysXPrerequisites.h"
  5. #include "Physics/BsPhysicsMesh.h"
  6. #include "PxMaterial.h"
  7. namespace bs
  8. {
  9. /** @addtogroup PhysX
  10. * @{
  11. */
  12. /** PhysX implementation of a PhysicsMesh. */
  13. class PhysXMesh : public PhysicsMesh
  14. {
  15. public:
  16. PhysXMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type);
  17. private:
  18. /** @copydoc PhysicsMesh::initialize() */
  19. void initialize() override;
  20. /** @copydoc PhysicsMesh::initialize() */
  21. void destroy() override;
  22. // Note: Must not have its own RTTI type, it's important it shares the same type ID as PhysicsMesh so the
  23. // system knows to recognize it. Use FPhysicsMesh instead.
  24. };
  25. /** PhysX implementation of the PhysicsMesh foundation, FPhysicsMesh. */
  26. class FPhysXMesh : public FPhysicsMesh
  27. {
  28. public:
  29. FPhysXMesh(const SPtr<MeshData>& meshData, PhysicsMeshType type);
  30. ~FPhysXMesh();
  31. /** @copydoc PhysicsMesh::getMeshData */
  32. SPtr<MeshData> getMeshData() const override;
  33. /**
  34. * Returns the internal PhysX representation of a triangle mesh. Caller must ensure the physics mesh type is
  35. * triangle.
  36. */
  37. physx::PxTriangleMesh* _getTriangle() const { assert(mType == PhysicsMeshType::Triangle); return mTriangleMesh; }
  38. /**
  39. * Returns the internal PhysX representation of a convex mesh. Caller must ensure the physics mesh type is
  40. * convex.
  41. */
  42. physx::PxConvexMesh* _getConvex() const { assert(mType == PhysicsMeshType::Convex); return mConvexMesh; }
  43. private:
  44. /** Creates the internal triangle/convex mesh */
  45. void initialize();
  46. physx::PxTriangleMesh* mTriangleMesh = nullptr;
  47. physx::PxConvexMesh* mConvexMesh = nullptr;
  48. UINT8* mCookedData = nullptr;
  49. UINT32 mCookedDataSize = 0;
  50. /************************************************************************/
  51. /* SERIALIZATION */
  52. /************************************************************************/
  53. public:
  54. FPhysXMesh(); // Serialization only
  55. friend class FPhysXMeshRTTI;
  56. static RTTITypeBase* getRTTIStatic();
  57. RTTITypeBase* getRTTI() const override;
  58. };
  59. /** @} */
  60. }