summaryrefslogtreecommitdiff
path: root/assetFactory
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-01 17:56:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-01 17:56:26 +0000
commitd5cdbbf38380239524e351cb69aec94090884ca5 (patch)
tree5d7dff2f2775701069806eceb4eaef23b22eba3f /assetFactory
parentReformat with new clang-format (diff)
parentRemove more use of legacy types (diff)
downloadilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.bz2
ilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.xz
ilt-d5cdbbf38380239524e351cb69aec94090884ca5.zip
Merge remote-tracking branch 'origin/terrain'
Diffstat (limited to 'assetFactory')
-rw-r--r--assetFactory/assetFactory.h5
-rw-r--r--assetFactory/cuboid.cpp2
-rw-r--r--assetFactory/cylinder.cpp10
-rw-r--r--assetFactory/factoryMesh.cpp2
-rw-r--r--assetFactory/factoryMesh.h3
-rw-r--r--assetFactory/modelFactoryMesh.h36
-rw-r--r--assetFactory/mutation.h7
-rw-r--r--assetFactory/plane.cpp2
-rw-r--r--assetFactory/shape.cpp4
-rw-r--r--assetFactory/shape.h3
-rw-r--r--assetFactory/style.cpp14
-rw-r--r--assetFactory/style.h6
-rw-r--r--assetFactory/texturePacker.cpp4
-rw-r--r--assetFactory/texturePacker.h7
14 files changed, 39 insertions, 66 deletions
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<std::string, Asset::Ptr, std::less<>>;
using AssImps = std::map<std::string, AssImp::Ptr, std::less<>>;
using TextureFragments = std::map<std::string, TextureFragment::Ptr, std::less<>>;
- using Colour = glm::vec3;
- using ColourAlpha = glm::vec4;
+ using Colour = RGB;
+ using ColourAlpha = RGBA;
using Colours = std::map<std::string, Colour, std::less<>>;
- using TextureFragmentCoords = std::array<glm::vec2, 4>;
AssetFactory();
[[nodiscard]] static std::shared_ptr<AssetFactory> loadXML(const std::filesystem::path &);
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<glm::vec3, 8> VERTICES {{
+ static constexpr std::array<Position3D, 8> VERTICES {{
// bottom
{n, n, z},
{n, y, z},
diff --git a/assetFactory/cylinder.cpp b/assetFactory/cylinder.cpp
index 7d22e36..58980cf 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<float>(P);
// Generate 2D circumference points
- std::vector<glm::vec2> circumference(P);
- std::generate(circumference.begin(), circumference.end(), [a = 0.f, step]() mutable {
+ std::vector<Position2D> 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<OpenMesh::VertexHandle> 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<OpenMesh::VertexHandle> 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<std::pair<OpenMesh::VertexHandle, OpenMesh::VertexHandle>> 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();
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<unsigned int>(std::distance(existingItr, vertices.rend()) - 1));
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/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h
index 32e7ab5..06fd7b8 100644
--- a/assetFactory/modelFactoryMesh.h
+++ b/assetFactory/modelFactoryMesh.h
@@ -1,47 +1,23 @@
#pragma once
+#include "config/types.h"
#include "modelFactoryMesh_fwd.h"
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
-#include <OpenMesh/Core/Mesh/Traits.hh>
#include <glad/gl.h>
-#include <glm/geometric.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
-
-namespace glm {
- template<length_t L, typename T, qualifier Q>
- auto
- norm(const vec<L, T, Q> & v)
- {
- return length(v);
- }
-
- template<length_t L, typename T, qualifier Q, typename S>
- auto
- vectorize(vec<L, T, Q> & v, S scalar)
- {
- v = vec<L, T, Q> {static_cast<T>(scalar)};
- }
-}
-
-namespace OpenMesh {
- template<glm::length_t L, typename T, glm::qualifier Q> struct vector_traits<glm::vec<L, T, Q>> {
- using vector_type = glm::vec<L, T, Q>;
- using value_type = T;
- static constexpr glm::length_t size_ = L;
- };
-}
+#include <thirdparty/openmesh/glmcompat.h>
struct ModelFactoryTraits : public OpenMesh::DefaultTraits {
FaceAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status | OpenMesh::Attributes::Color);
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<ModelFactoryTraits> {
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 <glm/mat4x4.hpp>
#include <glm/vec3.hpp>
@@ -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/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<glm::vec3, 4> VERTICES {{
+ static constexpr std::array<Position3D, 4> 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<OpenMesh::VertexHandle>
-Shape::addToMesh(ModelFactoryMesh & mesh, const std::span<const glm::vec3> vertices)
+Shape::addToMesh(ModelFactoryMesh & mesh, const std::span<const Position3D> vertices)
{
std::vector<OpenMesh::VertexHandle> vhs;
std::transform(vertices.begin(), vertices.end(), std::back_inserter(vhs), [&mesh](const auto & p) {
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 <OpenMesh/Core/Mesh/Handles.hh>
@@ -21,5 +22,5 @@ public:
virtual CreatedFaces createMesh(ModelFactoryMesh &, float levelOfDetailFactor) const = 0;
static std::vector<OpenMesh::VertexHandle> addToMesh(
- ModelFactoryMesh & mesh, const std::span<const glm::vec3> vertices);
+ ModelFactoryMesh & mesh, const std::span<const Position3D> vertices);
};
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<ModelFactoryTraits::TexCoord2D, 4> 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<ColourAlpha> {
- using Persistence::SelectionV<ColourAlpha>::SelectionV;
- using Persistence::SelectionV<ColourAlpha>::setValue;
+ struct ColourParser : public Persistence::SelectionV<RGBA> {
+ using Persistence::SelectionV<RGBA>::SelectionV;
+ using Persistence::SelectionV<RGBA>::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<const Style *>;
- using Colour = glm::vec3;
- using ColourAlpha = glm::vec4;
- using EffectiveColour = std::optional<std::reference_wrapper<const ColourAlpha>>;
+ using EffectiveColour = std::optional<std::reference_wrapper<const RGBA>>;
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<bool> smooth;
std::string texture;
std::string textureRotation; // Multiples of 90deg, no int/enum support
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<const Image> 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<unsigned int>(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 <glm/vec2.hpp>
#include <span>
#include <vector>
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<const Image> inputImages;
std::vector<size_t> sortedIndexes;
- unsigned int maxTextureSize;
+ GLsizei maxTextureSize;
};