diff options
Diffstat (limited to 'assetFactory')
| -rw-r--r-- | assetFactory/asset.cpp | 6 | ||||
| -rw-r--r-- | assetFactory/asset.h | 8 | ||||
| -rw-r--r-- | assetFactory/assetFactory.cpp | 8 | ||||
| -rw-r--r-- | assetFactory/assetFactory.h | 2 | ||||
| -rw-r--r-- | assetFactory/cylinder.cpp | 2 | ||||
| -rw-r--r-- | assetFactory/factoryMesh.cpp | 11 | ||||
| -rw-r--r-- | assetFactory/lights.cpp | 14 | ||||
| -rw-r--r-- | assetFactory/lights.h | 18 | ||||
| -rw-r--r-- | assetFactory/modelFactoryMesh.cpp | 8 | ||||
| -rw-r--r-- | assetFactory/modelFactoryMesh.h | 11 | ||||
| -rw-r--r-- | assetFactory/mutation.cpp | 5 |
11 files changed, 68 insertions, 25 deletions
diff --git a/assetFactory/asset.cpp b/assetFactory/asset.cpp index e3f5feb..0254943 100644 --- a/assetFactory/asset.cpp +++ b/assetFactory/asset.cpp @@ -7,6 +7,12 @@ Asset::persist(Persistence::PersistenceStore & store) return STORE_MEMBER(id) && STORE_MEMBER(name); } +std::any +Asset::createAt(const Location &) const +{ + return {}; +} + Asset::TexturePtr Asset::getTexture() const { diff --git a/assetFactory/asset.h b/assetFactory/asset.h index 5bdd2f2..d8b42f6 100644 --- a/assetFactory/asset.h +++ b/assetFactory/asset.h @@ -2,14 +2,22 @@ #include "factoryMesh.h" #include "persistence.h" +#include <any> +#include <manyPtr.h> #include <stdTypeDefs.h> class TextureAtlas; +class Renderable; +class Location; class Asset : public Persistence::Persistable, public StdTypeDefs<Asset> { public: + using ManyPtr = ManySharedPtr<Asset, Renderable>; using TexturePtr = std::shared_ptr<TextureAtlas>; + /// Used only for the asset viewer + [[nodiscard]] virtual std::any createAt(const Location &) const; + std::string id; std::string name; diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index 176e1f5..a8d6036 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -3,8 +3,10 @@ #include "cuboid.h" #include "cylinder.h" #include "filesystem.h" +#include "gfx/gl/gldebug.h" #include "gfx/image.h" #include "gfx/models/texture.h" +#include "gfx/renderable.h" #include "object.h" #include "plane.h" #include "saxParse-persistence.h" @@ -25,6 +27,7 @@ AssetFactory::AssetFactory() : std::shared_ptr<AssetFactory> AssetFactory::loadXML(const std::filesystem::path & filename) { + glDebugScope _ {0, filename.native()}; filesystem::FileStar file {filename.c_str(), "r"}; return Persistence::SAXParsePersistence {}.loadState<std::shared_ptr<AssetFactory>>(file); } @@ -32,6 +35,7 @@ AssetFactory::loadXML(const std::filesystem::path & filename) AssetFactory::Assets AssetFactory::loadAll(const std::filesystem::path & root) { + glDebugScope _ {0}; return std::accumulate(std::filesystem::recursive_directory_iterator {root}, std::filesystem::recursive_directory_iterator {}, Assets {}, [](auto out, const auto & path) { if (path.path().extension() == ".xml") { @@ -114,6 +118,7 @@ void AssetFactory::createTexutre() const { if (!textureFragments.empty() && !texture) { + glDebugScope _ {0}; // * layout images std::map<const TextureFragment *, std::unique_ptr<const Image>> images; std::transform( @@ -139,6 +144,7 @@ AssetFactory::createTexutre() const size++; return decltype(textureFragmentPositions)::value_type {i.first->id, m}; }); + texture->complete(); } } @@ -146,7 +152,7 @@ bool AssetFactory::persist(Persistence::PersistenceStore & store) { using MapObjects = Persistence::MapByMember<Shapes, std::shared_ptr<Object>>; - using MapAssets = Persistence::MapByMember<Assets>; + using MapAssets = Persistence::MapByMember<Assets, Asset::Ptr>; using MapTextureFragments = Persistence::MapByMember<TextureFragments>; using MapAssImp = Persistence::MapByMember<AssImps, std::shared_ptr<AssImp>, &AssImp::path>; return STORE_TYPE && STORE_NAME_HELPER("object", shapes, MapObjects) diff --git a/assetFactory/assetFactory.h b/assetFactory/assetFactory.h index 787f0a4..864e882 100644 --- a/assetFactory/assetFactory.h +++ b/assetFactory/assetFactory.h @@ -12,7 +12,7 @@ class Texture; class AssetFactory : public Persistence::Persistable { public: using Shapes = std::map<std::string, Shape::Ptr, std::less<>>; - using Assets = std::map<std::string, Asset::Ptr, std::less<>>; + using Assets = std::map<std::string, Asset::ManyPtr, std::less<>>; using AssImps = std::map<std::string, AssImp::Ptr, std::less<>>; using TextureFragments = std::map<std::string, TextureFragment::Ptr, std::less<>>; using Colour = RGB; diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index f41bfd4..432fb16 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -12,7 +12,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, Scale3D lodf) const // Generate 2D circumference points std::vector<RelativePosition2D> circumference(P); std::generate(circumference.begin(), circumference.end(), [a = 0.F, step]() mutable { - return sincosf(a += step) * .5F; + return sincos(a += step) * .5F; }); CreatedFaces surface; diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp index bf4706e..eb9d525 100644 --- a/assetFactory/factoryMesh.cpp +++ b/assetFactory/factoryMesh.cpp @@ -25,11 +25,12 @@ FactoryMesh::createMesh() const std::vector<unsigned int> faceIndices; for (const auto & heh : mesh.fh_range(face)) { const auto & vertex = mesh.to_vertex_handle(heh); - const auto & textureUV = mesh.texcoord2D(heh); - const auto & point = mesh.point(vertex); - const auto & normal = useVertexNormals ? mesh.property(mesh.vertex_normals_pph(), vertex) - : mesh.property(mesh.face_normals_pph(), face); - Vertex outVertex {point * 1000.F, textureUV, normal, colour, material}; + Vertex outVertex {.pos = mesh.point(vertex) * 1000.F, + .texCoord = mesh.texcoord2D(heh), + .normal = useVertexNormals ? mesh.property(mesh.vertex_normals_pph(), vertex) + : mesh.property(mesh.face_normals_pph(), face), + .colour = colour, + .material = material}; if (const auto existingItr = std::find(vertices.rbegin(), vertices.rend(), outVertex); existingItr != vertices.rend()) { faceIndices.push_back(static_cast<unsigned int>(std::distance(existingItr, vertices.rend()) - 1)); diff --git a/assetFactory/lights.cpp b/assetFactory/lights.cpp new file mode 100644 index 0000000..ec8e17e --- /dev/null +++ b/assetFactory/lights.cpp @@ -0,0 +1,14 @@ +#include "lights.h" + +bool +SpotLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq) + && STORE_MEMBER(arc); +} + +bool +PointLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq); +} diff --git a/assetFactory/lights.h b/assetFactory/lights.h new file mode 100644 index 0000000..8657d85 --- /dev/null +++ b/assetFactory/lights.h @@ -0,0 +1,18 @@ +#pragma once + +#include "gfx/models/lights.h" +#include "persistence.h" +#include "stdTypeDefs.h" + +struct SpotLight : Persistence::Persistable, SpotLightDef, StdTypeDefs<SpotLight> { +private: + friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>; + bool persist(Persistence::PersistenceStore & store) override; +}; + +struct PointLight : Persistence::Persistable, PointLightDef, StdTypeDefs<PointLight> { +private: + friend Persistence::SelectionPtrBase<std::shared_ptr<PointLight>>; + bool persist(Persistence::PersistenceStore & store) override; +}; + diff --git a/assetFactory/modelFactoryMesh.cpp b/assetFactory/modelFactoryMesh.cpp index 3d4b5f3..3660fb7 100644 --- a/assetFactory/modelFactoryMesh.cpp +++ b/assetFactory/modelFactoryMesh.cpp @@ -1,13 +1,5 @@ #include "modelFactoryMesh.h" -ModelFactoryMesh::ModelFactoryMesh() -{ - add_property(smoothFaceProperty); - add_property(materialFaceProperty); - add_property(nameFaceProperty); - add_property(nameAdjFaceProperty); -} - void ModelFactoryMesh::configNamedFace(const std::string & name, OpenMesh::FaceHandle handle) { diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 299986e..6a18155 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -8,6 +8,7 @@ #include <glm/vec3.hpp> #include <glm/vec4.hpp> #include <thirdparty/openmesh/glmcompat.h> +#include <thirdparty/openmesh/helpers.h> struct ModelFactoryTraits : public OpenMesh::DefaultTraits { FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status | OpenMesh::Attributes::Color); @@ -21,13 +22,11 @@ struct ModelFactoryTraits : public OpenMesh::DefaultTraits { }; struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT<ModelFactoryTraits> { - ModelFactoryMesh(); - bool normalsProvidedProperty {}; - OpenMesh::FPropHandleT<bool> smoothFaceProperty; - OpenMesh::FPropHandleT<GLuint> materialFaceProperty; - OpenMesh::FPropHandleT<std::string> nameFaceProperty; - OpenMesh::HPropHandleT<std::string> nameAdjFaceProperty; + const OpenMesh::Helpers::Property<bool, OpenMesh::FPropHandleT> smoothFaceProperty {this}; + const OpenMesh::Helpers::Property<GLuint, OpenMesh::FPropHandleT> materialFaceProperty {this}; + const OpenMesh::Helpers::Property<std::string, OpenMesh::FPropHandleT> nameFaceProperty {this}; + const OpenMesh::Helpers::Property<std::string, OpenMesh::HPropHandleT> nameAdjFaceProperty {this}; template<typename... Vs> std::pair<std::string, OpenMesh::FaceHandle> diff --git a/assetFactory/mutation.cpp b/assetFactory/mutation.cpp index 6695dff..2ab2a76 100644 --- a/assetFactory/mutation.cpp +++ b/assetFactory/mutation.cpp @@ -1,12 +1,11 @@ #include "mutation.h" -#include <algorithm> #include <glm/gtx/transform.hpp> #include <maths.h> Mutation::Matrix Mutation::getMatrix() const { - return glm::translate(glm::identity<Matrix>(), position) * rotate_ypr(rotation) + return glm::translate(glm::identity<Matrix>(), position) * rotate_ypr<4>(rotation) * glm::scale(glm::identity<Matrix>(), scale); } @@ -19,7 +18,7 @@ Mutation::getDeformationMatrix() const Mutation::Matrix Mutation::getLocationMatrix() const { - return glm::translate(glm::identity<Matrix>(), position) * rotate_ypr(rotation); + return glm::translate(glm::identity<Matrix>(), position) * rotate_ypr<4>(rotation); } bool |
