| 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 "BsCorePrerequisites.h" |
| 6 | #include "Reflection/BsRTTIType.h" |
| 7 | #include "BsCoreApplication.h" |
| 8 | #include "Mesh/BsMesh.h" |
| 9 | #include "Animation/BsSkeleton.h" |
| 10 | #include "Animation/BsMorphShapes.h" |
| 11 | #include "CoreThread/BsCoreThread.h" |
| 12 | |
| 13 | namespace bs |
| 14 | { |
| 15 | /** @cond RTTI */ |
| 16 | /** @addtogroup RTTI-Impl-Core |
| 17 | * @{ |
| 18 | */ |
| 19 | |
| 20 | class MeshRTTI : public RTTIType<Mesh, MeshBase, MeshRTTI> |
| 21 | { |
| 22 | BS_BEGIN_RTTI_MEMBERS |
| 23 | BS_RTTI_MEMBER_REFLPTR(mVertexDesc, 0) |
| 24 | BS_RTTI_MEMBER_PLAIN(mIndexType, 1) |
| 25 | BS_RTTI_MEMBER_PLAIN(mUsage, 2) |
| 26 | BS_RTTI_MEMBER_REFLPTR(mSkeleton, 4) |
| 27 | BS_RTTI_MEMBER_REFLPTR(mMorphShapes, 5) |
| 28 | BS_END_RTTI_MEMBERS |
| 29 | |
| 30 | SPtr<MeshData> getMeshData(Mesh* obj) |
| 31 | { |
| 32 | SPtr<MeshData> meshData = obj->allocBuffer(); |
| 33 | |
| 34 | obj->readData(meshData); |
| 35 | gCoreThread().submitAll(true); |
| 36 | |
| 37 | return meshData; |
| 38 | } |
| 39 | |
| 40 | void setMeshData(Mesh* obj, SPtr<MeshData> meshData) |
| 41 | { |
| 42 | obj->mCPUData = meshData; |
| 43 | } |
| 44 | |
| 45 | public: |
| 46 | MeshRTTI() |
| 47 | { |
| 48 | addReflectablePtrField("mMeshData" , 3, &MeshRTTI::getMeshData, &MeshRTTI::setMeshData); |
| 49 | } |
| 50 | |
| 51 | void onDeserializationEnded(IReflectable* obj, SerializationContext* context) override |
| 52 | { |
| 53 | Mesh* mesh = static_cast<Mesh*>(obj); |
| 54 | mesh->initialize(); |
| 55 | } |
| 56 | |
| 57 | SPtr<IReflectable> newRTTIObject() override |
| 58 | { |
| 59 | return Mesh::createEmpty(); |
| 60 | } |
| 61 | |
| 62 | const String& getRTTIName() override |
| 63 | { |
| 64 | static String name = "Mesh" ; |
| 65 | return name; |
| 66 | } |
| 67 | |
| 68 | UINT32 getRTTIId() override |
| 69 | { |
| 70 | return TID_Mesh; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | /** @} */ |
| 75 | /** @endcond */ |
| 76 | } |
| 77 | |