BsMeshRTTI.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "BsMorphShapes.h"
  10. #include "BsCoreThread.h"
  11. namespace bs
  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_RTTI_MEMBER_REFLPTR(mMorphShapes, 5)
  25. BS_END_RTTI_MEMBERS
  26. SPtr<MeshData> getMeshData(Mesh* obj)
  27. {
  28. SPtr<MeshData> meshData = obj->allocBuffer();
  29. int usage = obj->mUsage;
  30. if((usage & MU_CPUREADABLE) || BS_EDITOR_BUILD)
  31. {
  32. obj->readData(meshData);
  33. gCoreThread().submit(true);
  34. return meshData;
  35. }
  36. if(usage & MU_CPUCACHED)
  37. {
  38. obj->readCachedData(*meshData);
  39. return meshData;
  40. }
  41. LOGERR("Attempting to save a mesh that isn't flagged with either MU_CPUCACHED OR MU_GPUREADABLE flags.");
  42. return meshData;
  43. }
  44. void setMeshData(Mesh* obj, SPtr<MeshData> meshData)
  45. {
  46. obj->mCPUData = meshData;
  47. }
  48. public:
  49. MeshRTTI()
  50. :mInitMembers(this)
  51. {
  52. addReflectablePtrField("mMeshData", 3, &MeshRTTI::getMeshData, &MeshRTTI::setMeshData);
  53. }
  54. void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
  55. {
  56. Mesh* mesh = static_cast<Mesh*>(obj);
  57. mesh->initialize();
  58. }
  59. SPtr<IReflectable> newRTTIObject() override
  60. {
  61. return Mesh::createEmpty();
  62. }
  63. const String& getRTTIName() override
  64. {
  65. static String name = "Mesh";
  66. return name;
  67. }
  68. UINT32 getRTTIId() override
  69. {
  70. return TID_Mesh;
  71. }
  72. };
  73. /** @} */
  74. /** @endcond */
  75. }