BsMeshRTTI.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsRTTIType.h"
  6. #include "BsCoreApplication.h"
  7. #include "BsMesh.h"
  8. #include "BsSkeleton.h"
  9. #include "BsMeshManager.h"
  10. #include "BsCoreThread.h"
  11. namespace BansheeEngine
  12. {
  13. /** @cond RTTI */
  14. /** @addtogroup RTTI-Impl-Core
  15. * @{
  16. */
  17. class MeshRTTI : public RTTIType<Mesh, MeshBase, MeshRTTI>
  18. {
  19. BS_BEGIN_RTTI_MEMBERS
  20. BS_RTTI_MEMBER_REFLPTR(mVertexDesc, 0)
  21. BS_RTTI_MEMBER_PLAIN(mIndexType, 1)
  22. BS_RTTI_MEMBER_PLAIN(mUsage, 2)
  23. BS_RTTI_MEMBER_REFLPTR(mSkeleton, 4)
  24. BS_END_RTTI_MEMBERS
  25. SPtr<MeshData> getMeshData(Mesh* obj)
  26. {
  27. SPtr<MeshData> meshData = obj->allocateSubresourceBuffer(0);
  28. obj->readSubresource(gCoreAccessor(), 0, meshData);
  29. gCoreAccessor().submitToCoreThread(true);
  30. return meshData;
  31. }
  32. void setMeshData(Mesh* obj, SPtr<MeshData> meshData)
  33. {
  34. obj->mCPUData = meshData;
  35. }
  36. public:
  37. MeshRTTI()
  38. :mInitMembers(this)
  39. {
  40. addReflectablePtrField("mMeshData", 3, &MeshRTTI::getMeshData, &MeshRTTI::setMeshData);
  41. }
  42. void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
  43. {
  44. Mesh* mesh = static_cast<Mesh*>(obj);
  45. mesh->initialize();
  46. }
  47. SPtr<IReflectable> newRTTIObject() override
  48. {
  49. return MeshManager::instance().createEmpty();
  50. }
  51. const String& getRTTIName() override
  52. {
  53. static String name = "Mesh";
  54. return name;
  55. }
  56. UINT32 getRTTIId() override
  57. {
  58. return TID_Mesh;
  59. }
  60. };
  61. /** @} */
  62. /** @endcond */
  63. }