BsPhysXMeshRTTI.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "BsRTTIType.h"
  6. #include "BsPhysXMesh.h"
  7. namespace BansheeEngine
  8. {
  9. class BS_PHYSX_EXPORT PhysXMeshRTTI : public RTTIType<PhysXMesh, PhysicsMesh, PhysXMeshRTTI>
  10. {
  11. private:
  12. ManagedDataBlock getCookedData(PhysXMesh* obj)
  13. {
  14. ManagedDataBlock dataBlock((UINT8*)obj->mCookedData, obj->mCookedDataSize);
  15. return dataBlock;
  16. }
  17. void setCookedData(PhysXMesh* obj, ManagedDataBlock val)
  18. {
  19. // Nothing to do here, the pointer we provided in allocateCookedData() already belongs to PhysXMesh
  20. // so the data is already written
  21. }
  22. static UINT8* allocateCookedData(PhysXMesh* obj, UINT32 numBytes)
  23. {
  24. obj->mCookedData = (UINT8*)bs_alloc(numBytes);
  25. obj->mCookedDataSize = numBytes;
  26. return obj->mCookedData;
  27. }
  28. public:
  29. PhysXMeshRTTI()
  30. {
  31. addDataBlockField("mCookedData", 0,
  32. &PhysXMeshRTTI::getCookedData, &PhysXMeshRTTI::setCookedData, 0, &PhysXMeshRTTI::allocateCookedData);
  33. }
  34. void onDeserializationEnded(IReflectable* obj) override
  35. {
  36. PhysXMesh* mesh = static_cast<PhysXMesh*>(obj);
  37. mesh->initialize();
  38. }
  39. const String& getRTTIName() override
  40. {
  41. static String name = "PhysXMesh";
  42. return name;
  43. }
  44. UINT32 getRTTIId() override
  45. {
  46. return TID_PhysXMesh;
  47. }
  48. SPtr<IReflectable> newRTTIObject() override
  49. {
  50. return PhysicsMesh::_createPtr(nullptr, PhysicsMeshType::Convex);
  51. }
  52. };
  53. }