summaryrefslogtreecommitdiff
path: root/assetFactory
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-04 14:17:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-04 14:20:30 +0000
commit29ce7770c3e8373d2efea0b47fe50a13a81e75a2 (patch)
treec79441401b1bda954775fd4b958b89790b5567f3 /assetFactory
parentSplit Asset into its own file (diff)
downloadilt-29ce7770c3e8373d2efea0b47fe50a13a81e75a2.tar.bz2
ilt-29ce7770c3e8373d2efea0b47fe50a13a81e75a2.tar.xz
ilt-29ce7770c3e8373d2efea0b47fe50a13a81e75a2.zip
Add Asset helpers to construct OpenGL ready meshes from Asset Factory meshes during load
Diffstat (limited to 'assetFactory')
-rw-r--r--assetFactory/asset.cpp29
-rw-r--r--assetFactory/asset.h22
2 files changed, 50 insertions, 1 deletions
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<FactoryMesh::Collection>);
}
+
+Asset::MeshConstruct::MeshConstruct(Mesh::Ptr & m) :
+ Persistence::SelectionPtrBase<FactoryMesh::Ptr> {fmesh}, out {m} { }
+
+void
+Asset::MeshConstruct::endObject(Persistence::Stack & stk)
+{
+ out = fmesh->createMesh();
+ Persistence::SelectionPtrBase<FactoryMesh::Ptr>::endObject(stk);
+}
+
+Asset::MeshArrayConstruct::MeshArrayConstruct(std::span<Mesh::Ptr> m) :
+ Persistence::SelectionPtrBase<FactoryMesh::Ptr> {fmesh}, out {m}
+{
+}
+
+void
+Asset::MeshArrayConstruct::endObject(Persistence::Stack & stk)
+{
+ for (auto & outMesh : out) {
+ if (!outMesh) {
+ outMesh = fmesh->createMesh();
+ break;
+ }
+ }
+ Persistence::SelectionPtrBase<FactoryMesh::Ptr>::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<FactoryMesh::Ptr> {
+ using Persistence::SelectionPtrBase<FactoryMesh::Ptr>::setValue;
+
+ MeshConstruct(Mesh::Ptr & m);
+
+ void endObject(Persistence::Stack & stk) override;
+
+ FactoryMesh::Ptr fmesh;
+ Mesh::Ptr & out;
+ };
+
+ struct MeshArrayConstruct : public Persistence::SelectionPtrBase<FactoryMesh::Ptr> {
+ using Persistence::SelectionPtrBase<FactoryMesh::Ptr>::setValue;
+
+ MeshArrayConstruct(std::span<Mesh::Ptr> m);
+
+ void endObject(Persistence::Stack & stk) override;
+
+ FactoryMesh::Ptr fmesh;
+ std::span<Mesh::Ptr> out;
+ };
+
friend Persistence::SelectionPtrBase<std::shared_ptr<Asset>>;
bool persist(Persistence::PersistenceStore & store) override;
};