From 6ec18905acdb9b30e5bfc5eee9be0182ce1744c9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 26 Oct 2023 20:34:55 +0100 Subject: Move OpenMesh/GLM compatibility structs to common place --- assetFactory/modelFactoryMesh.h | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 32e7ab5..2129fb5 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -2,36 +2,11 @@ #include "modelFactoryMesh_fwd.h" #include -#include #include -#include #include #include #include - -namespace glm { - template - auto - norm(const vec & v) - { - return length(v); - } - - template - auto - vectorize(vec & v, S scalar) - { - v = vec {static_cast(scalar)}; - } -} - -namespace OpenMesh { - template struct vector_traits> { - using vector_type = glm::vec; - using value_type = T; - static constexpr glm::length_t size_ = L; - }; -} +#include struct ModelFactoryTraits : public OpenMesh::DefaultTraits { FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status | OpenMesh::Attributes::Color); -- cgit v1.2.3 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- assetFactory/factoryMesh.h | 3 ++- assetFactory/mutation.h | 7 ++++--- assetFactory/shape.h | 3 ++- assetFactory/texturePacker.cpp | 4 +--- assetFactory/texturePacker.h | 7 ++++--- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/factoryMesh.h b/assetFactory/factoryMesh.h index f71c737..b09b54f 100644 --- a/assetFactory/factoryMesh.h +++ b/assetFactory/factoryMesh.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "gfx/models/mesh.h" #include "stdTypeDefs.h" #include "use.h" @@ -9,7 +10,7 @@ public: Mesh::Ptr createMesh() const; std::string id; - glm::vec3 size; + Size3D size; Use::Collection uses; private: diff --git a/assetFactory/mutation.h b/assetFactory/mutation.h index 2432174..b571dea 100644 --- a/assetFactory/mutation.h +++ b/assetFactory/mutation.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "persistence.h" #include #include @@ -13,9 +14,9 @@ struct Mutation { float relativeLevelOfDetail() const; - glm::vec3 position {}; - glm::vec3 rotation {}; - glm::vec3 scale {1}; + Position3D position {}; + Rotation3D rotation {}; + Scale3D scale {1}; protected: bool persist(Persistence::PersistenceStore & store); diff --git a/assetFactory/shape.h b/assetFactory/shape.h index ea3e4e7..136e24f 100644 --- a/assetFactory/shape.h +++ b/assetFactory/shape.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "modelFactoryMesh_fwd.h" #include "stdTypeDefs.h" #include @@ -21,5 +22,5 @@ public: virtual CreatedFaces createMesh(ModelFactoryMesh &, float levelOfDetailFactor) const = 0; static std::vector addToMesh( - ModelFactoryMesh & mesh, const std::span vertices); + ModelFactoryMesh & mesh, const std::span vertices); }; diff --git a/assetFactory/texturePacker.cpp b/assetFactory/texturePacker.cpp index dbafc4b..0d0fdb6 100644 --- a/assetFactory/texturePacker.cpp +++ b/assetFactory/texturePacker.cpp @@ -14,9 +14,7 @@ TexturePacker::TexturePacker(std::span in) : std::sort(sortedIndexes.rbegin(), sortedIndexes.rend(), [this](const auto a, const auto b) { return area(inputImages[a]) < area(inputImages[b]); }); - int mts; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mts); - maxTextureSize = static_cast(mts); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); } TexturePacker::Result diff --git a/assetFactory/texturePacker.h b/assetFactory/texturePacker.h index 93413eb..05e3204 100644 --- a/assetFactory/texturePacker.h +++ b/assetFactory/texturePacker.h @@ -1,13 +1,14 @@ #pragma once +#include "config/types.h" #include #include #include class TexturePacker { public: - using Position = glm::uvec2; - using Size = glm::uvec2; + using Position = TextureAbsCoord; + using Size = TextureAbsCoord; struct Area { #ifndef __cpp_aggregate_paren_init @@ -40,5 +41,5 @@ public: private: std::span inputImages; std::vector sortedIndexes; - unsigned int maxTextureSize; + GLsizei maxTextureSize; }; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- assetFactory/cuboid.cpp | 2 +- assetFactory/cylinder.cpp | 6 +++--- assetFactory/plane.cpp | 2 +- assetFactory/shape.cpp | 4 +--- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/cuboid.cpp b/assetFactory/cuboid.cpp index a8ddcd9..cfb6cfb 100644 --- a/assetFactory/cuboid.cpp +++ b/assetFactory/cuboid.cpp @@ -4,7 +4,7 @@ Cuboid::CreatedFaces Cuboid::createMesh(ModelFactoryMesh & mesh, float) const { - static constexpr std::array VERTICES {{ + static constexpr std::array VERTICES {{ // bottom {n, n, z}, {n, y, z}, diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index 7d22e36..ed034fd 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -9,8 +9,8 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const const auto step = two_pi / static_cast(P); // Generate 2D circumference points - std::vector circumference(P); - std::generate(circumference.begin(), circumference.end(), [a = 0.f, step]() mutable { + std::vector circumference(P); + std::generate(circumference.begin(), circumference.end(), [a = 0.F, step]() mutable { return sincosf(a += step) * .5F; }); @@ -19,7 +19,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const // Generate bottom face vertices std::vector bottom(P); std::transform(circumference.begin(), circumference.end(), bottom.begin(), [&mesh](const auto & xy) { - return mesh.add_vertex(xy ^ 0.f); + return mesh.add_vertex(xy ^ 0.F); }); surface.insert(mesh.add_namedFace("bottom", bottom)); } diff --git a/assetFactory/plane.cpp b/assetFactory/plane.cpp index c6e1b5a..28fb690 100644 --- a/assetFactory/plane.cpp +++ b/assetFactory/plane.cpp @@ -4,7 +4,7 @@ Plane::CreatedFaces Plane::createMesh(ModelFactoryMesh & mesh, float) const { - static constexpr std::array VERTICES {{ + static constexpr std::array VERTICES {{ {n, n, z}, {y, n, z}, {y, y, z}, diff --git a/assetFactory/shape.cpp b/assetFactory/shape.cpp index 1bfbdbb..0f83ee5 100644 --- a/assetFactory/shape.cpp +++ b/assetFactory/shape.cpp @@ -1,11 +1,9 @@ #include "shape.h" -#include "gfx/models/vertex.h" -#include "maths.h" #include "modelFactoryMesh.h" #include "shape.h" std::vector -Shape::addToMesh(ModelFactoryMesh & mesh, const std::span vertices) +Shape::addToMesh(ModelFactoryMesh & mesh, const std::span vertices) { std::vector vhs; std::transform(vertices.begin(), vertices.end(), std::back_inserter(vhs), [&mesh](const auto & p) { -- cgit v1.2.3 From d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 01:57:27 +0000 Subject: WIP typedefing just about everything else --- assetFactory/assetFactory.h | 5 ++--- assetFactory/modelFactoryMesh.h | 9 +++++---- assetFactory/style.cpp | 14 +++++++------- assetFactory/style.h | 6 ++---- 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/assetFactory.h b/assetFactory/assetFactory.h index e449ce2..787f0a4 100644 --- a/assetFactory/assetFactory.h +++ b/assetFactory/assetFactory.h @@ -15,10 +15,9 @@ public: using Assets = std::map>; using AssImps = std::map>; using TextureFragments = std::map>; - using Colour = glm::vec3; - using ColourAlpha = glm::vec4; + using Colour = RGB; + using ColourAlpha = RGBA; using Colours = std::map>; - using TextureFragmentCoords = std::array; AssetFactory(); [[nodiscard]] static std::shared_ptr loadXML(const std::filesystem::path &); diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 32e7ab5..480bf7f 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "modelFactoryMesh_fwd.h" #include #include @@ -38,10 +39,10 @@ struct ModelFactoryTraits : public OpenMesh::DefaultTraits { EdgeAttributes(OpenMesh::Attributes::Status); VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); HalfedgeAttributes(OpenMesh::Attributes::TexCoord2D); - using Point = glm::vec3; - using Normal = glm::vec3; - using Color = glm::vec4; - using TexCoord2D = glm::vec2; + using Point = Position3D; + using Normal = Normal3D; + using Color = RGBA; + using TexCoord2D = TextureRelCoord; }; struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT { diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 81a5441..265becb 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -33,10 +33,10 @@ Style::applyStyle( const auto material = mf->getMaterialIndex(texture); mesh.property(mesh.materialFaceProperty, face) = material; static constexpr std::array coords {{ - {0.f, 0.f}, - {1.f, 0.f}, - {1.f, 1.f}, - {0.f, 1.f}, + {0.F, 0.F}, + {1.F, 0.F}, + {1.F, 1.F}, + {0.F, 1.F}, }}; auto coord = coords.begin(); // Wild assumption that face is a quad and the texture should apply linearly @@ -58,9 +58,9 @@ Style::getColour(const StyleStack & parents) bool Style::persist(Persistence::PersistenceStore & store) { - struct ColourParser : public Persistence::SelectionV { - using Persistence::SelectionV::SelectionV; - using Persistence::SelectionV::setValue; + struct ColourParser : public Persistence::SelectionV { + using Persistence::SelectionV::SelectionV; + using Persistence::SelectionV::setValue; void setValue(std::string && str) override diff --git a/assetFactory/style.h b/assetFactory/style.h index d931f98..2a437aa 100644 --- a/assetFactory/style.h +++ b/assetFactory/style.h @@ -10,9 +10,7 @@ class Style { public: using StyleStack = std::vector; - using Colour = glm::vec3; - using ColourAlpha = glm::vec4; - using EffectiveColour = std::optional>; + using EffectiveColour = std::optional>; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; @@ -30,7 +28,7 @@ public: static EffectiveColour getColour(const StyleStack & parents); - ColourAlpha colour {}; + RGBA colour {}; std::optional smooth; std::string texture; std::string textureRotation; // Multiples of 90deg, no int/enum support -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- assetFactory/factoryMesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'assetFactory') diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp index 46bcf6f..3caf5e8 100644 --- a/assetFactory/factoryMesh.cpp +++ b/assetFactory/factoryMesh.cpp @@ -30,7 +30,7 @@ FactoryMesh::createMesh() const 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, textureUV, normal, colour, material}; + Vertex outVertex {point * 1000.F, textureUV, normal, colour, material}; if (const auto existingItr = std::find(vertices.rbegin(), vertices.rend(), outVertex); existingItr != vertices.rend()) { faceIndices.push_back(static_cast(std::distance(existingItr, vertices.rend()) - 1)); -- cgit v1.2.3 From 048f18e2a0b32044525cef41fa053984433c74b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 29 Dec 2023 14:12:40 +0000 Subject: Remove misleading power operator^ on vec2/3 --- assetFactory/cylinder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp index ed034fd..58980cf 100644 --- a/assetFactory/cylinder.cpp +++ b/assetFactory/cylinder.cpp @@ -19,7 +19,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const // Generate bottom face vertices std::vector bottom(P); std::transform(circumference.begin(), circumference.end(), bottom.begin(), [&mesh](const auto & xy) { - return mesh.add_vertex(xy ^ 0.F); + return mesh.add_vertex(xy || 0.F); }); surface.insert(mesh.add_namedFace("bottom", bottom)); } @@ -27,7 +27,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const // Generate top face vertices std::vector top(P); std::transform(circumference.rbegin(), circumference.rend(), top.begin(), [&mesh](const auto & xy) { - return mesh.add_vertex(xy ^ 1); + return mesh.add_vertex(xy || 1.F); }); surface.insert(mesh.add_namedFace("top", top)); } @@ -35,7 +35,7 @@ Cylinder::createMesh(ModelFactoryMesh & mesh, float lodf) const // Generate edge vertices std::vector> edge(P + 1); std::transform(circumference.begin(), circumference.end(), edge.begin(), [&mesh](const auto & xy) { - return std::make_pair(mesh.add_vertex(xy ^ 0), mesh.add_vertex(xy ^ 1)); + return std::make_pair(mesh.add_vertex(xy || 0.F), mesh.add_vertex(xy || 1.F)); }); // Wrap around edge.back() = edge.front(); -- cgit v1.2.3