From 29ce7770c3e8373d2efea0b47fe50a13a81e75a2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 14:17:00 +0000 Subject: Add Asset helpers to construct OpenGL ready meshes from Asset Factory meshes during load --- assetFactory/asset.cpp | 29 ++++++++++++++++++++++++++++- assetFactory/asset.h | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/assetFactory/asset.cpp b/assetFactory/asset.cpp index fa30a78..659a950 100644 --- a/assetFactory/asset.cpp +++ b/assetFactory/asset.cpp @@ -3,6 +3,33 @@ bool Asset::persist(Persistence::PersistenceStore & store) { - return STORE_TYPE && STORE_MEMBER(id) && STORE_MEMBER(name) + return STORE_MEMBER(id) && STORE_MEMBER(name) && STORE_NAME_HELPER("mesh", meshes, Persistence::Appender); } + +Asset::MeshConstruct::MeshConstruct(Mesh::Ptr & m) : + Persistence::SelectionPtrBase {fmesh}, out {m} { } + +void +Asset::MeshConstruct::endObject(Persistence::Stack & stk) +{ + out = fmesh->createMesh(); + Persistence::SelectionPtrBase::endObject(stk); +} + +Asset::MeshArrayConstruct::MeshArrayConstruct(std::span m) : + Persistence::SelectionPtrBase {fmesh}, out {m} +{ +} + +void +Asset::MeshArrayConstruct::endObject(Persistence::Stack & stk) +{ + for (auto & outMesh : out) { + if (!outMesh) { + outMesh = fmesh->createMesh(); + break; + } + } + Persistence::SelectionPtrBase::endObject(stk); +} diff --git a/assetFactory/asset.h b/assetFactory/asset.h index d86b804..8dd1ecb 100644 --- a/assetFactory/asset.h +++ b/assetFactory/asset.h @@ -12,6 +12,28 @@ public: FactoryMesh::Collection meshes; protected: + struct MeshConstruct : public Persistence::SelectionPtrBase { + using Persistence::SelectionPtrBase::setValue; + + MeshConstruct(Mesh::Ptr & m); + + void endObject(Persistence::Stack & stk) override; + + FactoryMesh::Ptr fmesh; + Mesh::Ptr & out; + }; + + struct MeshArrayConstruct : public Persistence::SelectionPtrBase { + using Persistence::SelectionPtrBase::setValue; + + MeshArrayConstruct(std::span m); + + void endObject(Persistence::Stack & stk) override; + + FactoryMesh::Ptr fmesh; + std::span out; + }; + friend Persistence::SelectionPtrBase>; bool persist(Persistence::PersistenceStore & store) override; }; -- cgit v1.2.3